@contentful/field-editor-rich-text 2.0.0-next.5 → 2.0.0-next.9
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 +1112 -764
- 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 +1115 -767
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/editor.d.ts +1 -0
- package/dist/helpers/environment.d.ts +1 -0
- 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/dist/test-utils/jsx.d.ts +1 -1
- package/dist/test-utils/mockPlugin.d.ts +1 -1
- package/package.json +11 -11
- package/dist/plugins/List/getListInsertFragment.d.ts +0 -6
|
@@ -3,16 +3,16 @@ 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 {
|
|
15
|
-
import { useSelected, useReadOnly, ReactEditor, useFocused } from 'slate-react';
|
|
15
|
+
import { ReactEditor, useSelected, useReadOnly, 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';
|
|
18
18
|
import get from 'lodash-es/get';
|
|
@@ -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';
|
|
@@ -341,8 +342,8 @@ var schema = {
|
|
|
341
342
|
function getContentfulEditorId(sdk) {
|
|
342
343
|
var entry = sdk.entry,
|
|
343
344
|
field = sdk.field;
|
|
344
|
-
var
|
|
345
|
-
return "rich-text-editor-" +
|
|
345
|
+
var sys = entry.getSys();
|
|
346
|
+
return "rich-text-editor-" + sys.id + "-" + field.id + "-" + field.locale;
|
|
346
347
|
}
|
|
347
348
|
|
|
348
349
|
function useContentfulEditorHook(_ref) {
|
|
@@ -483,6 +484,18 @@ function getParents(el) {
|
|
|
483
484
|
return parents;
|
|
484
485
|
}
|
|
485
486
|
|
|
487
|
+
// "modern" Edge was released at 79.x
|
|
488
|
+
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
|
|
489
|
+
// and older, Chrome 76+ can use `beforeInput` though.
|
|
490
|
+
|
|
491
|
+
var IS_CHROME_LEGACY = typeof navigator !== 'undefined' && /*#__PURE__*/ /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent); // COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
|
|
492
|
+
// Chrome Legacy doesn't support `beforeinput` correctly
|
|
493
|
+
|
|
494
|
+
var HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY && !IS_EDGE_LEGACY && // globalThis is undefined in older browsers
|
|
495
|
+
typeof globalThis !== 'undefined' && globalThis.InputEvent && typeof globalThis.InputEvent.prototype.getTargetRanges === 'function'; // The `getTargetRanges` property isn't recognized.
|
|
496
|
+
|
|
497
|
+
var IS_SAFARI = typeof navigator !== 'undefined' && /*#__PURE__*/ /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
498
|
+
|
|
486
499
|
var LINK_TYPES = [INLINES.HYPERLINK, INLINES.ENTRY_HYPERLINK, INLINES.ASSET_HYPERLINK];
|
|
487
500
|
function isBlockSelected(editor, type) {
|
|
488
501
|
var _Array$from = Array.from(Editor.nodes(editor, {
|
|
@@ -700,16 +713,27 @@ var isInlineOrText = function isInlineOrText(node) {
|
|
|
700
713
|
// either text or inline elements
|
|
701
714
|
return Text.isText(node) || Element.isElement(node) && INLINE_TYPES.includes(node.type);
|
|
702
715
|
};
|
|
716
|
+
var focus = function focus(editor) {
|
|
717
|
+
var x = window.scrollX;
|
|
718
|
+
var y = window.scrollY;
|
|
719
|
+
ReactEditor.focus(editor); // Safari has issues with `editor.focus({ preventScroll: true })`, it ignores the option `preventScroll`
|
|
720
|
+
|
|
721
|
+
if (IS_SAFARI) {
|
|
722
|
+
setTimeout(function () {
|
|
723
|
+
window.scrollTo(x, y); // restore position
|
|
724
|
+
}, 0);
|
|
725
|
+
}
|
|
726
|
+
};
|
|
703
727
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
728
|
+
function withLinkTracking(tracking, Component) {
|
|
729
|
+
return function ComponentWithTracking(props) {
|
|
730
|
+
return /*#__PURE__*/React__default.createElement(Component, Object.assign({}, props, {
|
|
731
|
+
onEntityFetchComplete: function onEntityFetchComplete() {
|
|
732
|
+
tracking.onViewportAction('linkRendered');
|
|
733
|
+
}
|
|
734
|
+
}));
|
|
735
|
+
};
|
|
736
|
+
}
|
|
713
737
|
|
|
714
738
|
function useSdk(_ref) {
|
|
715
739
|
var sdk = _ref.sdk;
|
|
@@ -847,10 +871,19 @@ function FetchingWrappedAssetCard(props) {
|
|
|
847
871
|
var asset = assets[props.assetId];
|
|
848
872
|
var defaultLocaleCode = props.sdk.locales["default"];
|
|
849
873
|
var entityFile = asset != null && (_asset$fields = asset.fields) != null && _asset$fields.file ? asset.fields.file[props.locale] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
874
|
+
var onEntityFetchComplete = props.onEntityFetchComplete;
|
|
850
875
|
useEffect(function () {
|
|
851
876
|
getOrLoadAsset(props.assetId);
|
|
852
877
|
}, [props.assetId]); // eslint-disable-line
|
|
853
878
|
|
|
879
|
+
useEffect(function () {
|
|
880
|
+
if (!asset) {
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
|
|
885
|
+
}, [asset, onEntityFetchComplete]);
|
|
886
|
+
|
|
854
887
|
function getAssetSrc() {
|
|
855
888
|
if (!(entityFile != null && entityFile.url)) return '';
|
|
856
889
|
return entityFile.url + "?h=300";
|
|
@@ -975,6 +1008,7 @@ function FetchingWrappedEntryCard(props) {
|
|
|
975
1008
|
});
|
|
976
1009
|
}, [props.sdk, entry]);
|
|
977
1010
|
var defaultLocaleCode = props.sdk.locales["default"];
|
|
1011
|
+
var onEntityFetchComplete = props.onEntityFetchComplete;
|
|
978
1012
|
useEffect(function () {
|
|
979
1013
|
if (!entry || entry === 'failed') return;
|
|
980
1014
|
entityHelpers.getEntryImage({
|
|
@@ -990,6 +1024,14 @@ function FetchingWrappedEntryCard(props) {
|
|
|
990
1024
|
getOrLoadEntry(props.entryId);
|
|
991
1025
|
}, [props.entryId]); // eslint-disable-line
|
|
992
1026
|
|
|
1027
|
+
useEffect(function () {
|
|
1028
|
+
if (!entry) {
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
|
|
1033
|
+
}, [entry, onEntityFetchComplete]);
|
|
1034
|
+
|
|
993
1035
|
function renderDropdown() {
|
|
994
1036
|
if (!props.onEdit || !props.onRemove) return undefined;
|
|
995
1037
|
return [props.onEdit ? /*#__PURE__*/createElement(MenuItem, {
|
|
@@ -1071,13 +1113,14 @@ function FetchingWrappedEntryCard(props) {
|
|
|
1071
1113
|
|
|
1072
1114
|
var styles$3 = {
|
|
1073
1115
|
root: /*#__PURE__*/css({
|
|
1074
|
-
marginBottom: '1.25rem'
|
|
1116
|
+
marginBottom: '1.25rem !important'
|
|
1075
1117
|
})
|
|
1076
1118
|
};
|
|
1077
1119
|
function LinkedEntityBlock(props) {
|
|
1078
1120
|
var attributes = props.attributes,
|
|
1079
1121
|
children = props.children,
|
|
1080
|
-
element = props.element
|
|
1122
|
+
element = props.element,
|
|
1123
|
+
onEntityFetchComplete = props.onEntityFetchComplete;
|
|
1081
1124
|
var isSelected = useSelected();
|
|
1082
1125
|
var editor = useContentfulEditor();
|
|
1083
1126
|
var sdk = useSdkContext();
|
|
@@ -1119,7 +1162,8 @@ function LinkedEntityBlock(props) {
|
|
|
1119
1162
|
isDisabled: isDisabled,
|
|
1120
1163
|
isSelected: isSelected,
|
|
1121
1164
|
onRemove: handleRemoveClick,
|
|
1122
|
-
onEdit: handleEditClick
|
|
1165
|
+
onEdit: handleEditClick,
|
|
1166
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
1123
1167
|
}), entityType === 'Asset' && /*#__PURE__*/React__default.createElement(FetchingWrappedAssetCard, {
|
|
1124
1168
|
sdk: sdk,
|
|
1125
1169
|
assetId: entityId,
|
|
@@ -1127,7 +1171,8 @@ function LinkedEntityBlock(props) {
|
|
|
1127
1171
|
isDisabled: isDisabled,
|
|
1128
1172
|
isSelected: isSelected,
|
|
1129
1173
|
onRemove: handleRemoveClick,
|
|
1130
|
-
onEdit: handleEditClick
|
|
1174
|
+
onEdit: handleEditClick,
|
|
1175
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
1131
1176
|
})), children);
|
|
1132
1177
|
}
|
|
1133
1178
|
|
|
@@ -1135,201 +1180,197 @@ function createCommonjsModule(fn, module) {
|
|
|
1135
1180
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
1136
1181
|
}
|
|
1137
1182
|
|
|
1138
|
-
var runtime_1 = createCommonjsModule(function (module) {
|
|
1139
|
-
/**
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1183
|
+
var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
|
|
1184
|
+
/**
|
|
1185
|
+
* Copyright (c) 2014-present, Facebook, Inc.
|
|
1186
|
+
*
|
|
1187
|
+
* This source code is licensed under the MIT license found in the
|
|
1188
|
+
* LICENSE file in the root directory of this source tree.
|
|
1189
|
+
*/
|
|
1190
|
+
var runtime = function (exports) {
|
|
1191
|
+
|
|
1192
|
+
var Op = Object.prototype;
|
|
1193
|
+
var hasOwn = Op.hasOwnProperty;
|
|
1194
|
+
var undefined$1; // More compressible than void 0.
|
|
1195
|
+
|
|
1196
|
+
var $Symbol = typeof Symbol === "function" ? Symbol : {};
|
|
1197
|
+
var iteratorSymbol = $Symbol.iterator || "@@iterator";
|
|
1198
|
+
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
|
1199
|
+
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
1200
|
+
|
|
1201
|
+
function define(obj, key, value) {
|
|
1202
|
+
Object.defineProperty(obj, key, {
|
|
1203
|
+
value: value,
|
|
1204
|
+
enumerable: true,
|
|
1205
|
+
configurable: true,
|
|
1206
|
+
writable: true
|
|
1207
|
+
});
|
|
1208
|
+
return obj[key];
|
|
1209
|
+
}
|
|
1145
1210
|
|
|
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
|
-
}
|
|
1211
|
+
try {
|
|
1212
|
+
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
|
|
1213
|
+
define({}, "");
|
|
1214
|
+
} catch (err) {
|
|
1215
|
+
define = function define(obj, key, value) {
|
|
1216
|
+
return obj[key] = value;
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1173
1219
|
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1220
|
+
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
1221
|
+
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
|
|
1222
|
+
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
|
|
1223
|
+
var generator = Object.create(protoGenerator.prototype);
|
|
1224
|
+
var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
|
|
1225
|
+
// .throw, and .return methods.
|
|
1179
1226
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1227
|
+
generator._invoke = makeInvokeMethod(innerFn, self, context);
|
|
1228
|
+
return generator;
|
|
1229
|
+
}
|
|
1183
1230
|
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1231
|
+
exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
|
|
1232
|
+
// record like context.tryEntries[i].completion. This interface could
|
|
1233
|
+
// have been (and was previously) designed to take a closure to be
|
|
1234
|
+
// invoked without arguments, but in all the cases we care about we
|
|
1235
|
+
// already have an existing method we want to call, so there's no need
|
|
1236
|
+
// to create a new function object. We can even get away with assuming
|
|
1237
|
+
// the method takes exactly one argument, since that happens to be true
|
|
1238
|
+
// in every case, so we don't have to touch the arguments object. The
|
|
1239
|
+
// only additional allocation required is the completion record, which
|
|
1240
|
+
// has a stable shape and so hopefully should be cheap to allocate.
|
|
1241
|
+
|
|
1242
|
+
function tryCatch(fn, obj, arg) {
|
|
1243
|
+
try {
|
|
1244
|
+
return {
|
|
1245
|
+
type: "normal",
|
|
1246
|
+
arg: fn.call(obj, arg)
|
|
1247
|
+
};
|
|
1248
|
+
} catch (err) {
|
|
1249
|
+
return {
|
|
1250
|
+
type: "throw",
|
|
1251
|
+
arg: err
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1203
1254
|
}
|
|
1204
|
-
}
|
|
1205
1255
|
|
|
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
|
-
});
|
|
1256
|
+
var GenStateSuspendedStart = "suspendedStart";
|
|
1257
|
+
var GenStateSuspendedYield = "suspendedYield";
|
|
1258
|
+
var GenStateExecuting = "executing";
|
|
1259
|
+
var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
|
|
1260
|
+
// breaking out of the dispatch switch statement.
|
|
1229
1261
|
|
|
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
|
-
}
|
|
1262
|
+
var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
|
|
1263
|
+
// .constructor.prototype properties for functions that return Generator
|
|
1264
|
+
// objects. For full spec compliance, you may wish to configure your
|
|
1265
|
+
// minifier not to mangle the names of these two functions.
|
|
1239
1266
|
|
|
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
|
-
);
|
|
1267
|
+
function Generator() {}
|
|
1250
1268
|
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1269
|
+
function GeneratorFunction() {}
|
|
1270
|
+
|
|
1271
|
+
function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
|
|
1272
|
+
// don't natively support it.
|
|
1273
|
+
|
|
1274
|
+
|
|
1275
|
+
var IteratorPrototype = {};
|
|
1276
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
|
1277
|
+
return this;
|
|
1258
1278
|
});
|
|
1259
|
-
|
|
1279
|
+
var getProto = Object.getPrototypeOf;
|
|
1280
|
+
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
1260
1281
|
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
// do is to check its .name property.
|
|
1267
|
-
(ctor.displayName || ctor.name) === "GeneratorFunction"
|
|
1268
|
-
: false;
|
|
1269
|
-
};
|
|
1282
|
+
if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
|
1283
|
+
// This environment has a native %IteratorPrototype%; use it instead
|
|
1284
|
+
// of the polyfill.
|
|
1285
|
+
IteratorPrototype = NativeIteratorPrototype;
|
|
1286
|
+
}
|
|
1270
1287
|
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1288
|
+
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
1289
|
+
GeneratorFunction.prototype = GeneratorFunctionPrototype;
|
|
1290
|
+
define(Gp, "constructor", GeneratorFunctionPrototype);
|
|
1291
|
+
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
|
|
1292
|
+
GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
|
|
1293
|
+
// Iterator interface in terms of a single ._invoke method.
|
|
1294
|
+
|
|
1295
|
+
function defineIteratorMethods(prototype) {
|
|
1296
|
+
["next", "throw", "return"].forEach(function (method) {
|
|
1297
|
+
define(prototype, method, function (arg) {
|
|
1298
|
+
return this._invoke(method, arg);
|
|
1299
|
+
});
|
|
1300
|
+
});
|
|
1277
1301
|
}
|
|
1278
|
-
genFun.prototype = Object.create(Gp);
|
|
1279
|
-
return genFun;
|
|
1280
|
-
};
|
|
1281
1302
|
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
};
|
|
1303
|
+
exports.isGeneratorFunction = function (genFun) {
|
|
1304
|
+
var ctor = typeof genFun === "function" && genFun.constructor;
|
|
1305
|
+
return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
|
|
1306
|
+
// do is to check its .name property.
|
|
1307
|
+
(ctor.displayName || ctor.name) === "GeneratorFunction" : false;
|
|
1308
|
+
};
|
|
1289
1309
|
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
if (record.type === "throw") {
|
|
1294
|
-
reject(record.arg);
|
|
1310
|
+
exports.mark = function (genFun) {
|
|
1311
|
+
if (Object.setPrototypeOf) {
|
|
1312
|
+
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
|
1295
1313
|
} else {
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1314
|
+
genFun.__proto__ = GeneratorFunctionPrototype;
|
|
1315
|
+
define(genFun, toStringTagSymbol, "GeneratorFunction");
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
genFun.prototype = Object.create(Gp);
|
|
1319
|
+
return genFun;
|
|
1320
|
+
}; // Within the body of any async function, `await x` is transformed to
|
|
1321
|
+
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
|
|
1322
|
+
// `hasOwn.call(value, "__await")` to determine if the yielded value is
|
|
1323
|
+
// meant to be awaited.
|
|
1324
|
+
|
|
1325
|
+
|
|
1326
|
+
exports.awrap = function (arg) {
|
|
1327
|
+
return {
|
|
1328
|
+
__await: arg
|
|
1329
|
+
};
|
|
1330
|
+
};
|
|
1331
|
+
|
|
1332
|
+
function AsyncIterator(generator, PromiseImpl) {
|
|
1333
|
+
function invoke(method, arg, resolve, reject) {
|
|
1334
|
+
var record = tryCatch(generator[method], generator, arg);
|
|
1335
|
+
|
|
1336
|
+
if (record.type === "throw") {
|
|
1337
|
+
reject(record.arg);
|
|
1338
|
+
} else {
|
|
1339
|
+
var result = record.arg;
|
|
1340
|
+
var value = result.value;
|
|
1341
|
+
|
|
1342
|
+
if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
|
|
1343
|
+
return PromiseImpl.resolve(value.__await).then(function (value) {
|
|
1344
|
+
invoke("next", value, resolve, reject);
|
|
1345
|
+
}, function (err) {
|
|
1346
|
+
invoke("throw", err, resolve, reject);
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
return PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
1351
|
+
// When a yielded Promise is resolved, its final value becomes
|
|
1352
|
+
// the .value of the Promise<{value,done}> result for the
|
|
1353
|
+
// current iteration.
|
|
1354
|
+
result.value = unwrapped;
|
|
1355
|
+
resolve(result);
|
|
1356
|
+
}, function (error) {
|
|
1357
|
+
// If a rejected Promise was yielded, throw the rejection back
|
|
1358
|
+
// into the async generator function so it can be handled there.
|
|
1359
|
+
return invoke("throw", error, resolve, reject);
|
|
1305
1360
|
});
|
|
1306
1361
|
}
|
|
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
1362
|
}
|
|
1320
|
-
}
|
|
1321
1363
|
|
|
1322
|
-
|
|
1364
|
+
var previousPromise;
|
|
1323
1365
|
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1366
|
+
function enqueue(method, arg) {
|
|
1367
|
+
function callInvokeWithMethodAndArg() {
|
|
1368
|
+
return new PromiseImpl(function (resolve, reject) {
|
|
1369
|
+
invoke(method, arg, resolve, reject);
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1330
1372
|
|
|
1331
|
-
|
|
1332
|
-
// If enqueue has been called before, then we want to wait until
|
|
1373
|
+
return previousPromise = // If enqueue has been called before, then we want to wait until
|
|
1333
1374
|
// all previous Promises have been resolved before calling invoke,
|
|
1334
1375
|
// so that results are always delivered in the correct order. If
|
|
1335
1376
|
// enqueue has not been called before, then it is important to
|
|
@@ -1341,554 +1382,527 @@ var runtime = (function (exports) {
|
|
|
1341
1382
|
// execute code before the first await. Since we implement simple
|
|
1342
1383
|
// async functions in terms of async generators, it is especially
|
|
1343
1384
|
// important to get this right, even though it requires care.
|
|
1344
|
-
previousPromise ? previousPromise.then(
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1385
|
+
previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
|
|
1386
|
+
// invocations of the iterator.
|
|
1387
|
+
callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
1388
|
+
} // Define the unified helper method that is used to implement .next,
|
|
1389
|
+
// .throw, and .return (see defineIteratorMethods).
|
|
1390
|
+
|
|
1391
|
+
|
|
1392
|
+
this._invoke = enqueue;
|
|
1350
1393
|
}
|
|
1351
1394
|
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1395
|
+
defineIteratorMethods(AsyncIterator.prototype);
|
|
1396
|
+
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
1397
|
+
return this;
|
|
1398
|
+
});
|
|
1399
|
+
exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
|
|
1400
|
+
// AsyncIterator objects; they just return a Promise for the value of
|
|
1401
|
+
// the final result produced by the iterator.
|
|
1402
|
+
|
|
1403
|
+
exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
1404
|
+
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
1405
|
+
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
1406
|
+
return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
|
|
1407
|
+
: iter.next().then(function (result) {
|
|
1408
|
+
return result.done ? result.value : iter.next();
|
|
1409
|
+
});
|
|
1410
|
+
};
|
|
1356
1411
|
|
|
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
|
-
};
|
|
1412
|
+
function makeInvokeMethod(innerFn, self, context) {
|
|
1413
|
+
var state = GenStateSuspendedStart;
|
|
1414
|
+
return function invoke(method, arg) {
|
|
1415
|
+
if (state === GenStateExecuting) {
|
|
1416
|
+
throw new Error("Generator is already running");
|
|
1417
|
+
}
|
|
1380
1418
|
|
|
1381
|
-
|
|
1382
|
-
|
|
1419
|
+
if (state === GenStateCompleted) {
|
|
1420
|
+
if (method === "throw") {
|
|
1421
|
+
throw arg;
|
|
1422
|
+
} // Be forgiving, per 25.3.3.3.3 of the spec:
|
|
1423
|
+
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
|
|
1383
1424
|
|
|
1384
|
-
return function invoke(method, arg) {
|
|
1385
|
-
if (state === GenStateExecuting) {
|
|
1386
|
-
throw new Error("Generator is already running");
|
|
1387
|
-
}
|
|
1388
1425
|
|
|
1389
|
-
|
|
1390
|
-
if (method === "throw") {
|
|
1391
|
-
throw arg;
|
|
1426
|
+
return doneResult();
|
|
1392
1427
|
}
|
|
1393
1428
|
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1429
|
+
context.method = method;
|
|
1430
|
+
context.arg = arg;
|
|
1431
|
+
|
|
1432
|
+
while (true) {
|
|
1433
|
+
var delegate = context.delegate;
|
|
1398
1434
|
|
|
1399
|
-
|
|
1400
|
-
|
|
1435
|
+
if (delegate) {
|
|
1436
|
+
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
1401
1437
|
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
if (delegateResult) {
|
|
1407
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
1408
|
-
return delegateResult;
|
|
1438
|
+
if (delegateResult) {
|
|
1439
|
+
if (delegateResult === ContinueSentinel) continue;
|
|
1440
|
+
return delegateResult;
|
|
1441
|
+
}
|
|
1409
1442
|
}
|
|
1410
|
-
}
|
|
1411
1443
|
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1444
|
+
if (context.method === "next") {
|
|
1445
|
+
// Setting context._sent for legacy support of Babel's
|
|
1446
|
+
// function.sent implementation.
|
|
1447
|
+
context.sent = context._sent = context.arg;
|
|
1448
|
+
} else if (context.method === "throw") {
|
|
1449
|
+
if (state === GenStateSuspendedStart) {
|
|
1450
|
+
state = GenStateCompleted;
|
|
1451
|
+
throw context.arg;
|
|
1452
|
+
}
|
|
1416
1453
|
|
|
1417
|
-
|
|
1418
|
-
if (
|
|
1419
|
-
|
|
1420
|
-
throw context.arg;
|
|
1454
|
+
context.dispatchException(context.arg);
|
|
1455
|
+
} else if (context.method === "return") {
|
|
1456
|
+
context.abrupt("return", context.arg);
|
|
1421
1457
|
}
|
|
1422
1458
|
|
|
1423
|
-
|
|
1459
|
+
state = GenStateExecuting;
|
|
1460
|
+
var record = tryCatch(innerFn, self, context);
|
|
1424
1461
|
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1462
|
+
if (record.type === "normal") {
|
|
1463
|
+
// If an exception is thrown from innerFn, we leave state ===
|
|
1464
|
+
// GenStateExecuting and loop back for another invocation.
|
|
1465
|
+
state = context.done ? GenStateCompleted : GenStateSuspendedYield;
|
|
1428
1466
|
|
|
1429
|
-
|
|
1467
|
+
if (record.arg === ContinueSentinel) {
|
|
1468
|
+
continue;
|
|
1469
|
+
}
|
|
1430
1470
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1471
|
+
return {
|
|
1472
|
+
value: record.arg,
|
|
1473
|
+
done: context.done
|
|
1474
|
+
};
|
|
1475
|
+
} else if (record.type === "throw") {
|
|
1476
|
+
state = GenStateCompleted; // Dispatch the exception by looping back around to the
|
|
1477
|
+
// context.dispatchException(context.arg) call above.
|
|
1438
1478
|
|
|
1439
|
-
|
|
1440
|
-
|
|
1479
|
+
context.method = "throw";
|
|
1480
|
+
context.arg = record.arg;
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
} // Call delegate.iterator[context.method](context.arg) and handle the
|
|
1485
|
+
// result, either by returning a { value, done } result from the
|
|
1486
|
+
// delegate iterator, or by modifying context.method and context.arg,
|
|
1487
|
+
// setting context.delegate to null, and returning the ContinueSentinel.
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
function maybeInvokeDelegate(delegate, context) {
|
|
1491
|
+
var method = delegate.iterator[context.method];
|
|
1492
|
+
|
|
1493
|
+
if (method === undefined$1) {
|
|
1494
|
+
// A .throw or .return when the delegate iterator has no .throw
|
|
1495
|
+
// method always terminates the yield* loop.
|
|
1496
|
+
context.delegate = null;
|
|
1497
|
+
|
|
1498
|
+
if (context.method === "throw") {
|
|
1499
|
+
// Note: ["return"] must be used for ES3 parsing compatibility.
|
|
1500
|
+
if (delegate.iterator["return"]) {
|
|
1501
|
+
// If the delegate iterator has a return method, give it a
|
|
1502
|
+
// chance to clean up.
|
|
1503
|
+
context.method = "return";
|
|
1504
|
+
context.arg = undefined$1;
|
|
1505
|
+
maybeInvokeDelegate(delegate, context);
|
|
1506
|
+
|
|
1507
|
+
if (context.method === "throw") {
|
|
1508
|
+
// If maybeInvokeDelegate(context) changed context.method from
|
|
1509
|
+
// "return" to "throw", let that override the TypeError below.
|
|
1510
|
+
return ContinueSentinel;
|
|
1511
|
+
}
|
|
1441
1512
|
}
|
|
1442
1513
|
|
|
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
1514
|
context.method = "throw";
|
|
1453
|
-
context.arg =
|
|
1515
|
+
context.arg = new TypeError("The iterator does not provide a 'throw' method");
|
|
1454
1516
|
}
|
|
1517
|
+
|
|
1518
|
+
return ContinueSentinel;
|
|
1455
1519
|
}
|
|
1456
|
-
};
|
|
1457
|
-
}
|
|
1458
1520
|
|
|
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;
|
|
1521
|
+
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
1469
1522
|
|
|
1470
|
-
if (
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
context.arg = undefined$1;
|
|
1477
|
-
maybeInvokeDelegate(delegate, context);
|
|
1523
|
+
if (record.type === "throw") {
|
|
1524
|
+
context.method = "throw";
|
|
1525
|
+
context.arg = record.arg;
|
|
1526
|
+
context.delegate = null;
|
|
1527
|
+
return ContinueSentinel;
|
|
1528
|
+
}
|
|
1478
1529
|
|
|
1479
|
-
|
|
1480
|
-
// If maybeInvokeDelegate(context) changed context.method from
|
|
1481
|
-
// "return" to "throw", let that override the TypeError below.
|
|
1482
|
-
return ContinueSentinel;
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1530
|
+
var info = record.arg;
|
|
1485
1531
|
|
|
1532
|
+
if (!info) {
|
|
1486
1533
|
context.method = "throw";
|
|
1487
|
-
context.arg = new TypeError(
|
|
1488
|
-
|
|
1534
|
+
context.arg = new TypeError("iterator result is not an object");
|
|
1535
|
+
context.delegate = null;
|
|
1536
|
+
return ContinueSentinel;
|
|
1489
1537
|
}
|
|
1490
1538
|
|
|
1491
|
-
|
|
1492
|
-
|
|
1539
|
+
if (info.done) {
|
|
1540
|
+
// Assign the result of the finished delegate to the temporary
|
|
1541
|
+
// variable specified by delegate.resultName (see delegateYield).
|
|
1542
|
+
context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
|
|
1493
1543
|
|
|
1494
|
-
|
|
1544
|
+
context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
|
|
1545
|
+
// exception, let the outer generator proceed normally. If
|
|
1546
|
+
// context.method was "next", forget context.arg since it has been
|
|
1547
|
+
// "consumed" by the delegate iterator. If context.method was
|
|
1548
|
+
// "return", allow the original .return call to continue in the
|
|
1549
|
+
// outer generator.
|
|
1495
1550
|
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1551
|
+
if (context.method !== "return") {
|
|
1552
|
+
context.method = "next";
|
|
1553
|
+
context.arg = undefined$1;
|
|
1554
|
+
}
|
|
1555
|
+
} else {
|
|
1556
|
+
// Re-yield the result returned by the delegate method.
|
|
1557
|
+
return info;
|
|
1558
|
+
} // The delegate iterator is finished, so forget it and continue with
|
|
1559
|
+
// the outer generator.
|
|
1502
1560
|
|
|
1503
|
-
var info = record.arg;
|
|
1504
1561
|
|
|
1505
|
-
if (! info) {
|
|
1506
|
-
context.method = "throw";
|
|
1507
|
-
context.arg = new TypeError("iterator result is not an object");
|
|
1508
1562
|
context.delegate = null;
|
|
1509
1563
|
return ContinueSentinel;
|
|
1510
|
-
}
|
|
1564
|
+
} // Define Generator.prototype.{next,throw,return} in terms of the
|
|
1565
|
+
// unified ._invoke helper method.
|
|
1511
1566
|
|
|
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
|
-
}
|
|
1535
1567
|
|
|
1536
|
-
|
|
1537
|
-
// the
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
// Define Generator.prototype.{next,throw,return} in terms of the
|
|
1543
|
-
// unified ._invoke helper method.
|
|
1544
|
-
defineIteratorMethods(Gp);
|
|
1568
|
+
defineIteratorMethods(Gp);
|
|
1569
|
+
define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
|
|
1570
|
+
// @@iterator function is called on it. Some browsers' implementations of the
|
|
1571
|
+
// iterator prototype chain incorrectly implement this, causing the Generator
|
|
1572
|
+
// object to not be returned from this call. This ensures that doesn't happen.
|
|
1573
|
+
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
1545
1574
|
|
|
1546
|
-
|
|
1575
|
+
define(Gp, iteratorSymbol, function () {
|
|
1576
|
+
return this;
|
|
1577
|
+
});
|
|
1578
|
+
define(Gp, "toString", function () {
|
|
1579
|
+
return "[object Generator]";
|
|
1580
|
+
});
|
|
1547
1581
|
|
|
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
|
-
});
|
|
1582
|
+
function pushTryEntry(locs) {
|
|
1583
|
+
var entry = {
|
|
1584
|
+
tryLoc: locs[0]
|
|
1585
|
+
};
|
|
1556
1586
|
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1587
|
+
if (1 in locs) {
|
|
1588
|
+
entry.catchLoc = locs[1];
|
|
1589
|
+
}
|
|
1560
1590
|
|
|
1561
|
-
|
|
1562
|
-
|
|
1591
|
+
if (2 in locs) {
|
|
1592
|
+
entry.finallyLoc = locs[2];
|
|
1593
|
+
entry.afterLoc = locs[3];
|
|
1594
|
+
}
|
|
1563
1595
|
|
|
1564
|
-
|
|
1565
|
-
entry.catchLoc = locs[1];
|
|
1596
|
+
this.tryEntries.push(entry);
|
|
1566
1597
|
}
|
|
1567
1598
|
|
|
1568
|
-
|
|
1569
|
-
entry.
|
|
1570
|
-
|
|
1599
|
+
function resetTryEntry(entry) {
|
|
1600
|
+
var record = entry.completion || {};
|
|
1601
|
+
record.type = "normal";
|
|
1602
|
+
delete record.arg;
|
|
1603
|
+
entry.completion = record;
|
|
1571
1604
|
}
|
|
1572
1605
|
|
|
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);
|
|
1606
|
+
function Context(tryLocsList) {
|
|
1607
|
+
// The root entry object (effectively a try statement without a catch
|
|
1608
|
+
// or a finally block) gives us a place to store values thrown from
|
|
1609
|
+
// locations where there is no enclosing try statement.
|
|
1610
|
+
this.tryEntries = [{
|
|
1611
|
+
tryLoc: "root"
|
|
1612
|
+
}];
|
|
1613
|
+
tryLocsList.forEach(pushTryEntry, this);
|
|
1614
|
+
this.reset(true);
|
|
1596
1615
|
}
|
|
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
1616
|
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
// also ensures that the minifier will not anonymize the function.
|
|
1614
|
-
next.done = true;
|
|
1615
|
-
return next;
|
|
1616
|
-
};
|
|
1617
|
-
};
|
|
1617
|
+
exports.keys = function (object) {
|
|
1618
|
+
var keys = [];
|
|
1618
1619
|
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
1622
|
-
if (iteratorMethod) {
|
|
1623
|
-
return iteratorMethod.call(iterable);
|
|
1620
|
+
for (var key in object) {
|
|
1621
|
+
keys.push(key);
|
|
1624
1622
|
}
|
|
1625
1623
|
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
}
|
|
1624
|
+
keys.reverse(); // Rather than returning an object with a next method, we keep
|
|
1625
|
+
// things simple and return the next function itself.
|
|
1629
1626
|
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
if (hasOwn.call(iterable, i)) {
|
|
1634
|
-
next.value = iterable[i];
|
|
1635
|
-
next.done = false;
|
|
1636
|
-
return next;
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1627
|
+
return function next() {
|
|
1628
|
+
while (keys.length) {
|
|
1629
|
+
var key = keys.pop();
|
|
1639
1630
|
|
|
1640
|
-
|
|
1641
|
-
|
|
1631
|
+
if (key in object) {
|
|
1632
|
+
next.value = key;
|
|
1633
|
+
next.done = false;
|
|
1634
|
+
return next;
|
|
1635
|
+
}
|
|
1636
|
+
} // To avoid creating an additional object, we just hang the .value
|
|
1637
|
+
// and .done properties off the next function object itself. This
|
|
1638
|
+
// also ensures that the minifier will not anonymize the function.
|
|
1642
1639
|
|
|
1643
|
-
return next;
|
|
1644
|
-
};
|
|
1645
1640
|
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1641
|
+
next.done = true;
|
|
1642
|
+
return next;
|
|
1643
|
+
};
|
|
1644
|
+
};
|
|
1649
1645
|
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
exports.values = values;
|
|
1646
|
+
function values(iterable) {
|
|
1647
|
+
if (iterable) {
|
|
1648
|
+
var iteratorMethod = iterable[iteratorSymbol];
|
|
1654
1649
|
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1650
|
+
if (iteratorMethod) {
|
|
1651
|
+
return iteratorMethod.call(iterable);
|
|
1652
|
+
}
|
|
1658
1653
|
|
|
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
|
-
}
|
|
1654
|
+
if (typeof iterable.next === "function") {
|
|
1655
|
+
return iterable;
|
|
1684
1656
|
}
|
|
1685
|
-
}
|
|
1686
|
-
},
|
|
1687
1657
|
|
|
1688
|
-
|
|
1689
|
-
|
|
1658
|
+
if (!isNaN(iterable.length)) {
|
|
1659
|
+
var i = -1,
|
|
1660
|
+
next = function next() {
|
|
1661
|
+
while (++i < iterable.length) {
|
|
1662
|
+
if (hasOwn.call(iterable, i)) {
|
|
1663
|
+
next.value = iterable[i];
|
|
1664
|
+
next.done = false;
|
|
1665
|
+
return next;
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1690
1668
|
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
}
|
|
1669
|
+
next.value = undefined$1;
|
|
1670
|
+
next.done = true;
|
|
1671
|
+
return next;
|
|
1672
|
+
};
|
|
1696
1673
|
|
|
1697
|
-
|
|
1698
|
-
|
|
1674
|
+
return next.next = next;
|
|
1675
|
+
}
|
|
1676
|
+
} // Return an iterator with no values.
|
|
1699
1677
|
|
|
1700
|
-
dispatchException: function(exception) {
|
|
1701
|
-
if (this.done) {
|
|
1702
|
-
throw exception;
|
|
1703
|
-
}
|
|
1704
1678
|
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
context.next = loc;
|
|
1679
|
+
return {
|
|
1680
|
+
next: doneResult
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1710
1683
|
|
|
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
|
-
}
|
|
1684
|
+
exports.values = values;
|
|
1717
1685
|
|
|
1718
|
-
|
|
1719
|
-
|
|
1686
|
+
function doneResult() {
|
|
1687
|
+
return {
|
|
1688
|
+
value: undefined$1,
|
|
1689
|
+
done: true
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1720
1692
|
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1693
|
+
Context.prototype = {
|
|
1694
|
+
constructor: Context,
|
|
1695
|
+
reset: function reset(skipTempReset) {
|
|
1696
|
+
this.prev = 0;
|
|
1697
|
+
this.next = 0; // Resetting context._sent for legacy support of Babel's
|
|
1698
|
+
// function.sent implementation.
|
|
1699
|
+
|
|
1700
|
+
this.sent = this._sent = undefined$1;
|
|
1701
|
+
this.done = false;
|
|
1702
|
+
this.delegate = null;
|
|
1703
|
+
this.method = "next";
|
|
1704
|
+
this.arg = undefined$1;
|
|
1705
|
+
this.tryEntries.forEach(resetTryEntry);
|
|
1724
1706
|
|
|
1725
|
-
if (
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1707
|
+
if (!skipTempReset) {
|
|
1708
|
+
for (var name in this) {
|
|
1709
|
+
// Not sure about the optimal order of these conditions:
|
|
1710
|
+
if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
|
|
1711
|
+
this[name] = undefined$1;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1730
1714
|
}
|
|
1715
|
+
},
|
|
1716
|
+
stop: function stop() {
|
|
1717
|
+
this.done = true;
|
|
1718
|
+
var rootEntry = this.tryEntries[0];
|
|
1719
|
+
var rootRecord = rootEntry.completion;
|
|
1731
1720
|
|
|
1732
|
-
if (
|
|
1733
|
-
|
|
1734
|
-
|
|
1721
|
+
if (rootRecord.type === "throw") {
|
|
1722
|
+
throw rootRecord.arg;
|
|
1723
|
+
}
|
|
1735
1724
|
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1725
|
+
return this.rval;
|
|
1726
|
+
},
|
|
1727
|
+
dispatchException: function dispatchException(exception) {
|
|
1728
|
+
if (this.done) {
|
|
1729
|
+
throw exception;
|
|
1730
|
+
}
|
|
1742
1731
|
|
|
1743
|
-
|
|
1744
|
-
if (this.prev < entry.catchLoc) {
|
|
1745
|
-
return handle(entry.catchLoc, true);
|
|
1746
|
-
}
|
|
1732
|
+
var context = this;
|
|
1747
1733
|
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1734
|
+
function handle(loc, caught) {
|
|
1735
|
+
record.type = "throw";
|
|
1736
|
+
record.arg = exception;
|
|
1737
|
+
context.next = loc;
|
|
1752
1738
|
|
|
1753
|
-
|
|
1754
|
-
|
|
1739
|
+
if (caught) {
|
|
1740
|
+
// If the dispatched exception was caught by a catch block,
|
|
1741
|
+
// then let that catch block handle the exception normally.
|
|
1742
|
+
context.method = "next";
|
|
1743
|
+
context.arg = undefined$1;
|
|
1755
1744
|
}
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
},
|
|
1759
1745
|
|
|
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;
|
|
1746
|
+
return !!caught;
|
|
1768
1747
|
}
|
|
1769
|
-
}
|
|
1770
1748
|
|
|
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
|
-
}
|
|
1749
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1750
|
+
var entry = this.tryEntries[i];
|
|
1751
|
+
var record = entry.completion;
|
|
1780
1752
|
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1753
|
+
if (entry.tryLoc === "root") {
|
|
1754
|
+
// Exception thrown outside of any try block that could handle
|
|
1755
|
+
// it, so set the completion value of the entire function to
|
|
1756
|
+
// throw the exception.
|
|
1757
|
+
return handle("end");
|
|
1758
|
+
}
|
|
1784
1759
|
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
return ContinueSentinel;
|
|
1789
|
-
}
|
|
1760
|
+
if (entry.tryLoc <= this.prev) {
|
|
1761
|
+
var hasCatch = hasOwn.call(entry, "catchLoc");
|
|
1762
|
+
var hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
1790
1763
|
|
|
1791
|
-
|
|
1792
|
-
|
|
1764
|
+
if (hasCatch && hasFinally) {
|
|
1765
|
+
if (this.prev < entry.catchLoc) {
|
|
1766
|
+
return handle(entry.catchLoc, true);
|
|
1767
|
+
} else if (this.prev < entry.finallyLoc) {
|
|
1768
|
+
return handle(entry.finallyLoc);
|
|
1769
|
+
}
|
|
1770
|
+
} else if (hasCatch) {
|
|
1771
|
+
if (this.prev < entry.catchLoc) {
|
|
1772
|
+
return handle(entry.catchLoc, true);
|
|
1773
|
+
}
|
|
1774
|
+
} else if (hasFinally) {
|
|
1775
|
+
if (this.prev < entry.finallyLoc) {
|
|
1776
|
+
return handle(entry.finallyLoc);
|
|
1777
|
+
}
|
|
1778
|
+
} else {
|
|
1779
|
+
throw new Error("try statement without catch or finally");
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
},
|
|
1784
|
+
abrupt: function abrupt(type, arg) {
|
|
1785
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1786
|
+
var entry = this.tryEntries[i];
|
|
1793
1787
|
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1788
|
+
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
1789
|
+
var finallyEntry = entry;
|
|
1790
|
+
break;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1798
1793
|
|
|
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
|
-
}
|
|
1794
|
+
if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
|
|
1795
|
+
// Ignore the finally entry if control is not jumping to a
|
|
1796
|
+
// location outside the try/catch block.
|
|
1797
|
+
finallyEntry = null;
|
|
1798
|
+
}
|
|
1809
1799
|
|
|
1810
|
-
|
|
1811
|
-
|
|
1800
|
+
var record = finallyEntry ? finallyEntry.completion : {};
|
|
1801
|
+
record.type = type;
|
|
1802
|
+
record.arg = arg;
|
|
1812
1803
|
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
if (entry.finallyLoc === finallyLoc) {
|
|
1817
|
-
this.complete(entry.completion, entry.afterLoc);
|
|
1818
|
-
resetTryEntry(entry);
|
|
1804
|
+
if (finallyEntry) {
|
|
1805
|
+
this.method = "next";
|
|
1806
|
+
this.next = finallyEntry.finallyLoc;
|
|
1819
1807
|
return ContinueSentinel;
|
|
1820
1808
|
}
|
|
1821
|
-
}
|
|
1822
|
-
},
|
|
1823
1809
|
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
if (
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1810
|
+
return this.complete(record);
|
|
1811
|
+
},
|
|
1812
|
+
complete: function complete(record, afterLoc) {
|
|
1813
|
+
if (record.type === "throw") {
|
|
1814
|
+
throw record.arg;
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
if (record.type === "break" || record.type === "continue") {
|
|
1818
|
+
this.next = record.arg;
|
|
1819
|
+
} else if (record.type === "return") {
|
|
1820
|
+
this.rval = this.arg = record.arg;
|
|
1821
|
+
this.method = "return";
|
|
1822
|
+
this.next = "end";
|
|
1823
|
+
} else if (record.type === "normal" && afterLoc) {
|
|
1824
|
+
this.next = afterLoc;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
return ContinueSentinel;
|
|
1828
|
+
},
|
|
1829
|
+
finish: function finish(finallyLoc) {
|
|
1830
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1831
|
+
var entry = this.tryEntries[i];
|
|
1832
|
+
|
|
1833
|
+
if (entry.finallyLoc === finallyLoc) {
|
|
1834
|
+
this.complete(entry.completion, entry.afterLoc);
|
|
1831
1835
|
resetTryEntry(entry);
|
|
1836
|
+
return ContinueSentinel;
|
|
1832
1837
|
}
|
|
1833
|
-
return thrown;
|
|
1834
1838
|
}
|
|
1835
|
-
}
|
|
1839
|
+
},
|
|
1840
|
+
"catch": function _catch(tryLoc) {
|
|
1841
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1842
|
+
var entry = this.tryEntries[i];
|
|
1836
1843
|
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
throw new Error("illegal catch attempt");
|
|
1840
|
-
},
|
|
1844
|
+
if (entry.tryLoc === tryLoc) {
|
|
1845
|
+
var record = entry.completion;
|
|
1841
1846
|
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
nextLoc: nextLoc
|
|
1847
|
-
};
|
|
1847
|
+
if (record.type === "throw") {
|
|
1848
|
+
var thrown = record.arg;
|
|
1849
|
+
resetTryEntry(entry);
|
|
1850
|
+
}
|
|
1848
1851
|
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
//
|
|
1852
|
-
|
|
1853
|
-
}
|
|
1852
|
+
return thrown;
|
|
1853
|
+
}
|
|
1854
|
+
} // The context.catch method must only be called with a location
|
|
1855
|
+
// argument that corresponds to a known catch block.
|
|
1854
1856
|
|
|
1855
|
-
return ContinueSentinel;
|
|
1856
|
-
}
|
|
1857
|
-
};
|
|
1858
1857
|
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1858
|
+
throw new Error("illegal catch attempt");
|
|
1859
|
+
},
|
|
1860
|
+
delegateYield: function delegateYield(iterable, resultName, nextLoc) {
|
|
1861
|
+
this.delegate = {
|
|
1862
|
+
iterator: values(iterable),
|
|
1863
|
+
resultName: resultName,
|
|
1864
|
+
nextLoc: nextLoc
|
|
1865
|
+
};
|
|
1866
|
+
|
|
1867
|
+
if (this.method === "next") {
|
|
1868
|
+
// Deliberately forget the last sent value so that we don't
|
|
1869
|
+
// accidentally pass it on to the delegate.
|
|
1870
|
+
this.arg = undefined$1;
|
|
1871
|
+
}
|
|
1864
1872
|
|
|
1865
|
-
|
|
1866
|
-
|
|
1873
|
+
return ContinueSentinel;
|
|
1874
|
+
}
|
|
1875
|
+
}; // Regardless of whether this script is executing as a CommonJS module
|
|
1876
|
+
// or not, return the runtime object so that we can declare the variable
|
|
1877
|
+
// regeneratorRuntime in the outer scope, which allows this module to be
|
|
1878
|
+
// injected easily by `bin/regenerator --include-runtime script.js`.
|
|
1879
|
+
|
|
1880
|
+
return exports;
|
|
1881
|
+
}( // If this script is executing as a CommonJS module, use module.exports
|
|
1867
1882
|
// as the regeneratorRuntime namespace. Otherwise create a new empty
|
|
1868
1883
|
// object. Either way, the resulting object will be used to initialize
|
|
1869
1884
|
// 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
|
-
|
|
1885
|
+
module.exports );
|
|
1886
|
+
|
|
1887
|
+
try {
|
|
1888
|
+
regeneratorRuntime = runtime;
|
|
1889
|
+
} catch (accidentalStrictMode) {
|
|
1890
|
+
// This module should not be running in strict mode, so the above
|
|
1891
|
+
// assignment should always work unless something is misconfigured. Just
|
|
1892
|
+
// in case runtime.js accidentally runs in strict mode, in modern engines
|
|
1893
|
+
// we can explicitly access globalThis. In older engines we can escape
|
|
1894
|
+
// strict mode using a global Function call. This could conceivably fail
|
|
1895
|
+
// if a Content Security Policy forbids using Function, but in that case
|
|
1896
|
+
// the proper solution is to fix the accidental strict mode problem. If
|
|
1897
|
+
// you've misconfigured your bundler to force strict mode and applied a
|
|
1898
|
+
// CSP to forbid Function, and you're not willing to fix either of those
|
|
1899
|
+
// problems, please detail your unique predicament in a GitHub issue.
|
|
1900
|
+
if (typeof globalThis === "object") {
|
|
1901
|
+
globalThis.regeneratorRuntime = runtime;
|
|
1902
|
+
} else {
|
|
1903
|
+
Function("r", "regeneratorRuntime = r")(runtime);
|
|
1904
|
+
}
|
|
1890
1905
|
}
|
|
1891
|
-
}
|
|
1892
1906
|
});
|
|
1893
1907
|
|
|
1894
1908
|
/* eslint-disable you-dont-need-lodash-underscore/find */
|
|
@@ -2063,7 +2077,7 @@ function insertBlock(editor, nodeType, entity) {
|
|
|
2063
2077
|
Transforms.setNodes(editor, linkedEntityBlock);
|
|
2064
2078
|
}
|
|
2065
2079
|
|
|
2066
|
-
|
|
2080
|
+
focus(editor);
|
|
2067
2081
|
}
|
|
2068
2082
|
|
|
2069
2083
|
var styles$4 = {
|
|
@@ -2157,13 +2171,13 @@ function getWithEmbeddedEntityEvents(nodeType, sdk) {
|
|
|
2157
2171
|
}
|
|
2158
2172
|
|
|
2159
2173
|
var createEmbeddedEntityPlugin = function createEmbeddedEntityPlugin(nodeType, hotkey) {
|
|
2160
|
-
return function (sdk) {
|
|
2174
|
+
return function (sdk, tracking) {
|
|
2161
2175
|
return {
|
|
2162
2176
|
key: nodeType,
|
|
2163
2177
|
type: nodeType,
|
|
2164
2178
|
isElement: true,
|
|
2165
2179
|
isVoid: true,
|
|
2166
|
-
component: LinkedEntityBlock,
|
|
2180
|
+
component: withLinkTracking(tracking, LinkedEntityBlock),
|
|
2167
2181
|
options: {
|
|
2168
2182
|
hotkey: hotkey
|
|
2169
2183
|
},
|
|
@@ -2221,12 +2235,20 @@ function FetchingWrappedInlineEntryCard(props) {
|
|
|
2221
2235
|
return entries[props.entryId];
|
|
2222
2236
|
}, [entries, props.entryId]);
|
|
2223
2237
|
var allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
2238
|
+
var onEntityFetchComplete = props.onEntityFetchComplete;
|
|
2224
2239
|
var contentType = React__default.useMemo(function () {
|
|
2225
2240
|
if (!entry || entry === 'failed' || !allContentTypes) return undefined;
|
|
2226
2241
|
return allContentTypes.find(function (contentType) {
|
|
2227
2242
|
return contentType.sys.id === entry.sys.contentType.sys.id;
|
|
2228
2243
|
});
|
|
2229
2244
|
}, [allContentTypes, entry]);
|
|
2245
|
+
React__default.useEffect(function () {
|
|
2246
|
+
if (!entry) {
|
|
2247
|
+
return;
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
|
|
2251
|
+
}, [entry, onEntityFetchComplete]);
|
|
2230
2252
|
var contentTypeName = contentType ? contentType.name : '';
|
|
2231
2253
|
var title = React__default.useMemo(function () {
|
|
2232
2254
|
return getEntryTitle({
|
|
@@ -2322,12 +2344,10 @@ var styles$6 = {
|
|
|
2322
2344
|
marginRight: '10px'
|
|
2323
2345
|
}),
|
|
2324
2346
|
root: /*#__PURE__*/css({
|
|
2325
|
-
|
|
2347
|
+
display: 'inline-block',
|
|
2348
|
+
margin: "0 " + tokens.spacing2Xs,
|
|
2326
2349
|
fontSize: 'inherit',
|
|
2327
2350
|
span: {
|
|
2328
|
-
webkitUserSelect: 'none',
|
|
2329
|
-
mozUserSelect: 'none',
|
|
2330
|
-
msUserSelect: 'none',
|
|
2331
2351
|
userSelect: 'none'
|
|
2332
2352
|
}
|
|
2333
2353
|
})
|
|
@@ -2370,7 +2390,8 @@ function EmbeddedEntityInline(props) {
|
|
|
2370
2390
|
isSelected: isSelected,
|
|
2371
2391
|
isDisabled: isDisabled,
|
|
2372
2392
|
onRemove: handleRemoveClick,
|
|
2373
|
-
onEdit: handleEditClick
|
|
2393
|
+
onEdit: handleEditClick,
|
|
2394
|
+
onEntityFetchComplete: props.onEntityFetchComplete
|
|
2374
2395
|
})), props.children);
|
|
2375
2396
|
}
|
|
2376
2397
|
|
|
@@ -2394,7 +2415,7 @@ function _selectEntityAndInsert$1() {
|
|
|
2394
2415
|
|
|
2395
2416
|
case 4:
|
|
2396
2417
|
entry = _context2.sent;
|
|
2397
|
-
|
|
2418
|
+
focus(editor); // Dialog steals focus from editor, return it.
|
|
2398
2419
|
|
|
2399
2420
|
if (entry) {
|
|
2400
2421
|
_context2.next = 8;
|
|
@@ -2480,7 +2501,7 @@ function ToolbarEmbeddedEntityInlineButton(props) {
|
|
|
2480
2501
|
className: "rich-text__embedded-entry-list-icon " + styles$6.icon
|
|
2481
2502
|
}), /*#__PURE__*/createElement("span", null, "Inline entry")));
|
|
2482
2503
|
}
|
|
2483
|
-
function createEmbeddedEntityInlinePlugin(sdk) {
|
|
2504
|
+
function createEmbeddedEntityInlinePlugin(sdk, tracking) {
|
|
2484
2505
|
var htmlAttributeName = 'data-embedded-entity-inline-id';
|
|
2485
2506
|
return {
|
|
2486
2507
|
key: INLINES.EMBEDDED_ENTRY,
|
|
@@ -2488,7 +2509,7 @@ function createEmbeddedEntityInlinePlugin(sdk) {
|
|
|
2488
2509
|
isElement: true,
|
|
2489
2510
|
isInline: true,
|
|
2490
2511
|
isVoid: true,
|
|
2491
|
-
component: EmbeddedEntityInline,
|
|
2512
|
+
component: withLinkTracking(tracking, EmbeddedEntityInline),
|
|
2492
2513
|
options: {
|
|
2493
2514
|
hotkey: 'mod+shift+2'
|
|
2494
2515
|
},
|
|
@@ -2602,14 +2623,25 @@ function ToolbarHeadingButton(props) {
|
|
|
2602
2623
|
unwrapFromRoot(editor);
|
|
2603
2624
|
}
|
|
2604
2625
|
|
|
2626
|
+
var prevOnChange = editor.onChange;
|
|
2627
|
+
/*
|
|
2628
|
+
The focus might happen at point in time when
|
|
2629
|
+
`toggleNodeType` changes aren't rendered yet, causing the browser
|
|
2630
|
+
to place the cursor at the start of the text.
|
|
2631
|
+
We wait for the change event before focusing
|
|
2632
|
+
the editor again. This ensures the cursor is back at the previous
|
|
2633
|
+
position.*/
|
|
2634
|
+
|
|
2635
|
+
editor.onChange = function () {
|
|
2636
|
+
focus(editor);
|
|
2637
|
+
editor.onChange = prevOnChange;
|
|
2638
|
+
prevOnChange.apply(void 0, arguments);
|
|
2639
|
+
};
|
|
2640
|
+
|
|
2605
2641
|
toggleNodeType(editor, {
|
|
2606
2642
|
activeType: type,
|
|
2607
2643
|
inactiveType: type
|
|
2608
|
-
});
|
|
2609
|
-
|
|
2610
|
-
setTimeout(function () {
|
|
2611
|
-
ReactEditor.focus(editor);
|
|
2612
|
-
}, 0);
|
|
2644
|
+
});
|
|
2613
2645
|
};
|
|
2614
2646
|
}
|
|
2615
2647
|
|
|
@@ -2739,16 +2771,6 @@ var createHeadingPlugin = function createHeadingPlugin() {
|
|
|
2739
2771
|
allow: HEADINGS
|
|
2740
2772
|
}
|
|
2741
2773
|
}],
|
|
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
2774
|
normalizer: [{
|
|
2753
2775
|
match: {
|
|
2754
2776
|
type: HEADINGS
|
|
@@ -2759,6 +2781,31 @@ var createHeadingPlugin = function createHeadingPlugin() {
|
|
|
2759
2781
|
},
|
|
2760
2782
|
transform: (_transform = {}, _transform[BLOCKS.PARAGRAPH] = transformUnwrap, _transform["default"] = transformLift, _transform)
|
|
2761
2783
|
}],
|
|
2784
|
+
then: function then(editor) {
|
|
2785
|
+
return {
|
|
2786
|
+
exitBreak: [// Pressing ENTER at the start or end of a heading text inserts a
|
|
2787
|
+
// normal paragraph.
|
|
2788
|
+
{
|
|
2789
|
+
hotkey: 'enter',
|
|
2790
|
+
query: {
|
|
2791
|
+
allow: HEADINGS,
|
|
2792
|
+
end: true,
|
|
2793
|
+
start: true,
|
|
2794
|
+
// Exclude headings inside lists as it interferes with the list's
|
|
2795
|
+
// insertBreak implementation
|
|
2796
|
+
filter: function filter(_ref2) {
|
|
2797
|
+
var path = _ref2[1];
|
|
2798
|
+
return !getAbove(editor, {
|
|
2799
|
+
at: path,
|
|
2800
|
+
match: {
|
|
2801
|
+
type: BLOCKS.LIST_ITEM
|
|
2802
|
+
}
|
|
2803
|
+
});
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
}]
|
|
2807
|
+
};
|
|
2808
|
+
},
|
|
2762
2809
|
plugins: HEADINGS.map(function (nodeType, idx) {
|
|
2763
2810
|
var level = idx + 1;
|
|
2764
2811
|
var tagName = "h" + level;
|
|
@@ -2881,7 +2928,7 @@ function ToolbarHrButton(props) {
|
|
|
2881
2928
|
hasText ? Transforms.insertNodes(editor, hr) : setNodes(editor, hr); // Move focus to the next paragraph (added by TrailingParagraph plugin)
|
|
2882
2929
|
|
|
2883
2930
|
moveToTheNextLine(editor);
|
|
2884
|
-
|
|
2931
|
+
focus(editor);
|
|
2885
2932
|
}
|
|
2886
2933
|
|
|
2887
2934
|
if (!editor) return null;
|
|
@@ -3373,7 +3420,7 @@ function _addOrEditLink() {
|
|
|
3373
3420
|
path: path
|
|
3374
3421
|
});
|
|
3375
3422
|
});
|
|
3376
|
-
|
|
3423
|
+
focus(editor);
|
|
3377
3424
|
|
|
3378
3425
|
case 15:
|
|
3379
3426
|
case "end":
|
|
@@ -3462,6 +3509,13 @@ function EntityHyperlink(props) {
|
|
|
3462
3509
|
var isReadOnly = useReadOnly();
|
|
3463
3510
|
var sdk = useSdkContext();
|
|
3464
3511
|
var target = props.element.data.target;
|
|
3512
|
+
var onEntityFetchComplete = props.onEntityFetchComplete;
|
|
3513
|
+
useEffect(function () {
|
|
3514
|
+
// The real entity loading happens in the tooltip
|
|
3515
|
+
// Since that is deferred the link is considered rendered as soon
|
|
3516
|
+
// the component mounts (link text displayed)
|
|
3517
|
+
onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
|
|
3518
|
+
}, [onEntityFetchComplete]);
|
|
3465
3519
|
if (!target) return null;
|
|
3466
3520
|
|
|
3467
3521
|
function handleClick(event) {
|
|
@@ -3592,7 +3646,7 @@ var getNodeOfType = function getNodeOfType(type) {
|
|
|
3592
3646
|
};
|
|
3593
3647
|
};
|
|
3594
3648
|
|
|
3595
|
-
var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
|
|
3649
|
+
var createHyperlinkPlugin = function createHyperlinkPlugin(sdk, tracking) {
|
|
3596
3650
|
var common = {
|
|
3597
3651
|
isElement: true,
|
|
3598
3652
|
isInline: true
|
|
@@ -3623,7 +3677,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
|
|
|
3623
3677
|
_extends({}, common, {
|
|
3624
3678
|
key: INLINES.ENTRY_HYPERLINK,
|
|
3625
3679
|
type: INLINES.ENTRY_HYPERLINK,
|
|
3626
|
-
component: EntityHyperlink,
|
|
3680
|
+
component: withLinkTracking(tracking, EntityHyperlink),
|
|
3627
3681
|
deserializeHtml: {
|
|
3628
3682
|
rules: [{
|
|
3629
3683
|
validNodeName: ['A']
|
|
@@ -3637,7 +3691,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
|
|
|
3637
3691
|
_extends({}, common, {
|
|
3638
3692
|
key: INLINES.ASSET_HYPERLINK,
|
|
3639
3693
|
type: INLINES.ASSET_HYPERLINK,
|
|
3640
|
-
component: EntityHyperlink,
|
|
3694
|
+
component: withLinkTracking(tracking, EntityHyperlink),
|
|
3641
3695
|
deserializeHtml: {
|
|
3642
3696
|
rules: [{
|
|
3643
3697
|
validNodeName: ['A']
|
|
@@ -3659,7 +3713,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
|
|
|
3659
3713
|
};
|
|
3660
3714
|
|
|
3661
3715
|
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);
|
|
3716
|
+
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
3717
|
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
3718
|
|
|
3665
3719
|
function createList(Tag, block) {
|
|
@@ -3674,7 +3728,7 @@ var ListUL = /*#__PURE__*/createList('ul', BLOCKS.UL_LIST);
|
|
|
3674
3728
|
var ListOL = /*#__PURE__*/createList('ol', BLOCKS.OL_LIST);
|
|
3675
3729
|
|
|
3676
3730
|
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);
|
|
3731
|
+
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
3732
|
function ListItem(props) {
|
|
3679
3733
|
return /*#__PURE__*/createElement("li", Object.assign({}, props.attributes, {
|
|
3680
3734
|
className: style
|
|
@@ -3742,66 +3796,285 @@ var insertParagraphAsChild = function insertParagraphAsChild(editor, _ref5) {
|
|
|
3742
3796
|
};
|
|
3743
3797
|
|
|
3744
3798
|
/**
|
|
3745
|
-
*
|
|
3746
|
-
* to support pasting any element
|
|
3799
|
+
* Build a new list item node while preserving marks
|
|
3747
3800
|
*/
|
|
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
3801
|
|
|
3754
|
-
|
|
3755
|
-
|
|
3802
|
+
var emptyListItemNode = function emptyListItemNode(editor, withChildren) {
|
|
3803
|
+
if (withChildren === void 0) {
|
|
3804
|
+
withChildren = false;
|
|
3805
|
+
}
|
|
3806
|
+
|
|
3807
|
+
var children = [];
|
|
3808
|
+
|
|
3809
|
+
if (withChildren) {
|
|
3810
|
+
var marks = Editor.marks(editor) || {};
|
|
3811
|
+
children = [{
|
|
3812
|
+
type: BLOCKS.PARAGRAPH,
|
|
3813
|
+
data: {},
|
|
3814
|
+
children: [_extends({
|
|
3815
|
+
text: ''
|
|
3816
|
+
}, marks)]
|
|
3817
|
+
}];
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3820
|
+
return {
|
|
3821
|
+
type: BLOCKS.LIST_ITEM,
|
|
3822
|
+
data: {},
|
|
3823
|
+
children: children
|
|
3756
3824
|
};
|
|
3825
|
+
};
|
|
3826
|
+
/**
|
|
3827
|
+
* Insert list item if selection is in li>p.
|
|
3828
|
+
*/
|
|
3757
3829
|
|
|
3758
|
-
var getFirstAncestorOfType = function getFirstAncestorOfType(root, entry, _ref) {
|
|
3759
|
-
var type = _ref.type;
|
|
3760
|
-
var ancestor = Path.parent(entry[1]);
|
|
3761
3830
|
|
|
3762
|
-
|
|
3763
|
-
|
|
3831
|
+
var insertListItem = function insertListItem(editor) {
|
|
3832
|
+
if (!editor.selection) {
|
|
3833
|
+
return false;
|
|
3834
|
+
} // Naming it paragraph for simplicity but can be a heading as well
|
|
3835
|
+
|
|
3836
|
+
|
|
3837
|
+
var paragraph = getAbove(editor, {
|
|
3838
|
+
match: {
|
|
3839
|
+
type: TEXT_CONTAINERS
|
|
3764
3840
|
}
|
|
3841
|
+
});
|
|
3765
3842
|
|
|
3766
|
-
|
|
3767
|
-
|
|
3843
|
+
if (!paragraph) {
|
|
3844
|
+
return false;
|
|
3845
|
+
}
|
|
3846
|
+
|
|
3847
|
+
var paragraphPath = paragraph[1];
|
|
3848
|
+
var listItem = getParent(editor, paragraphPath);
|
|
3849
|
+
|
|
3850
|
+
if (!listItem) {
|
|
3851
|
+
return false;
|
|
3852
|
+
}
|
|
3853
|
+
|
|
3854
|
+
var listItemNode = listItem[0],
|
|
3855
|
+
listItemPath = listItem[1];
|
|
3856
|
+
|
|
3857
|
+
if (listItemNode.type !== BLOCKS.LIST_ITEM) {
|
|
3858
|
+
return false;
|
|
3859
|
+
} // We are in a li>p (or heading)
|
|
3860
|
+
|
|
3861
|
+
|
|
3862
|
+
Editor.withoutNormalizing(editor, function () {
|
|
3863
|
+
if (!editor.selection) {
|
|
3864
|
+
return;
|
|
3865
|
+
} // Check the cursor position in the current paragraph
|
|
3866
|
+
|
|
3867
|
+
|
|
3868
|
+
var isAtStart = isSelectionAtBlockStart(editor);
|
|
3869
|
+
var isAtEnd = isSelectionAtBlockEnd(editor);
|
|
3870
|
+
var isAtStartOfListItem = isAtStart && isFirstChild(paragraphPath);
|
|
3871
|
+
var shouldSplit = !isAtStart && !isAtEnd; // Split the current paragraph content if necessary
|
|
3872
|
+
|
|
3873
|
+
if (shouldSplit) {
|
|
3874
|
+
Transforms.splitNodes(editor);
|
|
3875
|
+
} // Insert the new li
|
|
3876
|
+
|
|
3877
|
+
|
|
3878
|
+
var newListItemPath = isAtStartOfListItem ? listItemPath : Path.next(listItemPath);
|
|
3879
|
+
insertNodes(editor, // Add an empty paragraph to the new li if We will not move some
|
|
3880
|
+
// paragraphs over there.
|
|
3881
|
+
emptyListItemNode(editor, !shouldSplit), {
|
|
3882
|
+
at: newListItemPath
|
|
3883
|
+
}); // Move children *after* selection to the new li
|
|
3884
|
+
|
|
3885
|
+
var fromPath = isAtStart ? paragraphPath : Path.next(paragraphPath);
|
|
3886
|
+
var fromStartIndex = fromPath[fromPath.length - 1] || 0; // On split we don't add paragraph to the new li so we move
|
|
3887
|
+
// content to the very beginning. Otherwise, account for the empty
|
|
3888
|
+
// paragraph at the beginning by moving the content after
|
|
3889
|
+
|
|
3890
|
+
var toPath = newListItemPath.concat([shouldSplit ? 0 : 1]);
|
|
3891
|
+
|
|
3892
|
+
if (!isAtStartOfListItem) {
|
|
3893
|
+
moveChildren(editor, {
|
|
3894
|
+
at: listItemPath,
|
|
3895
|
+
to: toPath,
|
|
3896
|
+
fromStartIndex: fromStartIndex
|
|
3897
|
+
});
|
|
3898
|
+
} // Move cursor to the start of the new li
|
|
3899
|
+
|
|
3900
|
+
|
|
3901
|
+
Transforms.select(editor, newListItemPath);
|
|
3902
|
+
Transforms.collapse(editor, {
|
|
3903
|
+
edge: 'start'
|
|
3904
|
+
});
|
|
3905
|
+
}); // Returning True skips processing other editor.insertBreak handlers
|
|
3906
|
+
|
|
3907
|
+
return true;
|
|
3908
|
+
};
|
|
3909
|
+
|
|
3910
|
+
/**
|
|
3911
|
+
* Credit: Copied & modified version from Plate's list plugin to support
|
|
3912
|
+
* list items with multiple children.
|
|
3913
|
+
*
|
|
3914
|
+
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
3915
|
+
*/
|
|
3916
|
+
|
|
3917
|
+
var listBreak = function listBreak(editor) {
|
|
3918
|
+
if (!editor.selection) return false;
|
|
3919
|
+
var res = getListItemEntry(editor, {});
|
|
3920
|
+
var moved; // If selection is in a li
|
|
3921
|
+
|
|
3922
|
+
if (res) {
|
|
3923
|
+
var list = res.list,
|
|
3924
|
+
listItem = res.listItem;
|
|
3925
|
+
var childNode = listItem[0].children[0]; // If selected li is empty, move it up.
|
|
3926
|
+
|
|
3927
|
+
if (isBlockAboveEmpty(editor) && listItem[0].children.length === 1 && TEXT_CONTAINERS.includes(childNode.type)) {
|
|
3928
|
+
moved = moveListItemUp(editor, {
|
|
3929
|
+
list: list,
|
|
3930
|
+
listItem: listItem
|
|
3931
|
+
});
|
|
3932
|
+
if (moved) return true;
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3935
|
+
|
|
3936
|
+
var didReset = onKeyDownResetNode(editor, mockPlugin({
|
|
3937
|
+
options: {
|
|
3938
|
+
rules: [{
|
|
3939
|
+
types: [getPluginType(editor, ELEMENT_LI)],
|
|
3940
|
+
defaultType: getPluginType(editor, ELEMENT_DEFAULT),
|
|
3941
|
+
predicate: function predicate() {
|
|
3942
|
+
return !moved && isBlockAboveEmpty(editor);
|
|
3943
|
+
},
|
|
3944
|
+
onReset: function onReset(_editor) {
|
|
3945
|
+
return unwrapList(_editor);
|
|
3946
|
+
}
|
|
3947
|
+
}]
|
|
3948
|
+
}
|
|
3949
|
+
}))(SIMULATE_BACKSPACE);
|
|
3950
|
+
|
|
3951
|
+
if (didReset) {
|
|
3952
|
+
return true;
|
|
3953
|
+
}
|
|
3768
3954
|
/**
|
|
3769
|
-
*
|
|
3770
|
-
*
|
|
3771
|
-
* @returns If argument is not a list root, returns it, otherwise returns ul[] or li[].
|
|
3955
|
+
* If selection is in li > p, insert li.
|
|
3772
3956
|
*/
|
|
3773
3957
|
|
|
3774
3958
|
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3959
|
+
if (!moved) {
|
|
3960
|
+
var inserted = insertListItem(editor);
|
|
3961
|
+
if (inserted) return true;
|
|
3962
|
+
}
|
|
3963
|
+
|
|
3964
|
+
return false;
|
|
3965
|
+
};
|
|
3779
3966
|
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
return isListRoot(commonAncestorEntry[0]) ? commonAncestorEntry[0].children : [commonAncestorEntry[0]];
|
|
3967
|
+
var insertListBreak = function insertListBreak(editor) {
|
|
3968
|
+
var insertBreak = editor.insertBreak;
|
|
3969
|
+
return function () {
|
|
3970
|
+
if (listBreak(editor)) return;
|
|
3971
|
+
insertBreak();
|
|
3786
3972
|
};
|
|
3973
|
+
};
|
|
3787
3974
|
|
|
3975
|
+
/**
|
|
3976
|
+
* Credit: Modified version of Plate's list plugin
|
|
3977
|
+
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
3978
|
+
*/
|
|
3979
|
+
|
|
3980
|
+
var getFirstAncestorOfType = function getFirstAncestorOfType(root, entry) {
|
|
3981
|
+
var ancestor = Path.parent(entry[1]);
|
|
3982
|
+
|
|
3983
|
+
while (Node.get(root, ancestor).type !== BLOCKS.LIST_ITEM) {
|
|
3984
|
+
ancestor = Path.parent(ancestor);
|
|
3985
|
+
}
|
|
3986
|
+
|
|
3987
|
+
return [Node.get(root, ancestor), ancestor];
|
|
3988
|
+
};
|
|
3989
|
+
|
|
3990
|
+
var isListRoot = function isListRoot(node) {
|
|
3991
|
+
return [BLOCKS.UL_LIST, BLOCKS.OL_LIST].includes(node.type);
|
|
3992
|
+
};
|
|
3993
|
+
/**
|
|
3994
|
+
* Removes the "empty" leading lis. Empty in this context means lis only with other lis as children.
|
|
3995
|
+
*
|
|
3996
|
+
* @returns If argument is not a list root, returns it, otherwise returns ul[] or li[].
|
|
3997
|
+
*/
|
|
3998
|
+
|
|
3999
|
+
|
|
4000
|
+
var trimList = function trimList(listRoot) {
|
|
4001
|
+
if (!isListRoot(listRoot)) {
|
|
4002
|
+
return [listRoot];
|
|
4003
|
+
}
|
|
4004
|
+
|
|
4005
|
+
var textEntries = Array.from(Node.texts(listRoot));
|
|
4006
|
+
var commonAncestorEntry = textEntries.reduce(function (commonAncestor, textEntry) {
|
|
4007
|
+
return Path.isAncestor(commonAncestor[1], textEntry[1]) ? commonAncestor : Node.common(listRoot, textEntry[1], commonAncestor[1]);
|
|
4008
|
+
}, // any list item would do, we grab the first one
|
|
4009
|
+
getFirstAncestorOfType(listRoot, textEntries[0]));
|
|
4010
|
+
return isListRoot(commonAncestorEntry[0]) ? commonAncestorEntry[0].children : [commonAncestorEntry[0]];
|
|
4011
|
+
};
|
|
4012
|
+
/**
|
|
4013
|
+
* Removes leading li when pasting a single li with a single child.
|
|
4014
|
+
*/
|
|
4015
|
+
|
|
4016
|
+
|
|
4017
|
+
var trimLiWrapper = function trimLiWrapper(nodes) {
|
|
4018
|
+
if (nodes.length !== 1) {
|
|
4019
|
+
return nodes;
|
|
4020
|
+
}
|
|
4021
|
+
|
|
4022
|
+
var node = nodes[0];
|
|
4023
|
+
|
|
4024
|
+
if (node.type !== BLOCKS.LIST_ITEM || node.children.length !== 1) {
|
|
4025
|
+
return nodes;
|
|
4026
|
+
}
|
|
4027
|
+
|
|
4028
|
+
return node.children;
|
|
4029
|
+
};
|
|
4030
|
+
|
|
4031
|
+
var unwrapTextContainerAtStart = function unwrapTextContainerAtStart(nodes) {
|
|
4032
|
+
var node = nodes[0];
|
|
4033
|
+
|
|
4034
|
+
if (TEXT_CONTAINERS.includes(node.type)) {
|
|
4035
|
+
return [].concat(node.children, nodes.slice(1));
|
|
4036
|
+
}
|
|
4037
|
+
|
|
4038
|
+
return nodes;
|
|
4039
|
+
};
|
|
4040
|
+
|
|
4041
|
+
var insertListFragment = function insertListFragment(editor) {
|
|
4042
|
+
var insertFragment = editor.insertFragment;
|
|
3788
4043
|
return function (fragment) {
|
|
4044
|
+
if (!editor.selection) {
|
|
4045
|
+
return;
|
|
4046
|
+
}
|
|
4047
|
+
|
|
3789
4048
|
var liEntry = findNode(editor, {
|
|
3790
4049
|
match: {
|
|
3791
|
-
type:
|
|
4050
|
+
type: BLOCKS.LIST_ITEM
|
|
3792
4051
|
},
|
|
3793
4052
|
mode: 'lowest'
|
|
3794
4053
|
});
|
|
3795
4054
|
|
|
3796
4055
|
if (liEntry) {
|
|
3797
|
-
var
|
|
3798
|
-
// non-text elements
|
|
3799
|
-
|
|
3800
|
-
var nodes = fragment.flatMap(function (node) {
|
|
4056
|
+
var nodes = unwrapTextContainerAtStart(trimLiWrapper(fragment.flatMap(function (node) {
|
|
3801
4057
|
return trimList(node);
|
|
4058
|
+
})));
|
|
4059
|
+
var firstBlockIndex = nodes.findIndex(function (node) {
|
|
4060
|
+
return Editor.isBlock(editor, node);
|
|
3802
4061
|
});
|
|
3803
|
-
|
|
3804
|
-
|
|
4062
|
+
|
|
4063
|
+
if (firstBlockIndex < 0) {
|
|
4064
|
+
firstBlockIndex = nodes.length;
|
|
4065
|
+
}
|
|
4066
|
+
|
|
4067
|
+
var inlines = nodes.slice(0, firstBlockIndex);
|
|
4068
|
+
var blocks = nodes.slice(firstBlockIndex); // Two calls to insertNodes are required here. Otherwise, all blocks
|
|
4069
|
+
// after a text or inline element occurrence will be unwrapped for
|
|
4070
|
+
// some reason.
|
|
4071
|
+
|
|
4072
|
+
Transforms.insertNodes(editor, inlines, {
|
|
4073
|
+
at: editor.selection,
|
|
4074
|
+
select: true
|
|
4075
|
+
});
|
|
4076
|
+
return Transforms.insertNodes(editor, blocks, {
|
|
4077
|
+
at: editor.selection,
|
|
3805
4078
|
select: true
|
|
3806
4079
|
});
|
|
3807
4080
|
}
|
|
@@ -3813,18 +4086,37 @@ var getListInsertFragment = function getListInsertFragment(editor) {
|
|
|
3813
4086
|
};
|
|
3814
4087
|
};
|
|
3815
4088
|
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
4089
|
+
/**
|
|
4090
|
+
* Credit: Modified version of Plate's list plugin
|
|
4091
|
+
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
4092
|
+
*/
|
|
4093
|
+
var validLiChildrenTypes = LIST_ITEM_BLOCKS;
|
|
4094
|
+
var withList = function withList(editor) {
|
|
4095
|
+
var deleteBackward = editor.deleteBackward,
|
|
4096
|
+
deleteForward = editor.deleteForward,
|
|
4097
|
+
deleteFragment = editor.deleteFragment;
|
|
4098
|
+
|
|
4099
|
+
editor.deleteBackward = function (unit) {
|
|
4100
|
+
if (deleteBackwardList(editor, unit)) return;
|
|
4101
|
+
deleteBackward(unit);
|
|
4102
|
+
};
|
|
3824
4103
|
|
|
3825
|
-
editor.
|
|
4104
|
+
editor.deleteForward = function (unit) {
|
|
4105
|
+
if (deleteForwardList(editor)) return;
|
|
4106
|
+
deleteForward(unit);
|
|
4107
|
+
};
|
|
4108
|
+
|
|
4109
|
+
editor.deleteFragment = function () {
|
|
4110
|
+
if (deleteFragmentList(editor)) return;
|
|
4111
|
+
deleteFragment();
|
|
4112
|
+
};
|
|
4113
|
+
|
|
4114
|
+
editor.insertBreak = insertListBreak(editor);
|
|
4115
|
+
editor.insertFragment = insertListFragment(editor); // TODO: replace with Normalizer rules
|
|
3826
4116
|
|
|
3827
|
-
editor.
|
|
4117
|
+
editor.normalizeNode = normalizeList(editor, {
|
|
4118
|
+
validLiChildrenTypes: validLiChildrenTypes
|
|
4119
|
+
});
|
|
3828
4120
|
return editor;
|
|
3829
4121
|
};
|
|
3830
4122
|
|
|
@@ -3882,7 +4174,7 @@ function ToolbarListButton(props) {
|
|
|
3882
4174
|
toggleList(editor, {
|
|
3883
4175
|
type: type
|
|
3884
4176
|
});
|
|
3885
|
-
|
|
4177
|
+
focus(editor);
|
|
3886
4178
|
};
|
|
3887
4179
|
}
|
|
3888
4180
|
|
|
@@ -3910,7 +4202,7 @@ function ToolbarBoldButton(props) {
|
|
|
3910
4202
|
toggleMark(editor, {
|
|
3911
4203
|
key: MARKS.BOLD
|
|
3912
4204
|
});
|
|
3913
|
-
|
|
4205
|
+
focus(editor);
|
|
3914
4206
|
}
|
|
3915
4207
|
|
|
3916
4208
|
if (!editor) return null;
|
|
@@ -3969,7 +4261,7 @@ function ToolbarCodeButton(props) {
|
|
|
3969
4261
|
toggleMark(editor, {
|
|
3970
4262
|
key: MARKS.CODE
|
|
3971
4263
|
});
|
|
3972
|
-
|
|
4264
|
+
focus(editor);
|
|
3973
4265
|
}
|
|
3974
4266
|
|
|
3975
4267
|
if (!editor) return null;
|
|
@@ -4019,7 +4311,7 @@ function ToolbarItalicButton(props) {
|
|
|
4019
4311
|
toggleMark(editor, {
|
|
4020
4312
|
key: MARKS.ITALIC
|
|
4021
4313
|
});
|
|
4022
|
-
|
|
4314
|
+
focus(editor);
|
|
4023
4315
|
}
|
|
4024
4316
|
|
|
4025
4317
|
if (!editor) return null;
|
|
@@ -4073,7 +4365,7 @@ function ToolbarUnderlineButton(props) {
|
|
|
4073
4365
|
toggleMark(editor, {
|
|
4074
4366
|
key: MARKS.UNDERLINE
|
|
4075
4367
|
});
|
|
4076
|
-
|
|
4368
|
+
focus(editor);
|
|
4077
4369
|
}
|
|
4078
4370
|
|
|
4079
4371
|
if (!editor) return null;
|
|
@@ -4558,7 +4850,7 @@ function ToolbarQuoteButton(props) {
|
|
|
4558
4850
|
function handleOnClick() {
|
|
4559
4851
|
if (!editor) return;
|
|
4560
4852
|
toggleQuote(editor);
|
|
4561
|
-
|
|
4853
|
+
focus(editor);
|
|
4562
4854
|
}
|
|
4563
4855
|
|
|
4564
4856
|
if (!editor) return null;
|
|
@@ -4914,11 +5206,7 @@ var TableActions = function TableActions() {
|
|
|
4914
5206
|
|
|
4915
5207
|
var close = React__default.useCallback(function () {
|
|
4916
5208
|
setOpen(false);
|
|
4917
|
-
|
|
4918
|
-
// the dropdown menu
|
|
4919
|
-
|
|
4920
|
-
ReactEditor.focus(editor);
|
|
4921
|
-
}, [editor]);
|
|
5209
|
+
}, []);
|
|
4922
5210
|
React__default.useEffect(function () {
|
|
4923
5211
|
setHeaderEnabled(Boolean(editor && isTableHeaderEnabled(editor)));
|
|
4924
5212
|
}, [editor]);
|
|
@@ -5187,7 +5475,7 @@ function ToolbarTableButton(props) {
|
|
|
5187
5475
|
case 2:
|
|
5188
5476
|
onViewportAction('insertTable');
|
|
5189
5477
|
insertTableAndFocusFirstCell(editor);
|
|
5190
|
-
|
|
5478
|
+
focus(editor);
|
|
5191
5479
|
|
|
5192
5480
|
case 5:
|
|
5193
5481
|
case "end":
|
|
@@ -5214,36 +5502,49 @@ function createTextPlugin() {
|
|
|
5214
5502
|
return {
|
|
5215
5503
|
key: 'TextPlugin',
|
|
5216
5504
|
withOverrides: function withOverrides(editor) {
|
|
5217
|
-
|
|
5505
|
+
// Reverts the change made upstream that caused the cursor
|
|
5506
|
+
// to be trapped inside inline elements.
|
|
5507
|
+
//
|
|
5508
|
+
// Reverts https://github.com/ianstormtaylor/slate/pull/4578/
|
|
5509
|
+
// Related https://github.com/ianstormtaylor/slate/issues/4704
|
|
5510
|
+
var insertText = editor.insertText;
|
|
5511
|
+
|
|
5512
|
+
editor.insertText = function (text) {
|
|
5513
|
+
var selection = editor.selection; // If the cursor is at the end of an inline, move it outside
|
|
5514
|
+
// before inserting
|
|
5515
|
+
|
|
5516
|
+
if (selection && Range.isCollapsed(selection)) {
|
|
5517
|
+
var _Editor$above;
|
|
5518
|
+
|
|
5519
|
+
var inlinePath = (_Editor$above = Editor.above(editor, {
|
|
5520
|
+
match: function match(n) {
|
|
5521
|
+
return Editor.isInline(editor, n);
|
|
5522
|
+
},
|
|
5523
|
+
mode: 'highest'
|
|
5524
|
+
})) == null ? void 0 : _Editor$above[1];
|
|
5525
|
+
|
|
5526
|
+
if (inlinePath && Editor.isEnd(editor, selection.anchor, inlinePath)) {
|
|
5527
|
+
var point = Editor.after(editor, inlinePath);
|
|
5528
|
+
Transforms.setSelection(editor, {
|
|
5529
|
+
anchor: point,
|
|
5530
|
+
focus: point
|
|
5531
|
+
});
|
|
5532
|
+
}
|
|
5533
|
+
}
|
|
5218
5534
|
|
|
5219
|
-
|
|
5220
|
-
|
|
5535
|
+
return insertText(text);
|
|
5536
|
+
}; // When pressing delete instead of backspace
|
|
5221
5537
|
|
|
5222
|
-
var _Editor$nodes = Editor.nodes(editor, {
|
|
5223
|
-
at: (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path,
|
|
5224
|
-
match: function match(node) {
|
|
5225
|
-
return TEXT_CONTAINERS.includes(node.type);
|
|
5226
|
-
}
|
|
5227
|
-
}),
|
|
5228
|
-
nodes = _Editor$nodes[0];
|
|
5229
5538
|
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
path = nodes[1];
|
|
5233
|
-
var isTextEmpty = isAncestorEmpty(editor, paragraphOrHeading); // We ignore paragraphs/headings that are children of ul, ol, blockquote, tables, etc
|
|
5539
|
+
var deleteForward = editor.deleteForward,
|
|
5540
|
+
deleteBackward = editor.deleteBackward;
|
|
5234
5541
|
|
|
5235
|
-
|
|
5542
|
+
editor.deleteBackward = function (unit) {
|
|
5543
|
+
deleteEmptyParagraph(unit, editor, deleteBackward);
|
|
5544
|
+
};
|
|
5236
5545
|
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
at: path
|
|
5240
|
-
});
|
|
5241
|
-
} else {
|
|
5242
|
-
deleteForward(unit);
|
|
5243
|
-
}
|
|
5244
|
-
} else {
|
|
5245
|
-
deleteForward(unit);
|
|
5246
|
-
}
|
|
5546
|
+
editor.deleteForward = function (unit) {
|
|
5547
|
+
deleteEmptyParagraph(unit, editor, deleteForward);
|
|
5247
5548
|
};
|
|
5248
5549
|
|
|
5249
5550
|
return editor;
|
|
@@ -5251,6 +5552,32 @@ function createTextPlugin() {
|
|
|
5251
5552
|
};
|
|
5252
5553
|
}
|
|
5253
5554
|
|
|
5555
|
+
function deleteEmptyParagraph(unit, editor, deleteFunction) {
|
|
5556
|
+
var entry = getAbove(editor, {
|
|
5557
|
+
match: {
|
|
5558
|
+
type: TEXT_CONTAINERS
|
|
5559
|
+
}
|
|
5560
|
+
});
|
|
5561
|
+
|
|
5562
|
+
if (entry) {
|
|
5563
|
+
var paragraphOrHeading = entry[0],
|
|
5564
|
+
path = entry[1];
|
|
5565
|
+
var isTextEmpty = isAncestorEmpty(editor, paragraphOrHeading); // We ignore paragraphs/headings that are children of ul, ol, blockquote, tables, etc
|
|
5566
|
+
|
|
5567
|
+
var isRootLevel = path.length === 1;
|
|
5568
|
+
|
|
5569
|
+
if (isTextEmpty && isRootLevel) {
|
|
5570
|
+
Transforms.removeNodes(editor, {
|
|
5571
|
+
at: path
|
|
5572
|
+
});
|
|
5573
|
+
} else {
|
|
5574
|
+
deleteFunction(unit);
|
|
5575
|
+
}
|
|
5576
|
+
} else {
|
|
5577
|
+
deleteFunction(unit);
|
|
5578
|
+
}
|
|
5579
|
+
}
|
|
5580
|
+
|
|
5254
5581
|
var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
|
|
5255
5582
|
return createTrailingBlockPlugin({
|
|
5256
5583
|
options: {
|
|
@@ -5286,8 +5613,9 @@ var transformVoid = function transformVoid(editor, _ref) {
|
|
|
5286
5613
|
var createVoidsPlugin = function createVoidsPlugin() {
|
|
5287
5614
|
return {
|
|
5288
5615
|
key: 'VoidsPlugin',
|
|
5289
|
-
exitBreak: [
|
|
5290
|
-
|
|
5616
|
+
exitBreak: [{
|
|
5617
|
+
// Inserts a new paragraph *before* a void element if it's the very first
|
|
5618
|
+
// node on the editor
|
|
5291
5619
|
hotkey: 'enter',
|
|
5292
5620
|
before: true,
|
|
5293
5621
|
query: {
|
|
@@ -5297,14 +5625,17 @@ var createVoidsPlugin = function createVoidsPlugin() {
|
|
|
5297
5625
|
return isRootLevel(path) && isFirstChild(path) && !!node.isVoid;
|
|
5298
5626
|
}
|
|
5299
5627
|
}
|
|
5300
|
-
},
|
|
5301
|
-
|
|
5628
|
+
}, {
|
|
5629
|
+
// Inserts a new paragraph on enter when a void element is focused
|
|
5302
5630
|
hotkey: 'enter',
|
|
5631
|
+
// exploit the internal use of Array.slice(0, level + 1) by the exitBreak plugin
|
|
5632
|
+
// to stay in the parent element
|
|
5633
|
+
level: -2,
|
|
5303
5634
|
query: {
|
|
5304
5635
|
filter: function filter(_ref2) {
|
|
5305
5636
|
var node = _ref2[0],
|
|
5306
5637
|
path = _ref2[1];
|
|
5307
|
-
return !isFirstChild(path) && !!node.isVoid;
|
|
5638
|
+
return !(isRootLevel(path) && isFirstChild(path)) && !!node.isVoid;
|
|
5308
5639
|
}
|
|
5309
5640
|
}
|
|
5310
5641
|
}],
|
|
@@ -5333,8 +5664,8 @@ var getPlugins = function getPlugins(sdk, tracking) {
|
|
|
5333
5664
|
return [// AST must come after the HTML deserializer
|
|
5334
5665
|
createDeserializeHtmlPlugin(), createDeserializeAstPlugin(), createDeserializeDocxPlugin(), // Global shortcuts
|
|
5335
5666
|
createDragAndDropPlugin(), // Block Elements
|
|
5336
|
-
createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk), createEmbeddedAssetBlockPlugin(sdk), // Inline elements
|
|
5337
|
-
createHyperlinkPlugin(sdk), createEmbeddedEntityInlinePlugin(sdk), // Marks
|
|
5667
|
+
createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk, tracking), createEmbeddedAssetBlockPlugin(sdk, tracking), // Inline elements
|
|
5668
|
+
createHyperlinkPlugin(sdk, tracking), createEmbeddedEntityInlinePlugin(sdk, tracking), // Marks
|
|
5338
5669
|
createMarksPlugin(), // Other
|
|
5339
5670
|
createTrailingParagraphPlugin(), createTextPlugin(), createVoidsPlugin(), createSelectOnBackspacePlugin(), // Pasting content from other sources
|
|
5340
5671
|
createPasteHTMLPlugin(), // These plugins drive their configurations from the list of plugins
|
|
@@ -5605,13 +5936,9 @@ var StickyToolbarWrapper = function StickyToolbarWrapper(_ref) {
|
|
|
5605
5936
|
var _excluded = ["sdk", "isInitiallyDisabled", "onAction"];
|
|
5606
5937
|
var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
|
|
5607
5938
|
var tracking = useTrackingContext();
|
|
5608
|
-
var
|
|
5609
|
-
document: props.value || EMPTY_DOCUMENT,
|
|
5610
|
-
schema: schema
|
|
5611
|
-
});
|
|
5612
|
-
var doc = sanitizeIncomingSlateDoc(docFromAdapter);
|
|
5939
|
+
var editor = useContentfulEditor();
|
|
5613
5940
|
|
|
5614
|
-
var _useState = useState(
|
|
5941
|
+
var _useState = useState([]),
|
|
5615
5942
|
value = _useState[0],
|
|
5616
5943
|
setValue = _useState[1];
|
|
5617
5944
|
|
|
@@ -5621,12 +5948,33 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
|
|
|
5621
5948
|
var plugins = React__default.useMemo(function () {
|
|
5622
5949
|
return getPlugins(props.sdk, tracking);
|
|
5623
5950
|
}, [props.sdk, tracking]);
|
|
5951
|
+
React__default.useEffect(function () {
|
|
5952
|
+
if (!editor) {
|
|
5953
|
+
return;
|
|
5954
|
+
}
|
|
5955
|
+
|
|
5956
|
+
var docFromAdapter = toSlatejsDocument({
|
|
5957
|
+
document: props.value || EMPTY_DOCUMENT,
|
|
5958
|
+
schema: schema
|
|
5959
|
+
});
|
|
5960
|
+
var doc = sanitizeIncomingSlateDoc(docFromAdapter); // Slate throws an error if the value on the initial render is invalid
|
|
5961
|
+
// so we directly set the value on the editor in order
|
|
5962
|
+
// to be able to trigger normalization on the initial value before rendering
|
|
5963
|
+
// TODO: use https://plate.udecode.io/docs/Plate#normalizeinitialvalue when working
|
|
5964
|
+
|
|
5965
|
+
editor.children = doc;
|
|
5966
|
+
Editor.normalize(editor, {
|
|
5967
|
+
force: true
|
|
5968
|
+
}); // We set the value so that the rendering can take over from here
|
|
5969
|
+
|
|
5970
|
+
setValue(editor.children);
|
|
5971
|
+
}, [props.value, editor]);
|
|
5624
5972
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
5625
5973
|
className: styles$j.root,
|
|
5626
5974
|
"data-test-id": "rich-text-editor"
|
|
5627
5975
|
}, /*#__PURE__*/React__default.createElement(Plate, {
|
|
5628
5976
|
id: getContentfulEditorId(props.sdk),
|
|
5629
|
-
|
|
5977
|
+
value: value,
|
|
5630
5978
|
plugins: plugins,
|
|
5631
5979
|
disableCorePlugins: disableCorePlugins,
|
|
5632
5980
|
editableProps: {
|