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

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
  }
@@ -607,6 +611,13 @@ var focus = function focus(editor) {
607
611
  }, 0);
608
612
  }
609
613
  };
614
+ function toggleElement(editor, options, editorOptions) {
615
+ plateCore.toggleNodeType(editor, options, editorOptions); // We must reset `data` from one element to another
616
+
617
+ slate.Transforms.setNodes(editor, {
618
+ data: {}
619
+ });
620
+ }
610
621
 
611
622
  function withLinkTracking(Component) {
612
623
  return function ComponentWithTracking(props) {
@@ -1065,197 +1076,201 @@ function createCommonjsModule(fn, module) {
1065
1076
  return module = { exports: {} }, fn(module, module.exports), module.exports;
1066
1077
  }
1067
1078
 
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
- }
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
+ */
1095
1086
 
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
- }
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
+ }
1104
1114
 
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.
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 || []);
1111
1120
 
1112
- generator._invoke = makeInvokeMethod(innerFn, self, context);
1113
- return generator;
1114
- }
1121
+ // The ._invoke method unifies the implementations of the .next,
1122
+ // .throw, and .return methods.
1123
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
1115
1124
 
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
- }
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 };
1139
1144
  }
1145
+ }
1140
1146
 
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.
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
+ });
1158
1170
 
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
+ }
1159
1180
 
1160
- var IteratorPrototype = {};
1161
- define(IteratorPrototype, iteratorSymbol, function () {
1162
- return this;
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
+ });
1163
1199
  });
1164
- var getProto = Object.getPrototypeOf;
1165
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1200
+ }
1166
1201
 
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
- }
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
+ };
1172
1211
 
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
- });
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");
1186
1218
  }
1219
+ genFun.prototype = Object.create(Gp);
1220
+ return genFun;
1221
+ };
1187
1222
 
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
- };
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
+ };
1194
1230
 
1195
- exports.mark = function (genFun) {
1196
- if (Object.setPrototypeOf) {
1197
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
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);
1198
1236
  } 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);
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);
1245
1246
  });
1246
1247
  }
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
+ });
1247
1260
  }
1261
+ }
1248
1262
 
1249
- var previousPromise;
1263
+ var previousPromise;
1250
1264
 
1251
- function enqueue(method, arg) {
1252
- function callInvokeWithMethodAndArg() {
1253
- return new PromiseImpl(function (resolve, reject) {
1254
- invoke(method, arg, resolve, reject);
1255
- });
1256
- }
1265
+ function enqueue(method, arg) {
1266
+ function callInvokeWithMethodAndArg() {
1267
+ return new PromiseImpl(function(resolve, reject) {
1268
+ invoke(method, arg, resolve, reject);
1269
+ });
1270
+ }
1257
1271
 
1258
- return previousPromise = // If enqueue has been called before, then we want to wait until
1272
+ return previousPromise =
1273
+ // If enqueue has been called before, then we want to wait until
1259
1274
  // all previous Promises have been resolved before calling invoke,
1260
1275
  // so that results are always delivered in the correct order. If
1261
1276
  // enqueue has not been called before, then it is important to
@@ -1267,527 +1282,554 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1267
1282
  // execute code before the first await. Since we implement simple
1268
1283
  // async functions in terms of async generators, it is especially
1269
1284
  // 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;
1285
+ previousPromise ? previousPromise.then(
1286
+ callInvokeWithMethodAndArg,
1287
+ // Avoid propagating failures to Promises returned by later
1288
+ // invocations of the iterator.
1289
+ callInvokeWithMethodAndArg
1290
+ ) : callInvokeWithMethodAndArg();
1278
1291
  }
1279
1292
 
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
- };
1293
+ // Define the unified helper method that is used to implement .next,
1294
+ // .throw, and .return (see defineIteratorMethods).
1295
+ this._invoke = enqueue;
1296
+ }
1296
1297
 
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
- }
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
+ };
1303
1321
 
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
1322
+ function makeInvokeMethod(innerFn, self, context) {
1323
+ var state = GenStateSuspendedStart;
1309
1324
 
1325
+ return function invoke(method, arg) {
1326
+ if (state === GenStateExecuting) {
1327
+ throw new Error("Generator is already running");
1328
+ }
1310
1329
 
1311
- return doneResult();
1330
+ if (state === GenStateCompleted) {
1331
+ if (method === "throw") {
1332
+ throw arg;
1312
1333
  }
1313
1334
 
1314
- context.method = method;
1315
- context.arg = arg;
1316
-
1317
- while (true) {
1318
- var delegate = context.delegate;
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
+ }
1319
1339
 
1320
- if (delegate) {
1321
- var delegateResult = maybeInvokeDelegate(delegate, context);
1340
+ context.method = method;
1341
+ context.arg = arg;
1322
1342
 
1323
- if (delegateResult) {
1324
- if (delegateResult === ContinueSentinel) continue;
1325
- return delegateResult;
1326
- }
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;
1327
1350
  }
1351
+ }
1328
1352
 
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
- }
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;
1338
1357
 
1339
- context.dispatchException(context.arg);
1340
- } else if (context.method === "return") {
1341
- context.abrupt("return", context.arg);
1358
+ } else if (context.method === "throw") {
1359
+ if (state === GenStateSuspendedStart) {
1360
+ state = GenStateCompleted;
1361
+ throw context.arg;
1342
1362
  }
1343
1363
 
1344
- state = GenStateExecuting;
1345
- var record = tryCatch(innerFn, self, context);
1364
+ context.dispatchException(context.arg);
1346
1365
 
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;
1366
+ } else if (context.method === "return") {
1367
+ context.abrupt("return", context.arg);
1368
+ }
1351
1369
 
1352
- if (record.arg === ContinueSentinel) {
1353
- continue;
1354
- }
1370
+ state = GenStateExecuting;
1355
1371
 
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.
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;
1363
1379
 
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
- }
1380
+ if (record.arg === ContinueSentinel) {
1381
+ continue;
1397
1382
  }
1398
1383
 
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.
1399
1393
  context.method = "throw";
1400
- context.arg = new TypeError("The iterator does not provide a 'throw' method");
1394
+ context.arg = record.arg;
1401
1395
  }
1402
-
1403
- return ContinueSentinel;
1404
1396
  }
1397
+ };
1398
+ }
1405
1399
 
1406
- var record = tryCatch(method, delegate.iterator, context.arg);
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;
1407
1410
 
1408
- if (record.type === "throw") {
1409
- context.method = "throw";
1410
- context.arg = record.arg;
1411
- context.delegate = null;
1412
- return ContinueSentinel;
1413
- }
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);
1414
1419
 
1415
- var info = record.arg;
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
+ }
1416
1426
 
1417
- if (!info) {
1418
1427
  context.method = "throw";
1419
- context.arg = new TypeError("iterator result is not an object");
1420
- context.delegate = null;
1421
- return ContinueSentinel;
1428
+ context.arg = new TypeError(
1429
+ "The iterator does not provide a 'throw' method");
1422
1430
  }
1423
1431
 
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.
1432
+ return ContinueSentinel;
1433
+ }
1445
1434
 
1435
+ var record = tryCatch(method, delegate.iterator, context.arg);
1446
1436
 
1437
+ if (record.type === "throw") {
1438
+ context.method = "throw";
1439
+ context.arg = record.arg;
1447
1440
  context.delegate = null;
1448
1441
  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
- });
1442
+ }
1466
1443
 
1467
- function pushTryEntry(locs) {
1468
- var entry = {
1469
- tryLoc: locs[0]
1470
- };
1444
+ var info = record.arg;
1471
1445
 
1472
- if (1 in locs) {
1473
- entry.catchLoc = locs[1];
1474
- }
1446
+ if (! info) {
1447
+ context.method = "throw";
1448
+ context.arg = new TypeError("iterator result is not an object");
1449
+ context.delegate = null;
1450
+ return ContinueSentinel;
1451
+ }
1475
1452
 
1476
- if (2 in locs) {
1477
- entry.finallyLoc = locs[2];
1478
- entry.afterLoc = locs[3];
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;
1479
1470
  }
1480
1471
 
1481
- this.tryEntries.push(entry);
1472
+ } else {
1473
+ // Re-yield the result returned by the delegate method.
1474
+ return info;
1482
1475
  }
1483
1476
 
1484
- function resetTryEntry(entry) {
1485
- var record = entry.completion || {};
1486
- record.type = "normal";
1487
- delete record.arg;
1488
- entry.completion = record;
1489
- }
1477
+ // The delegate iterator is finished, so forget it and continue with
1478
+ // the outer generator.
1479
+ context.delegate = null;
1480
+ return ContinueSentinel;
1481
+ }
1490
1482
 
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
- }
1483
+ // Define Generator.prototype.{next,throw,return} in terms of the
1484
+ // unified ._invoke helper method.
1485
+ defineIteratorMethods(Gp);
1501
1486
 
1502
- exports.keys = function (object) {
1503
- var keys = [];
1487
+ define(Gp, toStringTagSymbol, "Generator");
1504
1488
 
1505
- for (var key in object) {
1506
- keys.push(key);
1507
- }
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
+ });
1508
1497
 
1509
- keys.reverse(); // Rather than returning an object with a next method, we keep
1510
- // things simple and return the next function itself.
1498
+ define(Gp, "toString", function() {
1499
+ return "[object Generator]";
1500
+ });
1511
1501
 
1512
- return function next() {
1513
- while (keys.length) {
1514
- var key = keys.pop();
1502
+ function pushTryEntry(locs) {
1503
+ var entry = { tryLoc: locs[0] };
1515
1504
 
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.
1505
+ if (1 in locs) {
1506
+ entry.catchLoc = locs[1];
1507
+ }
1524
1508
 
1509
+ if (2 in locs) {
1510
+ entry.finallyLoc = locs[2];
1511
+ entry.afterLoc = locs[3];
1512
+ }
1525
1513
 
1526
- next.done = true;
1527
- return next;
1528
- };
1529
- };
1514
+ this.tryEntries.push(entry);
1515
+ }
1530
1516
 
1531
- function values(iterable) {
1532
- if (iterable) {
1533
- var iteratorMethod = iterable[iteratorSymbol];
1517
+ function resetTryEntry(entry) {
1518
+ var record = entry.completion || {};
1519
+ record.type = "normal";
1520
+ delete record.arg;
1521
+ entry.completion = record;
1522
+ }
1534
1523
 
1535
- if (iteratorMethod) {
1536
- return iteratorMethod.call(iterable);
1537
- }
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
+ }
1538
1532
 
1539
- if (typeof iterable.next === "function") {
1540
- return iterable;
1533
+ exports.keys = function(object) {
1534
+ var keys = [];
1535
+ for (var key in object) {
1536
+ keys.push(key);
1537
+ }
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;
1541
1549
  }
1550
+ }
1542
1551
 
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
- }
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
+ };
1553
1559
 
1554
- next.value = undefined$1;
1555
- next.done = true;
1556
- return next;
1557
- };
1560
+ function values(iterable) {
1561
+ if (iterable) {
1562
+ var iteratorMethod = iterable[iteratorSymbol];
1563
+ if (iteratorMethod) {
1564
+ return iteratorMethod.call(iterable);
1565
+ }
1558
1566
 
1559
- return next.next = next;
1560
- }
1561
- } // Return an iterator with no values.
1567
+ if (typeof iterable.next === "function") {
1568
+ return iterable;
1569
+ }
1562
1570
 
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
+ }
1563
1580
 
1564
- return {
1565
- next: doneResult
1566
- };
1567
- }
1581
+ next.value = undefined$1;
1582
+ next.done = true;
1568
1583
 
1569
- exports.values = values;
1584
+ return next;
1585
+ };
1570
1586
 
1571
- function doneResult() {
1572
- return {
1573
- value: undefined$1,
1574
- done: true
1575
- };
1587
+ return next.next = next;
1588
+ }
1576
1589
  }
1577
1590
 
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.
1591
+ // Return an iterator with no values.
1592
+ return { next: doneResult };
1593
+ }
1594
+ exports.values = values;
1584
1595
 
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);
1596
+ function doneResult() {
1597
+ return { value: undefined$1, done: true };
1598
+ }
1591
1599
 
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
- }
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;
1598
1624
  }
1599
1625
  }
1600
- },
1601
- stop: function stop() {
1602
- this.done = true;
1603
- var rootEntry = this.tryEntries[0];
1604
- var rootRecord = rootEntry.completion;
1626
+ }
1627
+ },
1605
1628
 
1606
- if (rootRecord.type === "throw") {
1607
- throw rootRecord.arg;
1608
- }
1629
+ stop: function() {
1630
+ this.done = true;
1609
1631
 
1610
- return this.rval;
1611
- },
1612
- dispatchException: function dispatchException(exception) {
1613
- if (this.done) {
1614
- throw exception;
1615
- }
1632
+ var rootEntry = this.tryEntries[0];
1633
+ var rootRecord = rootEntry.completion;
1634
+ if (rootRecord.type === "throw") {
1635
+ throw rootRecord.arg;
1636
+ }
1616
1637
 
1617
- var context = this;
1638
+ return this.rval;
1639
+ },
1618
1640
 
1619
- function handle(loc, caught) {
1620
- record.type = "throw";
1621
- record.arg = exception;
1622
- context.next = loc;
1641
+ dispatchException: function(exception) {
1642
+ if (this.done) {
1643
+ throw exception;
1644
+ }
1623
1645
 
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
- }
1646
+ var context = this;
1647
+ function handle(loc, caught) {
1648
+ record.type = "throw";
1649
+ record.arg = exception;
1650
+ context.next = loc;
1630
1651
 
1631
- return !!caught;
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;
1632
1657
  }
1633
1658
 
1634
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1635
- var entry = this.tryEntries[i];
1636
- var record = entry.completion;
1659
+ return !! caught;
1660
+ }
1637
1661
 
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
- }
1662
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1663
+ var entry = this.tryEntries[i];
1664
+ var record = entry.completion;
1644
1665
 
1645
- if (entry.tryLoc <= this.prev) {
1646
- var hasCatch = hasOwn.call(entry, "catchLoc");
1647
- var hasFinally = hasOwn.call(entry, "finallyLoc");
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");
1671
+ }
1648
1672
 
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");
1673
+ if (entry.tryLoc <= this.prev) {
1674
+ var hasCatch = hasOwn.call(entry, "catchLoc");
1675
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
1676
+
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
+ }
1683
+
1684
+ } else if (hasCatch) {
1685
+ if (this.prev < entry.catchLoc) {
1686
+ return handle(entry.catchLoc, true);
1665
1687
  }
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
1688
 
1673
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1674
- var finallyEntry = entry;
1675
- break;
1689
+ } else if (hasFinally) {
1690
+ if (this.prev < entry.finallyLoc) {
1691
+ return handle(entry.finallyLoc);
1692
+ }
1693
+
1694
+ } else {
1695
+ throw new Error("try statement without catch or finally");
1676
1696
  }
1677
1697
  }
1698
+ }
1699
+ },
1678
1700
 
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;
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;
1683
1709
  }
1710
+ }
1684
1711
 
1685
- var record = finallyEntry ? finallyEntry.completion : {};
1686
- record.type = type;
1687
- record.arg = arg;
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
+ }
1688
1721
 
1689
- if (finallyEntry) {
1690
- this.method = "next";
1691
- this.next = finallyEntry.finallyLoc;
1692
- return ContinueSentinel;
1693
- }
1722
+ var record = finallyEntry ? finallyEntry.completion : {};
1723
+ record.type = type;
1724
+ record.arg = arg;
1694
1725
 
1695
- return this.complete(record);
1696
- },
1697
- complete: function complete(record, afterLoc) {
1698
- if (record.type === "throw") {
1699
- throw record.arg;
1700
- }
1726
+ if (finallyEntry) {
1727
+ this.method = "next";
1728
+ this.next = finallyEntry.finallyLoc;
1729
+ return ContinueSentinel;
1730
+ }
1701
1731
 
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
- }
1732
+ return this.complete(record);
1733
+ },
1711
1734
 
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];
1735
+ complete: function(record, afterLoc) {
1736
+ if (record.type === "throw") {
1737
+ throw record.arg;
1738
+ }
1717
1739
 
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];
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
+ }
1728
1750
 
1729
- if (entry.tryLoc === tryLoc) {
1730
- var record = entry.completion;
1751
+ return ContinueSentinel;
1752
+ },
1731
1753
 
1732
- if (record.type === "throw") {
1733
- var thrown = record.arg;
1734
- resetTryEntry(entry);
1735
- }
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);
1760
+ return ContinueSentinel;
1761
+ }
1762
+ }
1763
+ },
1736
1764
 
1737
- return thrown;
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;
1772
+ resetTryEntry(entry);
1738
1773
  }
1739
- } // The context.catch method must only be called with a location
1740
- // argument that corresponds to a known catch block.
1741
-
1774
+ return thrown;
1775
+ }
1776
+ }
1742
1777
 
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
- };
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
+ },
1751
1782
 
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
- }
1783
+ delegateYield: function(iterable, resultName, nextLoc) {
1784
+ this.delegate = {
1785
+ iterator: values(iterable),
1786
+ resultName: resultName,
1787
+ nextLoc: nextLoc
1788
+ };
1757
1789
 
1758
- return ContinueSentinel;
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;
1759
1794
  }
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
1795
 
1765
- return exports;
1766
- }( // If this script is executing as a CommonJS module, use module.exports
1796
+ return ContinueSentinel;
1797
+ }
1798
+ };
1799
+
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;
1805
+
1806
+ }(
1807
+ // If this script is executing as a CommonJS module, use module.exports
1767
1808
  // as the regeneratorRuntime namespace. Otherwise create a new empty
1768
1809
  // object. Either way, the resulting object will be used to initialize
1769
1810
  // 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
- }
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);
1790
1831
  }
1832
+ }
1791
1833
  });
1792
1834
 
1793
1835
  /* eslint-disable you-dont-need-lodash-underscore/find */
@@ -2498,7 +2540,7 @@ function ToolbarHeadingButton(props) {
2498
2540
  var prevOnChange = editor.onChange;
2499
2541
  /*
2500
2542
  The focus might happen at point in time when
2501
- `toggleNodeType` changes aren't rendered yet, causing the browser
2543
+ `toggleElement` (helper for toggleNodeType) changes aren't rendered yet, causing the browser
2502
2544
  to place the cursor at the start of the text.
2503
2545
  We wait for the change event before focusing
2504
2546
  the editor again. This ensures the cursor is back at the previous
@@ -2514,7 +2556,7 @@ function ToolbarHeadingButton(props) {
2514
2556
  editor.tracking.onToolbarAction(isActive ? 'remove' : 'insert', {
2515
2557
  nodeType: type
2516
2558
  });
2517
- plateCore.toggleNodeType(editor, {
2559
+ toggleElement(editor, {
2518
2560
  activeType: type,
2519
2561
  inactiveType: type
2520
2562
  });
@@ -2644,7 +2686,7 @@ var buildHeadingEventHandler = function buildHeadingEventHandler(type) {
2644
2686
  editor.tracking.onShortcutAction(isActive ? 'remove' : 'insert', {
2645
2687
  nodeType: type
2646
2688
  });
2647
- plateCore.toggleNodeType(editor, {
2689
+ toggleElement(editor, {
2648
2690
  activeType: type,
2649
2691
  inactiveType: Contentful.BLOCKS.PARAGRAPH
2650
2692
  });
@@ -4089,6 +4131,178 @@ var createListPlugin = function createListPlugin() {
4089
4131
  });
4090
4132
  };
4091
4133
 
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;
4167
+ return slate.Editor.withoutNormalizing(editor, function () {
4168
+ if (!editor.selection) {
4169
+ return;
4170
+ }
4171
+
4172
+ if (plateCore.isCollapsed(editor.selection) || !plateCore.isRangeAcrossBlocks(editor)) {
4173
+ // selection is collapsed
4174
+ var res = plateList.getListItemEntry(editor);
4175
+
4176
+ if (res) {
4177
+ var list = res.list;
4178
+
4179
+ if (list[0].type !== type) {
4180
+ plateCore.setNodes(editor, {
4181
+ type: type
4182
+ }, {
4183
+ at: editor.selection,
4184
+ match: function match(n) {
4185
+ return listTypes.includes(n.type);
4186
+ },
4187
+ mode: 'lowest'
4188
+ });
4189
+ } else {
4190
+ unwrapList(editor);
4191
+ }
4192
+ } else {
4193
+ var _list = {
4194
+ type: type,
4195
+ children: [],
4196
+ data: {}
4197
+ };
4198
+ plateCore.wrapNodes(editor, _list);
4199
+ var nodes = [].concat(plateCore.getNodes(editor, {
4200
+ match: {
4201
+ type: plateCore.getPluginType(editor, plateCore.ELEMENT_DEFAULT)
4202
+ }
4203
+ }));
4204
+ var listItem = {
4205
+ type: Contentful.BLOCKS.LIST_ITEM,
4206
+ children: [],
4207
+ data: {}
4208
+ };
4209
+
4210
+ for (var _iterator = _createForOfIteratorHelperLoose(nodes), _step; !(_step = _iterator()).done;) {
4211
+ var _step$value = _step.value,
4212
+ path = _step$value[1];
4213
+ plateCore.wrapNodes(editor, listItem, {
4214
+ at: path
4215
+ });
4216
+ }
4217
+ }
4218
+ } else {
4219
+ // selection is a range
4220
+ var _Range$edges = slate.Range.edges(editor.selection),
4221
+ startPoint = _Range$edges[0],
4222
+ endPoint = _Range$edges[1];
4223
+
4224
+ var commonEntry = slate.Node.common(editor, startPoint.path, endPoint.path);
4225
+
4226
+ if (listTypes.includes(commonEntry[0].type) || commonEntry[0].type === Contentful.BLOCKS.LIST_ITEM) {
4227
+ if (commonEntry[0].type !== type) {
4228
+ var startList = plateCore.findNode(editor, {
4229
+ at: slate.Range.start(editor.selection),
4230
+ match: {
4231
+ type: listTypes
4232
+ },
4233
+ mode: 'lowest'
4234
+ });
4235
+ var endList = plateCore.findNode(editor, {
4236
+ at: slate.Range.end(editor.selection),
4237
+ match: {
4238
+ type: listTypes
4239
+ },
4240
+ mode: 'lowest'
4241
+ });
4242
+
4243
+ if (!startList || !endList) {
4244
+ return;
4245
+ }
4246
+
4247
+ var rangeLength = Math.min(startList[1].length, endList[1].length);
4248
+ plateCore.setNodes(editor, {
4249
+ type: type
4250
+ }, {
4251
+ at: editor.selection,
4252
+ match: function match(n, path) {
4253
+ return listTypes.includes(n.type) && path.length >= rangeLength;
4254
+ },
4255
+ mode: 'all'
4256
+ });
4257
+ } else {
4258
+ unwrapList(editor);
4259
+ }
4260
+ } else {
4261
+ var rootPathLength = commonEntry[1].length;
4262
+
4263
+ var _nodes = Array.from(plateCore.getNodes(editor, {
4264
+ mode: 'all'
4265
+ })).filter(function (_ref3) {
4266
+ var path = _ref3[1];
4267
+ return path.length === rootPathLength + 1;
4268
+ }).reverse();
4269
+
4270
+ _nodes.forEach(function (n) {
4271
+ if (listTypes.includes(n[0].type)) {
4272
+ plateCore.setNodes(editor, {
4273
+ type: type
4274
+ }, {
4275
+ at: n[1]
4276
+ });
4277
+ } else {
4278
+ plateCore.setNodes(editor, {
4279
+ type: plateCore.getPluginType(editor, plateList.ELEMENT_LIC)
4280
+ }, {
4281
+ at: n[1]
4282
+ });
4283
+ var _listItem = {
4284
+ type: Contentful.BLOCKS.LIST_ITEM,
4285
+ children: [],
4286
+ data: {}
4287
+ };
4288
+ plateCore.wrapNodes(editor, _listItem, {
4289
+ at: n[1]
4290
+ });
4291
+ var _list2 = {
4292
+ type: type,
4293
+ children: [],
4294
+ data: {}
4295
+ };
4296
+ plateCore.wrapNodes(editor, _list2, {
4297
+ at: n[1]
4298
+ });
4299
+ }
4300
+ });
4301
+ }
4302
+ }
4303
+ });
4304
+ };
4305
+
4092
4306
  function ToolbarListButton(props) {
4093
4307
  var sdk = useSdkContext();
4094
4308
  var editor = useContentfulEditor();
@@ -4096,7 +4310,7 @@ function ToolbarListButton(props) {
4096
4310
  function handleClick(type) {
4097
4311
  return function () {
4098
4312
  if (!(editor != null && editor.selection)) return;
4099
- plateList.toggleList(editor, {
4313
+ toggleList(editor, {
4100
4314
  type: type
4101
4315
  });
4102
4316
  focus(editor);
@@ -4557,6 +4771,18 @@ function isEmptyElement(element) {
4557
4771
  return element.textContent === '';
4558
4772
  }
4559
4773
 
4774
+ var buildParagraphKeyDownHandler = function buildParagraphKeyDownHandler(editor, _ref) {
4775
+ var hotkey = _ref.options.hotkey;
4776
+ return function (event) {
4777
+ if (editor.selection && hotkey && isHotkey(hotkey, event)) {
4778
+ toggleElement(editor, {
4779
+ activeType: Contentful.BLOCKS.PARAGRAPH,
4780
+ inactiveType: Contentful.BLOCKS.PARAGRAPH
4781
+ });
4782
+ }
4783
+ };
4784
+ };
4785
+
4560
4786
  var createParagraphPlugin = function createParagraphPlugin() {
4561
4787
  var _transform;
4562
4788
 
@@ -4566,6 +4792,9 @@ var createParagraphPlugin = function createParagraphPlugin() {
4566
4792
  options: {
4567
4793
  hotkey: ['mod+opt+0']
4568
4794
  },
4795
+ handlers: {
4796
+ onKeyDown: buildParagraphKeyDownHandler
4797
+ },
4569
4798
  softBreak: [// create a new line with SHIFT+Enter inside a paragraph
4570
4799
  {
4571
4800
  hotkey: 'shift+enter',
@@ -4582,8 +4811,8 @@ var createParagraphPlugin = function createParagraphPlugin() {
4582
4811
  }
4583
4812
  },
4584
4813
  normalizer: [{
4585
- validChildren: function validChildren(_, _ref) {
4586
- var node = _ref[0];
4814
+ validChildren: function validChildren(_, _ref2) {
4815
+ var node = _ref2[0];
4587
4816
  return isInlineOrText(node);
4588
4817
  },
4589
4818
  transform: (_transform = {}, _transform[Contentful.BLOCKS.PARAGRAPH] = transformUnwrap, _transform["default"] = transformLift, _transform)
@@ -6150,8 +6379,9 @@ var useOnValueChanged = function useOnValueChanged(_ref) {
6150
6379
 
6151
6380
  var _excluded = ["sdk", "isInitiallyDisabled", "onAction"];
6152
6381
  var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
6153
- var id = useContentfulEditorId();
6154
- var editor = useContentfulEditor();
6382
+ var id = getContentfulEditorId(props.sdk); // TODO: remove in favor of getting the editor from useNormalizedSlateValue after upgrading to Plate v10
6383
+
6384
+ var editor = useContentfulEditor(id);
6155
6385
  var plugins = React__default.useMemo(function () {
6156
6386
  var _props$onAction;
6157
6387
 
@@ -6169,7 +6399,20 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
6169
6399
  var classNames = emotion.cx(styles$j.editor, props.minHeight !== undefined ? emotion.css({
6170
6400
  minHeight: props.minHeight
6171
6401
  }) : undefined, props.isDisabled ? styles$j.disabled : styles$j.enabled, props.isToolbarHidden && styles$j.hiddenToolbar);
6172
- return /*#__PURE__*/React__default.createElement("div", {
6402
+ React.useEffect(function () {
6403
+ // Ensure the plate state is cleared after the component unmounts
6404
+ // This prevent new editors for the same field to display old outdated values
6405
+ // Typical scenario: coming back to the entry editor after restoring a previous entry version
6406
+ plateCore.getPlateActions(id).enabled(true);
6407
+ return function () {
6408
+ return plateCore.getPlateActions(id).enabled(false);
6409
+ };
6410
+ }, [id]);
6411
+ return /*#__PURE__*/React__default.createElement(SdkProvider, {
6412
+ sdk: props.sdk
6413
+ }, /*#__PURE__*/React__default.createElement(ContentfulEditorIdProvider, {
6414
+ value: id
6415
+ }, /*#__PURE__*/React__default.createElement("div", {
6173
6416
  className: styles$j.root,
6174
6417
  "data-test-id": "rich-text-editor"
6175
6418
  }, /*#__PURE__*/React__default.createElement(plateCore.Plate, {
@@ -6186,7 +6429,7 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
6186
6429
  isDisabled: props.isDisabled
6187
6430
  }, /*#__PURE__*/React__default.createElement(Toolbar, {
6188
6431
  isDisabled: props.isDisabled
6189
- }))));
6432
+ }))))));
6190
6433
  };
6191
6434
 
6192
6435
  var RichTextEditor = function RichTextEditor(props) {
@@ -6198,11 +6441,8 @@ var RichTextEditor = function RichTextEditor(props) {
6198
6441
  var isEmptyValue = React.useCallback(function (value) {
6199
6442
  return !value || deepEquals(value, Contentful.EMPTY_DOCUMENT);
6200
6443
  }, []);
6201
- var editorId = getContentfulEditorId(sdk);
6202
6444
  return /*#__PURE__*/React__default.createElement(fieldEditorReference.EntityProvider, {
6203
6445
  sdk: sdk
6204
- }, /*#__PURE__*/React__default.createElement(SdkProvider, {
6205
- sdk: sdk
6206
6446
  }, /*#__PURE__*/React__default.createElement(fieldEditorShared.FieldConnector, {
6207
6447
  throttle: 0,
6208
6448
  field: sdk.field,
@@ -6214,17 +6454,15 @@ var RichTextEditor = function RichTextEditor(props) {
6214
6454
  disabled = _ref.disabled,
6215
6455
  setValue = _ref.setValue,
6216
6456
  externalReset = _ref.externalReset;
6217
- return /*#__PURE__*/React__default.createElement(ContentfulEditorIdProvider, {
6218
- value: editorId
6219
- }, /*#__PURE__*/React__default.createElement(ConnectedRichTextEditor, Object.assign({}, otherProps, {
6457
+ return /*#__PURE__*/React__default.createElement(ConnectedRichTextEditor, Object.assign({}, otherProps, {
6220
6458
  key: "rich-text-editor-" + externalReset,
6221
6459
  value: lastRemoteValue,
6222
6460
  sdk: sdk,
6223
6461
  onAction: onAction,
6224
6462
  isDisabled: disabled,
6225
6463
  onChange: setValue
6226
- })));
6227
- })));
6464
+ }));
6465
+ }));
6228
6466
  };
6229
6467
 
6230
6468
  var LINK_TYPES$1 = {