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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
- import React__default, { useContext, createContext, useMemo, createElement, useEffect, useState, memo, Fragment, useCallback } from 'react';
1
+ import React__default, { createContext, useContext, useMemo, createElement, useEffect, useState, memo, Fragment, useCallback } from 'react';
2
2
  import { useEntities, ScheduledIconWithTooltip, MissingEntityCard, AssetThumbnail, getScheduleTooltipContent, EntityProvider } from '@contentful/field-editor-reference';
3
3
  import { entityHelpers, shortenStorageUnit, isValidImage, ModalDialogLauncher, FieldConnector } from '@contentful/field-editor-shared';
4
4
  import { BLOCKS, INLINES, TABLE_BLOCKS, TEXT_CONTAINERS, HEADINGS, LIST_ITEM_BLOCKS, MARKS, CONTAINERS, TOP_LEVEL_BLOCKS, VOID_BLOCKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
5
- import { usePlateEditorState, usePlateEditorRef, getNodes, getText, toggleNodeType, getAbove, setNodes, isAncestorEmpty, getParent, getBlockAbove, isSelectionAtBlockStart, isSelectionAtBlockEnd, isFirstChild, insertNodes, moveChildren, isBlockAboveEmpty, mockPlugin, getPluginType, ELEMENT_DEFAULT, findNode, isMarkActive, toggleMark, someHtmlElement, match, KEY_DESERIALIZE_HTML, someNode, getChildren as getChildren$1, getLastChildPath, createDeserializeHtmlPlugin, createDeserializeAstPlugin, createPlateEditor, Plate } from '@udecode/plate-core';
5
+ import { usePlateEditorState, usePlateEditorRef, getNodes, toggleNodeType, getText, getAbove, setNodes, isAncestorEmpty, getParent, getBlockAbove, isSelectionAtBlockStart, isSelectionAtBlockEnd, isFirstChild, insertNodes, moveChildren, isBlockAboveEmpty, mockPlugin, getPluginType, ELEMENT_DEFAULT, findNode, isCollapsed, isRangeAcrossBlocks, wrapNodes, unwrapNodes, isMarkActive, toggleMark, someHtmlElement, match, KEY_DESERIALIZE_HTML, someNode, getChildren as getChildren$1, getLastChildPath, createDeserializeHtmlPlugin, createDeserializeAstPlugin, createPlateEditor, getPlateActions, Plate } from '@udecode/plate-core';
6
6
  import { css, cx } from 'emotion';
7
7
  import deepEquals from 'fast-deep-equal';
8
8
  import noop from 'lodash-es/noop';
@@ -19,7 +19,7 @@ import { ClockIcon, AssetIcon, EmbeddedEntryBlockIcon, EmbeddedEntryInlineIcon,
19
19
  import tokens from '@contentful/f36-tokens';
20
20
  import find from 'lodash-es/find';
21
21
  import flow from 'lodash-es/flow';
22
- import { getListItemEntry, moveListItemUp, ELEMENT_LI, unwrapList, deleteBackwardList, deleteForwardList, deleteFragmentList, normalizeList, createListPlugin as createListPlugin$1, ELEMENT_UL, ELEMENT_OL, ELEMENT_LIC, toggleList } from '@udecode/plate-list';
22
+ import { getListItemEntry, moveListItemUp, ELEMENT_LI, unwrapList as unwrapList$1, deleteBackwardList, deleteForwardList, deleteFragmentList, normalizeList, createListPlugin as createListPlugin$1, ELEMENT_UL, ELEMENT_OL, ELEMENT_LIC } from '@udecode/plate-list';
23
23
  import { onKeyDownResetNode, SIMULATE_BACKSPACE } from '@udecode/plate-reset-node';
24
24
  import { createBoldPlugin as createBoldPlugin$1, createCodePlugin as createCodePlugin$1, createItalicPlugin as createItalicPlugin$1, createUnderlinePlugin as createUnderlinePlugin$1 } from '@udecode/plate-basic-marks';
25
25
  import isPlainObject from 'is-plain-obj';
@@ -247,25 +247,29 @@ function getContentfulEditorId(sdk) {
247
247
  }
248
248
  var editorContext = /*#__PURE__*/createContext('');
249
249
  var ContentfulEditorIdProvider = editorContext.Provider;
250
- function useContentfulEditorId() {
251
- var id = useContext(editorContext);
250
+ function useContentfulEditorId(id) {
251
+ var contextId = useContext(editorContext);
252
252
 
253
- if (!id) {
253
+ if (id) {
254
+ return id;
255
+ }
256
+
257
+ if (!contextId) {
254
258
  throw new Error('could not find editor id. Please ensure the component is wrapped in <ContentfulEditorIdProvider> ');
255
259
  }
256
260
 
257
- return id;
261
+ return contextId;
258
262
  } // This hook re-renders when the value changes
259
263
  // Use case: Toolbar icons, for example
260
264
 
261
- function useContentfulEditor() {
262
- var editorId = useContentfulEditorId();
265
+ function useContentfulEditor(id) {
266
+ var editorId = useContentfulEditorId(id);
263
267
  var editor = usePlateEditorState(editorId);
264
268
  return editor;
265
269
  } // This doesn't re-render when the value changes
266
270
 
267
- function useContentfulEditorRef() {
268
- var editorId = useContentfulEditorId();
271
+ function useContentfulEditorRef(id) {
272
+ var editorId = useContentfulEditorId(id);
269
273
  var editor = usePlateEditorRef(editorId);
270
274
  return editor;
271
275
  }
@@ -414,6 +418,23 @@ function moveToTheNextLine(editor) {
414
418
  unit: 'line'
415
419
  });
416
420
  }
421
+ function moveToTheNextChar(editor) {
422
+ Transforms.move(editor, {
423
+ distance: 1,
424
+ unit: 'character'
425
+ });
426
+ }
427
+ function insertEmptyParagraph(editor) {
428
+ var emptyParagraph = {
429
+ type: BLOCKS.PARAGRAPH,
430
+ children: [{
431
+ text: ''
432
+ }],
433
+ data: {},
434
+ isVoid: false
435
+ };
436
+ Transforms.insertNodes(editor, emptyParagraph);
437
+ }
417
438
  function getElementFromCurrentSelection(editor) {
418
439
  if (!editor.selection) return [];
419
440
  return Array.from(Editor.nodes(editor, {
@@ -600,6 +621,13 @@ var focus = function focus(editor) {
600
621
  }, 0);
601
622
  }
602
623
  };
624
+ function toggleElement(editor, options, editorOptions) {
625
+ toggleNodeType(editor, options, editorOptions); // We must reset `data` from one element to another
626
+
627
+ Transforms.setNodes(editor, {
628
+ data: {}
629
+ });
630
+ }
603
631
 
604
632
  function withLinkTracking(Component) {
605
633
  return function ComponentWithTracking(props) {
@@ -1058,197 +1086,201 @@ function createCommonjsModule(fn, module) {
1058
1086
  return module = { exports: {} }, fn(module, module.exports), module.exports;
1059
1087
  }
1060
1088
 
1061
- var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1062
- /**
1063
- * Copyright (c) 2014-present, Facebook, Inc.
1064
- *
1065
- * This source code is licensed under the MIT license found in the
1066
- * LICENSE file in the root directory of this source tree.
1067
- */
1068
- var runtime = function (exports) {
1069
-
1070
- var Op = Object.prototype;
1071
- var hasOwn = Op.hasOwnProperty;
1072
- var undefined$1; // More compressible than void 0.
1073
-
1074
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
1075
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
1076
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
1077
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1078
-
1079
- function define(obj, key, value) {
1080
- Object.defineProperty(obj, key, {
1081
- value: value,
1082
- enumerable: true,
1083
- configurable: true,
1084
- writable: true
1085
- });
1086
- return obj[key];
1087
- }
1089
+ var runtime_1 = createCommonjsModule(function (module) {
1090
+ /**
1091
+ * Copyright (c) 2014-present, Facebook, Inc.
1092
+ *
1093
+ * This source code is licensed under the MIT license found in the
1094
+ * LICENSE file in the root directory of this source tree.
1095
+ */
1088
1096
 
1089
- try {
1090
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
1091
- define({}, "");
1092
- } catch (err) {
1093
- define = function define(obj, key, value) {
1094
- return obj[key] = value;
1095
- };
1096
- }
1097
+ var runtime = (function (exports) {
1098
+
1099
+ var Op = Object.prototype;
1100
+ var hasOwn = Op.hasOwnProperty;
1101
+ var undefined$1; // More compressible than void 0.
1102
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
1103
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
1104
+ var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
1105
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1106
+
1107
+ function define(obj, key, value) {
1108
+ Object.defineProperty(obj, key, {
1109
+ value: value,
1110
+ enumerable: true,
1111
+ configurable: true,
1112
+ writable: true
1113
+ });
1114
+ return obj[key];
1115
+ }
1116
+ try {
1117
+ // IE 8 has a broken Object.defineProperty that only works on DOM objects.
1118
+ define({}, "");
1119
+ } catch (err) {
1120
+ define = function(obj, key, value) {
1121
+ return obj[key] = value;
1122
+ };
1123
+ }
1097
1124
 
1098
- function wrap(innerFn, outerFn, self, tryLocsList) {
1099
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
1100
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
1101
- var generator = Object.create(protoGenerator.prototype);
1102
- var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
1103
- // .throw, and .return methods.
1125
+ function wrap(innerFn, outerFn, self, tryLocsList) {
1126
+ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
1127
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
1128
+ var generator = Object.create(protoGenerator.prototype);
1129
+ var context = new Context(tryLocsList || []);
1104
1130
 
1105
- generator._invoke = makeInvokeMethod(innerFn, self, context);
1106
- return generator;
1107
- }
1131
+ // The ._invoke method unifies the implementations of the .next,
1132
+ // .throw, and .return methods.
1133
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
1108
1134
 
1109
- exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
1110
- // record like context.tryEntries[i].completion. This interface could
1111
- // have been (and was previously) designed to take a closure to be
1112
- // invoked without arguments, but in all the cases we care about we
1113
- // already have an existing method we want to call, so there's no need
1114
- // to create a new function object. We can even get away with assuming
1115
- // the method takes exactly one argument, since that happens to be true
1116
- // in every case, so we don't have to touch the arguments object. The
1117
- // only additional allocation required is the completion record, which
1118
- // has a stable shape and so hopefully should be cheap to allocate.
1119
-
1120
- function tryCatch(fn, obj, arg) {
1121
- try {
1122
- return {
1123
- type: "normal",
1124
- arg: fn.call(obj, arg)
1125
- };
1126
- } catch (err) {
1127
- return {
1128
- type: "throw",
1129
- arg: err
1130
- };
1131
- }
1135
+ return generator;
1136
+ }
1137
+ exports.wrap = wrap;
1138
+
1139
+ // Try/catch helper to minimize deoptimizations. Returns a completion
1140
+ // record like context.tryEntries[i].completion. This interface could
1141
+ // have been (and was previously) designed to take a closure to be
1142
+ // invoked without arguments, but in all the cases we care about we
1143
+ // already have an existing method we want to call, so there's no need
1144
+ // to create a new function object. We can even get away with assuming
1145
+ // the method takes exactly one argument, since that happens to be true
1146
+ // in every case, so we don't have to touch the arguments object. The
1147
+ // only additional allocation required is the completion record, which
1148
+ // has a stable shape and so hopefully should be cheap to allocate.
1149
+ function tryCatch(fn, obj, arg) {
1150
+ try {
1151
+ return { type: "normal", arg: fn.call(obj, arg) };
1152
+ } catch (err) {
1153
+ return { type: "throw", arg: err };
1132
1154
  }
1155
+ }
1133
1156
 
1134
- var GenStateSuspendedStart = "suspendedStart";
1135
- var GenStateSuspendedYield = "suspendedYield";
1136
- var GenStateExecuting = "executing";
1137
- var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
1138
- // breaking out of the dispatch switch statement.
1139
-
1140
- var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
1141
- // .constructor.prototype properties for functions that return Generator
1142
- // objects. For full spec compliance, you may wish to configure your
1143
- // minifier not to mangle the names of these two functions.
1144
-
1145
- function Generator() {}
1146
-
1147
- function GeneratorFunction() {}
1148
-
1149
- function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
1150
- // don't natively support it.
1157
+ var GenStateSuspendedStart = "suspendedStart";
1158
+ var GenStateSuspendedYield = "suspendedYield";
1159
+ var GenStateExecuting = "executing";
1160
+ var GenStateCompleted = "completed";
1161
+
1162
+ // Returning this object from the innerFn has the same effect as
1163
+ // breaking out of the dispatch switch statement.
1164
+ var ContinueSentinel = {};
1165
+
1166
+ // Dummy constructor functions that we use as the .constructor and
1167
+ // .constructor.prototype properties for functions that return Generator
1168
+ // objects. For full spec compliance, you may wish to configure your
1169
+ // minifier not to mangle the names of these two functions.
1170
+ function Generator() {}
1171
+ function GeneratorFunction() {}
1172
+ function GeneratorFunctionPrototype() {}
1173
+
1174
+ // This is a polyfill for %IteratorPrototype% for environments that
1175
+ // don't natively support it.
1176
+ var IteratorPrototype = {};
1177
+ define(IteratorPrototype, iteratorSymbol, function () {
1178
+ return this;
1179
+ });
1151
1180
 
1181
+ var getProto = Object.getPrototypeOf;
1182
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1183
+ if (NativeIteratorPrototype &&
1184
+ NativeIteratorPrototype !== Op &&
1185
+ hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
1186
+ // This environment has a native %IteratorPrototype%; use it instead
1187
+ // of the polyfill.
1188
+ IteratorPrototype = NativeIteratorPrototype;
1189
+ }
1152
1190
 
1153
- var IteratorPrototype = {};
1154
- define(IteratorPrototype, iteratorSymbol, function () {
1155
- return this;
1191
+ var Gp = GeneratorFunctionPrototype.prototype =
1192
+ Generator.prototype = Object.create(IteratorPrototype);
1193
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
1194
+ define(Gp, "constructor", GeneratorFunctionPrototype);
1195
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
1196
+ GeneratorFunction.displayName = define(
1197
+ GeneratorFunctionPrototype,
1198
+ toStringTagSymbol,
1199
+ "GeneratorFunction"
1200
+ );
1201
+
1202
+ // Helper for defining the .next, .throw, and .return methods of the
1203
+ // Iterator interface in terms of a single ._invoke method.
1204
+ function defineIteratorMethods(prototype) {
1205
+ ["next", "throw", "return"].forEach(function(method) {
1206
+ define(prototype, method, function(arg) {
1207
+ return this._invoke(method, arg);
1208
+ });
1156
1209
  });
1157
- var getProto = Object.getPrototypeOf;
1158
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1210
+ }
1159
1211
 
1160
- if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
1161
- // This environment has a native %IteratorPrototype%; use it instead
1162
- // of the polyfill.
1163
- IteratorPrototype = NativeIteratorPrototype;
1164
- }
1212
+ exports.isGeneratorFunction = function(genFun) {
1213
+ var ctor = typeof genFun === "function" && genFun.constructor;
1214
+ return ctor
1215
+ ? ctor === GeneratorFunction ||
1216
+ // For the native GeneratorFunction constructor, the best we can
1217
+ // do is to check its .name property.
1218
+ (ctor.displayName || ctor.name) === "GeneratorFunction"
1219
+ : false;
1220
+ };
1165
1221
 
1166
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1167
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
1168
- define(Gp, "constructor", GeneratorFunctionPrototype);
1169
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
1170
- GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
1171
- // Iterator interface in terms of a single ._invoke method.
1172
-
1173
- function defineIteratorMethods(prototype) {
1174
- ["next", "throw", "return"].forEach(function (method) {
1175
- define(prototype, method, function (arg) {
1176
- return this._invoke(method, arg);
1177
- });
1178
- });
1222
+ exports.mark = function(genFun) {
1223
+ if (Object.setPrototypeOf) {
1224
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
1225
+ } else {
1226
+ genFun.__proto__ = GeneratorFunctionPrototype;
1227
+ define(genFun, toStringTagSymbol, "GeneratorFunction");
1179
1228
  }
1229
+ genFun.prototype = Object.create(Gp);
1230
+ return genFun;
1231
+ };
1180
1232
 
1181
- exports.isGeneratorFunction = function (genFun) {
1182
- var ctor = typeof genFun === "function" && genFun.constructor;
1183
- return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
1184
- // do is to check its .name property.
1185
- (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
1186
- };
1233
+ // Within the body of any async function, `await x` is transformed to
1234
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
1235
+ // `hasOwn.call(value, "__await")` to determine if the yielded value is
1236
+ // meant to be awaited.
1237
+ exports.awrap = function(arg) {
1238
+ return { __await: arg };
1239
+ };
1187
1240
 
1188
- exports.mark = function (genFun) {
1189
- if (Object.setPrototypeOf) {
1190
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
1241
+ function AsyncIterator(generator, PromiseImpl) {
1242
+ function invoke(method, arg, resolve, reject) {
1243
+ var record = tryCatch(generator[method], generator, arg);
1244
+ if (record.type === "throw") {
1245
+ reject(record.arg);
1191
1246
  } else {
1192
- genFun.__proto__ = GeneratorFunctionPrototype;
1193
- define(genFun, toStringTagSymbol, "GeneratorFunction");
1194
- }
1195
-
1196
- genFun.prototype = Object.create(Gp);
1197
- return genFun;
1198
- }; // Within the body of any async function, `await x` is transformed to
1199
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
1200
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
1201
- // meant to be awaited.
1202
-
1203
-
1204
- exports.awrap = function (arg) {
1205
- return {
1206
- __await: arg
1207
- };
1208
- };
1209
-
1210
- function AsyncIterator(generator, PromiseImpl) {
1211
- function invoke(method, arg, resolve, reject) {
1212
- var record = tryCatch(generator[method], generator, arg);
1213
-
1214
- if (record.type === "throw") {
1215
- reject(record.arg);
1216
- } else {
1217
- var result = record.arg;
1218
- var value = result.value;
1219
-
1220
- if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
1221
- return PromiseImpl.resolve(value.__await).then(function (value) {
1222
- invoke("next", value, resolve, reject);
1223
- }, function (err) {
1224
- invoke("throw", err, resolve, reject);
1225
- });
1226
- }
1227
-
1228
- return PromiseImpl.resolve(value).then(function (unwrapped) {
1229
- // When a yielded Promise is resolved, its final value becomes
1230
- // the .value of the Promise<{value,done}> result for the
1231
- // current iteration.
1232
- result.value = unwrapped;
1233
- resolve(result);
1234
- }, function (error) {
1235
- // If a rejected Promise was yielded, throw the rejection back
1236
- // into the async generator function so it can be handled there.
1237
- return invoke("throw", error, resolve, reject);
1247
+ var result = record.arg;
1248
+ var value = result.value;
1249
+ if (value &&
1250
+ typeof value === "object" &&
1251
+ hasOwn.call(value, "__await")) {
1252
+ return PromiseImpl.resolve(value.__await).then(function(value) {
1253
+ invoke("next", value, resolve, reject);
1254
+ }, function(err) {
1255
+ invoke("throw", err, resolve, reject);
1238
1256
  });
1239
1257
  }
1258
+
1259
+ return PromiseImpl.resolve(value).then(function(unwrapped) {
1260
+ // When a yielded Promise is resolved, its final value becomes
1261
+ // the .value of the Promise<{value,done}> result for the
1262
+ // current iteration.
1263
+ result.value = unwrapped;
1264
+ resolve(result);
1265
+ }, function(error) {
1266
+ // If a rejected Promise was yielded, throw the rejection back
1267
+ // into the async generator function so it can be handled there.
1268
+ return invoke("throw", error, resolve, reject);
1269
+ });
1240
1270
  }
1271
+ }
1241
1272
 
1242
- var previousPromise;
1273
+ var previousPromise;
1243
1274
 
1244
- function enqueue(method, arg) {
1245
- function callInvokeWithMethodAndArg() {
1246
- return new PromiseImpl(function (resolve, reject) {
1247
- invoke(method, arg, resolve, reject);
1248
- });
1249
- }
1275
+ function enqueue(method, arg) {
1276
+ function callInvokeWithMethodAndArg() {
1277
+ return new PromiseImpl(function(resolve, reject) {
1278
+ invoke(method, arg, resolve, reject);
1279
+ });
1280
+ }
1250
1281
 
1251
- return previousPromise = // If enqueue has been called before, then we want to wait until
1282
+ return previousPromise =
1283
+ // If enqueue has been called before, then we want to wait until
1252
1284
  // all previous Promises have been resolved before calling invoke,
1253
1285
  // so that results are always delivered in the correct order. If
1254
1286
  // enqueue has not been called before, then it is important to
@@ -1260,527 +1292,554 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1260
1292
  // execute code before the first await. Since we implement simple
1261
1293
  // async functions in terms of async generators, it is especially
1262
1294
  // important to get this right, even though it requires care.
1263
- previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
1264
- // invocations of the iterator.
1265
- callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1266
- } // Define the unified helper method that is used to implement .next,
1267
- // .throw, and .return (see defineIteratorMethods).
1268
-
1269
-
1270
- this._invoke = enqueue;
1295
+ previousPromise ? previousPromise.then(
1296
+ callInvokeWithMethodAndArg,
1297
+ // Avoid propagating failures to Promises returned by later
1298
+ // invocations of the iterator.
1299
+ callInvokeWithMethodAndArg
1300
+ ) : callInvokeWithMethodAndArg();
1271
1301
  }
1272
1302
 
1273
- defineIteratorMethods(AsyncIterator.prototype);
1274
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1275
- return this;
1276
- });
1277
- exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
1278
- // AsyncIterator objects; they just return a Promise for the value of
1279
- // the final result produced by the iterator.
1280
-
1281
- exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1282
- if (PromiseImpl === void 0) PromiseImpl = Promise;
1283
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1284
- return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
1285
- : iter.next().then(function (result) {
1286
- return result.done ? result.value : iter.next();
1287
- });
1288
- };
1303
+ // Define the unified helper method that is used to implement .next,
1304
+ // .throw, and .return (see defineIteratorMethods).
1305
+ this._invoke = enqueue;
1306
+ }
1289
1307
 
1290
- function makeInvokeMethod(innerFn, self, context) {
1291
- var state = GenStateSuspendedStart;
1292
- return function invoke(method, arg) {
1293
- if (state === GenStateExecuting) {
1294
- throw new Error("Generator is already running");
1295
- }
1308
+ defineIteratorMethods(AsyncIterator.prototype);
1309
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1310
+ return this;
1311
+ });
1312
+ exports.AsyncIterator = AsyncIterator;
1313
+
1314
+ // Note that simple async functions are implemented on top of
1315
+ // AsyncIterator objects; they just return a Promise for the value of
1316
+ // the final result produced by the iterator.
1317
+ exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1318
+ if (PromiseImpl === void 0) PromiseImpl = Promise;
1319
+
1320
+ var iter = new AsyncIterator(
1321
+ wrap(innerFn, outerFn, self, tryLocsList),
1322
+ PromiseImpl
1323
+ );
1324
+
1325
+ return exports.isGeneratorFunction(outerFn)
1326
+ ? iter // If outerFn is a generator, return the full iterator.
1327
+ : iter.next().then(function(result) {
1328
+ return result.done ? result.value : iter.next();
1329
+ });
1330
+ };
1296
1331
 
1297
- if (state === GenStateCompleted) {
1298
- if (method === "throw") {
1299
- throw arg;
1300
- } // Be forgiving, per 25.3.3.3.3 of the spec:
1301
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
1332
+ function makeInvokeMethod(innerFn, self, context) {
1333
+ var state = GenStateSuspendedStart;
1302
1334
 
1335
+ return function invoke(method, arg) {
1336
+ if (state === GenStateExecuting) {
1337
+ throw new Error("Generator is already running");
1338
+ }
1303
1339
 
1304
- return doneResult();
1340
+ if (state === GenStateCompleted) {
1341
+ if (method === "throw") {
1342
+ throw arg;
1305
1343
  }
1306
1344
 
1307
- context.method = method;
1308
- context.arg = arg;
1309
-
1310
- while (true) {
1311
- var delegate = context.delegate;
1345
+ // Be forgiving, per 25.3.3.3.3 of the spec:
1346
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
1347
+ return doneResult();
1348
+ }
1312
1349
 
1313
- if (delegate) {
1314
- var delegateResult = maybeInvokeDelegate(delegate, context);
1350
+ context.method = method;
1351
+ context.arg = arg;
1315
1352
 
1316
- if (delegateResult) {
1317
- if (delegateResult === ContinueSentinel) continue;
1318
- return delegateResult;
1319
- }
1353
+ while (true) {
1354
+ var delegate = context.delegate;
1355
+ if (delegate) {
1356
+ var delegateResult = maybeInvokeDelegate(delegate, context);
1357
+ if (delegateResult) {
1358
+ if (delegateResult === ContinueSentinel) continue;
1359
+ return delegateResult;
1320
1360
  }
1361
+ }
1321
1362
 
1322
- if (context.method === "next") {
1323
- // Setting context._sent for legacy support of Babel's
1324
- // function.sent implementation.
1325
- context.sent = context._sent = context.arg;
1326
- } else if (context.method === "throw") {
1327
- if (state === GenStateSuspendedStart) {
1328
- state = GenStateCompleted;
1329
- throw context.arg;
1330
- }
1363
+ if (context.method === "next") {
1364
+ // Setting context._sent for legacy support of Babel's
1365
+ // function.sent implementation.
1366
+ context.sent = context._sent = context.arg;
1331
1367
 
1332
- context.dispatchException(context.arg);
1333
- } else if (context.method === "return") {
1334
- context.abrupt("return", context.arg);
1368
+ } else if (context.method === "throw") {
1369
+ if (state === GenStateSuspendedStart) {
1370
+ state = GenStateCompleted;
1371
+ throw context.arg;
1335
1372
  }
1336
1373
 
1337
- state = GenStateExecuting;
1338
- var record = tryCatch(innerFn, self, context);
1374
+ context.dispatchException(context.arg);
1339
1375
 
1340
- if (record.type === "normal") {
1341
- // If an exception is thrown from innerFn, we leave state ===
1342
- // GenStateExecuting and loop back for another invocation.
1343
- state = context.done ? GenStateCompleted : GenStateSuspendedYield;
1376
+ } else if (context.method === "return") {
1377
+ context.abrupt("return", context.arg);
1378
+ }
1344
1379
 
1345
- if (record.arg === ContinueSentinel) {
1346
- continue;
1347
- }
1380
+ state = GenStateExecuting;
1348
1381
 
1349
- return {
1350
- value: record.arg,
1351
- done: context.done
1352
- };
1353
- } else if (record.type === "throw") {
1354
- state = GenStateCompleted; // Dispatch the exception by looping back around to the
1355
- // context.dispatchException(context.arg) call above.
1382
+ var record = tryCatch(innerFn, self, context);
1383
+ if (record.type === "normal") {
1384
+ // If an exception is thrown from innerFn, we leave state ===
1385
+ // GenStateExecuting and loop back for another invocation.
1386
+ state = context.done
1387
+ ? GenStateCompleted
1388
+ : GenStateSuspendedYield;
1356
1389
 
1357
- context.method = "throw";
1358
- context.arg = record.arg;
1359
- }
1360
- }
1361
- };
1362
- } // Call delegate.iterator[context.method](context.arg) and handle the
1363
- // result, either by returning a { value, done } result from the
1364
- // delegate iterator, or by modifying context.method and context.arg,
1365
- // setting context.delegate to null, and returning the ContinueSentinel.
1366
-
1367
-
1368
- function maybeInvokeDelegate(delegate, context) {
1369
- var method = delegate.iterator[context.method];
1370
-
1371
- if (method === undefined$1) {
1372
- // A .throw or .return when the delegate iterator has no .throw
1373
- // method always terminates the yield* loop.
1374
- context.delegate = null;
1375
-
1376
- if (context.method === "throw") {
1377
- // Note: ["return"] must be used for ES3 parsing compatibility.
1378
- if (delegate.iterator["return"]) {
1379
- // If the delegate iterator has a return method, give it a
1380
- // chance to clean up.
1381
- context.method = "return";
1382
- context.arg = undefined$1;
1383
- maybeInvokeDelegate(delegate, context);
1384
-
1385
- if (context.method === "throw") {
1386
- // If maybeInvokeDelegate(context) changed context.method from
1387
- // "return" to "throw", let that override the TypeError below.
1388
- return ContinueSentinel;
1389
- }
1390
+ if (record.arg === ContinueSentinel) {
1391
+ continue;
1390
1392
  }
1391
1393
 
1394
+ return {
1395
+ value: record.arg,
1396
+ done: context.done
1397
+ };
1398
+
1399
+ } else if (record.type === "throw") {
1400
+ state = GenStateCompleted;
1401
+ // Dispatch the exception by looping back around to the
1402
+ // context.dispatchException(context.arg) call above.
1392
1403
  context.method = "throw";
1393
- context.arg = new TypeError("The iterator does not provide a 'throw' method");
1404
+ context.arg = record.arg;
1394
1405
  }
1395
-
1396
- return ContinueSentinel;
1397
1406
  }
1407
+ };
1408
+ }
1398
1409
 
1399
- var record = tryCatch(method, delegate.iterator, context.arg);
1410
+ // Call delegate.iterator[context.method](context.arg) and handle the
1411
+ // result, either by returning a { value, done } result from the
1412
+ // delegate iterator, or by modifying context.method and context.arg,
1413
+ // setting context.delegate to null, and returning the ContinueSentinel.
1414
+ function maybeInvokeDelegate(delegate, context) {
1415
+ var method = delegate.iterator[context.method];
1416
+ if (method === undefined$1) {
1417
+ // A .throw or .return when the delegate iterator has no .throw
1418
+ // method always terminates the yield* loop.
1419
+ context.delegate = null;
1400
1420
 
1401
- if (record.type === "throw") {
1402
- context.method = "throw";
1403
- context.arg = record.arg;
1404
- context.delegate = null;
1405
- return ContinueSentinel;
1406
- }
1421
+ if (context.method === "throw") {
1422
+ // Note: ["return"] must be used for ES3 parsing compatibility.
1423
+ if (delegate.iterator["return"]) {
1424
+ // If the delegate iterator has a return method, give it a
1425
+ // chance to clean up.
1426
+ context.method = "return";
1427
+ context.arg = undefined$1;
1428
+ maybeInvokeDelegate(delegate, context);
1407
1429
 
1408
- var info = record.arg;
1430
+ if (context.method === "throw") {
1431
+ // If maybeInvokeDelegate(context) changed context.method from
1432
+ // "return" to "throw", let that override the TypeError below.
1433
+ return ContinueSentinel;
1434
+ }
1435
+ }
1409
1436
 
1410
- if (!info) {
1411
1437
  context.method = "throw";
1412
- context.arg = new TypeError("iterator result is not an object");
1413
- context.delegate = null;
1414
- return ContinueSentinel;
1438
+ context.arg = new TypeError(
1439
+ "The iterator does not provide a 'throw' method");
1415
1440
  }
1416
1441
 
1417
- if (info.done) {
1418
- // Assign the result of the finished delegate to the temporary
1419
- // variable specified by delegate.resultName (see delegateYield).
1420
- context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
1421
-
1422
- context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
1423
- // exception, let the outer generator proceed normally. If
1424
- // context.method was "next", forget context.arg since it has been
1425
- // "consumed" by the delegate iterator. If context.method was
1426
- // "return", allow the original .return call to continue in the
1427
- // outer generator.
1428
-
1429
- if (context.method !== "return") {
1430
- context.method = "next";
1431
- context.arg = undefined$1;
1432
- }
1433
- } else {
1434
- // Re-yield the result returned by the delegate method.
1435
- return info;
1436
- } // The delegate iterator is finished, so forget it and continue with
1437
- // the outer generator.
1442
+ return ContinueSentinel;
1443
+ }
1438
1444
 
1445
+ var record = tryCatch(method, delegate.iterator, context.arg);
1439
1446
 
1447
+ if (record.type === "throw") {
1448
+ context.method = "throw";
1449
+ context.arg = record.arg;
1440
1450
  context.delegate = null;
1441
1451
  return ContinueSentinel;
1442
- } // Define Generator.prototype.{next,throw,return} in terms of the
1443
- // unified ._invoke helper method.
1444
-
1445
-
1446
- defineIteratorMethods(Gp);
1447
- define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
1448
- // @@iterator function is called on it. Some browsers' implementations of the
1449
- // iterator prototype chain incorrectly implement this, causing the Generator
1450
- // object to not be returned from this call. This ensures that doesn't happen.
1451
- // See https://github.com/facebook/regenerator/issues/274 for more details.
1452
-
1453
- define(Gp, iteratorSymbol, function () {
1454
- return this;
1455
- });
1456
- define(Gp, "toString", function () {
1457
- return "[object Generator]";
1458
- });
1452
+ }
1459
1453
 
1460
- function pushTryEntry(locs) {
1461
- var entry = {
1462
- tryLoc: locs[0]
1463
- };
1454
+ var info = record.arg;
1464
1455
 
1465
- if (1 in locs) {
1466
- entry.catchLoc = locs[1];
1467
- }
1456
+ if (! info) {
1457
+ context.method = "throw";
1458
+ context.arg = new TypeError("iterator result is not an object");
1459
+ context.delegate = null;
1460
+ return ContinueSentinel;
1461
+ }
1468
1462
 
1469
- if (2 in locs) {
1470
- entry.finallyLoc = locs[2];
1471
- entry.afterLoc = locs[3];
1463
+ if (info.done) {
1464
+ // Assign the result of the finished delegate to the temporary
1465
+ // variable specified by delegate.resultName (see delegateYield).
1466
+ context[delegate.resultName] = info.value;
1467
+
1468
+ // Resume execution at the desired location (see delegateYield).
1469
+ context.next = delegate.nextLoc;
1470
+
1471
+ // If context.method was "throw" but the delegate handled the
1472
+ // exception, let the outer generator proceed normally. If
1473
+ // context.method was "next", forget context.arg since it has been
1474
+ // "consumed" by the delegate iterator. If context.method was
1475
+ // "return", allow the original .return call to continue in the
1476
+ // outer generator.
1477
+ if (context.method !== "return") {
1478
+ context.method = "next";
1479
+ context.arg = undefined$1;
1472
1480
  }
1473
1481
 
1474
- this.tryEntries.push(entry);
1482
+ } else {
1483
+ // Re-yield the result returned by the delegate method.
1484
+ return info;
1475
1485
  }
1476
1486
 
1477
- function resetTryEntry(entry) {
1478
- var record = entry.completion || {};
1479
- record.type = "normal";
1480
- delete record.arg;
1481
- entry.completion = record;
1482
- }
1487
+ // The delegate iterator is finished, so forget it and continue with
1488
+ // the outer generator.
1489
+ context.delegate = null;
1490
+ return ContinueSentinel;
1491
+ }
1483
1492
 
1484
- function Context(tryLocsList) {
1485
- // The root entry object (effectively a try statement without a catch
1486
- // or a finally block) gives us a place to store values thrown from
1487
- // locations where there is no enclosing try statement.
1488
- this.tryEntries = [{
1489
- tryLoc: "root"
1490
- }];
1491
- tryLocsList.forEach(pushTryEntry, this);
1492
- this.reset(true);
1493
- }
1493
+ // Define Generator.prototype.{next,throw,return} in terms of the
1494
+ // unified ._invoke helper method.
1495
+ defineIteratorMethods(Gp);
1494
1496
 
1495
- exports.keys = function (object) {
1496
- var keys = [];
1497
+ define(Gp, toStringTagSymbol, "Generator");
1497
1498
 
1498
- for (var key in object) {
1499
- keys.push(key);
1500
- }
1499
+ // A Generator should always return itself as the iterator object when the
1500
+ // @@iterator function is called on it. Some browsers' implementations of the
1501
+ // iterator prototype chain incorrectly implement this, causing the Generator
1502
+ // object to not be returned from this call. This ensures that doesn't happen.
1503
+ // See https://github.com/facebook/regenerator/issues/274 for more details.
1504
+ define(Gp, iteratorSymbol, function() {
1505
+ return this;
1506
+ });
1501
1507
 
1502
- keys.reverse(); // Rather than returning an object with a next method, we keep
1503
- // things simple and return the next function itself.
1508
+ define(Gp, "toString", function() {
1509
+ return "[object Generator]";
1510
+ });
1504
1511
 
1505
- return function next() {
1506
- while (keys.length) {
1507
- var key = keys.pop();
1512
+ function pushTryEntry(locs) {
1513
+ var entry = { tryLoc: locs[0] };
1508
1514
 
1509
- if (key in object) {
1510
- next.value = key;
1511
- next.done = false;
1512
- return next;
1513
- }
1514
- } // To avoid creating an additional object, we just hang the .value
1515
- // and .done properties off the next function object itself. This
1516
- // also ensures that the minifier will not anonymize the function.
1515
+ if (1 in locs) {
1516
+ entry.catchLoc = locs[1];
1517
+ }
1517
1518
 
1519
+ if (2 in locs) {
1520
+ entry.finallyLoc = locs[2];
1521
+ entry.afterLoc = locs[3];
1522
+ }
1518
1523
 
1519
- next.done = true;
1520
- return next;
1521
- };
1522
- };
1524
+ this.tryEntries.push(entry);
1525
+ }
1523
1526
 
1524
- function values(iterable) {
1525
- if (iterable) {
1526
- var iteratorMethod = iterable[iteratorSymbol];
1527
+ function resetTryEntry(entry) {
1528
+ var record = entry.completion || {};
1529
+ record.type = "normal";
1530
+ delete record.arg;
1531
+ entry.completion = record;
1532
+ }
1527
1533
 
1528
- if (iteratorMethod) {
1529
- return iteratorMethod.call(iterable);
1530
- }
1534
+ function Context(tryLocsList) {
1535
+ // The root entry object (effectively a try statement without a catch
1536
+ // or a finally block) gives us a place to store values thrown from
1537
+ // locations where there is no enclosing try statement.
1538
+ this.tryEntries = [{ tryLoc: "root" }];
1539
+ tryLocsList.forEach(pushTryEntry, this);
1540
+ this.reset(true);
1541
+ }
1531
1542
 
1532
- if (typeof iterable.next === "function") {
1533
- return iterable;
1543
+ exports.keys = function(object) {
1544
+ var keys = [];
1545
+ for (var key in object) {
1546
+ keys.push(key);
1547
+ }
1548
+ keys.reverse();
1549
+
1550
+ // Rather than returning an object with a next method, we keep
1551
+ // things simple and return the next function itself.
1552
+ return function next() {
1553
+ while (keys.length) {
1554
+ var key = keys.pop();
1555
+ if (key in object) {
1556
+ next.value = key;
1557
+ next.done = false;
1558
+ return next;
1534
1559
  }
1560
+ }
1535
1561
 
1536
- if (!isNaN(iterable.length)) {
1537
- var i = -1,
1538
- next = function next() {
1539
- while (++i < iterable.length) {
1540
- if (hasOwn.call(iterable, i)) {
1541
- next.value = iterable[i];
1542
- next.done = false;
1543
- return next;
1544
- }
1545
- }
1562
+ // To avoid creating an additional object, we just hang the .value
1563
+ // and .done properties off the next function object itself. This
1564
+ // also ensures that the minifier will not anonymize the function.
1565
+ next.done = true;
1566
+ return next;
1567
+ };
1568
+ };
1546
1569
 
1547
- next.value = undefined$1;
1548
- next.done = true;
1549
- return next;
1550
- };
1570
+ function values(iterable) {
1571
+ if (iterable) {
1572
+ var iteratorMethod = iterable[iteratorSymbol];
1573
+ if (iteratorMethod) {
1574
+ return iteratorMethod.call(iterable);
1575
+ }
1551
1576
 
1552
- return next.next = next;
1553
- }
1554
- } // Return an iterator with no values.
1577
+ if (typeof iterable.next === "function") {
1578
+ return iterable;
1579
+ }
1555
1580
 
1581
+ if (!isNaN(iterable.length)) {
1582
+ var i = -1, next = function next() {
1583
+ while (++i < iterable.length) {
1584
+ if (hasOwn.call(iterable, i)) {
1585
+ next.value = iterable[i];
1586
+ next.done = false;
1587
+ return next;
1588
+ }
1589
+ }
1556
1590
 
1557
- return {
1558
- next: doneResult
1559
- };
1560
- }
1591
+ next.value = undefined$1;
1592
+ next.done = true;
1561
1593
 
1562
- exports.values = values;
1594
+ return next;
1595
+ };
1563
1596
 
1564
- function doneResult() {
1565
- return {
1566
- value: undefined$1,
1567
- done: true
1568
- };
1597
+ return next.next = next;
1598
+ }
1569
1599
  }
1570
1600
 
1571
- Context.prototype = {
1572
- constructor: Context,
1573
- reset: function reset(skipTempReset) {
1574
- this.prev = 0;
1575
- this.next = 0; // Resetting context._sent for legacy support of Babel's
1576
- // function.sent implementation.
1601
+ // Return an iterator with no values.
1602
+ return { next: doneResult };
1603
+ }
1604
+ exports.values = values;
1577
1605
 
1578
- this.sent = this._sent = undefined$1;
1579
- this.done = false;
1580
- this.delegate = null;
1581
- this.method = "next";
1582
- this.arg = undefined$1;
1583
- this.tryEntries.forEach(resetTryEntry);
1606
+ function doneResult() {
1607
+ return { value: undefined$1, done: true };
1608
+ }
1584
1609
 
1585
- if (!skipTempReset) {
1586
- for (var name in this) {
1587
- // Not sure about the optimal order of these conditions:
1588
- if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
1589
- this[name] = undefined$1;
1590
- }
1610
+ Context.prototype = {
1611
+ constructor: Context,
1612
+
1613
+ reset: function(skipTempReset) {
1614
+ this.prev = 0;
1615
+ this.next = 0;
1616
+ // Resetting context._sent for legacy support of Babel's
1617
+ // function.sent implementation.
1618
+ this.sent = this._sent = undefined$1;
1619
+ this.done = false;
1620
+ this.delegate = null;
1621
+
1622
+ this.method = "next";
1623
+ this.arg = undefined$1;
1624
+
1625
+ this.tryEntries.forEach(resetTryEntry);
1626
+
1627
+ if (!skipTempReset) {
1628
+ for (var name in this) {
1629
+ // Not sure about the optimal order of these conditions:
1630
+ if (name.charAt(0) === "t" &&
1631
+ hasOwn.call(this, name) &&
1632
+ !isNaN(+name.slice(1))) {
1633
+ this[name] = undefined$1;
1591
1634
  }
1592
1635
  }
1593
- },
1594
- stop: function stop() {
1595
- this.done = true;
1596
- var rootEntry = this.tryEntries[0];
1597
- var rootRecord = rootEntry.completion;
1636
+ }
1637
+ },
1598
1638
 
1599
- if (rootRecord.type === "throw") {
1600
- throw rootRecord.arg;
1601
- }
1639
+ stop: function() {
1640
+ this.done = true;
1602
1641
 
1603
- return this.rval;
1604
- },
1605
- dispatchException: function dispatchException(exception) {
1606
- if (this.done) {
1607
- throw exception;
1608
- }
1642
+ var rootEntry = this.tryEntries[0];
1643
+ var rootRecord = rootEntry.completion;
1644
+ if (rootRecord.type === "throw") {
1645
+ throw rootRecord.arg;
1646
+ }
1609
1647
 
1610
- var context = this;
1648
+ return this.rval;
1649
+ },
1611
1650
 
1612
- function handle(loc, caught) {
1613
- record.type = "throw";
1614
- record.arg = exception;
1615
- context.next = loc;
1651
+ dispatchException: function(exception) {
1652
+ if (this.done) {
1653
+ throw exception;
1654
+ }
1616
1655
 
1617
- if (caught) {
1618
- // If the dispatched exception was caught by a catch block,
1619
- // then let that catch block handle the exception normally.
1620
- context.method = "next";
1621
- context.arg = undefined$1;
1622
- }
1656
+ var context = this;
1657
+ function handle(loc, caught) {
1658
+ record.type = "throw";
1659
+ record.arg = exception;
1660
+ context.next = loc;
1623
1661
 
1624
- return !!caught;
1662
+ if (caught) {
1663
+ // If the dispatched exception was caught by a catch block,
1664
+ // then let that catch block handle the exception normally.
1665
+ context.method = "next";
1666
+ context.arg = undefined$1;
1625
1667
  }
1626
1668
 
1627
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1628
- var entry = this.tryEntries[i];
1629
- var record = entry.completion;
1669
+ return !! caught;
1670
+ }
1630
1671
 
1631
- if (entry.tryLoc === "root") {
1632
- // Exception thrown outside of any try block that could handle
1633
- // it, so set the completion value of the entire function to
1634
- // throw the exception.
1635
- return handle("end");
1636
- }
1672
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1673
+ var entry = this.tryEntries[i];
1674
+ var record = entry.completion;
1637
1675
 
1638
- if (entry.tryLoc <= this.prev) {
1639
- var hasCatch = hasOwn.call(entry, "catchLoc");
1640
- var hasFinally = hasOwn.call(entry, "finallyLoc");
1676
+ if (entry.tryLoc === "root") {
1677
+ // Exception thrown outside of any try block that could handle
1678
+ // it, so set the completion value of the entire function to
1679
+ // throw the exception.
1680
+ return handle("end");
1681
+ }
1641
1682
 
1642
- if (hasCatch && hasFinally) {
1643
- if (this.prev < entry.catchLoc) {
1644
- return handle(entry.catchLoc, true);
1645
- } else if (this.prev < entry.finallyLoc) {
1646
- return handle(entry.finallyLoc);
1647
- }
1648
- } else if (hasCatch) {
1649
- if (this.prev < entry.catchLoc) {
1650
- return handle(entry.catchLoc, true);
1651
- }
1652
- } else if (hasFinally) {
1653
- if (this.prev < entry.finallyLoc) {
1654
- return handle(entry.finallyLoc);
1655
- }
1656
- } else {
1657
- throw new Error("try statement without catch or finally");
1683
+ if (entry.tryLoc <= this.prev) {
1684
+ var hasCatch = hasOwn.call(entry, "catchLoc");
1685
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
1686
+
1687
+ if (hasCatch && hasFinally) {
1688
+ if (this.prev < entry.catchLoc) {
1689
+ return handle(entry.catchLoc, true);
1690
+ } else if (this.prev < entry.finallyLoc) {
1691
+ return handle(entry.finallyLoc);
1692
+ }
1693
+
1694
+ } else if (hasCatch) {
1695
+ if (this.prev < entry.catchLoc) {
1696
+ return handle(entry.catchLoc, true);
1697
+ }
1698
+
1699
+ } else if (hasFinally) {
1700
+ if (this.prev < entry.finallyLoc) {
1701
+ return handle(entry.finallyLoc);
1658
1702
  }
1659
- }
1660
- }
1661
- },
1662
- abrupt: function abrupt(type, arg) {
1663
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1664
- var entry = this.tryEntries[i];
1665
1703
 
1666
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1667
- var finallyEntry = entry;
1668
- break;
1704
+ } else {
1705
+ throw new Error("try statement without catch or finally");
1669
1706
  }
1670
1707
  }
1708
+ }
1709
+ },
1671
1710
 
1672
- if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
1673
- // Ignore the finally entry if control is not jumping to a
1674
- // location outside the try/catch block.
1675
- finallyEntry = null;
1711
+ abrupt: function(type, arg) {
1712
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1713
+ var entry = this.tryEntries[i];
1714
+ if (entry.tryLoc <= this.prev &&
1715
+ hasOwn.call(entry, "finallyLoc") &&
1716
+ this.prev < entry.finallyLoc) {
1717
+ var finallyEntry = entry;
1718
+ break;
1676
1719
  }
1720
+ }
1677
1721
 
1678
- var record = finallyEntry ? finallyEntry.completion : {};
1679
- record.type = type;
1680
- record.arg = arg;
1722
+ if (finallyEntry &&
1723
+ (type === "break" ||
1724
+ type === "continue") &&
1725
+ finallyEntry.tryLoc <= arg &&
1726
+ arg <= finallyEntry.finallyLoc) {
1727
+ // Ignore the finally entry if control is not jumping to a
1728
+ // location outside the try/catch block.
1729
+ finallyEntry = null;
1730
+ }
1681
1731
 
1682
- if (finallyEntry) {
1683
- this.method = "next";
1684
- this.next = finallyEntry.finallyLoc;
1685
- return ContinueSentinel;
1686
- }
1732
+ var record = finallyEntry ? finallyEntry.completion : {};
1733
+ record.type = type;
1734
+ record.arg = arg;
1687
1735
 
1688
- return this.complete(record);
1689
- },
1690
- complete: function complete(record, afterLoc) {
1691
- if (record.type === "throw") {
1692
- throw record.arg;
1693
- }
1736
+ if (finallyEntry) {
1737
+ this.method = "next";
1738
+ this.next = finallyEntry.finallyLoc;
1739
+ return ContinueSentinel;
1740
+ }
1694
1741
 
1695
- if (record.type === "break" || record.type === "continue") {
1696
- this.next = record.arg;
1697
- } else if (record.type === "return") {
1698
- this.rval = this.arg = record.arg;
1699
- this.method = "return";
1700
- this.next = "end";
1701
- } else if (record.type === "normal" && afterLoc) {
1702
- this.next = afterLoc;
1703
- }
1742
+ return this.complete(record);
1743
+ },
1704
1744
 
1705
- return ContinueSentinel;
1706
- },
1707
- finish: function finish(finallyLoc) {
1708
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1709
- var entry = this.tryEntries[i];
1745
+ complete: function(record, afterLoc) {
1746
+ if (record.type === "throw") {
1747
+ throw record.arg;
1748
+ }
1710
1749
 
1711
- if (entry.finallyLoc === finallyLoc) {
1712
- this.complete(entry.completion, entry.afterLoc);
1713
- resetTryEntry(entry);
1714
- return ContinueSentinel;
1715
- }
1716
- }
1717
- },
1718
- "catch": function _catch(tryLoc) {
1719
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1720
- var entry = this.tryEntries[i];
1750
+ if (record.type === "break" ||
1751
+ record.type === "continue") {
1752
+ this.next = record.arg;
1753
+ } else if (record.type === "return") {
1754
+ this.rval = this.arg = record.arg;
1755
+ this.method = "return";
1756
+ this.next = "end";
1757
+ } else if (record.type === "normal" && afterLoc) {
1758
+ this.next = afterLoc;
1759
+ }
1721
1760
 
1722
- if (entry.tryLoc === tryLoc) {
1723
- var record = entry.completion;
1761
+ return ContinueSentinel;
1762
+ },
1724
1763
 
1725
- if (record.type === "throw") {
1726
- var thrown = record.arg;
1727
- resetTryEntry(entry);
1728
- }
1764
+ finish: function(finallyLoc) {
1765
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1766
+ var entry = this.tryEntries[i];
1767
+ if (entry.finallyLoc === finallyLoc) {
1768
+ this.complete(entry.completion, entry.afterLoc);
1769
+ resetTryEntry(entry);
1770
+ return ContinueSentinel;
1771
+ }
1772
+ }
1773
+ },
1729
1774
 
1730
- return thrown;
1775
+ "catch": function(tryLoc) {
1776
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1777
+ var entry = this.tryEntries[i];
1778
+ if (entry.tryLoc === tryLoc) {
1779
+ var record = entry.completion;
1780
+ if (record.type === "throw") {
1781
+ var thrown = record.arg;
1782
+ resetTryEntry(entry);
1731
1783
  }
1732
- } // The context.catch method must only be called with a location
1733
- // argument that corresponds to a known catch block.
1734
-
1784
+ return thrown;
1785
+ }
1786
+ }
1735
1787
 
1736
- throw new Error("illegal catch attempt");
1737
- },
1738
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
1739
- this.delegate = {
1740
- iterator: values(iterable),
1741
- resultName: resultName,
1742
- nextLoc: nextLoc
1743
- };
1788
+ // The context.catch method must only be called with a location
1789
+ // argument that corresponds to a known catch block.
1790
+ throw new Error("illegal catch attempt");
1791
+ },
1744
1792
 
1745
- if (this.method === "next") {
1746
- // Deliberately forget the last sent value so that we don't
1747
- // accidentally pass it on to the delegate.
1748
- this.arg = undefined$1;
1749
- }
1793
+ delegateYield: function(iterable, resultName, nextLoc) {
1794
+ this.delegate = {
1795
+ iterator: values(iterable),
1796
+ resultName: resultName,
1797
+ nextLoc: nextLoc
1798
+ };
1750
1799
 
1751
- return ContinueSentinel;
1800
+ if (this.method === "next") {
1801
+ // Deliberately forget the last sent value so that we don't
1802
+ // accidentally pass it on to the delegate.
1803
+ this.arg = undefined$1;
1752
1804
  }
1753
- }; // Regardless of whether this script is executing as a CommonJS module
1754
- // or not, return the runtime object so that we can declare the variable
1755
- // regeneratorRuntime in the outer scope, which allows this module to be
1756
- // injected easily by `bin/regenerator --include-runtime script.js`.
1757
1805
 
1758
- return exports;
1759
- }( // If this script is executing as a CommonJS module, use module.exports
1806
+ return ContinueSentinel;
1807
+ }
1808
+ };
1809
+
1810
+ // Regardless of whether this script is executing as a CommonJS module
1811
+ // or not, return the runtime object so that we can declare the variable
1812
+ // regeneratorRuntime in the outer scope, which allows this module to be
1813
+ // injected easily by `bin/regenerator --include-runtime script.js`.
1814
+ return exports;
1815
+
1816
+ }(
1817
+ // If this script is executing as a CommonJS module, use module.exports
1760
1818
  // as the regeneratorRuntime namespace. Otherwise create a new empty
1761
1819
  // object. Either way, the resulting object will be used to initialize
1762
1820
  // the regeneratorRuntime variable at the top of this file.
1763
- module.exports );
1764
-
1765
- try {
1766
- regeneratorRuntime = runtime;
1767
- } catch (accidentalStrictMode) {
1768
- // This module should not be running in strict mode, so the above
1769
- // assignment should always work unless something is misconfigured. Just
1770
- // in case runtime.js accidentally runs in strict mode, in modern engines
1771
- // we can explicitly access globalThis. In older engines we can escape
1772
- // strict mode using a global Function call. This could conceivably fail
1773
- // if a Content Security Policy forbids using Function, but in that case
1774
- // the proper solution is to fix the accidental strict mode problem. If
1775
- // you've misconfigured your bundler to force strict mode and applied a
1776
- // CSP to forbid Function, and you're not willing to fix either of those
1777
- // problems, please detail your unique predicament in a GitHub issue.
1778
- if (typeof globalThis === "object") {
1779
- globalThis.regeneratorRuntime = runtime;
1780
- } else {
1781
- Function("r", "regeneratorRuntime = r")(runtime);
1782
- }
1821
+ module.exports
1822
+ ));
1823
+
1824
+ try {
1825
+ regeneratorRuntime = runtime;
1826
+ } catch (accidentalStrictMode) {
1827
+ // This module should not be running in strict mode, so the above
1828
+ // assignment should always work unless something is misconfigured. Just
1829
+ // in case runtime.js accidentally runs in strict mode, in modern engines
1830
+ // we can explicitly access globalThis. In older engines we can escape
1831
+ // strict mode using a global Function call. This could conceivably fail
1832
+ // if a Content Security Policy forbids using Function, but in that case
1833
+ // the proper solution is to fix the accidental strict mode problem. If
1834
+ // you've misconfigured your bundler to force strict mode and applied a
1835
+ // CSP to forbid Function, and you're not willing to fix either of those
1836
+ // problems, please detail your unique predicament in a GitHub issue.
1837
+ if (typeof globalThis === "object") {
1838
+ globalThis.regeneratorRuntime = runtime;
1839
+ } else {
1840
+ Function("r", "regeneratorRuntime = r")(runtime);
1783
1841
  }
1842
+ }
1784
1843
  });
1785
1844
 
1786
1845
  /* eslint-disable you-dont-need-lodash-underscore/find */
@@ -1894,11 +1953,12 @@ function _selectEntityAndInsert() {
1894
1953
  case 12:
1895
1954
  Transforms.select(editor, selection);
1896
1955
  insertBlock(editor, nodeType, entity);
1956
+ ensureFollowingParagraph(editor);
1897
1957
  logAction('insert', {
1898
1958
  nodeType: nodeType
1899
1959
  });
1900
1960
 
1901
- case 15:
1961
+ case 16:
1902
1962
  case "end":
1903
1963
  return _context.stop();
1904
1964
  }
@@ -1908,6 +1968,43 @@ function _selectEntityAndInsert() {
1908
1968
  return _selectEntityAndInsert.apply(this, arguments);
1909
1969
  }
1910
1970
 
1971
+ function ensureFollowingParagraph(editor) {
1972
+ /*
1973
+ If the new block isn't followed by a sibling paragraph we insert a new empty one
1974
+ */
1975
+ var next = Editor.next(editor);
1976
+
1977
+ if (!next) {
1978
+ return insertEmptyParagraph(editor);
1979
+ }
1980
+
1981
+ var parent = Editor.above(editor, {
1982
+ voids: false,
1983
+ match: function match(e) {
1984
+ return !Element.isElement(e) || ![BLOCKS.EMBEDDED_ASSET, BLOCKS.EMBEDDED_ENTRY].includes(e.type);
1985
+ }
1986
+ });
1987
+
1988
+ if (Editor.isEditor(parent)) {
1989
+ // at level 0, a following paragraph is handled by the tralingParagraph plugin
1990
+ moveToTheNextChar(editor);
1991
+ return;
1992
+ }
1993
+
1994
+ var paragraph = Editor.above(editor, {
1995
+ at: next[1],
1996
+ match: function match(e) {
1997
+ return Element.isElement(e) && TEXT_CONTAINERS.includes(e.type);
1998
+ }
1999
+ });
2000
+
2001
+ if (!paragraph || !parent || !Path.isChild(paragraph[1], parent[1])) {
2002
+ return insertEmptyParagraph(editor);
2003
+ }
2004
+
2005
+ moveToTheNextChar(editor);
2006
+ }
2007
+
1911
2008
  var createNode = function createNode(nodeType, entity) {
1912
2009
  return {
1913
2010
  type: nodeType,
@@ -1955,11 +2052,29 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
1955
2052
  var editor = useContentfulEditor();
1956
2053
  var sdk = useSdkContext();
1957
2054
 
1958
- var handleClick = function handleClick(event) {
1959
- event.preventDefault();
1960
- onClose();
1961
- selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onToolbarAction);
1962
- };
2055
+ var handleClick = /*#__PURE__*/function () {
2056
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(event) {
2057
+ return runtime_1.wrap(function _callee$(_context) {
2058
+ while (1) {
2059
+ switch (_context.prev = _context.next) {
2060
+ case 0:
2061
+ event.preventDefault();
2062
+ onClose();
2063
+ _context.next = 4;
2064
+ return selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onToolbarAction);
2065
+
2066
+ case 4:
2067
+ case "end":
2068
+ return _context.stop();
2069
+ }
2070
+ }
2071
+ }, _callee);
2072
+ }));
2073
+
2074
+ return function handleClick(_x) {
2075
+ return _ref2.apply(this, arguments);
2076
+ };
2077
+ }();
1963
2078
 
1964
2079
  var type = getEntityTypeFromNodeType(nodeType);
1965
2080
  var baseClass = "rich-text__" + nodeType;
@@ -2292,15 +2407,18 @@ function _selectEntityAndInsert$1() {
2292
2407
  return _context2.abrupt("return");
2293
2408
 
2294
2409
  case 10:
2295
- inlineEntryNode = createInlineEntryNode(entry.sys.id); // Got to wait until focus is really back on the editor or setSelection() won't work.
2296
-
2297
- setTimeout(function () {
2298
- Transforms.setSelection(editor, selection);
2299
- Transforms.insertNodes(editor, inlineEntryNode);
2300
- }, 0);
2410
+ inlineEntryNode = createInlineEntryNode(entry.sys.id);
2301
2411
  logAction('insert', {
2302
2412
  nodeType: INLINES.EMBEDDED_ENTRY
2303
- });
2413
+ }); // Got to wait until focus is really back on the editor or setSelection() won't work.
2414
+
2415
+ return _context2.abrupt("return", new Promise(function (resolve) {
2416
+ setTimeout(function () {
2417
+ Transforms.setSelection(editor, selection);
2418
+ Transforms.insertNodes(editor, inlineEntryNode);
2419
+ resolve();
2420
+ }, 0);
2421
+ }));
2304
2422
 
2305
2423
  case 13:
2306
2424
  case "end":
@@ -2341,6 +2459,9 @@ function ToolbarEmbeddedEntityInlineButton(props) {
2341
2459
  return selectEntityAndInsert$1(editor, sdk, editor.tracking.onToolbarAction);
2342
2460
 
2343
2461
  case 6:
2462
+ moveToTheNextChar(editor);
2463
+
2464
+ case 7:
2344
2465
  case "end":
2345
2466
  return _context.stop();
2346
2467
  }
@@ -2491,7 +2612,7 @@ function ToolbarHeadingButton(props) {
2491
2612
  var prevOnChange = editor.onChange;
2492
2613
  /*
2493
2614
  The focus might happen at point in time when
2494
- `toggleNodeType` changes aren't rendered yet, causing the browser
2615
+ `toggleElement` (helper for toggleNodeType) changes aren't rendered yet, causing the browser
2495
2616
  to place the cursor at the start of the text.
2496
2617
  We wait for the change event before focusing
2497
2618
  the editor again. This ensures the cursor is back at the previous
@@ -2507,7 +2628,7 @@ function ToolbarHeadingButton(props) {
2507
2628
  editor.tracking.onToolbarAction(isActive ? 'remove' : 'insert', {
2508
2629
  nodeType: type
2509
2630
  });
2510
- toggleNodeType(editor, {
2631
+ toggleElement(editor, {
2511
2632
  activeType: type,
2512
2633
  inactiveType: type
2513
2634
  });
@@ -2637,7 +2758,7 @@ var buildHeadingEventHandler = function buildHeadingEventHandler(type) {
2637
2758
  editor.tracking.onShortcutAction(isActive ? 'remove' : 'insert', {
2638
2759
  nodeType: type
2639
2760
  });
2640
- toggleNodeType(editor, {
2761
+ toggleElement(editor, {
2641
2762
  activeType: type,
2642
2763
  inactiveType: BLOCKS.PARAGRAPH
2643
2764
  });
@@ -3861,7 +3982,7 @@ var listBreak = function listBreak(editor) {
3861
3982
  return !moved && isBlockAboveEmpty(editor);
3862
3983
  },
3863
3984
  onReset: function onReset(_editor) {
3864
- return unwrapList(_editor);
3985
+ return unwrapList$1(_editor);
3865
3986
  }
3866
3987
  }]
3867
3988
  }
@@ -4082,6 +4203,178 @@ var createListPlugin = function createListPlugin() {
4082
4203
  });
4083
4204
  };
4084
4205
 
4206
+ var listTypes = [BLOCKS.UL_LIST, BLOCKS.OL_LIST];
4207
+
4208
+ var unwrapList = function unwrapList(editor, _temp) {
4209
+ var _ref = _temp === void 0 ? {} : _temp,
4210
+ at = _ref.at;
4211
+
4212
+ Editor.withoutNormalizing(editor, function () {
4213
+ do {
4214
+ unwrapNodes(editor, {
4215
+ at: at,
4216
+ match: {
4217
+ type: BLOCKS.LIST_ITEM
4218
+ },
4219
+ split: true
4220
+ });
4221
+ unwrapNodes(editor, {
4222
+ at: at,
4223
+ match: {
4224
+ type: listTypes
4225
+ },
4226
+ split: true
4227
+ });
4228
+ } while (getAbove(editor, {
4229
+ match: {
4230
+ type: listTypes,
4231
+ at: at
4232
+ }
4233
+ }));
4234
+ });
4235
+ };
4236
+
4237
+ var toggleList = function toggleList(editor, _ref2) {
4238
+ var type = _ref2.type;
4239
+ return Editor.withoutNormalizing(editor, function () {
4240
+ if (!editor.selection) {
4241
+ return;
4242
+ }
4243
+
4244
+ if (isCollapsed(editor.selection) || !isRangeAcrossBlocks(editor)) {
4245
+ // selection is collapsed
4246
+ var res = getListItemEntry(editor);
4247
+
4248
+ if (res) {
4249
+ var list = res.list;
4250
+
4251
+ if (list[0].type !== type) {
4252
+ setNodes(editor, {
4253
+ type: type
4254
+ }, {
4255
+ at: editor.selection,
4256
+ match: function match(n) {
4257
+ return listTypes.includes(n.type);
4258
+ },
4259
+ mode: 'lowest'
4260
+ });
4261
+ } else {
4262
+ unwrapList(editor);
4263
+ }
4264
+ } else {
4265
+ var _list = {
4266
+ type: type,
4267
+ children: [],
4268
+ data: {}
4269
+ };
4270
+ wrapNodes(editor, _list);
4271
+ var nodes = [].concat(getNodes(editor, {
4272
+ match: {
4273
+ type: getPluginType(editor, ELEMENT_DEFAULT)
4274
+ }
4275
+ }));
4276
+ var listItem = {
4277
+ type: BLOCKS.LIST_ITEM,
4278
+ children: [],
4279
+ data: {}
4280
+ };
4281
+
4282
+ for (var _iterator = _createForOfIteratorHelperLoose(nodes), _step; !(_step = _iterator()).done;) {
4283
+ var _step$value = _step.value,
4284
+ path = _step$value[1];
4285
+ wrapNodes(editor, listItem, {
4286
+ at: path
4287
+ });
4288
+ }
4289
+ }
4290
+ } else {
4291
+ // selection is a range
4292
+ var _Range$edges = Range.edges(editor.selection),
4293
+ startPoint = _Range$edges[0],
4294
+ endPoint = _Range$edges[1];
4295
+
4296
+ var commonEntry = Node.common(editor, startPoint.path, endPoint.path);
4297
+
4298
+ if (listTypes.includes(commonEntry[0].type) || commonEntry[0].type === BLOCKS.LIST_ITEM) {
4299
+ if (commonEntry[0].type !== type) {
4300
+ var startList = findNode(editor, {
4301
+ at: Range.start(editor.selection),
4302
+ match: {
4303
+ type: listTypes
4304
+ },
4305
+ mode: 'lowest'
4306
+ });
4307
+ var endList = findNode(editor, {
4308
+ at: Range.end(editor.selection),
4309
+ match: {
4310
+ type: listTypes
4311
+ },
4312
+ mode: 'lowest'
4313
+ });
4314
+
4315
+ if (!startList || !endList) {
4316
+ return;
4317
+ }
4318
+
4319
+ var rangeLength = Math.min(startList[1].length, endList[1].length);
4320
+ setNodes(editor, {
4321
+ type: type
4322
+ }, {
4323
+ at: editor.selection,
4324
+ match: function match(n, path) {
4325
+ return listTypes.includes(n.type) && path.length >= rangeLength;
4326
+ },
4327
+ mode: 'all'
4328
+ });
4329
+ } else {
4330
+ unwrapList(editor);
4331
+ }
4332
+ } else {
4333
+ var rootPathLength = commonEntry[1].length;
4334
+
4335
+ var _nodes = Array.from(getNodes(editor, {
4336
+ mode: 'all'
4337
+ })).filter(function (_ref3) {
4338
+ var path = _ref3[1];
4339
+ return path.length === rootPathLength + 1;
4340
+ }).reverse();
4341
+
4342
+ _nodes.forEach(function (n) {
4343
+ if (listTypes.includes(n[0].type)) {
4344
+ setNodes(editor, {
4345
+ type: type
4346
+ }, {
4347
+ at: n[1]
4348
+ });
4349
+ } else {
4350
+ setNodes(editor, {
4351
+ type: getPluginType(editor, ELEMENT_LIC)
4352
+ }, {
4353
+ at: n[1]
4354
+ });
4355
+ var _listItem = {
4356
+ type: BLOCKS.LIST_ITEM,
4357
+ children: [],
4358
+ data: {}
4359
+ };
4360
+ wrapNodes(editor, _listItem, {
4361
+ at: n[1]
4362
+ });
4363
+ var _list2 = {
4364
+ type: type,
4365
+ children: [],
4366
+ data: {}
4367
+ };
4368
+ wrapNodes(editor, _list2, {
4369
+ at: n[1]
4370
+ });
4371
+ }
4372
+ });
4373
+ }
4374
+ }
4375
+ });
4376
+ };
4377
+
4085
4378
  function ToolbarListButton(props) {
4086
4379
  var sdk = useSdkContext();
4087
4380
  var editor = useContentfulEditor();
@@ -4550,6 +4843,18 @@ function isEmptyElement(element) {
4550
4843
  return element.textContent === '';
4551
4844
  }
4552
4845
 
4846
+ var buildParagraphKeyDownHandler = function buildParagraphKeyDownHandler(editor, _ref) {
4847
+ var hotkey = _ref.options.hotkey;
4848
+ return function (event) {
4849
+ if (editor.selection && hotkey && isHotkey(hotkey, event)) {
4850
+ toggleElement(editor, {
4851
+ activeType: BLOCKS.PARAGRAPH,
4852
+ inactiveType: BLOCKS.PARAGRAPH
4853
+ });
4854
+ }
4855
+ };
4856
+ };
4857
+
4553
4858
  var createParagraphPlugin = function createParagraphPlugin() {
4554
4859
  var _transform;
4555
4860
 
@@ -4559,6 +4864,9 @@ var createParagraphPlugin = function createParagraphPlugin() {
4559
4864
  options: {
4560
4865
  hotkey: ['mod+opt+0']
4561
4866
  },
4867
+ handlers: {
4868
+ onKeyDown: buildParagraphKeyDownHandler
4869
+ },
4562
4870
  softBreak: [// create a new line with SHIFT+Enter inside a paragraph
4563
4871
  {
4564
4872
  hotkey: 'shift+enter',
@@ -4575,8 +4883,8 @@ var createParagraphPlugin = function createParagraphPlugin() {
4575
4883
  }
4576
4884
  },
4577
4885
  normalizer: [{
4578
- validChildren: function validChildren(_, _ref) {
4579
- var node = _ref[0];
4886
+ validChildren: function validChildren(_, _ref2) {
4887
+ var node = _ref2[0];
4580
4888
  return isInlineOrText(node);
4581
4889
  },
4582
4890
  transform: (_transform = {}, _transform[BLOCKS.PARAGRAPH] = transformUnwrap, _transform["default"] = transformLift, _transform)
@@ -4762,10 +5070,6 @@ function toggleQuote(editor, logAction) {
4762
5070
  },
4763
5071
  split: true
4764
5072
  });
4765
- var _editor$selection = editor.selection,
4766
- anchor = _editor$selection.anchor,
4767
- focus = _editor$selection.focus;
4768
- var isTripleSelection = anchor.path[0] !== focus.path[0] && anchor.offset === 0 && focus.offset === 0;
4769
5073
 
4770
5074
  if (!isActive) {
4771
5075
  var quote = {
@@ -4773,9 +5077,7 @@ function toggleQuote(editor, logAction) {
4773
5077
  data: {},
4774
5078
  children: []
4775
5079
  };
4776
- Transforms.wrapNodes(editor, quote, {
4777
- at: isTripleSelection ? editor.selection.anchor : undefined
4778
- });
5080
+ Transforms.wrapNodes(editor, quote);
4779
5081
  }
4780
5082
  });
4781
5083
  }
@@ -5352,15 +5654,7 @@ var createTablePlugin = function createTablePlugin() {
5352
5654
  });
5353
5655
 
5354
5656
  if (fragmentHasTable) {
5355
- var emptyParagraph = {
5356
- type: BLOCKS.PARAGRAPH,
5357
- children: [{
5358
- text: ''
5359
- }],
5360
- data: {},
5361
- isVoid: false
5362
- };
5363
- Transforms.insertNodes(editor, emptyParagraph);
5657
+ insertEmptyParagraph(editor);
5364
5658
  }
5365
5659
 
5366
5660
  insertFragment(fragments);
@@ -5489,6 +5783,20 @@ function ToolbarTableButton(props) {
5489
5783
  function createTextPlugin() {
5490
5784
  return {
5491
5785
  key: 'TextPlugin',
5786
+ handlers: {
5787
+ // Triple selection in a non-Firefox browser undesirably selects
5788
+ // the start of the next block. Editor.unhangRange helps removing
5789
+ // the extra block at the end.
5790
+ onMouseUp: function onMouseUp(editor) {
5791
+ return function () {
5792
+ if (!editor.selection) {
5793
+ return;
5794
+ }
5795
+
5796
+ Transforms.setSelection(editor, Editor.unhangRange(editor, editor.selection));
5797
+ };
5798
+ }
5799
+ },
5492
5800
  withOverrides: function withOverrides(editor) {
5493
5801
  // Reverts the change made upstream that caused the cursor
5494
5802
  // to be trapped inside inline elements.
@@ -6100,7 +6408,10 @@ var useNormalizedSlateValue = function useNormalizedSlateValue(_ref) {
6100
6408
  schema: schema
6101
6409
  }); // Sets editor value & kicks normalization
6102
6410
 
6103
- Transforms.insertNodes(editor, doc); // TODO: return the editor itself to avoid recompiling & initializing all
6411
+ editor.children = doc;
6412
+ Editor.normalize(editor, {
6413
+ force: true
6414
+ }); // TODO: return the editor itself to avoid recompiling & initializing all
6104
6415
  // of the plugins again. It's currently not possible due to a bug in Plate
6105
6416
  // with initialValues
6106
6417
  // See: https://slate-js.slack.com/archives/C013QHXSCG1/p1645112799942819
@@ -6143,8 +6454,9 @@ var useOnValueChanged = function useOnValueChanged(_ref) {
6143
6454
 
6144
6455
  var _excluded = ["sdk", "isInitiallyDisabled", "onAction"];
6145
6456
  var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
6146
- var id = useContentfulEditorId();
6147
- var editor = useContentfulEditor();
6457
+ var id = getContentfulEditorId(props.sdk); // TODO: remove in favor of getting the editor from useNormalizedSlateValue after upgrading to Plate v10
6458
+
6459
+ var editor = useContentfulEditor(id);
6148
6460
  var plugins = React__default.useMemo(function () {
6149
6461
  var _props$onAction;
6150
6462
 
@@ -6162,7 +6474,20 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
6162
6474
  var classNames = cx(styles$j.editor, props.minHeight !== undefined ? css({
6163
6475
  minHeight: props.minHeight
6164
6476
  }) : undefined, props.isDisabled ? styles$j.disabled : styles$j.enabled, props.isToolbarHidden && styles$j.hiddenToolbar);
6165
- return /*#__PURE__*/React__default.createElement("div", {
6477
+ useEffect(function () {
6478
+ // Ensure the plate state is cleared after the component unmounts
6479
+ // This prevent new editors for the same field to display old outdated values
6480
+ // Typical scenario: coming back to the entry editor after restoring a previous entry version
6481
+ getPlateActions(id).enabled(true);
6482
+ return function () {
6483
+ return getPlateActions(id).enabled(false);
6484
+ };
6485
+ }, [id]);
6486
+ return /*#__PURE__*/React__default.createElement(SdkProvider, {
6487
+ sdk: props.sdk
6488
+ }, /*#__PURE__*/React__default.createElement(ContentfulEditorIdProvider, {
6489
+ value: id
6490
+ }, /*#__PURE__*/React__default.createElement("div", {
6166
6491
  className: styles$j.root,
6167
6492
  "data-test-id": "rich-text-editor"
6168
6493
  }, /*#__PURE__*/React__default.createElement(Plate, {
@@ -6179,7 +6504,7 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
6179
6504
  isDisabled: props.isDisabled
6180
6505
  }, /*#__PURE__*/React__default.createElement(Toolbar, {
6181
6506
  isDisabled: props.isDisabled
6182
- }))));
6507
+ }))))));
6183
6508
  };
6184
6509
 
6185
6510
  var RichTextEditor = function RichTextEditor(props) {
@@ -6191,11 +6516,8 @@ var RichTextEditor = function RichTextEditor(props) {
6191
6516
  var isEmptyValue = useCallback(function (value) {
6192
6517
  return !value || deepEquals(value, EMPTY_DOCUMENT);
6193
6518
  }, []);
6194
- var editorId = getContentfulEditorId(sdk);
6195
6519
  return /*#__PURE__*/React__default.createElement(EntityProvider, {
6196
6520
  sdk: sdk
6197
- }, /*#__PURE__*/React__default.createElement(SdkProvider, {
6198
- sdk: sdk
6199
6521
  }, /*#__PURE__*/React__default.createElement(FieldConnector, {
6200
6522
  throttle: 0,
6201
6523
  field: sdk.field,
@@ -6207,17 +6529,15 @@ var RichTextEditor = function RichTextEditor(props) {
6207
6529
  disabled = _ref.disabled,
6208
6530
  setValue = _ref.setValue,
6209
6531
  externalReset = _ref.externalReset;
6210
- return /*#__PURE__*/React__default.createElement(ContentfulEditorIdProvider, {
6211
- value: editorId
6212
- }, /*#__PURE__*/React__default.createElement(ConnectedRichTextEditor, Object.assign({}, otherProps, {
6532
+ return /*#__PURE__*/React__default.createElement(ConnectedRichTextEditor, Object.assign({}, otherProps, {
6213
6533
  key: "rich-text-editor-" + externalReset,
6214
6534
  value: lastRemoteValue,
6215
6535
  sdk: sdk,
6216
6536
  onAction: onAction,
6217
6537
  isDisabled: disabled,
6218
6538
  onChange: setValue
6219
- })));
6220
- })));
6539
+ }));
6540
+ }));
6221
6541
  };
6222
6542
 
6223
6543
  var LINK_TYPES$1 = {