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