@contentful/field-editor-rich-text 2.0.0-next.18 → 2.0.0-next.20

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.
@@ -15,6 +15,7 @@ var deepEquals = _interopDefault(require('fast-deep-equal'));
15
15
  var noop = _interopDefault(require('lodash/noop'));
16
16
  var plateSerializerDocx = require('@udecode/plate-serializer-docx');
17
17
  var plateBreak = require('@udecode/plate-break');
18
+ var plateResetNode = require('@udecode/plate-reset-node');
18
19
  var isHotkey = _interopDefault(require('is-hotkey'));
19
20
  var slate = require('slate');
20
21
  var Slate = require('slate-react');
@@ -27,7 +28,6 @@ var tokens = _interopDefault(require('@contentful/f36-tokens'));
27
28
  var find = _interopDefault(require('lodash/find'));
28
29
  var flow = _interopDefault(require('lodash/flow'));
29
30
  var plateList = require('@udecode/plate-list');
30
- var plateResetNode = require('@udecode/plate-reset-node');
31
31
  var plateBasicMarks = require('@udecode/plate-basic-marks');
32
32
  var isPlainObject = _interopDefault(require('is-plain-obj'));
33
33
  var plateParagraph = require('@udecode/plate-paragraph');
@@ -314,6 +314,33 @@ var createExitBreakPlugin = function createExitBreakPlugin() {
314
314
  });
315
315
  };
316
316
 
317
+ var createResetNodePlugin = function createResetNodePlugin() {
318
+ return plateResetNode.createResetNodePlugin({
319
+ options: {
320
+ rules: []
321
+ },
322
+ then: function then(editor) {
323
+ var rules = editor.plugins.flatMap(function (p) {
324
+ return p.resetNode || [];
325
+ }); // set defaultType to Paragraph if not set
326
+
327
+ for (var _iterator = _createForOfIteratorHelperLoose(rules), _step; !(_step = _iterator()).done;) {
328
+ var rule = _step.value;
329
+
330
+ if (!rule.defaultType) {
331
+ rule.defaultType = Contentful.BLOCKS.PARAGRAPH;
332
+ }
333
+ }
334
+
335
+ return {
336
+ options: {
337
+ rules: rules
338
+ }
339
+ };
340
+ }
341
+ });
342
+ };
343
+
317
344
  function createDragAndDropPlugin() {
318
345
  var DRAGGABLE_TYPES = [Contentful.BLOCKS.EMBEDDED_ENTRY, Contentful.BLOCKS.EMBEDDED_ASSET, Contentful.BLOCKS.HR, Contentful.INLINES.EMBEDDED_ENTRY];
319
346
  /**
@@ -425,6 +452,23 @@ function moveToTheNextLine(editor) {
425
452
  unit: 'line'
426
453
  });
427
454
  }
455
+ function moveToTheNextChar(editor) {
456
+ slate.Transforms.move(editor, {
457
+ distance: 1,
458
+ unit: 'character'
459
+ });
460
+ }
461
+ function insertEmptyParagraph(editor) {
462
+ var emptyParagraph = {
463
+ type: Contentful.BLOCKS.PARAGRAPH,
464
+ children: [{
465
+ text: ''
466
+ }],
467
+ data: {},
468
+ isVoid: false
469
+ };
470
+ slate.Transforms.insertNodes(editor, emptyParagraph);
471
+ }
428
472
  function getElementFromCurrentSelection(editor) {
429
473
  if (!editor.selection) return [];
430
474
  return Array.from(slate.Editor.nodes(editor, {
@@ -1076,201 +1120,197 @@ function createCommonjsModule(fn, module) {
1076
1120
  return module = { exports: {} }, fn(module, module.exports), module.exports;
1077
1121
  }
1078
1122
 
1079
- var runtime_1 = createCommonjsModule(function (module) {
1080
- /**
1081
- * Copyright (c) 2014-present, Facebook, Inc.
1082
- *
1083
- * This source code is licensed under the MIT license found in the
1084
- * LICENSE file in the root directory of this source tree.
1085
- */
1123
+ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1124
+ /**
1125
+ * Copyright (c) 2014-present, Facebook, Inc.
1126
+ *
1127
+ * This source code is licensed under the MIT license found in the
1128
+ * LICENSE file in the root directory of this source tree.
1129
+ */
1130
+ var runtime = function (exports) {
1131
+
1132
+ var Op = Object.prototype;
1133
+ var hasOwn = Op.hasOwnProperty;
1134
+ var undefined$1; // More compressible than void 0.
1135
+
1136
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
1137
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
1138
+ var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
1139
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1140
+
1141
+ function define(obj, key, value) {
1142
+ Object.defineProperty(obj, key, {
1143
+ value: value,
1144
+ enumerable: true,
1145
+ configurable: true,
1146
+ writable: true
1147
+ });
1148
+ return obj[key];
1149
+ }
1086
1150
 
1087
- var runtime = (function (exports) {
1088
-
1089
- var Op = Object.prototype;
1090
- var hasOwn = Op.hasOwnProperty;
1091
- var undefined$1; // More compressible than void 0.
1092
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
1093
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
1094
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
1095
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1096
-
1097
- function define(obj, key, value) {
1098
- Object.defineProperty(obj, key, {
1099
- value: value,
1100
- enumerable: true,
1101
- configurable: true,
1102
- writable: true
1103
- });
1104
- return obj[key];
1105
- }
1106
- try {
1107
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
1108
- define({}, "");
1109
- } catch (err) {
1110
- define = function(obj, key, value) {
1111
- return obj[key] = value;
1112
- };
1113
- }
1151
+ try {
1152
+ // IE 8 has a broken Object.defineProperty that only works on DOM objects.
1153
+ define({}, "");
1154
+ } catch (err) {
1155
+ define = function define(obj, key, value) {
1156
+ return obj[key] = value;
1157
+ };
1158
+ }
1114
1159
 
1115
- function wrap(innerFn, outerFn, self, tryLocsList) {
1116
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
1117
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
1118
- var generator = Object.create(protoGenerator.prototype);
1119
- var context = new Context(tryLocsList || []);
1160
+ function wrap(innerFn, outerFn, self, tryLocsList) {
1161
+ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
1162
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
1163
+ var generator = Object.create(protoGenerator.prototype);
1164
+ var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
1165
+ // .throw, and .return methods.
1120
1166
 
1121
- // The ._invoke method unifies the implementations of the .next,
1122
- // .throw, and .return methods.
1123
- generator._invoke = makeInvokeMethod(innerFn, self, context);
1167
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
1168
+ return generator;
1169
+ }
1124
1170
 
1125
- return generator;
1126
- }
1127
- exports.wrap = wrap;
1128
-
1129
- // Try/catch helper to minimize deoptimizations. Returns a completion
1130
- // record like context.tryEntries[i].completion. This interface could
1131
- // have been (and was previously) designed to take a closure to be
1132
- // invoked without arguments, but in all the cases we care about we
1133
- // already have an existing method we want to call, so there's no need
1134
- // to create a new function object. We can even get away with assuming
1135
- // the method takes exactly one argument, since that happens to be true
1136
- // in every case, so we don't have to touch the arguments object. The
1137
- // only additional allocation required is the completion record, which
1138
- // has a stable shape and so hopefully should be cheap to allocate.
1139
- function tryCatch(fn, obj, arg) {
1140
- try {
1141
- return { type: "normal", arg: fn.call(obj, arg) };
1142
- } catch (err) {
1143
- return { type: "throw", arg: err };
1171
+ exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
1172
+ // record like context.tryEntries[i].completion. This interface could
1173
+ // have been (and was previously) designed to take a closure to be
1174
+ // invoked without arguments, but in all the cases we care about we
1175
+ // already have an existing method we want to call, so there's no need
1176
+ // to create a new function object. We can even get away with assuming
1177
+ // the method takes exactly one argument, since that happens to be true
1178
+ // in every case, so we don't have to touch the arguments object. The
1179
+ // only additional allocation required is the completion record, which
1180
+ // has a stable shape and so hopefully should be cheap to allocate.
1181
+
1182
+ function tryCatch(fn, obj, arg) {
1183
+ try {
1184
+ return {
1185
+ type: "normal",
1186
+ arg: fn.call(obj, arg)
1187
+ };
1188
+ } catch (err) {
1189
+ return {
1190
+ type: "throw",
1191
+ arg: err
1192
+ };
1193
+ }
1144
1194
  }
1145
- }
1146
1195
 
1147
- var GenStateSuspendedStart = "suspendedStart";
1148
- var GenStateSuspendedYield = "suspendedYield";
1149
- var GenStateExecuting = "executing";
1150
- var GenStateCompleted = "completed";
1151
-
1152
- // Returning this object from the innerFn has the same effect as
1153
- // breaking out of the dispatch switch statement.
1154
- var ContinueSentinel = {};
1155
-
1156
- // Dummy constructor functions that we use as the .constructor and
1157
- // .constructor.prototype properties for functions that return Generator
1158
- // objects. For full spec compliance, you may wish to configure your
1159
- // minifier not to mangle the names of these two functions.
1160
- function Generator() {}
1161
- function GeneratorFunction() {}
1162
- function GeneratorFunctionPrototype() {}
1163
-
1164
- // This is a polyfill for %IteratorPrototype% for environments that
1165
- // don't natively support it.
1166
- var IteratorPrototype = {};
1167
- define(IteratorPrototype, iteratorSymbol, function () {
1168
- return this;
1169
- });
1196
+ var GenStateSuspendedStart = "suspendedStart";
1197
+ var GenStateSuspendedYield = "suspendedYield";
1198
+ var GenStateExecuting = "executing";
1199
+ var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
1200
+ // breaking out of the dispatch switch statement.
1170
1201
 
1171
- var getProto = Object.getPrototypeOf;
1172
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1173
- if (NativeIteratorPrototype &&
1174
- NativeIteratorPrototype !== Op &&
1175
- hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
1176
- // This environment has a native %IteratorPrototype%; use it instead
1177
- // of the polyfill.
1178
- IteratorPrototype = NativeIteratorPrototype;
1179
- }
1202
+ var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
1203
+ // .constructor.prototype properties for functions that return Generator
1204
+ // objects. For full spec compliance, you may wish to configure your
1205
+ // minifier not to mangle the names of these two functions.
1180
1206
 
1181
- var Gp = GeneratorFunctionPrototype.prototype =
1182
- Generator.prototype = Object.create(IteratorPrototype);
1183
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
1184
- define(Gp, "constructor", GeneratorFunctionPrototype);
1185
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
1186
- GeneratorFunction.displayName = define(
1187
- GeneratorFunctionPrototype,
1188
- toStringTagSymbol,
1189
- "GeneratorFunction"
1190
- );
1191
-
1192
- // Helper for defining the .next, .throw, and .return methods of the
1193
- // Iterator interface in terms of a single ._invoke method.
1194
- function defineIteratorMethods(prototype) {
1195
- ["next", "throw", "return"].forEach(function(method) {
1196
- define(prototype, method, function(arg) {
1197
- return this._invoke(method, arg);
1198
- });
1207
+ function Generator() {}
1208
+
1209
+ function GeneratorFunction() {}
1210
+
1211
+ function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
1212
+ // don't natively support it.
1213
+
1214
+
1215
+ var IteratorPrototype = {};
1216
+ define(IteratorPrototype, iteratorSymbol, function () {
1217
+ return this;
1199
1218
  });
1200
- }
1219
+ var getProto = Object.getPrototypeOf;
1220
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1201
1221
 
1202
- exports.isGeneratorFunction = function(genFun) {
1203
- var ctor = typeof genFun === "function" && genFun.constructor;
1204
- return ctor
1205
- ? ctor === GeneratorFunction ||
1206
- // For the native GeneratorFunction constructor, the best we can
1207
- // do is to check its .name property.
1208
- (ctor.displayName || ctor.name) === "GeneratorFunction"
1209
- : false;
1210
- };
1222
+ if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
1223
+ // This environment has a native %IteratorPrototype%; use it instead
1224
+ // of the polyfill.
1225
+ IteratorPrototype = NativeIteratorPrototype;
1226
+ }
1211
1227
 
1212
- exports.mark = function(genFun) {
1213
- if (Object.setPrototypeOf) {
1214
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
1215
- } else {
1216
- genFun.__proto__ = GeneratorFunctionPrototype;
1217
- define(genFun, toStringTagSymbol, "GeneratorFunction");
1228
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1229
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
1230
+ define(Gp, "constructor", GeneratorFunctionPrototype);
1231
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
1232
+ GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
1233
+ // Iterator interface in terms of a single ._invoke method.
1234
+
1235
+ function defineIteratorMethods(prototype) {
1236
+ ["next", "throw", "return"].forEach(function (method) {
1237
+ define(prototype, method, function (arg) {
1238
+ return this._invoke(method, arg);
1239
+ });
1240
+ });
1218
1241
  }
1219
- genFun.prototype = Object.create(Gp);
1220
- return genFun;
1221
- };
1222
1242
 
1223
- // Within the body of any async function, `await x` is transformed to
1224
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
1225
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
1226
- // meant to be awaited.
1227
- exports.awrap = function(arg) {
1228
- return { __await: arg };
1229
- };
1243
+ exports.isGeneratorFunction = function (genFun) {
1244
+ var ctor = typeof genFun === "function" && genFun.constructor;
1245
+ return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
1246
+ // do is to check its .name property.
1247
+ (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
1248
+ };
1230
1249
 
1231
- function AsyncIterator(generator, PromiseImpl) {
1232
- function invoke(method, arg, resolve, reject) {
1233
- var record = tryCatch(generator[method], generator, arg);
1234
- if (record.type === "throw") {
1235
- reject(record.arg);
1250
+ exports.mark = function (genFun) {
1251
+ if (Object.setPrototypeOf) {
1252
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
1236
1253
  } else {
1237
- var result = record.arg;
1238
- var value = result.value;
1239
- if (value &&
1240
- typeof value === "object" &&
1241
- hasOwn.call(value, "__await")) {
1242
- return PromiseImpl.resolve(value.__await).then(function(value) {
1243
- invoke("next", value, resolve, reject);
1244
- }, function(err) {
1245
- invoke("throw", err, resolve, reject);
1254
+ genFun.__proto__ = GeneratorFunctionPrototype;
1255
+ define(genFun, toStringTagSymbol, "GeneratorFunction");
1256
+ }
1257
+
1258
+ genFun.prototype = Object.create(Gp);
1259
+ return genFun;
1260
+ }; // Within the body of any async function, `await x` is transformed to
1261
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
1262
+ // `hasOwn.call(value, "__await")` to determine if the yielded value is
1263
+ // meant to be awaited.
1264
+
1265
+
1266
+ exports.awrap = function (arg) {
1267
+ return {
1268
+ __await: arg
1269
+ };
1270
+ };
1271
+
1272
+ function AsyncIterator(generator, PromiseImpl) {
1273
+ function invoke(method, arg, resolve, reject) {
1274
+ var record = tryCatch(generator[method], generator, arg);
1275
+
1276
+ if (record.type === "throw") {
1277
+ reject(record.arg);
1278
+ } else {
1279
+ var result = record.arg;
1280
+ var value = result.value;
1281
+
1282
+ if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
1283
+ return PromiseImpl.resolve(value.__await).then(function (value) {
1284
+ invoke("next", value, resolve, reject);
1285
+ }, function (err) {
1286
+ invoke("throw", err, resolve, reject);
1287
+ });
1288
+ }
1289
+
1290
+ return PromiseImpl.resolve(value).then(function (unwrapped) {
1291
+ // When a yielded Promise is resolved, its final value becomes
1292
+ // the .value of the Promise<{value,done}> result for the
1293
+ // current iteration.
1294
+ result.value = unwrapped;
1295
+ resolve(result);
1296
+ }, function (error) {
1297
+ // If a rejected Promise was yielded, throw the rejection back
1298
+ // into the async generator function so it can be handled there.
1299
+ return invoke("throw", error, resolve, reject);
1246
1300
  });
1247
1301
  }
1248
-
1249
- return PromiseImpl.resolve(value).then(function(unwrapped) {
1250
- // When a yielded Promise is resolved, its final value becomes
1251
- // the .value of the Promise<{value,done}> result for the
1252
- // current iteration.
1253
- result.value = unwrapped;
1254
- resolve(result);
1255
- }, function(error) {
1256
- // If a rejected Promise was yielded, throw the rejection back
1257
- // into the async generator function so it can be handled there.
1258
- return invoke("throw", error, resolve, reject);
1259
- });
1260
1302
  }
1261
- }
1262
1303
 
1263
- var previousPromise;
1304
+ var previousPromise;
1264
1305
 
1265
- function enqueue(method, arg) {
1266
- function callInvokeWithMethodAndArg() {
1267
- return new PromiseImpl(function(resolve, reject) {
1268
- invoke(method, arg, resolve, reject);
1269
- });
1270
- }
1306
+ function enqueue(method, arg) {
1307
+ function callInvokeWithMethodAndArg() {
1308
+ return new PromiseImpl(function (resolve, reject) {
1309
+ invoke(method, arg, resolve, reject);
1310
+ });
1311
+ }
1271
1312
 
1272
- return previousPromise =
1273
- // If enqueue has been called before, then we want to wait until
1313
+ return previousPromise = // If enqueue has been called before, then we want to wait until
1274
1314
  // all previous Promises have been resolved before calling invoke,
1275
1315
  // so that results are always delivered in the correct order. If
1276
1316
  // enqueue has not been called before, then it is important to
@@ -1282,554 +1322,527 @@ var runtime = (function (exports) {
1282
1322
  // execute code before the first await. Since we implement simple
1283
1323
  // async functions in terms of async generators, it is especially
1284
1324
  // important to get this right, even though it requires care.
1285
- previousPromise ? previousPromise.then(
1286
- callInvokeWithMethodAndArg,
1287
- // Avoid propagating failures to Promises returned by later
1288
- // invocations of the iterator.
1289
- callInvokeWithMethodAndArg
1290
- ) : callInvokeWithMethodAndArg();
1325
+ previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
1326
+ // invocations of the iterator.
1327
+ callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1328
+ } // Define the unified helper method that is used to implement .next,
1329
+ // .throw, and .return (see defineIteratorMethods).
1330
+
1331
+
1332
+ this._invoke = enqueue;
1291
1333
  }
1292
1334
 
1293
- // Define the unified helper method that is used to implement .next,
1294
- // .throw, and .return (see defineIteratorMethods).
1295
- this._invoke = enqueue;
1296
- }
1335
+ defineIteratorMethods(AsyncIterator.prototype);
1336
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1337
+ return this;
1338
+ });
1339
+ exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
1340
+ // AsyncIterator objects; they just return a Promise for the value of
1341
+ // the final result produced by the iterator.
1342
+
1343
+ exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1344
+ if (PromiseImpl === void 0) PromiseImpl = Promise;
1345
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1346
+ return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
1347
+ : iter.next().then(function (result) {
1348
+ return result.done ? result.value : iter.next();
1349
+ });
1350
+ };
1297
1351
 
1298
- defineIteratorMethods(AsyncIterator.prototype);
1299
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1300
- return this;
1301
- });
1302
- exports.AsyncIterator = AsyncIterator;
1303
-
1304
- // Note that simple async functions are implemented on top of
1305
- // AsyncIterator objects; they just return a Promise for the value of
1306
- // the final result produced by the iterator.
1307
- exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1308
- if (PromiseImpl === void 0) PromiseImpl = Promise;
1309
-
1310
- var iter = new AsyncIterator(
1311
- wrap(innerFn, outerFn, self, tryLocsList),
1312
- PromiseImpl
1313
- );
1314
-
1315
- return exports.isGeneratorFunction(outerFn)
1316
- ? iter // If outerFn is a generator, return the full iterator.
1317
- : iter.next().then(function(result) {
1318
- return result.done ? result.value : iter.next();
1319
- });
1320
- };
1352
+ function makeInvokeMethod(innerFn, self, context) {
1353
+ var state = GenStateSuspendedStart;
1354
+ return function invoke(method, arg) {
1355
+ if (state === GenStateExecuting) {
1356
+ throw new Error("Generator is already running");
1357
+ }
1321
1358
 
1322
- function makeInvokeMethod(innerFn, self, context) {
1323
- var state = GenStateSuspendedStart;
1359
+ if (state === GenStateCompleted) {
1360
+ if (method === "throw") {
1361
+ throw arg;
1362
+ } // Be forgiving, per 25.3.3.3.3 of the spec:
1363
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
1324
1364
 
1325
- return function invoke(method, arg) {
1326
- if (state === GenStateExecuting) {
1327
- throw new Error("Generator is already running");
1328
- }
1329
1365
 
1330
- if (state === GenStateCompleted) {
1331
- if (method === "throw") {
1332
- throw arg;
1366
+ return doneResult();
1333
1367
  }
1334
1368
 
1335
- // Be forgiving, per 25.3.3.3.3 of the spec:
1336
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
1337
- return doneResult();
1338
- }
1369
+ context.method = method;
1370
+ context.arg = arg;
1339
1371
 
1340
- context.method = method;
1341
- context.arg = arg;
1372
+ while (true) {
1373
+ var delegate = context.delegate;
1342
1374
 
1343
- while (true) {
1344
- var delegate = context.delegate;
1345
- if (delegate) {
1346
- var delegateResult = maybeInvokeDelegate(delegate, context);
1347
- if (delegateResult) {
1348
- if (delegateResult === ContinueSentinel) continue;
1349
- return delegateResult;
1375
+ if (delegate) {
1376
+ var delegateResult = maybeInvokeDelegate(delegate, context);
1377
+
1378
+ if (delegateResult) {
1379
+ if (delegateResult === ContinueSentinel) continue;
1380
+ return delegateResult;
1381
+ }
1350
1382
  }
1351
- }
1352
1383
 
1353
- if (context.method === "next") {
1354
- // Setting context._sent for legacy support of Babel's
1355
- // function.sent implementation.
1356
- context.sent = context._sent = context.arg;
1384
+ if (context.method === "next") {
1385
+ // Setting context._sent for legacy support of Babel's
1386
+ // function.sent implementation.
1387
+ context.sent = context._sent = context.arg;
1388
+ } else if (context.method === "throw") {
1389
+ if (state === GenStateSuspendedStart) {
1390
+ state = GenStateCompleted;
1391
+ throw context.arg;
1392
+ }
1357
1393
 
1358
- } else if (context.method === "throw") {
1359
- if (state === GenStateSuspendedStart) {
1360
- state = GenStateCompleted;
1361
- throw context.arg;
1394
+ context.dispatchException(context.arg);
1395
+ } else if (context.method === "return") {
1396
+ context.abrupt("return", context.arg);
1362
1397
  }
1363
1398
 
1364
- context.dispatchException(context.arg);
1399
+ state = GenStateExecuting;
1400
+ var record = tryCatch(innerFn, self, context);
1365
1401
 
1366
- } else if (context.method === "return") {
1367
- context.abrupt("return", context.arg);
1368
- }
1402
+ if (record.type === "normal") {
1403
+ // If an exception is thrown from innerFn, we leave state ===
1404
+ // GenStateExecuting and loop back for another invocation.
1405
+ state = context.done ? GenStateCompleted : GenStateSuspendedYield;
1369
1406
 
1370
- state = GenStateExecuting;
1407
+ if (record.arg === ContinueSentinel) {
1408
+ continue;
1409
+ }
1371
1410
 
1372
- var record = tryCatch(innerFn, self, context);
1373
- if (record.type === "normal") {
1374
- // If an exception is thrown from innerFn, we leave state ===
1375
- // GenStateExecuting and loop back for another invocation.
1376
- state = context.done
1377
- ? GenStateCompleted
1378
- : GenStateSuspendedYield;
1411
+ return {
1412
+ value: record.arg,
1413
+ done: context.done
1414
+ };
1415
+ } else if (record.type === "throw") {
1416
+ state = GenStateCompleted; // Dispatch the exception by looping back around to the
1417
+ // context.dispatchException(context.arg) call above.
1379
1418
 
1380
- if (record.arg === ContinueSentinel) {
1381
- continue;
1419
+ context.method = "throw";
1420
+ context.arg = record.arg;
1421
+ }
1422
+ }
1423
+ };
1424
+ } // Call delegate.iterator[context.method](context.arg) and handle the
1425
+ // result, either by returning a { value, done } result from the
1426
+ // delegate iterator, or by modifying context.method and context.arg,
1427
+ // setting context.delegate to null, and returning the ContinueSentinel.
1428
+
1429
+
1430
+ function maybeInvokeDelegate(delegate, context) {
1431
+ var method = delegate.iterator[context.method];
1432
+
1433
+ if (method === undefined$1) {
1434
+ // A .throw or .return when the delegate iterator has no .throw
1435
+ // method always terminates the yield* loop.
1436
+ context.delegate = null;
1437
+
1438
+ if (context.method === "throw") {
1439
+ // Note: ["return"] must be used for ES3 parsing compatibility.
1440
+ if (delegate.iterator["return"]) {
1441
+ // If the delegate iterator has a return method, give it a
1442
+ // chance to clean up.
1443
+ context.method = "return";
1444
+ context.arg = undefined$1;
1445
+ maybeInvokeDelegate(delegate, context);
1446
+
1447
+ if (context.method === "throw") {
1448
+ // If maybeInvokeDelegate(context) changed context.method from
1449
+ // "return" to "throw", let that override the TypeError below.
1450
+ return ContinueSentinel;
1451
+ }
1382
1452
  }
1383
1453
 
1384
- return {
1385
- value: record.arg,
1386
- done: context.done
1387
- };
1388
-
1389
- } else if (record.type === "throw") {
1390
- state = GenStateCompleted;
1391
- // Dispatch the exception by looping back around to the
1392
- // context.dispatchException(context.arg) call above.
1393
1454
  context.method = "throw";
1394
- context.arg = record.arg;
1455
+ context.arg = new TypeError("The iterator does not provide a 'throw' method");
1395
1456
  }
1457
+
1458
+ return ContinueSentinel;
1396
1459
  }
1397
- };
1398
- }
1399
1460
 
1400
- // Call delegate.iterator[context.method](context.arg) and handle the
1401
- // result, either by returning a { value, done } result from the
1402
- // delegate iterator, or by modifying context.method and context.arg,
1403
- // setting context.delegate to null, and returning the ContinueSentinel.
1404
- function maybeInvokeDelegate(delegate, context) {
1405
- var method = delegate.iterator[context.method];
1406
- if (method === undefined$1) {
1407
- // A .throw or .return when the delegate iterator has no .throw
1408
- // method always terminates the yield* loop.
1409
- context.delegate = null;
1461
+ var record = tryCatch(method, delegate.iterator, context.arg);
1410
1462
 
1411
- if (context.method === "throw") {
1412
- // Note: ["return"] must be used for ES3 parsing compatibility.
1413
- if (delegate.iterator["return"]) {
1414
- // If the delegate iterator has a return method, give it a
1415
- // chance to clean up.
1416
- context.method = "return";
1417
- context.arg = undefined$1;
1418
- maybeInvokeDelegate(delegate, context);
1463
+ if (record.type === "throw") {
1464
+ context.method = "throw";
1465
+ context.arg = record.arg;
1466
+ context.delegate = null;
1467
+ return ContinueSentinel;
1468
+ }
1419
1469
 
1420
- if (context.method === "throw") {
1421
- // If maybeInvokeDelegate(context) changed context.method from
1422
- // "return" to "throw", let that override the TypeError below.
1423
- return ContinueSentinel;
1424
- }
1425
- }
1470
+ var info = record.arg;
1426
1471
 
1472
+ if (!info) {
1427
1473
  context.method = "throw";
1428
- context.arg = new TypeError(
1429
- "The iterator does not provide a 'throw' method");
1474
+ context.arg = new TypeError("iterator result is not an object");
1475
+ context.delegate = null;
1476
+ return ContinueSentinel;
1430
1477
  }
1431
1478
 
1432
- return ContinueSentinel;
1433
- }
1479
+ if (info.done) {
1480
+ // Assign the result of the finished delegate to the temporary
1481
+ // variable specified by delegate.resultName (see delegateYield).
1482
+ context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
1434
1483
 
1435
- var record = tryCatch(method, delegate.iterator, context.arg);
1484
+ context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
1485
+ // exception, let the outer generator proceed normally. If
1486
+ // context.method was "next", forget context.arg since it has been
1487
+ // "consumed" by the delegate iterator. If context.method was
1488
+ // "return", allow the original .return call to continue in the
1489
+ // outer generator.
1436
1490
 
1437
- if (record.type === "throw") {
1438
- context.method = "throw";
1439
- context.arg = record.arg;
1440
- context.delegate = null;
1441
- return ContinueSentinel;
1442
- }
1491
+ if (context.method !== "return") {
1492
+ context.method = "next";
1493
+ context.arg = undefined$1;
1494
+ }
1495
+ } else {
1496
+ // Re-yield the result returned by the delegate method.
1497
+ return info;
1498
+ } // The delegate iterator is finished, so forget it and continue with
1499
+ // the outer generator.
1443
1500
 
1444
- var info = record.arg;
1445
1501
 
1446
- if (! info) {
1447
- context.method = "throw";
1448
- context.arg = new TypeError("iterator result is not an object");
1449
1502
  context.delegate = null;
1450
1503
  return ContinueSentinel;
1451
- }
1452
-
1453
- if (info.done) {
1454
- // Assign the result of the finished delegate to the temporary
1455
- // variable specified by delegate.resultName (see delegateYield).
1456
- context[delegate.resultName] = info.value;
1457
-
1458
- // Resume execution at the desired location (see delegateYield).
1459
- context.next = delegate.nextLoc;
1460
-
1461
- // If context.method was "throw" but the delegate handled the
1462
- // exception, let the outer generator proceed normally. If
1463
- // context.method was "next", forget context.arg since it has been
1464
- // "consumed" by the delegate iterator. If context.method was
1465
- // "return", allow the original .return call to continue in the
1466
- // outer generator.
1467
- if (context.method !== "return") {
1468
- context.method = "next";
1469
- context.arg = undefined$1;
1470
- }
1504
+ } // Define Generator.prototype.{next,throw,return} in terms of the
1505
+ // unified ._invoke helper method.
1471
1506
 
1472
- } else {
1473
- // Re-yield the result returned by the delegate method.
1474
- return info;
1475
- }
1476
-
1477
- // The delegate iterator is finished, so forget it and continue with
1478
- // the outer generator.
1479
- context.delegate = null;
1480
- return ContinueSentinel;
1481
- }
1482
1507
 
1483
- // Define Generator.prototype.{next,throw,return} in terms of the
1484
- // unified ._invoke helper method.
1485
- defineIteratorMethods(Gp);
1508
+ defineIteratorMethods(Gp);
1509
+ define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
1510
+ // @@iterator function is called on it. Some browsers' implementations of the
1511
+ // iterator prototype chain incorrectly implement this, causing the Generator
1512
+ // object to not be returned from this call. This ensures that doesn't happen.
1513
+ // See https://github.com/facebook/regenerator/issues/274 for more details.
1486
1514
 
1487
- define(Gp, toStringTagSymbol, "Generator");
1515
+ define(Gp, iteratorSymbol, function () {
1516
+ return this;
1517
+ });
1518
+ define(Gp, "toString", function () {
1519
+ return "[object Generator]";
1520
+ });
1488
1521
 
1489
- // A Generator should always return itself as the iterator object when the
1490
- // @@iterator function is called on it. Some browsers' implementations of the
1491
- // iterator prototype chain incorrectly implement this, causing the Generator
1492
- // object to not be returned from this call. This ensures that doesn't happen.
1493
- // See https://github.com/facebook/regenerator/issues/274 for more details.
1494
- define(Gp, iteratorSymbol, function() {
1495
- return this;
1496
- });
1522
+ function pushTryEntry(locs) {
1523
+ var entry = {
1524
+ tryLoc: locs[0]
1525
+ };
1497
1526
 
1498
- define(Gp, "toString", function() {
1499
- return "[object Generator]";
1500
- });
1527
+ if (1 in locs) {
1528
+ entry.catchLoc = locs[1];
1529
+ }
1501
1530
 
1502
- function pushTryEntry(locs) {
1503
- var entry = { tryLoc: locs[0] };
1531
+ if (2 in locs) {
1532
+ entry.finallyLoc = locs[2];
1533
+ entry.afterLoc = locs[3];
1534
+ }
1504
1535
 
1505
- if (1 in locs) {
1506
- entry.catchLoc = locs[1];
1536
+ this.tryEntries.push(entry);
1507
1537
  }
1508
1538
 
1509
- if (2 in locs) {
1510
- entry.finallyLoc = locs[2];
1511
- entry.afterLoc = locs[3];
1539
+ function resetTryEntry(entry) {
1540
+ var record = entry.completion || {};
1541
+ record.type = "normal";
1542
+ delete record.arg;
1543
+ entry.completion = record;
1512
1544
  }
1513
1545
 
1514
- this.tryEntries.push(entry);
1515
- }
1516
-
1517
- function resetTryEntry(entry) {
1518
- var record = entry.completion || {};
1519
- record.type = "normal";
1520
- delete record.arg;
1521
- entry.completion = record;
1522
- }
1523
-
1524
- function Context(tryLocsList) {
1525
- // The root entry object (effectively a try statement without a catch
1526
- // or a finally block) gives us a place to store values thrown from
1527
- // locations where there is no enclosing try statement.
1528
- this.tryEntries = [{ tryLoc: "root" }];
1529
- tryLocsList.forEach(pushTryEntry, this);
1530
- this.reset(true);
1531
- }
1532
-
1533
- exports.keys = function(object) {
1534
- var keys = [];
1535
- for (var key in object) {
1536
- keys.push(key);
1546
+ function Context(tryLocsList) {
1547
+ // The root entry object (effectively a try statement without a catch
1548
+ // or a finally block) gives us a place to store values thrown from
1549
+ // locations where there is no enclosing try statement.
1550
+ this.tryEntries = [{
1551
+ tryLoc: "root"
1552
+ }];
1553
+ tryLocsList.forEach(pushTryEntry, this);
1554
+ this.reset(true);
1537
1555
  }
1538
- keys.reverse();
1539
-
1540
- // Rather than returning an object with a next method, we keep
1541
- // things simple and return the next function itself.
1542
- return function next() {
1543
- while (keys.length) {
1544
- var key = keys.pop();
1545
- if (key in object) {
1546
- next.value = key;
1547
- next.done = false;
1548
- return next;
1549
- }
1550
- }
1551
1556
 
1552
- // To avoid creating an additional object, we just hang the .value
1553
- // and .done properties off the next function object itself. This
1554
- // also ensures that the minifier will not anonymize the function.
1555
- next.done = true;
1556
- return next;
1557
- };
1558
- };
1557
+ exports.keys = function (object) {
1558
+ var keys = [];
1559
1559
 
1560
- function values(iterable) {
1561
- if (iterable) {
1562
- var iteratorMethod = iterable[iteratorSymbol];
1563
- if (iteratorMethod) {
1564
- return iteratorMethod.call(iterable);
1560
+ for (var key in object) {
1561
+ keys.push(key);
1565
1562
  }
1566
1563
 
1567
- if (typeof iterable.next === "function") {
1568
- return iterable;
1569
- }
1564
+ keys.reverse(); // Rather than returning an object with a next method, we keep
1565
+ // things simple and return the next function itself.
1570
1566
 
1571
- if (!isNaN(iterable.length)) {
1572
- var i = -1, next = function next() {
1573
- while (++i < iterable.length) {
1574
- if (hasOwn.call(iterable, i)) {
1575
- next.value = iterable[i];
1576
- next.done = false;
1577
- return next;
1578
- }
1579
- }
1567
+ return function next() {
1568
+ while (keys.length) {
1569
+ var key = keys.pop();
1580
1570
 
1581
- next.value = undefined$1;
1582
- next.done = true;
1571
+ if (key in object) {
1572
+ next.value = key;
1573
+ next.done = false;
1574
+ return next;
1575
+ }
1576
+ } // To avoid creating an additional object, we just hang the .value
1577
+ // and .done properties off the next function object itself. This
1578
+ // also ensures that the minifier will not anonymize the function.
1583
1579
 
1584
- return next;
1585
- };
1586
1580
 
1587
- return next.next = next;
1588
- }
1589
- }
1581
+ next.done = true;
1582
+ return next;
1583
+ };
1584
+ };
1590
1585
 
1591
- // Return an iterator with no values.
1592
- return { next: doneResult };
1593
- }
1594
- exports.values = values;
1586
+ function values(iterable) {
1587
+ if (iterable) {
1588
+ var iteratorMethod = iterable[iteratorSymbol];
1595
1589
 
1596
- function doneResult() {
1597
- return { value: undefined$1, done: true };
1598
- }
1590
+ if (iteratorMethod) {
1591
+ return iteratorMethod.call(iterable);
1592
+ }
1599
1593
 
1600
- Context.prototype = {
1601
- constructor: Context,
1602
-
1603
- reset: function(skipTempReset) {
1604
- this.prev = 0;
1605
- this.next = 0;
1606
- // Resetting context._sent for legacy support of Babel's
1607
- // function.sent implementation.
1608
- this.sent = this._sent = undefined$1;
1609
- this.done = false;
1610
- this.delegate = null;
1611
-
1612
- this.method = "next";
1613
- this.arg = undefined$1;
1614
-
1615
- this.tryEntries.forEach(resetTryEntry);
1616
-
1617
- if (!skipTempReset) {
1618
- for (var name in this) {
1619
- // Not sure about the optimal order of these conditions:
1620
- if (name.charAt(0) === "t" &&
1621
- hasOwn.call(this, name) &&
1622
- !isNaN(+name.slice(1))) {
1623
- this[name] = undefined$1;
1624
- }
1594
+ if (typeof iterable.next === "function") {
1595
+ return iterable;
1625
1596
  }
1626
- }
1627
- },
1628
1597
 
1629
- stop: function() {
1630
- this.done = true;
1598
+ if (!isNaN(iterable.length)) {
1599
+ var i = -1,
1600
+ next = function next() {
1601
+ while (++i < iterable.length) {
1602
+ if (hasOwn.call(iterable, i)) {
1603
+ next.value = iterable[i];
1604
+ next.done = false;
1605
+ return next;
1606
+ }
1607
+ }
1631
1608
 
1632
- var rootEntry = this.tryEntries[0];
1633
- var rootRecord = rootEntry.completion;
1634
- if (rootRecord.type === "throw") {
1635
- throw rootRecord.arg;
1636
- }
1609
+ next.value = undefined$1;
1610
+ next.done = true;
1611
+ return next;
1612
+ };
1637
1613
 
1638
- return this.rval;
1639
- },
1614
+ return next.next = next;
1615
+ }
1616
+ } // Return an iterator with no values.
1640
1617
 
1641
- dispatchException: function(exception) {
1642
- if (this.done) {
1643
- throw exception;
1644
- }
1645
1618
 
1646
- var context = this;
1647
- function handle(loc, caught) {
1648
- record.type = "throw";
1649
- record.arg = exception;
1650
- context.next = loc;
1619
+ return {
1620
+ next: doneResult
1621
+ };
1622
+ }
1651
1623
 
1652
- if (caught) {
1653
- // If the dispatched exception was caught by a catch block,
1654
- // then let that catch block handle the exception normally.
1655
- context.method = "next";
1656
- context.arg = undefined$1;
1657
- }
1624
+ exports.values = values;
1658
1625
 
1659
- return !! caught;
1660
- }
1626
+ function doneResult() {
1627
+ return {
1628
+ value: undefined$1,
1629
+ done: true
1630
+ };
1631
+ }
1632
+
1633
+ Context.prototype = {
1634
+ constructor: Context,
1635
+ reset: function reset(skipTempReset) {
1636
+ this.prev = 0;
1637
+ this.next = 0; // Resetting context._sent for legacy support of Babel's
1638
+ // function.sent implementation.
1661
1639
 
1662
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1663
- var entry = this.tryEntries[i];
1664
- var record = entry.completion;
1640
+ this.sent = this._sent = undefined$1;
1641
+ this.done = false;
1642
+ this.delegate = null;
1643
+ this.method = "next";
1644
+ this.arg = undefined$1;
1645
+ this.tryEntries.forEach(resetTryEntry);
1665
1646
 
1666
- if (entry.tryLoc === "root") {
1667
- // Exception thrown outside of any try block that could handle
1668
- // it, so set the completion value of the entire function to
1669
- // throw the exception.
1670
- return handle("end");
1647
+ if (!skipTempReset) {
1648
+ for (var name in this) {
1649
+ // Not sure about the optimal order of these conditions:
1650
+ if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
1651
+ this[name] = undefined$1;
1652
+ }
1653
+ }
1671
1654
  }
1655
+ },
1656
+ stop: function stop() {
1657
+ this.done = true;
1658
+ var rootEntry = this.tryEntries[0];
1659
+ var rootRecord = rootEntry.completion;
1672
1660
 
1673
- if (entry.tryLoc <= this.prev) {
1674
- var hasCatch = hasOwn.call(entry, "catchLoc");
1675
- var hasFinally = hasOwn.call(entry, "finallyLoc");
1661
+ if (rootRecord.type === "throw") {
1662
+ throw rootRecord.arg;
1663
+ }
1676
1664
 
1677
- if (hasCatch && hasFinally) {
1678
- if (this.prev < entry.catchLoc) {
1679
- return handle(entry.catchLoc, true);
1680
- } else if (this.prev < entry.finallyLoc) {
1681
- return handle(entry.finallyLoc);
1682
- }
1665
+ return this.rval;
1666
+ },
1667
+ dispatchException: function dispatchException(exception) {
1668
+ if (this.done) {
1669
+ throw exception;
1670
+ }
1683
1671
 
1684
- } else if (hasCatch) {
1685
- if (this.prev < entry.catchLoc) {
1686
- return handle(entry.catchLoc, true);
1687
- }
1672
+ var context = this;
1688
1673
 
1689
- } else if (hasFinally) {
1690
- if (this.prev < entry.finallyLoc) {
1691
- return handle(entry.finallyLoc);
1692
- }
1674
+ function handle(loc, caught) {
1675
+ record.type = "throw";
1676
+ record.arg = exception;
1677
+ context.next = loc;
1693
1678
 
1694
- } else {
1695
- throw new Error("try statement without catch or finally");
1679
+ if (caught) {
1680
+ // If the dispatched exception was caught by a catch block,
1681
+ // then let that catch block handle the exception normally.
1682
+ context.method = "next";
1683
+ context.arg = undefined$1;
1696
1684
  }
1697
- }
1698
- }
1699
- },
1700
1685
 
1701
- abrupt: function(type, arg) {
1702
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1703
- var entry = this.tryEntries[i];
1704
- if (entry.tryLoc <= this.prev &&
1705
- hasOwn.call(entry, "finallyLoc") &&
1706
- this.prev < entry.finallyLoc) {
1707
- var finallyEntry = entry;
1708
- break;
1686
+ return !!caught;
1709
1687
  }
1710
- }
1711
1688
 
1712
- if (finallyEntry &&
1713
- (type === "break" ||
1714
- type === "continue") &&
1715
- finallyEntry.tryLoc <= arg &&
1716
- arg <= finallyEntry.finallyLoc) {
1717
- // Ignore the finally entry if control is not jumping to a
1718
- // location outside the try/catch block.
1719
- finallyEntry = null;
1720
- }
1689
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1690
+ var entry = this.tryEntries[i];
1691
+ var record = entry.completion;
1721
1692
 
1722
- var record = finallyEntry ? finallyEntry.completion : {};
1723
- record.type = type;
1724
- record.arg = arg;
1693
+ if (entry.tryLoc === "root") {
1694
+ // Exception thrown outside of any try block that could handle
1695
+ // it, so set the completion value of the entire function to
1696
+ // throw the exception.
1697
+ return handle("end");
1698
+ }
1725
1699
 
1726
- if (finallyEntry) {
1727
- this.method = "next";
1728
- this.next = finallyEntry.finallyLoc;
1729
- return ContinueSentinel;
1730
- }
1700
+ if (entry.tryLoc <= this.prev) {
1701
+ var hasCatch = hasOwn.call(entry, "catchLoc");
1702
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
1731
1703
 
1732
- return this.complete(record);
1733
- },
1704
+ if (hasCatch && hasFinally) {
1705
+ if (this.prev < entry.catchLoc) {
1706
+ return handle(entry.catchLoc, true);
1707
+ } else if (this.prev < entry.finallyLoc) {
1708
+ return handle(entry.finallyLoc);
1709
+ }
1710
+ } else if (hasCatch) {
1711
+ if (this.prev < entry.catchLoc) {
1712
+ return handle(entry.catchLoc, true);
1713
+ }
1714
+ } else if (hasFinally) {
1715
+ if (this.prev < entry.finallyLoc) {
1716
+ return handle(entry.finallyLoc);
1717
+ }
1718
+ } else {
1719
+ throw new Error("try statement without catch or finally");
1720
+ }
1721
+ }
1722
+ }
1723
+ },
1724
+ abrupt: function abrupt(type, arg) {
1725
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1726
+ var entry = this.tryEntries[i];
1734
1727
 
1735
- complete: function(record, afterLoc) {
1736
- if (record.type === "throw") {
1737
- throw record.arg;
1738
- }
1728
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1729
+ var finallyEntry = entry;
1730
+ break;
1731
+ }
1732
+ }
1739
1733
 
1740
- if (record.type === "break" ||
1741
- record.type === "continue") {
1742
- this.next = record.arg;
1743
- } else if (record.type === "return") {
1744
- this.rval = this.arg = record.arg;
1745
- this.method = "return";
1746
- this.next = "end";
1747
- } else if (record.type === "normal" && afterLoc) {
1748
- this.next = afterLoc;
1749
- }
1734
+ if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
1735
+ // Ignore the finally entry if control is not jumping to a
1736
+ // location outside the try/catch block.
1737
+ finallyEntry = null;
1738
+ }
1750
1739
 
1751
- return ContinueSentinel;
1752
- },
1740
+ var record = finallyEntry ? finallyEntry.completion : {};
1741
+ record.type = type;
1742
+ record.arg = arg;
1753
1743
 
1754
- finish: function(finallyLoc) {
1755
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1756
- var entry = this.tryEntries[i];
1757
- if (entry.finallyLoc === finallyLoc) {
1758
- this.complete(entry.completion, entry.afterLoc);
1759
- resetTryEntry(entry);
1744
+ if (finallyEntry) {
1745
+ this.method = "next";
1746
+ this.next = finallyEntry.finallyLoc;
1760
1747
  return ContinueSentinel;
1761
1748
  }
1762
- }
1763
- },
1764
1749
 
1765
- "catch": function(tryLoc) {
1766
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1767
- var entry = this.tryEntries[i];
1768
- if (entry.tryLoc === tryLoc) {
1769
- var record = entry.completion;
1770
- if (record.type === "throw") {
1771
- var thrown = record.arg;
1750
+ return this.complete(record);
1751
+ },
1752
+ complete: function complete(record, afterLoc) {
1753
+ if (record.type === "throw") {
1754
+ throw record.arg;
1755
+ }
1756
+
1757
+ if (record.type === "break" || record.type === "continue") {
1758
+ this.next = record.arg;
1759
+ } else if (record.type === "return") {
1760
+ this.rval = this.arg = record.arg;
1761
+ this.method = "return";
1762
+ this.next = "end";
1763
+ } else if (record.type === "normal" && afterLoc) {
1764
+ this.next = afterLoc;
1765
+ }
1766
+
1767
+ return ContinueSentinel;
1768
+ },
1769
+ finish: function finish(finallyLoc) {
1770
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1771
+ var entry = this.tryEntries[i];
1772
+
1773
+ if (entry.finallyLoc === finallyLoc) {
1774
+ this.complete(entry.completion, entry.afterLoc);
1772
1775
  resetTryEntry(entry);
1776
+ return ContinueSentinel;
1773
1777
  }
1774
- return thrown;
1775
1778
  }
1776
- }
1779
+ },
1780
+ "catch": function _catch(tryLoc) {
1781
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1782
+ var entry = this.tryEntries[i];
1777
1783
 
1778
- // The context.catch method must only be called with a location
1779
- // argument that corresponds to a known catch block.
1780
- throw new Error("illegal catch attempt");
1781
- },
1784
+ if (entry.tryLoc === tryLoc) {
1785
+ var record = entry.completion;
1782
1786
 
1783
- delegateYield: function(iterable, resultName, nextLoc) {
1784
- this.delegate = {
1785
- iterator: values(iterable),
1786
- resultName: resultName,
1787
- nextLoc: nextLoc
1788
- };
1787
+ if (record.type === "throw") {
1788
+ var thrown = record.arg;
1789
+ resetTryEntry(entry);
1790
+ }
1789
1791
 
1790
- if (this.method === "next") {
1791
- // Deliberately forget the last sent value so that we don't
1792
- // accidentally pass it on to the delegate.
1793
- this.arg = undefined$1;
1794
- }
1792
+ return thrown;
1793
+ }
1794
+ } // The context.catch method must only be called with a location
1795
+ // argument that corresponds to a known catch block.
1795
1796
 
1796
- return ContinueSentinel;
1797
- }
1798
- };
1799
1797
 
1800
- // Regardless of whether this script is executing as a CommonJS module
1801
- // or not, return the runtime object so that we can declare the variable
1802
- // regeneratorRuntime in the outer scope, which allows this module to be
1803
- // injected easily by `bin/regenerator --include-runtime script.js`.
1804
- return exports;
1798
+ throw new Error("illegal catch attempt");
1799
+ },
1800
+ delegateYield: function delegateYield(iterable, resultName, nextLoc) {
1801
+ this.delegate = {
1802
+ iterator: values(iterable),
1803
+ resultName: resultName,
1804
+ nextLoc: nextLoc
1805
+ };
1806
+
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;
1811
+ }
1812
+
1813
+ return ContinueSentinel;
1814
+ }
1815
+ }; // Regardless of whether this script is executing as a CommonJS module
1816
+ // or not, return the runtime object so that we can declare the variable
1817
+ // regeneratorRuntime in the outer scope, which allows this module to be
1818
+ // injected easily by `bin/regenerator --include-runtime script.js`.
1805
1819
 
1806
- }(
1807
- // If this script is executing as a CommonJS module, use module.exports
1820
+ return exports;
1821
+ }( // If this script is executing as a CommonJS module, use module.exports
1808
1822
  // as the regeneratorRuntime namespace. Otherwise create a new empty
1809
1823
  // object. Either way, the resulting object will be used to initialize
1810
1824
  // the regeneratorRuntime variable at the top of this file.
1811
- module.exports
1812
- ));
1813
-
1814
- try {
1815
- regeneratorRuntime = runtime;
1816
- } catch (accidentalStrictMode) {
1817
- // This module should not be running in strict mode, so the above
1818
- // assignment should always work unless something is misconfigured. Just
1819
- // in case runtime.js accidentally runs in strict mode, in modern engines
1820
- // we can explicitly access globalThis. In older engines we can escape
1821
- // strict mode using a global Function call. This could conceivably fail
1822
- // if a Content Security Policy forbids using Function, but in that case
1823
- // the proper solution is to fix the accidental strict mode problem. If
1824
- // you've misconfigured your bundler to force strict mode and applied a
1825
- // CSP to forbid Function, and you're not willing to fix either of those
1826
- // problems, please detail your unique predicament in a GitHub issue.
1827
- if (typeof globalThis === "object") {
1828
- globalThis.regeneratorRuntime = runtime;
1829
- } else {
1830
- Function("r", "regeneratorRuntime = r")(runtime);
1825
+ module.exports );
1826
+
1827
+ try {
1828
+ regeneratorRuntime = runtime;
1829
+ } catch (accidentalStrictMode) {
1830
+ // This module should not be running in strict mode, so the above
1831
+ // assignment should always work unless something is misconfigured. Just
1832
+ // in case runtime.js accidentally runs in strict mode, in modern engines
1833
+ // we can explicitly access globalThis. In older engines we can escape
1834
+ // strict mode using a global Function call. This could conceivably fail
1835
+ // if a Content Security Policy forbids using Function, but in that case
1836
+ // the proper solution is to fix the accidental strict mode problem. If
1837
+ // you've misconfigured your bundler to force strict mode and applied a
1838
+ // CSP to forbid Function, and you're not willing to fix either of those
1839
+ // problems, please detail your unique predicament in a GitHub issue.
1840
+ if (typeof globalThis === "object") {
1841
+ globalThis.regeneratorRuntime = runtime;
1842
+ } else {
1843
+ Function("r", "regeneratorRuntime = r")(runtime);
1844
+ }
1831
1845
  }
1832
- }
1833
1846
  });
1834
1847
 
1835
1848
  /* eslint-disable you-dont-need-lodash-underscore/find */
@@ -1943,11 +1956,12 @@ function _selectEntityAndInsert() {
1943
1956
  case 12:
1944
1957
  slate.Transforms.select(editor, selection);
1945
1958
  insertBlock(editor, nodeType, entity);
1959
+ ensureFollowingParagraph(editor);
1946
1960
  logAction('insert', {
1947
1961
  nodeType: nodeType
1948
1962
  });
1949
1963
 
1950
- case 15:
1964
+ case 16:
1951
1965
  case "end":
1952
1966
  return _context.stop();
1953
1967
  }
@@ -1957,6 +1971,43 @@ function _selectEntityAndInsert() {
1957
1971
  return _selectEntityAndInsert.apply(this, arguments);
1958
1972
  }
1959
1973
 
1974
+ function ensureFollowingParagraph(editor) {
1975
+ /*
1976
+ If the new block isn't followed by a sibling paragraph we insert a new empty one
1977
+ */
1978
+ var next = slate.Editor.next(editor);
1979
+
1980
+ if (!next) {
1981
+ return insertEmptyParagraph(editor);
1982
+ }
1983
+
1984
+ var parent = slate.Editor.above(editor, {
1985
+ voids: false,
1986
+ match: function match(e) {
1987
+ return !slate.Element.isElement(e) || ![Contentful.BLOCKS.EMBEDDED_ASSET, Contentful.BLOCKS.EMBEDDED_ENTRY].includes(e.type);
1988
+ }
1989
+ });
1990
+
1991
+ if (slate.Editor.isEditor(parent)) {
1992
+ // at level 0, a following paragraph is handled by the tralingParagraph plugin
1993
+ moveToTheNextChar(editor);
1994
+ return;
1995
+ }
1996
+
1997
+ var paragraph = slate.Editor.above(editor, {
1998
+ at: next[1],
1999
+ match: function match(e) {
2000
+ return slate.Element.isElement(e) && Contentful.TEXT_CONTAINERS.includes(e.type);
2001
+ }
2002
+ });
2003
+
2004
+ if (!paragraph || !parent || !slate.Path.isChild(paragraph[1], parent[1])) {
2005
+ return insertEmptyParagraph(editor);
2006
+ }
2007
+
2008
+ moveToTheNextChar(editor);
2009
+ }
2010
+
1960
2011
  var createNode = function createNode(nodeType, entity) {
1961
2012
  return {
1962
2013
  type: nodeType,
@@ -2004,11 +2055,29 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
2004
2055
  var editor = useContentfulEditor();
2005
2056
  var sdk = useSdkContext();
2006
2057
 
2007
- var handleClick = function handleClick(event) {
2008
- event.preventDefault();
2009
- onClose();
2010
- selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onToolbarAction);
2011
- };
2058
+ var handleClick = /*#__PURE__*/function () {
2059
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(event) {
2060
+ return runtime_1.wrap(function _callee$(_context) {
2061
+ while (1) {
2062
+ switch (_context.prev = _context.next) {
2063
+ case 0:
2064
+ event.preventDefault();
2065
+ onClose();
2066
+ _context.next = 4;
2067
+ return selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onToolbarAction);
2068
+
2069
+ case 4:
2070
+ case "end":
2071
+ return _context.stop();
2072
+ }
2073
+ }
2074
+ }, _callee);
2075
+ }));
2076
+
2077
+ return function handleClick(_x) {
2078
+ return _ref2.apply(this, arguments);
2079
+ };
2080
+ }();
2012
2081
 
2013
2082
  var type = getEntityTypeFromNodeType(nodeType);
2014
2083
  var baseClass = "rich-text__" + nodeType;
@@ -2341,15 +2410,18 @@ function _selectEntityAndInsert$1() {
2341
2410
  return _context2.abrupt("return");
2342
2411
 
2343
2412
  case 10:
2344
- inlineEntryNode = createInlineEntryNode(entry.sys.id); // Got to wait until focus is really back on the editor or setSelection() won't work.
2345
-
2346
- setTimeout(function () {
2347
- slate.Transforms.setSelection(editor, selection);
2348
- slate.Transforms.insertNodes(editor, inlineEntryNode);
2349
- }, 0);
2413
+ inlineEntryNode = createInlineEntryNode(entry.sys.id);
2350
2414
  logAction('insert', {
2351
2415
  nodeType: Contentful.INLINES.EMBEDDED_ENTRY
2352
- });
2416
+ }); // Got to wait until focus is really back on the editor or setSelection() won't work.
2417
+
2418
+ return _context2.abrupt("return", new Promise(function (resolve) {
2419
+ setTimeout(function () {
2420
+ slate.Transforms.setSelection(editor, selection);
2421
+ slate.Transforms.insertNodes(editor, inlineEntryNode);
2422
+ resolve();
2423
+ }, 0);
2424
+ }));
2353
2425
 
2354
2426
  case 13:
2355
2427
  case "end":
@@ -2390,6 +2462,9 @@ function ToolbarEmbeddedEntityInlineButton(props) {
2390
2462
  return selectEntityAndInsert$1(editor, sdk, editor.tracking.onToolbarAction);
2391
2463
 
2392
2464
  case 6:
2465
+ moveToTheNextChar(editor);
2466
+
2467
+ case 7:
2393
2468
  case "end":
2394
2469
  return _context.stop();
2395
2470
  }
@@ -4054,6 +4129,101 @@ var insertListFragment = function insertListFragment(editor) {
4054
4129
  };
4055
4130
  };
4056
4131
 
4132
+ /**
4133
+ * Credit: Modified version of Plate's list plugin
4134
+ * See: https://github.com/udecode/plate/blob/main/packages/nodes/list
4135
+ */
4136
+ var listTypes = [Contentful.BLOCKS.UL_LIST, Contentful.BLOCKS.OL_LIST];
4137
+ var unwrapList = function unwrapList(editor, _temp) {
4138
+ var _ref = _temp === void 0 ? {} : _temp,
4139
+ at = _ref.at;
4140
+
4141
+ slate.Editor.withoutNormalizing(editor, function () {
4142
+ do {
4143
+ plateCore.unwrapNodes(editor, {
4144
+ at: at,
4145
+ match: {
4146
+ type: Contentful.BLOCKS.LIST_ITEM
4147
+ },
4148
+ split: true
4149
+ });
4150
+ plateCore.unwrapNodes(editor, {
4151
+ at: at,
4152
+ match: {
4153
+ type: listTypes
4154
+ },
4155
+ split: true
4156
+ });
4157
+ } while (plateCore.getAbove(editor, {
4158
+ match: {
4159
+ type: listTypes,
4160
+ at: at
4161
+ }
4162
+ }));
4163
+ });
4164
+ };
4165
+
4166
+ /**
4167
+ * Credit: Modified version of Plate's list plugin
4168
+ * See: https://github.com/udecode/plate/blob/main/packages/nodes/list
4169
+ */
4170
+ var deleteBackwardList = function deleteBackwardList(editor, unit) {
4171
+ var res = plateList.getListItemEntry(editor, {});
4172
+ var moved = false;
4173
+
4174
+ if (res) {
4175
+ var list = res.list,
4176
+ listItem = res.listItem;
4177
+
4178
+ if (plateCore.isSelectionAtBlockStart(editor, {
4179
+ match: function match(node) {
4180
+ return node.type === Contentful.BLOCKS.LIST_ITEM;
4181
+ }
4182
+ })) {
4183
+ slate.Editor.withoutNormalizing(editor, function () {
4184
+ moved = plateList.removeFirstListItem(editor, {
4185
+ list: list,
4186
+ listItem: listItem
4187
+ });
4188
+ if (moved) return;
4189
+ moved = plateList.removeListItem(editor, {
4190
+ list: list,
4191
+ listItem: listItem
4192
+ });
4193
+ if (moved) return;
4194
+
4195
+ if (plateCore.isFirstChild(listItem[1]) && !plateList.isListNested(editor, list[1])) {
4196
+ plateResetNode.onKeyDownResetNode(editor, plateCore.mockPlugin({
4197
+ options: {
4198
+ rules: [{
4199
+ types: [Contentful.BLOCKS.LIST_ITEM],
4200
+ defaultType: Contentful.BLOCKS.PARAGRAPH,
4201
+ hotkey: 'backspace',
4202
+ predicate: function predicate() {
4203
+ return plateCore.isSelectionAtBlockStart(editor);
4204
+ },
4205
+ onReset: function onReset(e) {
4206
+ return unwrapList(e);
4207
+ }
4208
+ }]
4209
+ }
4210
+ }))(plateResetNode.SIMULATE_BACKSPACE);
4211
+ moved = true;
4212
+ return;
4213
+ }
4214
+
4215
+ plateCore.deleteFragment(editor, {
4216
+ unit: unit,
4217
+ reverse: true
4218
+ });
4219
+ moved = true;
4220
+ });
4221
+ }
4222
+ }
4223
+
4224
+ return moved;
4225
+ };
4226
+
4057
4227
  /**
4058
4228
  * Credit: Modified version of Plate's list plugin
4059
4229
  * See: https://github.com/udecode/plate/blob/main/packages/nodes/list
@@ -4065,7 +4235,7 @@ var withList = function withList(editor) {
4065
4235
  deleteFragment = editor.deleteFragment;
4066
4236
 
4067
4237
  editor.deleteBackward = function (unit) {
4068
- if (plateList.deleteBackwardList(editor, unit)) return;
4238
+ if (deleteBackwardList(editor, unit)) return;
4069
4239
  deleteBackward(unit);
4070
4240
  };
4071
4241
 
@@ -4131,39 +4301,9 @@ var createListPlugin = function createListPlugin() {
4131
4301
  });
4132
4302
  };
4133
4303
 
4134
- var listTypes = [Contentful.BLOCKS.UL_LIST, Contentful.BLOCKS.OL_LIST];
4135
-
4136
- var unwrapList = function unwrapList(editor, _temp) {
4137
- var _ref = _temp === void 0 ? {} : _temp,
4138
- at = _ref.at;
4139
-
4140
- slate.Editor.withoutNormalizing(editor, function () {
4141
- do {
4142
- plateCore.unwrapNodes(editor, {
4143
- at: at,
4144
- match: {
4145
- type: Contentful.BLOCKS.LIST_ITEM
4146
- },
4147
- split: true
4148
- });
4149
- plateCore.unwrapNodes(editor, {
4150
- at: at,
4151
- match: {
4152
- type: listTypes
4153
- },
4154
- split: true
4155
- });
4156
- } while (plateCore.getAbove(editor, {
4157
- match: {
4158
- type: listTypes,
4159
- at: at
4160
- }
4161
- }));
4162
- });
4163
- };
4164
-
4165
- var toggleList = function toggleList(editor, _ref2) {
4166
- var type = _ref2.type;
4304
+ var listTypes$1 = [Contentful.BLOCKS.UL_LIST, Contentful.BLOCKS.OL_LIST];
4305
+ var toggleList = function toggleList(editor, _ref) {
4306
+ var type = _ref.type;
4167
4307
  return slate.Editor.withoutNormalizing(editor, function () {
4168
4308
  if (!editor.selection) {
4169
4309
  return;
@@ -4182,7 +4322,7 @@ var toggleList = function toggleList(editor, _ref2) {
4182
4322
  }, {
4183
4323
  at: editor.selection,
4184
4324
  match: function match(n) {
4185
- return listTypes.includes(n.type);
4325
+ return listTypes$1.includes(n.type);
4186
4326
  },
4187
4327
  mode: 'lowest'
4188
4328
  });
@@ -4223,19 +4363,19 @@ var toggleList = function toggleList(editor, _ref2) {
4223
4363
 
4224
4364
  var commonEntry = slate.Node.common(editor, startPoint.path, endPoint.path);
4225
4365
 
4226
- if (listTypes.includes(commonEntry[0].type) || commonEntry[0].type === Contentful.BLOCKS.LIST_ITEM) {
4366
+ if (listTypes$1.includes(commonEntry[0].type) || commonEntry[0].type === Contentful.BLOCKS.LIST_ITEM) {
4227
4367
  if (commonEntry[0].type !== type) {
4228
4368
  var startList = plateCore.findNode(editor, {
4229
4369
  at: slate.Range.start(editor.selection),
4230
4370
  match: {
4231
- type: listTypes
4371
+ type: listTypes$1
4232
4372
  },
4233
4373
  mode: 'lowest'
4234
4374
  });
4235
4375
  var endList = plateCore.findNode(editor, {
4236
4376
  at: slate.Range.end(editor.selection),
4237
4377
  match: {
4238
- type: listTypes
4378
+ type: listTypes$1
4239
4379
  },
4240
4380
  mode: 'lowest'
4241
4381
  });
@@ -4250,7 +4390,7 @@ var toggleList = function toggleList(editor, _ref2) {
4250
4390
  }, {
4251
4391
  at: editor.selection,
4252
4392
  match: function match(n, path) {
4253
- return listTypes.includes(n.type) && path.length >= rangeLength;
4393
+ return listTypes$1.includes(n.type) && path.length >= rangeLength;
4254
4394
  },
4255
4395
  mode: 'all'
4256
4396
  });
@@ -4262,13 +4402,13 @@ var toggleList = function toggleList(editor, _ref2) {
4262
4402
 
4263
4403
  var _nodes = Array.from(plateCore.getNodes(editor, {
4264
4404
  mode: 'all'
4265
- })).filter(function (_ref3) {
4266
- var path = _ref3[1];
4405
+ })).filter(function (_ref2) {
4406
+ var path = _ref2[1];
4267
4407
  return path.length === rootPathLength + 1;
4268
4408
  }).reverse();
4269
4409
 
4270
4410
  _nodes.forEach(function (n) {
4271
- if (listTypes.includes(n[0].type)) {
4411
+ if (listTypes$1.includes(n[0].type)) {
4272
4412
  plateCore.setNodes(editor, {
4273
4413
  type: type
4274
4414
  }, {
@@ -4984,10 +5124,51 @@ function Quote(props) {
4984
5124
  }), props.children);
4985
5125
  }
4986
5126
 
5127
+ /**
5128
+ * Returns true if we are:
5129
+ * 1) Inside a blockquote
5130
+ * 2) With no only one child paragraph/heading and
5131
+ * 3) that child is empty
5132
+ */
5133
+
5134
+ var shouldResetQuoteOnBackspace = function shouldResetQuoteOnBackspace(editor) {
5135
+ var container = plateCore.getAbove(editor, {
5136
+ match: {
5137
+ type: Contentful.TEXT_CONTAINERS
5138
+ },
5139
+ mode: 'lowest'
5140
+ });
5141
+
5142
+ if (!container) {
5143
+ return false;
5144
+ }
5145
+
5146
+ if (!plateCore.isAncestorEmpty(editor, container[0])) {
5147
+ return false;
5148
+ }
5149
+
5150
+ var quote = plateCore.getBlockAbove(editor, {
5151
+ match: {
5152
+ type: Contentful.BLOCKS.QUOTE
5153
+ },
5154
+ mode: 'lowest'
5155
+ });
5156
+
5157
+ if (!quote) {
5158
+ return false;
5159
+ }
5160
+
5161
+ if (plateCore.hasSingleChild(quote[0]) && plateCore.isLastChild(quote, container[1])) {
5162
+ return true;
5163
+ }
5164
+
5165
+ return false;
5166
+ };
5167
+
4987
5168
  function toggleQuote(editor, logAction) {
4988
5169
  if (!editor.selection) return;
4989
5170
  var isActive = isBlockSelected(editor, Contentful.BLOCKS.QUOTE);
4990
- logAction(isActive ? 'remove' : 'insert', {
5171
+ logAction == null ? void 0 : logAction(isActive ? 'remove' : 'insert', {
4991
5172
  nodeType: Contentful.BLOCKS.QUOTE
4992
5173
  });
4993
5174
  slate.Editor.withoutNormalizing(editor, function () {
@@ -4998,10 +5179,6 @@ function toggleQuote(editor, logAction) {
4998
5179
  },
4999
5180
  split: true
5000
5181
  });
5001
- var _editor$selection = editor.selection,
5002
- anchor = _editor$selection.anchor,
5003
- focus = _editor$selection.focus;
5004
- var isTripleSelection = anchor.path[0] !== focus.path[0] && anchor.offset === 0 && focus.offset === 0;
5005
5182
 
5006
5183
  if (!isActive) {
5007
5184
  var quote = {
@@ -5009,9 +5186,7 @@ function toggleQuote(editor, logAction) {
5009
5186
  data: {},
5010
5187
  children: []
5011
5188
  };
5012
- slate.Transforms.wrapNodes(editor, quote, {
5013
- at: isTripleSelection ? editor.selection.anchor : undefined
5014
- });
5189
+ slate.Transforms.wrapNodes(editor, quote);
5015
5190
  }
5016
5191
  });
5017
5192
  }
@@ -5026,6 +5201,54 @@ var onKeyDownToggleQuote = function onKeyDownToggleQuote(editor, plugin) {
5026
5201
  };
5027
5202
  };
5028
5203
 
5204
+ var withQuote = function withQuote(editor) {
5205
+ var insertFragment = editor.insertFragment;
5206
+
5207
+ editor.insertFragment = function (fragment) {
5208
+ var startingNode = fragment.length && fragment[0];
5209
+ var startsWithBlockquote = slate.Element.isElement(startingNode) && startingNode.type === Contentful.BLOCKS.QUOTE;
5210
+ var containerEntry = plateCore.getAbove(editor, {
5211
+ match: {
5212
+ type: Contentful.TEXT_CONTAINERS
5213
+ }
5214
+ });
5215
+ var containerIsNotEmpty = containerEntry && slate.Node.string(containerEntry[0]) !== '';
5216
+
5217
+ if (startsWithBlockquote && containerIsNotEmpty) {
5218
+ var selection = editor.selection;
5219
+
5220
+ var isContentSelected = function isContentSelected(selection) {
5221
+ return !!selection && slate.Point.compare(selection.anchor, selection.focus) !== 0;
5222
+ }; // if something is selected (highlighted) we replace the selection
5223
+
5224
+
5225
+ if (isContentSelected(selection)) {
5226
+ slate.Transforms["delete"](editor, {
5227
+ at: selection
5228
+ });
5229
+ } // get the cursor entry again, it may be different after deletion
5230
+
5231
+
5232
+ var _containerEntry = plateCore.getAbove(editor, {
5233
+ match: {
5234
+ type: Contentful.TEXT_CONTAINERS
5235
+ }
5236
+ });
5237
+
5238
+ var _containerIsNotEmpty = _containerEntry && slate.Node.string(_containerEntry[0]) !== '';
5239
+
5240
+ if (_containerIsNotEmpty) {
5241
+ slate.Transforms.insertNodes(editor, fragment);
5242
+ return;
5243
+ }
5244
+ }
5245
+
5246
+ insertFragment(fragment);
5247
+ };
5248
+
5249
+ return editor;
5250
+ };
5251
+
5029
5252
  function createQuotePlugin() {
5030
5253
  var _transform;
5031
5254
 
@@ -5045,57 +5268,18 @@ function createQuotePlugin() {
5045
5268
  validNodeName: 'BLOCKQUOTE'
5046
5269
  }]
5047
5270
  },
5271
+ resetNode: [{
5272
+ // toggle off blockquote on backspace when it's empty
5273
+ hotkey: 'backspace',
5274
+ types: [Contentful.BLOCKS.QUOTE],
5275
+ predicate: shouldResetQuoteOnBackspace,
5276
+ onReset: toggleQuote
5277
+ }],
5048
5278
  normalizer: [{
5049
5279
  validChildren: Contentful.CONTAINERS[Contentful.BLOCKS.QUOTE],
5050
5280
  transform: (_transform = {}, _transform[Contentful.BLOCKS.QUOTE] = transformUnwrap, _transform["default"] = transformLift, _transform)
5051
5281
  }],
5052
- withOverrides: function withOverrides(editor) {
5053
- var insertFragment = editor.insertFragment;
5054
-
5055
- editor.insertFragment = function (fragment) {
5056
- var startingNode = fragment.length && fragment[0];
5057
- var startsWithBlockquote = slate.Element.isElement(startingNode) && startingNode.type === Contentful.BLOCKS.QUOTE;
5058
- var containerEntry = plateCore.getAbove(editor, {
5059
- match: {
5060
- type: Contentful.TEXT_CONTAINERS
5061
- }
5062
- });
5063
- var containerIsNotEmpty = containerEntry && slate.Node.string(containerEntry[0]) !== '';
5064
-
5065
- if (startsWithBlockquote && containerIsNotEmpty) {
5066
- var selection = editor.selection;
5067
-
5068
- var isContentSelected = function isContentSelected(selection) {
5069
- return !!selection && slate.Point.compare(selection.anchor, selection.focus) !== 0;
5070
- }; // if something is selected (highlighted) we replace the selection
5071
-
5072
-
5073
- if (isContentSelected(selection)) {
5074
- slate.Transforms["delete"](editor, {
5075
- at: selection
5076
- });
5077
- } // get the cursor entry again, it may be different after deletion
5078
-
5079
-
5080
- var _containerEntry = plateCore.getAbove(editor, {
5081
- match: {
5082
- type: Contentful.TEXT_CONTAINERS
5083
- }
5084
- });
5085
-
5086
- var _containerIsNotEmpty = _containerEntry && slate.Node.string(_containerEntry[0]) !== '';
5087
-
5088
- if (_containerIsNotEmpty) {
5089
- slate.Transforms.insertNodes(editor, fragment);
5090
- return;
5091
- }
5092
- }
5093
-
5094
- insertFragment(fragment);
5095
- };
5096
-
5097
- return editor;
5098
- }
5282
+ withOverrides: withQuote
5099
5283
  };
5100
5284
  }
5101
5285
 
@@ -5588,15 +5772,7 @@ var createTablePlugin = function createTablePlugin() {
5588
5772
  });
5589
5773
 
5590
5774
  if (fragmentHasTable) {
5591
- var emptyParagraph = {
5592
- type: Contentful.BLOCKS.PARAGRAPH,
5593
- children: [{
5594
- text: ''
5595
- }],
5596
- data: {},
5597
- isVoid: false
5598
- };
5599
- slate.Transforms.insertNodes(editor, emptyParagraph);
5775
+ insertEmptyParagraph(editor);
5600
5776
  }
5601
5777
 
5602
5778
  insertFragment(fragments);
@@ -5725,6 +5901,20 @@ function ToolbarTableButton(props) {
5725
5901
  function createTextPlugin() {
5726
5902
  return {
5727
5903
  key: 'TextPlugin',
5904
+ handlers: {
5905
+ // Triple selection in a non-Firefox browser undesirably selects
5906
+ // the start of the next block. Editor.unhangRange helps removing
5907
+ // the extra block at the end.
5908
+ onMouseUp: function onMouseUp(editor) {
5909
+ return function () {
5910
+ if (!editor.selection) {
5911
+ return;
5912
+ }
5913
+
5914
+ slate.Transforms.setSelection(editor, slate.Editor.unhangRange(editor, editor.selection));
5915
+ };
5916
+ }
5917
+ },
5728
5918
  withOverrides: function withOverrides(editor) {
5729
5919
  // Reverts the change made upstream that caused the cursor
5730
5920
  // to be trapped inside inline elements.
@@ -5764,11 +5954,11 @@ function createTextPlugin() {
5764
5954
  deleteBackward = editor.deleteBackward;
5765
5955
 
5766
5956
  editor.deleteBackward = function (unit) {
5767
- deleteEmptyParagraph(unit, editor, deleteBackward);
5957
+ deleteFirstEmptyParagraph(unit, editor, deleteBackward);
5768
5958
  };
5769
5959
 
5770
5960
  editor.deleteForward = function (unit) {
5771
- deleteEmptyParagraph(unit, editor, deleteForward);
5961
+ deleteFirstEmptyParagraph(unit, editor, deleteForward);
5772
5962
  };
5773
5963
 
5774
5964
  return editor;
@@ -5776,7 +5966,7 @@ function createTextPlugin() {
5776
5966
  };
5777
5967
  }
5778
5968
 
5779
- function deleteEmptyParagraph(unit, editor, deleteFunction) {
5969
+ function deleteFirstEmptyParagraph(unit, editor, deleteFunction) {
5780
5970
  var entry = plateCore.getAbove(editor, {
5781
5971
  match: {
5782
5972
  type: Contentful.TEXT_CONTAINERS
@@ -5789,8 +5979,9 @@ function deleteEmptyParagraph(unit, editor, deleteFunction) {
5789
5979
  var isTextEmpty = plateCore.isAncestorEmpty(editor, paragraphOrHeading); // We ignore paragraphs/headings that are children of ul, ol, blockquote, tables, etc
5790
5980
 
5791
5981
  var isRootLevel = path.length === 1;
5982
+ var hasSiblings = editor.children.length > 1; // prevent editor from losing focus
5792
5983
 
5793
- if (isTextEmpty && isRootLevel) {
5984
+ if (isTextEmpty && isRootLevel && plateCore.isFirstChild(path) && hasSiblings) {
5794
5985
  slate.Transforms.removeNodes(editor, {
5795
5986
  at: path
5796
5987
  });
@@ -6041,7 +6232,7 @@ var getPlugins = function getPlugins(sdk, onAction) {
6041
6232
  createTrailingParagraphPlugin(), createTextPlugin(), createVoidsPlugin(), createSelectOnBackspacePlugin(), // Pasting content from other sources
6042
6233
  createPasteHTMLPlugin(), // These plugins drive their configurations from the list of plugins
6043
6234
  // above. They MUST come last.
6044
- createSoftBreakPlugin(), createExitBreakPlugin(), createNormalizerPlugin()];
6235
+ createSoftBreakPlugin(), createExitBreakPlugin(), createResetNodePlugin(), createNormalizerPlugin()];
6045
6236
  };
6046
6237
  var disableCorePlugins = {
6047
6238
  // Temporarily until the upstream issue is fixed.
@@ -6336,7 +6527,10 @@ var useNormalizedSlateValue = function useNormalizedSlateValue(_ref) {
6336
6527
  schema: schema
6337
6528
  }); // Sets editor value & kicks normalization
6338
6529
 
6339
- slate.Transforms.insertNodes(editor, doc); // TODO: return the editor itself to avoid recompiling & initializing all
6530
+ editor.children = doc;
6531
+ slate.Editor.normalize(editor, {
6532
+ force: true
6533
+ }); // TODO: return the editor itself to avoid recompiling & initializing all
6340
6534
  // of the plugins again. It's currently not possible due to a bug in Plate
6341
6535
  // with initialValues
6342
6536
  // See: https://slate-js.slack.com/archives/C013QHXSCG1/p1645112799942819