@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
|
@@ -14,11 +14,11 @@ var plateCore = require('@udecode/plate-core');
|
|
|
14
14
|
var emotion = require('emotion');
|
|
15
15
|
var deepEquals = _interopDefault(require('fast-deep-equal'));
|
|
16
16
|
var noop = _interopDefault(require('lodash/noop'));
|
|
17
|
+
var slate = require('slate');
|
|
17
18
|
var constate = _interopDefault(require('constate'));
|
|
18
19
|
var plateSerializerDocx = require('@udecode/plate-serializer-docx');
|
|
19
20
|
var plateBreak = require('@udecode/plate-break');
|
|
20
21
|
var isHotkey = _interopDefault(require('is-hotkey'));
|
|
21
|
-
var slate = require('slate');
|
|
22
22
|
var Slate = require('slate-react');
|
|
23
23
|
var f36Components = require('@contentful/f36-components');
|
|
24
24
|
var mimetype = _interopDefault(require('@contentful/mimetype'));
|
|
@@ -28,6 +28,7 @@ var tokens = _interopDefault(require('@contentful/f36-tokens'));
|
|
|
28
28
|
var find = _interopDefault(require('lodash/find'));
|
|
29
29
|
var flow = _interopDefault(require('lodash/flow'));
|
|
30
30
|
var plateList = require('@udecode/plate-list');
|
|
31
|
+
var plateResetNode = require('@udecode/plate-reset-node');
|
|
31
32
|
var plateBasicMarks = require('@udecode/plate-basic-marks');
|
|
32
33
|
var isPlainObject = _interopDefault(require('is-plain-obj'));
|
|
33
34
|
var plateParagraph = require('@udecode/plate-paragraph');
|
|
@@ -348,8 +349,8 @@ var schema = {
|
|
|
348
349
|
function getContentfulEditorId(sdk) {
|
|
349
350
|
var entry = sdk.entry,
|
|
350
351
|
field = sdk.field;
|
|
351
|
-
var
|
|
352
|
-
return "rich-text-editor-" +
|
|
352
|
+
var sys = entry.getSys();
|
|
353
|
+
return "rich-text-editor-" + sys.id + "-" + field.id + "-" + field.locale;
|
|
353
354
|
}
|
|
354
355
|
|
|
355
356
|
function useContentfulEditorHook(_ref) {
|
|
@@ -490,6 +491,18 @@ function getParents(el) {
|
|
|
490
491
|
return parents;
|
|
491
492
|
}
|
|
492
493
|
|
|
494
|
+
// "modern" Edge was released at 79.x
|
|
495
|
+
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
|
|
496
|
+
// and older, Chrome 76+ can use `beforeInput` though.
|
|
497
|
+
|
|
498
|
+
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
|
|
499
|
+
// Chrome Legacy doesn't support `beforeinput` correctly
|
|
500
|
+
|
|
501
|
+
var HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY && !IS_EDGE_LEGACY && // globalThis is undefined in older browsers
|
|
502
|
+
typeof globalThis !== 'undefined' && globalThis.InputEvent && typeof globalThis.InputEvent.prototype.getTargetRanges === 'function'; // The `getTargetRanges` property isn't recognized.
|
|
503
|
+
|
|
504
|
+
var IS_SAFARI = typeof navigator !== 'undefined' && /*#__PURE__*/ /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
505
|
+
|
|
493
506
|
var LINK_TYPES = [Contentful.INLINES.HYPERLINK, Contentful.INLINES.ENTRY_HYPERLINK, Contentful.INLINES.ASSET_HYPERLINK];
|
|
494
507
|
function isBlockSelected(editor, type) {
|
|
495
508
|
var _Array$from = Array.from(slate.Editor.nodes(editor, {
|
|
@@ -707,16 +720,27 @@ var isInlineOrText = function isInlineOrText(node) {
|
|
|
707
720
|
// either text or inline elements
|
|
708
721
|
return slate.Text.isText(node) || slate.Element.isElement(node) && INLINE_TYPES.includes(node.type);
|
|
709
722
|
};
|
|
723
|
+
var focus = function focus(editor) {
|
|
724
|
+
var x = window.scrollX;
|
|
725
|
+
var y = window.scrollY;
|
|
726
|
+
Slate.ReactEditor.focus(editor); // Safari has issues with `editor.focus({ preventScroll: true })`, it ignores the option `preventScroll`
|
|
727
|
+
|
|
728
|
+
if (IS_SAFARI) {
|
|
729
|
+
setTimeout(function () {
|
|
730
|
+
window.scrollTo(x, y); // restore position
|
|
731
|
+
}, 0);
|
|
732
|
+
}
|
|
733
|
+
};
|
|
710
734
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
735
|
+
function withLinkTracking(tracking, Component) {
|
|
736
|
+
return function ComponentWithTracking(props) {
|
|
737
|
+
return /*#__PURE__*/React__default.createElement(Component, Object.assign({}, props, {
|
|
738
|
+
onEntityFetchComplete: function onEntityFetchComplete() {
|
|
739
|
+
tracking.onViewportAction('linkRendered');
|
|
740
|
+
}
|
|
741
|
+
}));
|
|
742
|
+
};
|
|
743
|
+
}
|
|
720
744
|
|
|
721
745
|
function useSdk(_ref) {
|
|
722
746
|
var sdk = _ref.sdk;
|
|
@@ -854,10 +878,19 @@ function FetchingWrappedAssetCard(props) {
|
|
|
854
878
|
var asset = assets[props.assetId];
|
|
855
879
|
var defaultLocaleCode = props.sdk.locales["default"];
|
|
856
880
|
var entityFile = asset != null && (_asset$fields = asset.fields) != null && _asset$fields.file ? asset.fields.file[props.locale] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
881
|
+
var onEntityFetchComplete = props.onEntityFetchComplete;
|
|
857
882
|
React.useEffect(function () {
|
|
858
883
|
getOrLoadAsset(props.assetId);
|
|
859
884
|
}, [props.assetId]); // eslint-disable-line
|
|
860
885
|
|
|
886
|
+
React.useEffect(function () {
|
|
887
|
+
if (!asset) {
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
|
|
892
|
+
}, [asset, onEntityFetchComplete]);
|
|
893
|
+
|
|
861
894
|
function getAssetSrc() {
|
|
862
895
|
if (!(entityFile != null && entityFile.url)) return '';
|
|
863
896
|
return entityFile.url + "?h=300";
|
|
@@ -982,6 +1015,7 @@ function FetchingWrappedEntryCard(props) {
|
|
|
982
1015
|
});
|
|
983
1016
|
}, [props.sdk, entry]);
|
|
984
1017
|
var defaultLocaleCode = props.sdk.locales["default"];
|
|
1018
|
+
var onEntityFetchComplete = props.onEntityFetchComplete;
|
|
985
1019
|
React.useEffect(function () {
|
|
986
1020
|
if (!entry || entry === 'failed') return;
|
|
987
1021
|
fieldEditorShared.entityHelpers.getEntryImage({
|
|
@@ -997,6 +1031,14 @@ function FetchingWrappedEntryCard(props) {
|
|
|
997
1031
|
getOrLoadEntry(props.entryId);
|
|
998
1032
|
}, [props.entryId]); // eslint-disable-line
|
|
999
1033
|
|
|
1034
|
+
React.useEffect(function () {
|
|
1035
|
+
if (!entry) {
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
|
|
1040
|
+
}, [entry, onEntityFetchComplete]);
|
|
1041
|
+
|
|
1000
1042
|
function renderDropdown() {
|
|
1001
1043
|
if (!props.onEdit || !props.onRemove) return undefined;
|
|
1002
1044
|
return [props.onEdit ? /*#__PURE__*/React.createElement(f36Components.MenuItem, {
|
|
@@ -1078,13 +1120,14 @@ function FetchingWrappedEntryCard(props) {
|
|
|
1078
1120
|
|
|
1079
1121
|
var styles$3 = {
|
|
1080
1122
|
root: /*#__PURE__*/emotion.css({
|
|
1081
|
-
marginBottom: '1.25rem'
|
|
1123
|
+
marginBottom: '1.25rem !important'
|
|
1082
1124
|
})
|
|
1083
1125
|
};
|
|
1084
1126
|
function LinkedEntityBlock(props) {
|
|
1085
1127
|
var attributes = props.attributes,
|
|
1086
1128
|
children = props.children,
|
|
1087
|
-
element = props.element
|
|
1129
|
+
element = props.element,
|
|
1130
|
+
onEntityFetchComplete = props.onEntityFetchComplete;
|
|
1088
1131
|
var isSelected = Slate.useSelected();
|
|
1089
1132
|
var editor = useContentfulEditor();
|
|
1090
1133
|
var sdk = useSdkContext();
|
|
@@ -1126,7 +1169,8 @@ function LinkedEntityBlock(props) {
|
|
|
1126
1169
|
isDisabled: isDisabled,
|
|
1127
1170
|
isSelected: isSelected,
|
|
1128
1171
|
onRemove: handleRemoveClick,
|
|
1129
|
-
onEdit: handleEditClick
|
|
1172
|
+
onEdit: handleEditClick,
|
|
1173
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
1130
1174
|
}), entityType === 'Asset' && /*#__PURE__*/React__default.createElement(FetchingWrappedAssetCard, {
|
|
1131
1175
|
sdk: sdk,
|
|
1132
1176
|
assetId: entityId,
|
|
@@ -1134,7 +1178,8 @@ function LinkedEntityBlock(props) {
|
|
|
1134
1178
|
isDisabled: isDisabled,
|
|
1135
1179
|
isSelected: isSelected,
|
|
1136
1180
|
onRemove: handleRemoveClick,
|
|
1137
|
-
onEdit: handleEditClick
|
|
1181
|
+
onEdit: handleEditClick,
|
|
1182
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
1138
1183
|
})), children);
|
|
1139
1184
|
}
|
|
1140
1185
|
|
|
@@ -1142,201 +1187,197 @@ function createCommonjsModule(fn, module) {
|
|
|
1142
1187
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
1143
1188
|
}
|
|
1144
1189
|
|
|
1145
|
-
var runtime_1 = createCommonjsModule(function (module) {
|
|
1146
|
-
/**
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1190
|
+
var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
|
|
1191
|
+
/**
|
|
1192
|
+
* Copyright (c) 2014-present, Facebook, Inc.
|
|
1193
|
+
*
|
|
1194
|
+
* This source code is licensed under the MIT license found in the
|
|
1195
|
+
* LICENSE file in the root directory of this source tree.
|
|
1196
|
+
*/
|
|
1197
|
+
var runtime = function (exports) {
|
|
1198
|
+
|
|
1199
|
+
var Op = Object.prototype;
|
|
1200
|
+
var hasOwn = Op.hasOwnProperty;
|
|
1201
|
+
var undefined$1; // More compressible than void 0.
|
|
1202
|
+
|
|
1203
|
+
var $Symbol = typeof Symbol === "function" ? Symbol : {};
|
|
1204
|
+
var iteratorSymbol = $Symbol.iterator || "@@iterator";
|
|
1205
|
+
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
|
1206
|
+
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
1207
|
+
|
|
1208
|
+
function define(obj, key, value) {
|
|
1209
|
+
Object.defineProperty(obj, key, {
|
|
1210
|
+
value: value,
|
|
1211
|
+
enumerable: true,
|
|
1212
|
+
configurable: true,
|
|
1213
|
+
writable: true
|
|
1214
|
+
});
|
|
1215
|
+
return obj[key];
|
|
1216
|
+
}
|
|
1152
1217
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
1162
|
-
|
|
1163
|
-
function define(obj, key, value) {
|
|
1164
|
-
Object.defineProperty(obj, key, {
|
|
1165
|
-
value: value,
|
|
1166
|
-
enumerable: true,
|
|
1167
|
-
configurable: true,
|
|
1168
|
-
writable: true
|
|
1169
|
-
});
|
|
1170
|
-
return obj[key];
|
|
1171
|
-
}
|
|
1172
|
-
try {
|
|
1173
|
-
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
|
|
1174
|
-
define({}, "");
|
|
1175
|
-
} catch (err) {
|
|
1176
|
-
define = function(obj, key, value) {
|
|
1177
|
-
return obj[key] = value;
|
|
1178
|
-
};
|
|
1179
|
-
}
|
|
1218
|
+
try {
|
|
1219
|
+
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
|
|
1220
|
+
define({}, "");
|
|
1221
|
+
} catch (err) {
|
|
1222
|
+
define = function define(obj, key, value) {
|
|
1223
|
+
return obj[key] = value;
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1180
1226
|
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1227
|
+
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
1228
|
+
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
|
|
1229
|
+
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
|
|
1230
|
+
var generator = Object.create(protoGenerator.prototype);
|
|
1231
|
+
var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
|
|
1232
|
+
// .throw, and .return methods.
|
|
1186
1233
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1234
|
+
generator._invoke = makeInvokeMethod(innerFn, self, context);
|
|
1235
|
+
return generator;
|
|
1236
|
+
}
|
|
1190
1237
|
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1238
|
+
exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
|
|
1239
|
+
// record like context.tryEntries[i].completion. This interface could
|
|
1240
|
+
// have been (and was previously) designed to take a closure to be
|
|
1241
|
+
// invoked without arguments, but in all the cases we care about we
|
|
1242
|
+
// already have an existing method we want to call, so there's no need
|
|
1243
|
+
// to create a new function object. We can even get away with assuming
|
|
1244
|
+
// the method takes exactly one argument, since that happens to be true
|
|
1245
|
+
// in every case, so we don't have to touch the arguments object. The
|
|
1246
|
+
// only additional allocation required is the completion record, which
|
|
1247
|
+
// has a stable shape and so hopefully should be cheap to allocate.
|
|
1248
|
+
|
|
1249
|
+
function tryCatch(fn, obj, arg) {
|
|
1250
|
+
try {
|
|
1251
|
+
return {
|
|
1252
|
+
type: "normal",
|
|
1253
|
+
arg: fn.call(obj, arg)
|
|
1254
|
+
};
|
|
1255
|
+
} catch (err) {
|
|
1256
|
+
return {
|
|
1257
|
+
type: "throw",
|
|
1258
|
+
arg: err
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1210
1261
|
}
|
|
1211
|
-
}
|
|
1212
1262
|
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
// Returning this object from the innerFn has the same effect as
|
|
1219
|
-
// breaking out of the dispatch switch statement.
|
|
1220
|
-
var ContinueSentinel = {};
|
|
1221
|
-
|
|
1222
|
-
// Dummy constructor functions that we use as the .constructor and
|
|
1223
|
-
// .constructor.prototype properties for functions that return Generator
|
|
1224
|
-
// objects. For full spec compliance, you may wish to configure your
|
|
1225
|
-
// minifier not to mangle the names of these two functions.
|
|
1226
|
-
function Generator() {}
|
|
1227
|
-
function GeneratorFunction() {}
|
|
1228
|
-
function GeneratorFunctionPrototype() {}
|
|
1229
|
-
|
|
1230
|
-
// This is a polyfill for %IteratorPrototype% for environments that
|
|
1231
|
-
// don't natively support it.
|
|
1232
|
-
var IteratorPrototype = {};
|
|
1233
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
1234
|
-
return this;
|
|
1235
|
-
});
|
|
1263
|
+
var GenStateSuspendedStart = "suspendedStart";
|
|
1264
|
+
var GenStateSuspendedYield = "suspendedYield";
|
|
1265
|
+
var GenStateExecuting = "executing";
|
|
1266
|
+
var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
|
|
1267
|
+
// breaking out of the dispatch switch statement.
|
|
1236
1268
|
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
|
1242
|
-
// This environment has a native %IteratorPrototype%; use it instead
|
|
1243
|
-
// of the polyfill.
|
|
1244
|
-
IteratorPrototype = NativeIteratorPrototype;
|
|
1245
|
-
}
|
|
1269
|
+
var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
|
|
1270
|
+
// .constructor.prototype properties for functions that return Generator
|
|
1271
|
+
// objects. For full spec compliance, you may wish to configure your
|
|
1272
|
+
// minifier not to mangle the names of these two functions.
|
|
1246
1273
|
|
|
1247
|
-
|
|
1248
|
-
Generator.prototype = Object.create(IteratorPrototype);
|
|
1249
|
-
GeneratorFunction.prototype = GeneratorFunctionPrototype;
|
|
1250
|
-
define(Gp, "constructor", GeneratorFunctionPrototype);
|
|
1251
|
-
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
|
|
1252
|
-
GeneratorFunction.displayName = define(
|
|
1253
|
-
GeneratorFunctionPrototype,
|
|
1254
|
-
toStringTagSymbol,
|
|
1255
|
-
"GeneratorFunction"
|
|
1256
|
-
);
|
|
1274
|
+
function Generator() {}
|
|
1257
1275
|
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1276
|
+
function GeneratorFunction() {}
|
|
1277
|
+
|
|
1278
|
+
function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
|
|
1279
|
+
// don't natively support it.
|
|
1280
|
+
|
|
1281
|
+
|
|
1282
|
+
var IteratorPrototype = {};
|
|
1283
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
|
1284
|
+
return this;
|
|
1265
1285
|
});
|
|
1266
|
-
|
|
1286
|
+
var getProto = Object.getPrototypeOf;
|
|
1287
|
+
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
1267
1288
|
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
// do is to check its .name property.
|
|
1274
|
-
(ctor.displayName || ctor.name) === "GeneratorFunction"
|
|
1275
|
-
: false;
|
|
1276
|
-
};
|
|
1289
|
+
if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
|
1290
|
+
// This environment has a native %IteratorPrototype%; use it instead
|
|
1291
|
+
// of the polyfill.
|
|
1292
|
+
IteratorPrototype = NativeIteratorPrototype;
|
|
1293
|
+
}
|
|
1277
1294
|
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1295
|
+
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
1296
|
+
GeneratorFunction.prototype = GeneratorFunctionPrototype;
|
|
1297
|
+
define(Gp, "constructor", GeneratorFunctionPrototype);
|
|
1298
|
+
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
|
|
1299
|
+
GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
|
|
1300
|
+
// Iterator interface in terms of a single ._invoke method.
|
|
1301
|
+
|
|
1302
|
+
function defineIteratorMethods(prototype) {
|
|
1303
|
+
["next", "throw", "return"].forEach(function (method) {
|
|
1304
|
+
define(prototype, method, function (arg) {
|
|
1305
|
+
return this._invoke(method, arg);
|
|
1306
|
+
});
|
|
1307
|
+
});
|
|
1284
1308
|
}
|
|
1285
|
-
genFun.prototype = Object.create(Gp);
|
|
1286
|
-
return genFun;
|
|
1287
|
-
};
|
|
1288
1309
|
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
};
|
|
1310
|
+
exports.isGeneratorFunction = function (genFun) {
|
|
1311
|
+
var ctor = typeof genFun === "function" && genFun.constructor;
|
|
1312
|
+
return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
|
|
1313
|
+
// do is to check its .name property.
|
|
1314
|
+
(ctor.displayName || ctor.name) === "GeneratorFunction" : false;
|
|
1315
|
+
};
|
|
1296
1316
|
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
if (record.type === "throw") {
|
|
1301
|
-
reject(record.arg);
|
|
1317
|
+
exports.mark = function (genFun) {
|
|
1318
|
+
if (Object.setPrototypeOf) {
|
|
1319
|
+
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
|
1302
1320
|
} else {
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1321
|
+
genFun.__proto__ = GeneratorFunctionPrototype;
|
|
1322
|
+
define(genFun, toStringTagSymbol, "GeneratorFunction");
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
genFun.prototype = Object.create(Gp);
|
|
1326
|
+
return genFun;
|
|
1327
|
+
}; // Within the body of any async function, `await x` is transformed to
|
|
1328
|
+
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
|
|
1329
|
+
// `hasOwn.call(value, "__await")` to determine if the yielded value is
|
|
1330
|
+
// meant to be awaited.
|
|
1331
|
+
|
|
1332
|
+
|
|
1333
|
+
exports.awrap = function (arg) {
|
|
1334
|
+
return {
|
|
1335
|
+
__await: arg
|
|
1336
|
+
};
|
|
1337
|
+
};
|
|
1338
|
+
|
|
1339
|
+
function AsyncIterator(generator, PromiseImpl) {
|
|
1340
|
+
function invoke(method, arg, resolve, reject) {
|
|
1341
|
+
var record = tryCatch(generator[method], generator, arg);
|
|
1342
|
+
|
|
1343
|
+
if (record.type === "throw") {
|
|
1344
|
+
reject(record.arg);
|
|
1345
|
+
} else {
|
|
1346
|
+
var result = record.arg;
|
|
1347
|
+
var value = result.value;
|
|
1348
|
+
|
|
1349
|
+
if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
|
|
1350
|
+
return PromiseImpl.resolve(value.__await).then(function (value) {
|
|
1351
|
+
invoke("next", value, resolve, reject);
|
|
1352
|
+
}, function (err) {
|
|
1353
|
+
invoke("throw", err, resolve, reject);
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
return PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
1358
|
+
// When a yielded Promise is resolved, its final value becomes
|
|
1359
|
+
// the .value of the Promise<{value,done}> result for the
|
|
1360
|
+
// current iteration.
|
|
1361
|
+
result.value = unwrapped;
|
|
1362
|
+
resolve(result);
|
|
1363
|
+
}, function (error) {
|
|
1364
|
+
// If a rejected Promise was yielded, throw the rejection back
|
|
1365
|
+
// into the async generator function so it can be handled there.
|
|
1366
|
+
return invoke("throw", error, resolve, reject);
|
|
1312
1367
|
});
|
|
1313
1368
|
}
|
|
1314
|
-
|
|
1315
|
-
return PromiseImpl.resolve(value).then(function(unwrapped) {
|
|
1316
|
-
// When a yielded Promise is resolved, its final value becomes
|
|
1317
|
-
// the .value of the Promise<{value,done}> result for the
|
|
1318
|
-
// current iteration.
|
|
1319
|
-
result.value = unwrapped;
|
|
1320
|
-
resolve(result);
|
|
1321
|
-
}, function(error) {
|
|
1322
|
-
// If a rejected Promise was yielded, throw the rejection back
|
|
1323
|
-
// into the async generator function so it can be handled there.
|
|
1324
|
-
return invoke("throw", error, resolve, reject);
|
|
1325
|
-
});
|
|
1326
1369
|
}
|
|
1327
|
-
}
|
|
1328
1370
|
|
|
1329
|
-
|
|
1371
|
+
var previousPromise;
|
|
1330
1372
|
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1373
|
+
function enqueue(method, arg) {
|
|
1374
|
+
function callInvokeWithMethodAndArg() {
|
|
1375
|
+
return new PromiseImpl(function (resolve, reject) {
|
|
1376
|
+
invoke(method, arg, resolve, reject);
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1337
1379
|
|
|
1338
|
-
|
|
1339
|
-
// If enqueue has been called before, then we want to wait until
|
|
1380
|
+
return previousPromise = // If enqueue has been called before, then we want to wait until
|
|
1340
1381
|
// all previous Promises have been resolved before calling invoke,
|
|
1341
1382
|
// so that results are always delivered in the correct order. If
|
|
1342
1383
|
// enqueue has not been called before, then it is important to
|
|
@@ -1348,554 +1389,527 @@ var runtime = (function (exports) {
|
|
|
1348
1389
|
// execute code before the first await. Since we implement simple
|
|
1349
1390
|
// async functions in terms of async generators, it is especially
|
|
1350
1391
|
// important to get this right, even though it requires care.
|
|
1351
|
-
previousPromise ? previousPromise.then(
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1392
|
+
previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
|
|
1393
|
+
// invocations of the iterator.
|
|
1394
|
+
callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
1395
|
+
} // Define the unified helper method that is used to implement .next,
|
|
1396
|
+
// .throw, and .return (see defineIteratorMethods).
|
|
1397
|
+
|
|
1398
|
+
|
|
1399
|
+
this._invoke = enqueue;
|
|
1357
1400
|
}
|
|
1358
1401
|
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1402
|
+
defineIteratorMethods(AsyncIterator.prototype);
|
|
1403
|
+
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
1404
|
+
return this;
|
|
1405
|
+
});
|
|
1406
|
+
exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
|
|
1407
|
+
// AsyncIterator objects; they just return a Promise for the value of
|
|
1408
|
+
// the final result produced by the iterator.
|
|
1409
|
+
|
|
1410
|
+
exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
1411
|
+
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
1412
|
+
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
1413
|
+
return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
|
|
1414
|
+
: iter.next().then(function (result) {
|
|
1415
|
+
return result.done ? result.value : iter.next();
|
|
1416
|
+
});
|
|
1417
|
+
};
|
|
1363
1418
|
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
// Note that simple async functions are implemented on top of
|
|
1371
|
-
// AsyncIterator objects; they just return a Promise for the value of
|
|
1372
|
-
// the final result produced by the iterator.
|
|
1373
|
-
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
1374
|
-
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
1375
|
-
|
|
1376
|
-
var iter = new AsyncIterator(
|
|
1377
|
-
wrap(innerFn, outerFn, self, tryLocsList),
|
|
1378
|
-
PromiseImpl
|
|
1379
|
-
);
|
|
1380
|
-
|
|
1381
|
-
return exports.isGeneratorFunction(outerFn)
|
|
1382
|
-
? iter // If outerFn is a generator, return the full iterator.
|
|
1383
|
-
: iter.next().then(function(result) {
|
|
1384
|
-
return result.done ? result.value : iter.next();
|
|
1385
|
-
});
|
|
1386
|
-
};
|
|
1419
|
+
function makeInvokeMethod(innerFn, self, context) {
|
|
1420
|
+
var state = GenStateSuspendedStart;
|
|
1421
|
+
return function invoke(method, arg) {
|
|
1422
|
+
if (state === GenStateExecuting) {
|
|
1423
|
+
throw new Error("Generator is already running");
|
|
1424
|
+
}
|
|
1387
1425
|
|
|
1388
|
-
|
|
1389
|
-
|
|
1426
|
+
if (state === GenStateCompleted) {
|
|
1427
|
+
if (method === "throw") {
|
|
1428
|
+
throw arg;
|
|
1429
|
+
} // Be forgiving, per 25.3.3.3.3 of the spec:
|
|
1430
|
+
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
|
|
1390
1431
|
|
|
1391
|
-
return function invoke(method, arg) {
|
|
1392
|
-
if (state === GenStateExecuting) {
|
|
1393
|
-
throw new Error("Generator is already running");
|
|
1394
|
-
}
|
|
1395
1432
|
|
|
1396
|
-
|
|
1397
|
-
if (method === "throw") {
|
|
1398
|
-
throw arg;
|
|
1433
|
+
return doneResult();
|
|
1399
1434
|
}
|
|
1400
1435
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1436
|
+
context.method = method;
|
|
1437
|
+
context.arg = arg;
|
|
1438
|
+
|
|
1439
|
+
while (true) {
|
|
1440
|
+
var delegate = context.delegate;
|
|
1405
1441
|
|
|
1406
|
-
|
|
1407
|
-
|
|
1442
|
+
if (delegate) {
|
|
1443
|
+
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
1408
1444
|
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
if (delegateResult) {
|
|
1414
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
1415
|
-
return delegateResult;
|
|
1445
|
+
if (delegateResult) {
|
|
1446
|
+
if (delegateResult === ContinueSentinel) continue;
|
|
1447
|
+
return delegateResult;
|
|
1448
|
+
}
|
|
1416
1449
|
}
|
|
1417
|
-
}
|
|
1418
1450
|
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1451
|
+
if (context.method === "next") {
|
|
1452
|
+
// Setting context._sent for legacy support of Babel's
|
|
1453
|
+
// function.sent implementation.
|
|
1454
|
+
context.sent = context._sent = context.arg;
|
|
1455
|
+
} else if (context.method === "throw") {
|
|
1456
|
+
if (state === GenStateSuspendedStart) {
|
|
1457
|
+
state = GenStateCompleted;
|
|
1458
|
+
throw context.arg;
|
|
1459
|
+
}
|
|
1423
1460
|
|
|
1424
|
-
|
|
1425
|
-
if (
|
|
1426
|
-
|
|
1427
|
-
throw context.arg;
|
|
1461
|
+
context.dispatchException(context.arg);
|
|
1462
|
+
} else if (context.method === "return") {
|
|
1463
|
+
context.abrupt("return", context.arg);
|
|
1428
1464
|
}
|
|
1429
1465
|
|
|
1430
|
-
|
|
1466
|
+
state = GenStateExecuting;
|
|
1467
|
+
var record = tryCatch(innerFn, self, context);
|
|
1431
1468
|
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1469
|
+
if (record.type === "normal") {
|
|
1470
|
+
// If an exception is thrown from innerFn, we leave state ===
|
|
1471
|
+
// GenStateExecuting and loop back for another invocation.
|
|
1472
|
+
state = context.done ? GenStateCompleted : GenStateSuspendedYield;
|
|
1435
1473
|
|
|
1436
|
-
|
|
1474
|
+
if (record.arg === ContinueSentinel) {
|
|
1475
|
+
continue;
|
|
1476
|
+
}
|
|
1437
1477
|
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1478
|
+
return {
|
|
1479
|
+
value: record.arg,
|
|
1480
|
+
done: context.done
|
|
1481
|
+
};
|
|
1482
|
+
} else if (record.type === "throw") {
|
|
1483
|
+
state = GenStateCompleted; // Dispatch the exception by looping back around to the
|
|
1484
|
+
// context.dispatchException(context.arg) call above.
|
|
1445
1485
|
|
|
1446
|
-
|
|
1447
|
-
|
|
1486
|
+
context.method = "throw";
|
|
1487
|
+
context.arg = record.arg;
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
} // Call delegate.iterator[context.method](context.arg) and handle the
|
|
1492
|
+
// result, either by returning a { value, done } result from the
|
|
1493
|
+
// delegate iterator, or by modifying context.method and context.arg,
|
|
1494
|
+
// setting context.delegate to null, and returning the ContinueSentinel.
|
|
1495
|
+
|
|
1496
|
+
|
|
1497
|
+
function maybeInvokeDelegate(delegate, context) {
|
|
1498
|
+
var method = delegate.iterator[context.method];
|
|
1499
|
+
|
|
1500
|
+
if (method === undefined$1) {
|
|
1501
|
+
// A .throw or .return when the delegate iterator has no .throw
|
|
1502
|
+
// method always terminates the yield* loop.
|
|
1503
|
+
context.delegate = null;
|
|
1504
|
+
|
|
1505
|
+
if (context.method === "throw") {
|
|
1506
|
+
// Note: ["return"] must be used for ES3 parsing compatibility.
|
|
1507
|
+
if (delegate.iterator["return"]) {
|
|
1508
|
+
// If the delegate iterator has a return method, give it a
|
|
1509
|
+
// chance to clean up.
|
|
1510
|
+
context.method = "return";
|
|
1511
|
+
context.arg = undefined$1;
|
|
1512
|
+
maybeInvokeDelegate(delegate, context);
|
|
1513
|
+
|
|
1514
|
+
if (context.method === "throw") {
|
|
1515
|
+
// If maybeInvokeDelegate(context) changed context.method from
|
|
1516
|
+
// "return" to "throw", let that override the TypeError below.
|
|
1517
|
+
return ContinueSentinel;
|
|
1518
|
+
}
|
|
1448
1519
|
}
|
|
1449
1520
|
|
|
1450
|
-
return {
|
|
1451
|
-
value: record.arg,
|
|
1452
|
-
done: context.done
|
|
1453
|
-
};
|
|
1454
|
-
|
|
1455
|
-
} else if (record.type === "throw") {
|
|
1456
|
-
state = GenStateCompleted;
|
|
1457
|
-
// Dispatch the exception by looping back around to the
|
|
1458
|
-
// context.dispatchException(context.arg) call above.
|
|
1459
1521
|
context.method = "throw";
|
|
1460
|
-
context.arg =
|
|
1522
|
+
context.arg = new TypeError("The iterator does not provide a 'throw' method");
|
|
1461
1523
|
}
|
|
1524
|
+
|
|
1525
|
+
return ContinueSentinel;
|
|
1462
1526
|
}
|
|
1463
|
-
};
|
|
1464
|
-
}
|
|
1465
1527
|
|
|
1466
|
-
|
|
1467
|
-
// result, either by returning a { value, done } result from the
|
|
1468
|
-
// delegate iterator, or by modifying context.method and context.arg,
|
|
1469
|
-
// setting context.delegate to null, and returning the ContinueSentinel.
|
|
1470
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
1471
|
-
var method = delegate.iterator[context.method];
|
|
1472
|
-
if (method === undefined$1) {
|
|
1473
|
-
// A .throw or .return when the delegate iterator has no .throw
|
|
1474
|
-
// method always terminates the yield* loop.
|
|
1475
|
-
context.delegate = null;
|
|
1528
|
+
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
1476
1529
|
|
|
1477
|
-
if (
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
context.arg = undefined$1;
|
|
1484
|
-
maybeInvokeDelegate(delegate, context);
|
|
1530
|
+
if (record.type === "throw") {
|
|
1531
|
+
context.method = "throw";
|
|
1532
|
+
context.arg = record.arg;
|
|
1533
|
+
context.delegate = null;
|
|
1534
|
+
return ContinueSentinel;
|
|
1535
|
+
}
|
|
1485
1536
|
|
|
1486
|
-
|
|
1487
|
-
// If maybeInvokeDelegate(context) changed context.method from
|
|
1488
|
-
// "return" to "throw", let that override the TypeError below.
|
|
1489
|
-
return ContinueSentinel;
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1537
|
+
var info = record.arg;
|
|
1492
1538
|
|
|
1539
|
+
if (!info) {
|
|
1493
1540
|
context.method = "throw";
|
|
1494
|
-
context.arg = new TypeError(
|
|
1495
|
-
|
|
1541
|
+
context.arg = new TypeError("iterator result is not an object");
|
|
1542
|
+
context.delegate = null;
|
|
1543
|
+
return ContinueSentinel;
|
|
1496
1544
|
}
|
|
1497
1545
|
|
|
1498
|
-
|
|
1499
|
-
|
|
1546
|
+
if (info.done) {
|
|
1547
|
+
// Assign the result of the finished delegate to the temporary
|
|
1548
|
+
// variable specified by delegate.resultName (see delegateYield).
|
|
1549
|
+
context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
|
|
1500
1550
|
|
|
1501
|
-
|
|
1551
|
+
context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
|
|
1552
|
+
// exception, let the outer generator proceed normally. If
|
|
1553
|
+
// context.method was "next", forget context.arg since it has been
|
|
1554
|
+
// "consumed" by the delegate iterator. If context.method was
|
|
1555
|
+
// "return", allow the original .return call to continue in the
|
|
1556
|
+
// outer generator.
|
|
1502
1557
|
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1558
|
+
if (context.method !== "return") {
|
|
1559
|
+
context.method = "next";
|
|
1560
|
+
context.arg = undefined$1;
|
|
1561
|
+
}
|
|
1562
|
+
} else {
|
|
1563
|
+
// Re-yield the result returned by the delegate method.
|
|
1564
|
+
return info;
|
|
1565
|
+
} // The delegate iterator is finished, so forget it and continue with
|
|
1566
|
+
// the outer generator.
|
|
1509
1567
|
|
|
1510
|
-
var info = record.arg;
|
|
1511
1568
|
|
|
1512
|
-
if (! info) {
|
|
1513
|
-
context.method = "throw";
|
|
1514
|
-
context.arg = new TypeError("iterator result is not an object");
|
|
1515
1569
|
context.delegate = null;
|
|
1516
1570
|
return ContinueSentinel;
|
|
1517
|
-
}
|
|
1571
|
+
} // Define Generator.prototype.{next,throw,return} in terms of the
|
|
1572
|
+
// unified ._invoke helper method.
|
|
1518
1573
|
|
|
1519
|
-
if (info.done) {
|
|
1520
|
-
// Assign the result of the finished delegate to the temporary
|
|
1521
|
-
// variable specified by delegate.resultName (see delegateYield).
|
|
1522
|
-
context[delegate.resultName] = info.value;
|
|
1523
|
-
|
|
1524
|
-
// Resume execution at the desired location (see delegateYield).
|
|
1525
|
-
context.next = delegate.nextLoc;
|
|
1526
|
-
|
|
1527
|
-
// If context.method was "throw" but the delegate handled the
|
|
1528
|
-
// exception, let the outer generator proceed normally. If
|
|
1529
|
-
// context.method was "next", forget context.arg since it has been
|
|
1530
|
-
// "consumed" by the delegate iterator. If context.method was
|
|
1531
|
-
// "return", allow the original .return call to continue in the
|
|
1532
|
-
// outer generator.
|
|
1533
|
-
if (context.method !== "return") {
|
|
1534
|
-
context.method = "next";
|
|
1535
|
-
context.arg = undefined$1;
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
} else {
|
|
1539
|
-
// Re-yield the result returned by the delegate method.
|
|
1540
|
-
return info;
|
|
1541
|
-
}
|
|
1542
1574
|
|
|
1543
|
-
|
|
1544
|
-
// the
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
// Define Generator.prototype.{next,throw,return} in terms of the
|
|
1550
|
-
// unified ._invoke helper method.
|
|
1551
|
-
defineIteratorMethods(Gp);
|
|
1575
|
+
defineIteratorMethods(Gp);
|
|
1576
|
+
define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
|
|
1577
|
+
// @@iterator function is called on it. Some browsers' implementations of the
|
|
1578
|
+
// iterator prototype chain incorrectly implement this, causing the Generator
|
|
1579
|
+
// object to not be returned from this call. This ensures that doesn't happen.
|
|
1580
|
+
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
1552
1581
|
|
|
1553
|
-
|
|
1582
|
+
define(Gp, iteratorSymbol, function () {
|
|
1583
|
+
return this;
|
|
1584
|
+
});
|
|
1585
|
+
define(Gp, "toString", function () {
|
|
1586
|
+
return "[object Generator]";
|
|
1587
|
+
});
|
|
1554
1588
|
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
1560
|
-
define(Gp, iteratorSymbol, function() {
|
|
1561
|
-
return this;
|
|
1562
|
-
});
|
|
1589
|
+
function pushTryEntry(locs) {
|
|
1590
|
+
var entry = {
|
|
1591
|
+
tryLoc: locs[0]
|
|
1592
|
+
};
|
|
1563
1593
|
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1594
|
+
if (1 in locs) {
|
|
1595
|
+
entry.catchLoc = locs[1];
|
|
1596
|
+
}
|
|
1567
1597
|
|
|
1568
|
-
|
|
1569
|
-
|
|
1598
|
+
if (2 in locs) {
|
|
1599
|
+
entry.finallyLoc = locs[2];
|
|
1600
|
+
entry.afterLoc = locs[3];
|
|
1601
|
+
}
|
|
1570
1602
|
|
|
1571
|
-
|
|
1572
|
-
entry.catchLoc = locs[1];
|
|
1603
|
+
this.tryEntries.push(entry);
|
|
1573
1604
|
}
|
|
1574
1605
|
|
|
1575
|
-
|
|
1576
|
-
entry.
|
|
1577
|
-
|
|
1606
|
+
function resetTryEntry(entry) {
|
|
1607
|
+
var record = entry.completion || {};
|
|
1608
|
+
record.type = "normal";
|
|
1609
|
+
delete record.arg;
|
|
1610
|
+
entry.completion = record;
|
|
1578
1611
|
}
|
|
1579
1612
|
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
function Context(tryLocsList) {
|
|
1591
|
-
// The root entry object (effectively a try statement without a catch
|
|
1592
|
-
// or a finally block) gives us a place to store values thrown from
|
|
1593
|
-
// locations where there is no enclosing try statement.
|
|
1594
|
-
this.tryEntries = [{ tryLoc: "root" }];
|
|
1595
|
-
tryLocsList.forEach(pushTryEntry, this);
|
|
1596
|
-
this.reset(true);
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1599
|
-
exports.keys = function(object) {
|
|
1600
|
-
var keys = [];
|
|
1601
|
-
for (var key in object) {
|
|
1602
|
-
keys.push(key);
|
|
1613
|
+
function Context(tryLocsList) {
|
|
1614
|
+
// The root entry object (effectively a try statement without a catch
|
|
1615
|
+
// or a finally block) gives us a place to store values thrown from
|
|
1616
|
+
// locations where there is no enclosing try statement.
|
|
1617
|
+
this.tryEntries = [{
|
|
1618
|
+
tryLoc: "root"
|
|
1619
|
+
}];
|
|
1620
|
+
tryLocsList.forEach(pushTryEntry, this);
|
|
1621
|
+
this.reset(true);
|
|
1603
1622
|
}
|
|
1604
|
-
keys.reverse();
|
|
1605
|
-
|
|
1606
|
-
// Rather than returning an object with a next method, we keep
|
|
1607
|
-
// things simple and return the next function itself.
|
|
1608
|
-
return function next() {
|
|
1609
|
-
while (keys.length) {
|
|
1610
|
-
var key = keys.pop();
|
|
1611
|
-
if (key in object) {
|
|
1612
|
-
next.value = key;
|
|
1613
|
-
next.done = false;
|
|
1614
|
-
return next;
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
1623
|
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
// also ensures that the minifier will not anonymize the function.
|
|
1621
|
-
next.done = true;
|
|
1622
|
-
return next;
|
|
1623
|
-
};
|
|
1624
|
-
};
|
|
1624
|
+
exports.keys = function (object) {
|
|
1625
|
+
var keys = [];
|
|
1625
1626
|
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
1629
|
-
if (iteratorMethod) {
|
|
1630
|
-
return iteratorMethod.call(iterable);
|
|
1627
|
+
for (var key in object) {
|
|
1628
|
+
keys.push(key);
|
|
1631
1629
|
}
|
|
1632
1630
|
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
}
|
|
1631
|
+
keys.reverse(); // Rather than returning an object with a next method, we keep
|
|
1632
|
+
// things simple and return the next function itself.
|
|
1636
1633
|
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
if (hasOwn.call(iterable, i)) {
|
|
1641
|
-
next.value = iterable[i];
|
|
1642
|
-
next.done = false;
|
|
1643
|
-
return next;
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1634
|
+
return function next() {
|
|
1635
|
+
while (keys.length) {
|
|
1636
|
+
var key = keys.pop();
|
|
1646
1637
|
|
|
1647
|
-
|
|
1648
|
-
|
|
1638
|
+
if (key in object) {
|
|
1639
|
+
next.value = key;
|
|
1640
|
+
next.done = false;
|
|
1641
|
+
return next;
|
|
1642
|
+
}
|
|
1643
|
+
} // To avoid creating an additional object, we just hang the .value
|
|
1644
|
+
// and .done properties off the next function object itself. This
|
|
1645
|
+
// also ensures that the minifier will not anonymize the function.
|
|
1649
1646
|
|
|
1650
|
-
return next;
|
|
1651
|
-
};
|
|
1652
1647
|
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1648
|
+
next.done = true;
|
|
1649
|
+
return next;
|
|
1650
|
+
};
|
|
1651
|
+
};
|
|
1656
1652
|
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
exports.values = values;
|
|
1653
|
+
function values(iterable) {
|
|
1654
|
+
if (iterable) {
|
|
1655
|
+
var iteratorMethod = iterable[iteratorSymbol];
|
|
1661
1656
|
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1657
|
+
if (iteratorMethod) {
|
|
1658
|
+
return iteratorMethod.call(iterable);
|
|
1659
|
+
}
|
|
1665
1660
|
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
reset: function(skipTempReset) {
|
|
1670
|
-
this.prev = 0;
|
|
1671
|
-
this.next = 0;
|
|
1672
|
-
// Resetting context._sent for legacy support of Babel's
|
|
1673
|
-
// function.sent implementation.
|
|
1674
|
-
this.sent = this._sent = undefined$1;
|
|
1675
|
-
this.done = false;
|
|
1676
|
-
this.delegate = null;
|
|
1677
|
-
|
|
1678
|
-
this.method = "next";
|
|
1679
|
-
this.arg = undefined$1;
|
|
1680
|
-
|
|
1681
|
-
this.tryEntries.forEach(resetTryEntry);
|
|
1682
|
-
|
|
1683
|
-
if (!skipTempReset) {
|
|
1684
|
-
for (var name in this) {
|
|
1685
|
-
// Not sure about the optimal order of these conditions:
|
|
1686
|
-
if (name.charAt(0) === "t" &&
|
|
1687
|
-
hasOwn.call(this, name) &&
|
|
1688
|
-
!isNaN(+name.slice(1))) {
|
|
1689
|
-
this[name] = undefined$1;
|
|
1690
|
-
}
|
|
1661
|
+
if (typeof iterable.next === "function") {
|
|
1662
|
+
return iterable;
|
|
1691
1663
|
}
|
|
1692
|
-
}
|
|
1693
|
-
},
|
|
1694
1664
|
|
|
1695
|
-
|
|
1696
|
-
|
|
1665
|
+
if (!isNaN(iterable.length)) {
|
|
1666
|
+
var i = -1,
|
|
1667
|
+
next = function next() {
|
|
1668
|
+
while (++i < iterable.length) {
|
|
1669
|
+
if (hasOwn.call(iterable, i)) {
|
|
1670
|
+
next.value = iterable[i];
|
|
1671
|
+
next.done = false;
|
|
1672
|
+
return next;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1697
1675
|
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
}
|
|
1676
|
+
next.value = undefined$1;
|
|
1677
|
+
next.done = true;
|
|
1678
|
+
return next;
|
|
1679
|
+
};
|
|
1703
1680
|
|
|
1704
|
-
|
|
1705
|
-
|
|
1681
|
+
return next.next = next;
|
|
1682
|
+
}
|
|
1683
|
+
} // Return an iterator with no values.
|
|
1706
1684
|
|
|
1707
|
-
dispatchException: function(exception) {
|
|
1708
|
-
if (this.done) {
|
|
1709
|
-
throw exception;
|
|
1710
|
-
}
|
|
1711
1685
|
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
context.next = loc;
|
|
1686
|
+
return {
|
|
1687
|
+
next: doneResult
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1717
1690
|
|
|
1718
|
-
|
|
1719
|
-
// If the dispatched exception was caught by a catch block,
|
|
1720
|
-
// then let that catch block handle the exception normally.
|
|
1721
|
-
context.method = "next";
|
|
1722
|
-
context.arg = undefined$1;
|
|
1723
|
-
}
|
|
1691
|
+
exports.values = values;
|
|
1724
1692
|
|
|
1725
|
-
|
|
1726
|
-
|
|
1693
|
+
function doneResult() {
|
|
1694
|
+
return {
|
|
1695
|
+
value: undefined$1,
|
|
1696
|
+
done: true
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1727
1699
|
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1700
|
+
Context.prototype = {
|
|
1701
|
+
constructor: Context,
|
|
1702
|
+
reset: function reset(skipTempReset) {
|
|
1703
|
+
this.prev = 0;
|
|
1704
|
+
this.next = 0; // Resetting context._sent for legacy support of Babel's
|
|
1705
|
+
// function.sent implementation.
|
|
1706
|
+
|
|
1707
|
+
this.sent = this._sent = undefined$1;
|
|
1708
|
+
this.done = false;
|
|
1709
|
+
this.delegate = null;
|
|
1710
|
+
this.method = "next";
|
|
1711
|
+
this.arg = undefined$1;
|
|
1712
|
+
this.tryEntries.forEach(resetTryEntry);
|
|
1731
1713
|
|
|
1732
|
-
if (
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1714
|
+
if (!skipTempReset) {
|
|
1715
|
+
for (var name in this) {
|
|
1716
|
+
// Not sure about the optimal order of these conditions:
|
|
1717
|
+
if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
|
|
1718
|
+
this[name] = undefined$1;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1737
1721
|
}
|
|
1722
|
+
},
|
|
1723
|
+
stop: function stop() {
|
|
1724
|
+
this.done = true;
|
|
1725
|
+
var rootEntry = this.tryEntries[0];
|
|
1726
|
+
var rootRecord = rootEntry.completion;
|
|
1738
1727
|
|
|
1739
|
-
if (
|
|
1740
|
-
|
|
1741
|
-
|
|
1728
|
+
if (rootRecord.type === "throw") {
|
|
1729
|
+
throw rootRecord.arg;
|
|
1730
|
+
}
|
|
1742
1731
|
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1732
|
+
return this.rval;
|
|
1733
|
+
},
|
|
1734
|
+
dispatchException: function dispatchException(exception) {
|
|
1735
|
+
if (this.done) {
|
|
1736
|
+
throw exception;
|
|
1737
|
+
}
|
|
1749
1738
|
|
|
1750
|
-
|
|
1751
|
-
if (this.prev < entry.catchLoc) {
|
|
1752
|
-
return handle(entry.catchLoc, true);
|
|
1753
|
-
}
|
|
1739
|
+
var context = this;
|
|
1754
1740
|
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1741
|
+
function handle(loc, caught) {
|
|
1742
|
+
record.type = "throw";
|
|
1743
|
+
record.arg = exception;
|
|
1744
|
+
context.next = loc;
|
|
1759
1745
|
|
|
1760
|
-
|
|
1761
|
-
|
|
1746
|
+
if (caught) {
|
|
1747
|
+
// If the dispatched exception was caught by a catch block,
|
|
1748
|
+
// then let that catch block handle the exception normally.
|
|
1749
|
+
context.method = "next";
|
|
1750
|
+
context.arg = undefined$1;
|
|
1762
1751
|
}
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
},
|
|
1766
1752
|
|
|
1767
|
-
|
|
1768
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1769
|
-
var entry = this.tryEntries[i];
|
|
1770
|
-
if (entry.tryLoc <= this.prev &&
|
|
1771
|
-
hasOwn.call(entry, "finallyLoc") &&
|
|
1772
|
-
this.prev < entry.finallyLoc) {
|
|
1773
|
-
var finallyEntry = entry;
|
|
1774
|
-
break;
|
|
1753
|
+
return !!caught;
|
|
1775
1754
|
}
|
|
1776
|
-
}
|
|
1777
1755
|
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
finallyEntry.tryLoc <= arg &&
|
|
1782
|
-
arg <= finallyEntry.finallyLoc) {
|
|
1783
|
-
// Ignore the finally entry if control is not jumping to a
|
|
1784
|
-
// location outside the try/catch block.
|
|
1785
|
-
finallyEntry = null;
|
|
1786
|
-
}
|
|
1756
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1757
|
+
var entry = this.tryEntries[i];
|
|
1758
|
+
var record = entry.completion;
|
|
1787
1759
|
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1760
|
+
if (entry.tryLoc === "root") {
|
|
1761
|
+
// Exception thrown outside of any try block that could handle
|
|
1762
|
+
// it, so set the completion value of the entire function to
|
|
1763
|
+
// throw the exception.
|
|
1764
|
+
return handle("end");
|
|
1765
|
+
}
|
|
1791
1766
|
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
return ContinueSentinel;
|
|
1796
|
-
}
|
|
1767
|
+
if (entry.tryLoc <= this.prev) {
|
|
1768
|
+
var hasCatch = hasOwn.call(entry, "catchLoc");
|
|
1769
|
+
var hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
1797
1770
|
|
|
1798
|
-
|
|
1799
|
-
|
|
1771
|
+
if (hasCatch && hasFinally) {
|
|
1772
|
+
if (this.prev < entry.catchLoc) {
|
|
1773
|
+
return handle(entry.catchLoc, true);
|
|
1774
|
+
} else if (this.prev < entry.finallyLoc) {
|
|
1775
|
+
return handle(entry.finallyLoc);
|
|
1776
|
+
}
|
|
1777
|
+
} else if (hasCatch) {
|
|
1778
|
+
if (this.prev < entry.catchLoc) {
|
|
1779
|
+
return handle(entry.catchLoc, true);
|
|
1780
|
+
}
|
|
1781
|
+
} else if (hasFinally) {
|
|
1782
|
+
if (this.prev < entry.finallyLoc) {
|
|
1783
|
+
return handle(entry.finallyLoc);
|
|
1784
|
+
}
|
|
1785
|
+
} else {
|
|
1786
|
+
throw new Error("try statement without catch or finally");
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
},
|
|
1791
|
+
abrupt: function abrupt(type, arg) {
|
|
1792
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1793
|
+
var entry = this.tryEntries[i];
|
|
1800
1794
|
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1795
|
+
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
1796
|
+
var finallyEntry = entry;
|
|
1797
|
+
break;
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1805
1800
|
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
this.method = "return";
|
|
1812
|
-
this.next = "end";
|
|
1813
|
-
} else if (record.type === "normal" && afterLoc) {
|
|
1814
|
-
this.next = afterLoc;
|
|
1815
|
-
}
|
|
1801
|
+
if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
|
|
1802
|
+
// Ignore the finally entry if control is not jumping to a
|
|
1803
|
+
// location outside the try/catch block.
|
|
1804
|
+
finallyEntry = null;
|
|
1805
|
+
}
|
|
1816
1806
|
|
|
1817
|
-
|
|
1818
|
-
|
|
1807
|
+
var record = finallyEntry ? finallyEntry.completion : {};
|
|
1808
|
+
record.type = type;
|
|
1809
|
+
record.arg = arg;
|
|
1819
1810
|
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
if (entry.finallyLoc === finallyLoc) {
|
|
1824
|
-
this.complete(entry.completion, entry.afterLoc);
|
|
1825
|
-
resetTryEntry(entry);
|
|
1811
|
+
if (finallyEntry) {
|
|
1812
|
+
this.method = "next";
|
|
1813
|
+
this.next = finallyEntry.finallyLoc;
|
|
1826
1814
|
return ContinueSentinel;
|
|
1827
1815
|
}
|
|
1828
|
-
}
|
|
1829
|
-
},
|
|
1830
1816
|
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
if (
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1817
|
+
return this.complete(record);
|
|
1818
|
+
},
|
|
1819
|
+
complete: function complete(record, afterLoc) {
|
|
1820
|
+
if (record.type === "throw") {
|
|
1821
|
+
throw record.arg;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
if (record.type === "break" || record.type === "continue") {
|
|
1825
|
+
this.next = record.arg;
|
|
1826
|
+
} else if (record.type === "return") {
|
|
1827
|
+
this.rval = this.arg = record.arg;
|
|
1828
|
+
this.method = "return";
|
|
1829
|
+
this.next = "end";
|
|
1830
|
+
} else if (record.type === "normal" && afterLoc) {
|
|
1831
|
+
this.next = afterLoc;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
return ContinueSentinel;
|
|
1835
|
+
},
|
|
1836
|
+
finish: function finish(finallyLoc) {
|
|
1837
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1838
|
+
var entry = this.tryEntries[i];
|
|
1839
|
+
|
|
1840
|
+
if (entry.finallyLoc === finallyLoc) {
|
|
1841
|
+
this.complete(entry.completion, entry.afterLoc);
|
|
1838
1842
|
resetTryEntry(entry);
|
|
1843
|
+
return ContinueSentinel;
|
|
1839
1844
|
}
|
|
1840
|
-
return thrown;
|
|
1841
1845
|
}
|
|
1842
|
-
}
|
|
1846
|
+
},
|
|
1847
|
+
"catch": function _catch(tryLoc) {
|
|
1848
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1849
|
+
var entry = this.tryEntries[i];
|
|
1843
1850
|
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
throw new Error("illegal catch attempt");
|
|
1847
|
-
},
|
|
1851
|
+
if (entry.tryLoc === tryLoc) {
|
|
1852
|
+
var record = entry.completion;
|
|
1848
1853
|
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
nextLoc: nextLoc
|
|
1854
|
-
};
|
|
1854
|
+
if (record.type === "throw") {
|
|
1855
|
+
var thrown = record.arg;
|
|
1856
|
+
resetTryEntry(entry);
|
|
1857
|
+
}
|
|
1855
1858
|
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
//
|
|
1859
|
-
|
|
1860
|
-
}
|
|
1859
|
+
return thrown;
|
|
1860
|
+
}
|
|
1861
|
+
} // The context.catch method must only be called with a location
|
|
1862
|
+
// argument that corresponds to a known catch block.
|
|
1861
1863
|
|
|
1862
|
-
return ContinueSentinel;
|
|
1863
|
-
}
|
|
1864
|
-
};
|
|
1865
1864
|
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1865
|
+
throw new Error("illegal catch attempt");
|
|
1866
|
+
},
|
|
1867
|
+
delegateYield: function delegateYield(iterable, resultName, nextLoc) {
|
|
1868
|
+
this.delegate = {
|
|
1869
|
+
iterator: values(iterable),
|
|
1870
|
+
resultName: resultName,
|
|
1871
|
+
nextLoc: nextLoc
|
|
1872
|
+
};
|
|
1873
|
+
|
|
1874
|
+
if (this.method === "next") {
|
|
1875
|
+
// Deliberately forget the last sent value so that we don't
|
|
1876
|
+
// accidentally pass it on to the delegate.
|
|
1877
|
+
this.arg = undefined$1;
|
|
1878
|
+
}
|
|
1871
1879
|
|
|
1872
|
-
|
|
1873
|
-
|
|
1880
|
+
return ContinueSentinel;
|
|
1881
|
+
}
|
|
1882
|
+
}; // Regardless of whether this script is executing as a CommonJS module
|
|
1883
|
+
// or not, return the runtime object so that we can declare the variable
|
|
1884
|
+
// regeneratorRuntime in the outer scope, which allows this module to be
|
|
1885
|
+
// injected easily by `bin/regenerator --include-runtime script.js`.
|
|
1886
|
+
|
|
1887
|
+
return exports;
|
|
1888
|
+
}( // If this script is executing as a CommonJS module, use module.exports
|
|
1874
1889
|
// as the regeneratorRuntime namespace. Otherwise create a new empty
|
|
1875
1890
|
// object. Either way, the resulting object will be used to initialize
|
|
1876
1891
|
// the regeneratorRuntime variable at the top of this file.
|
|
1877
|
-
module.exports
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1892
|
+
module.exports );
|
|
1893
|
+
|
|
1894
|
+
try {
|
|
1895
|
+
regeneratorRuntime = runtime;
|
|
1896
|
+
} catch (accidentalStrictMode) {
|
|
1897
|
+
// This module should not be running in strict mode, so the above
|
|
1898
|
+
// assignment should always work unless something is misconfigured. Just
|
|
1899
|
+
// in case runtime.js accidentally runs in strict mode, in modern engines
|
|
1900
|
+
// we can explicitly access globalThis. In older engines we can escape
|
|
1901
|
+
// strict mode using a global Function call. This could conceivably fail
|
|
1902
|
+
// if a Content Security Policy forbids using Function, but in that case
|
|
1903
|
+
// the proper solution is to fix the accidental strict mode problem. If
|
|
1904
|
+
// you've misconfigured your bundler to force strict mode and applied a
|
|
1905
|
+
// CSP to forbid Function, and you're not willing to fix either of those
|
|
1906
|
+
// problems, please detail your unique predicament in a GitHub issue.
|
|
1907
|
+
if (typeof globalThis === "object") {
|
|
1908
|
+
globalThis.regeneratorRuntime = runtime;
|
|
1909
|
+
} else {
|
|
1910
|
+
Function("r", "regeneratorRuntime = r")(runtime);
|
|
1911
|
+
}
|
|
1897
1912
|
}
|
|
1898
|
-
}
|
|
1899
1913
|
});
|
|
1900
1914
|
|
|
1901
1915
|
/* eslint-disable you-dont-need-lodash-underscore/find */
|
|
@@ -2070,7 +2084,7 @@ function insertBlock(editor, nodeType, entity) {
|
|
|
2070
2084
|
slate.Transforms.setNodes(editor, linkedEntityBlock);
|
|
2071
2085
|
}
|
|
2072
2086
|
|
|
2073
|
-
|
|
2087
|
+
focus(editor);
|
|
2074
2088
|
}
|
|
2075
2089
|
|
|
2076
2090
|
var styles$4 = {
|
|
@@ -2164,13 +2178,13 @@ function getWithEmbeddedEntityEvents(nodeType, sdk) {
|
|
|
2164
2178
|
}
|
|
2165
2179
|
|
|
2166
2180
|
var createEmbeddedEntityPlugin = function createEmbeddedEntityPlugin(nodeType, hotkey) {
|
|
2167
|
-
return function (sdk) {
|
|
2181
|
+
return function (sdk, tracking) {
|
|
2168
2182
|
return {
|
|
2169
2183
|
key: nodeType,
|
|
2170
2184
|
type: nodeType,
|
|
2171
2185
|
isElement: true,
|
|
2172
2186
|
isVoid: true,
|
|
2173
|
-
component: LinkedEntityBlock,
|
|
2187
|
+
component: withLinkTracking(tracking, LinkedEntityBlock),
|
|
2174
2188
|
options: {
|
|
2175
2189
|
hotkey: hotkey
|
|
2176
2190
|
},
|
|
@@ -2228,12 +2242,20 @@ function FetchingWrappedInlineEntryCard(props) {
|
|
|
2228
2242
|
return entries[props.entryId];
|
|
2229
2243
|
}, [entries, props.entryId]);
|
|
2230
2244
|
var allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
2245
|
+
var onEntityFetchComplete = props.onEntityFetchComplete;
|
|
2231
2246
|
var contentType = React__default.useMemo(function () {
|
|
2232
2247
|
if (!entry || entry === 'failed' || !allContentTypes) return undefined;
|
|
2233
2248
|
return allContentTypes.find(function (contentType) {
|
|
2234
2249
|
return contentType.sys.id === entry.sys.contentType.sys.id;
|
|
2235
2250
|
});
|
|
2236
2251
|
}, [allContentTypes, entry]);
|
|
2252
|
+
React__default.useEffect(function () {
|
|
2253
|
+
if (!entry) {
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
|
|
2258
|
+
}, [entry, onEntityFetchComplete]);
|
|
2237
2259
|
var contentTypeName = contentType ? contentType.name : '';
|
|
2238
2260
|
var title = React__default.useMemo(function () {
|
|
2239
2261
|
return getEntryTitle({
|
|
@@ -2329,12 +2351,10 @@ var styles$6 = {
|
|
|
2329
2351
|
marginRight: '10px'
|
|
2330
2352
|
}),
|
|
2331
2353
|
root: /*#__PURE__*/emotion.css({
|
|
2332
|
-
|
|
2354
|
+
display: 'inline-block',
|
|
2355
|
+
margin: "0 " + tokens.spacing2Xs,
|
|
2333
2356
|
fontSize: 'inherit',
|
|
2334
2357
|
span: {
|
|
2335
|
-
webkitUserSelect: 'none',
|
|
2336
|
-
mozUserSelect: 'none',
|
|
2337
|
-
msUserSelect: 'none',
|
|
2338
2358
|
userSelect: 'none'
|
|
2339
2359
|
}
|
|
2340
2360
|
})
|
|
@@ -2377,7 +2397,8 @@ function EmbeddedEntityInline(props) {
|
|
|
2377
2397
|
isSelected: isSelected,
|
|
2378
2398
|
isDisabled: isDisabled,
|
|
2379
2399
|
onRemove: handleRemoveClick,
|
|
2380
|
-
onEdit: handleEditClick
|
|
2400
|
+
onEdit: handleEditClick,
|
|
2401
|
+
onEntityFetchComplete: props.onEntityFetchComplete
|
|
2381
2402
|
})), props.children);
|
|
2382
2403
|
}
|
|
2383
2404
|
|
|
@@ -2401,7 +2422,7 @@ function _selectEntityAndInsert$1() {
|
|
|
2401
2422
|
|
|
2402
2423
|
case 4:
|
|
2403
2424
|
entry = _context2.sent;
|
|
2404
|
-
|
|
2425
|
+
focus(editor); // Dialog steals focus from editor, return it.
|
|
2405
2426
|
|
|
2406
2427
|
if (entry) {
|
|
2407
2428
|
_context2.next = 8;
|
|
@@ -2487,7 +2508,7 @@ function ToolbarEmbeddedEntityInlineButton(props) {
|
|
|
2487
2508
|
className: "rich-text__embedded-entry-list-icon " + styles$6.icon
|
|
2488
2509
|
}), /*#__PURE__*/React.createElement("span", null, "Inline entry")));
|
|
2489
2510
|
}
|
|
2490
|
-
function createEmbeddedEntityInlinePlugin(sdk) {
|
|
2511
|
+
function createEmbeddedEntityInlinePlugin(sdk, tracking) {
|
|
2491
2512
|
var htmlAttributeName = 'data-embedded-entity-inline-id';
|
|
2492
2513
|
return {
|
|
2493
2514
|
key: Contentful.INLINES.EMBEDDED_ENTRY,
|
|
@@ -2495,7 +2516,7 @@ function createEmbeddedEntityInlinePlugin(sdk) {
|
|
|
2495
2516
|
isElement: true,
|
|
2496
2517
|
isInline: true,
|
|
2497
2518
|
isVoid: true,
|
|
2498
|
-
component: EmbeddedEntityInline,
|
|
2519
|
+
component: withLinkTracking(tracking, EmbeddedEntityInline),
|
|
2499
2520
|
options: {
|
|
2500
2521
|
hotkey: 'mod+shift+2'
|
|
2501
2522
|
},
|
|
@@ -2609,14 +2630,25 @@ function ToolbarHeadingButton(props) {
|
|
|
2609
2630
|
unwrapFromRoot(editor);
|
|
2610
2631
|
}
|
|
2611
2632
|
|
|
2633
|
+
var prevOnChange = editor.onChange;
|
|
2634
|
+
/*
|
|
2635
|
+
The focus might happen at point in time when
|
|
2636
|
+
`toggleNodeType` changes aren't rendered yet, causing the browser
|
|
2637
|
+
to place the cursor at the start of the text.
|
|
2638
|
+
We wait for the change event before focusing
|
|
2639
|
+
the editor again. This ensures the cursor is back at the previous
|
|
2640
|
+
position.*/
|
|
2641
|
+
|
|
2642
|
+
editor.onChange = function () {
|
|
2643
|
+
focus(editor);
|
|
2644
|
+
editor.onChange = prevOnChange;
|
|
2645
|
+
prevOnChange.apply(void 0, arguments);
|
|
2646
|
+
};
|
|
2647
|
+
|
|
2612
2648
|
plateCore.toggleNodeType(editor, {
|
|
2613
2649
|
activeType: type,
|
|
2614
2650
|
inactiveType: type
|
|
2615
|
-
});
|
|
2616
|
-
|
|
2617
|
-
setTimeout(function () {
|
|
2618
|
-
Slate.ReactEditor.focus(editor);
|
|
2619
|
-
}, 0);
|
|
2651
|
+
});
|
|
2620
2652
|
};
|
|
2621
2653
|
}
|
|
2622
2654
|
|
|
@@ -2746,16 +2778,6 @@ var createHeadingPlugin = function createHeadingPlugin() {
|
|
|
2746
2778
|
allow: Contentful.HEADINGS
|
|
2747
2779
|
}
|
|
2748
2780
|
}],
|
|
2749
|
-
exitBreak: [// Pressing ENTER at the start or end of a heading text inserts a
|
|
2750
|
-
// normal paragraph
|
|
2751
|
-
{
|
|
2752
|
-
hotkey: 'enter',
|
|
2753
|
-
query: {
|
|
2754
|
-
allow: Contentful.HEADINGS,
|
|
2755
|
-
end: true,
|
|
2756
|
-
start: true
|
|
2757
|
-
}
|
|
2758
|
-
}],
|
|
2759
2781
|
normalizer: [{
|
|
2760
2782
|
match: {
|
|
2761
2783
|
type: Contentful.HEADINGS
|
|
@@ -2766,6 +2788,31 @@ var createHeadingPlugin = function createHeadingPlugin() {
|
|
|
2766
2788
|
},
|
|
2767
2789
|
transform: (_transform = {}, _transform[Contentful.BLOCKS.PARAGRAPH] = transformUnwrap, _transform["default"] = transformLift, _transform)
|
|
2768
2790
|
}],
|
|
2791
|
+
then: function then(editor) {
|
|
2792
|
+
return {
|
|
2793
|
+
exitBreak: [// Pressing ENTER at the start or end of a heading text inserts a
|
|
2794
|
+
// normal paragraph.
|
|
2795
|
+
{
|
|
2796
|
+
hotkey: 'enter',
|
|
2797
|
+
query: {
|
|
2798
|
+
allow: Contentful.HEADINGS,
|
|
2799
|
+
end: true,
|
|
2800
|
+
start: true,
|
|
2801
|
+
// Exclude headings inside lists as it interferes with the list's
|
|
2802
|
+
// insertBreak implementation
|
|
2803
|
+
filter: function filter(_ref2) {
|
|
2804
|
+
var path = _ref2[1];
|
|
2805
|
+
return !plateCore.getAbove(editor, {
|
|
2806
|
+
at: path,
|
|
2807
|
+
match: {
|
|
2808
|
+
type: Contentful.BLOCKS.LIST_ITEM
|
|
2809
|
+
}
|
|
2810
|
+
});
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
}]
|
|
2814
|
+
};
|
|
2815
|
+
},
|
|
2769
2816
|
plugins: Contentful.HEADINGS.map(function (nodeType, idx) {
|
|
2770
2817
|
var level = idx + 1;
|
|
2771
2818
|
var tagName = "h" + level;
|
|
@@ -2888,7 +2935,7 @@ function ToolbarHrButton(props) {
|
|
|
2888
2935
|
hasText ? slate.Transforms.insertNodes(editor, hr) : plateCore.setNodes(editor, hr); // Move focus to the next paragraph (added by TrailingParagraph plugin)
|
|
2889
2936
|
|
|
2890
2937
|
moveToTheNextLine(editor);
|
|
2891
|
-
|
|
2938
|
+
focus(editor);
|
|
2892
2939
|
}
|
|
2893
2940
|
|
|
2894
2941
|
if (!editor) return null;
|
|
@@ -3380,7 +3427,7 @@ function _addOrEditLink() {
|
|
|
3380
3427
|
path: path
|
|
3381
3428
|
});
|
|
3382
3429
|
});
|
|
3383
|
-
|
|
3430
|
+
focus(editor);
|
|
3384
3431
|
|
|
3385
3432
|
case 15:
|
|
3386
3433
|
case "end":
|
|
@@ -3469,6 +3516,13 @@ function EntityHyperlink(props) {
|
|
|
3469
3516
|
var isReadOnly = Slate.useReadOnly();
|
|
3470
3517
|
var sdk = useSdkContext();
|
|
3471
3518
|
var target = props.element.data.target;
|
|
3519
|
+
var onEntityFetchComplete = props.onEntityFetchComplete;
|
|
3520
|
+
React.useEffect(function () {
|
|
3521
|
+
// The real entity loading happens in the tooltip
|
|
3522
|
+
// Since that is deferred the link is considered rendered as soon
|
|
3523
|
+
// the component mounts (link text displayed)
|
|
3524
|
+
onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
|
|
3525
|
+
}, [onEntityFetchComplete]);
|
|
3472
3526
|
if (!target) return null;
|
|
3473
3527
|
|
|
3474
3528
|
function handleClick(event) {
|
|
@@ -3599,7 +3653,7 @@ var getNodeOfType = function getNodeOfType(type) {
|
|
|
3599
3653
|
};
|
|
3600
3654
|
};
|
|
3601
3655
|
|
|
3602
|
-
var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
|
|
3656
|
+
var createHyperlinkPlugin = function createHyperlinkPlugin(sdk, tracking) {
|
|
3603
3657
|
var common = {
|
|
3604
3658
|
isElement: true,
|
|
3605
3659
|
isInline: true
|
|
@@ -3630,7 +3684,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
|
|
|
3630
3684
|
_extends({}, common, {
|
|
3631
3685
|
key: Contentful.INLINES.ENTRY_HYPERLINK,
|
|
3632
3686
|
type: Contentful.INLINES.ENTRY_HYPERLINK,
|
|
3633
|
-
component: EntityHyperlink,
|
|
3687
|
+
component: withLinkTracking(tracking, EntityHyperlink),
|
|
3634
3688
|
deserializeHtml: {
|
|
3635
3689
|
rules: [{
|
|
3636
3690
|
validNodeName: ['A']
|
|
@@ -3644,7 +3698,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
|
|
|
3644
3698
|
_extends({}, common, {
|
|
3645
3699
|
key: Contentful.INLINES.ASSET_HYPERLINK,
|
|
3646
3700
|
type: Contentful.INLINES.ASSET_HYPERLINK,
|
|
3647
|
-
component: EntityHyperlink,
|
|
3701
|
+
component: withLinkTracking(tracking, EntityHyperlink),
|
|
3648
3702
|
deserializeHtml: {
|
|
3649
3703
|
rules: [{
|
|
3650
3704
|
validNodeName: ['A']
|
|
@@ -3666,7 +3720,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
|
|
|
3666
3720
|
};
|
|
3667
3721
|
|
|
3668
3722
|
var _templateObject$4, _templateObject2$3, _templateObject3$3, _styles;
|
|
3669
|
-
var baseStyle = /*#__PURE__*/emotion.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);
|
|
3723
|
+
var baseStyle = /*#__PURE__*/emotion.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);
|
|
3670
3724
|
var styles$d = (_styles = {}, _styles[Contentful.BLOCKS.UL_LIST] = /*#__PURE__*/emotion.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[Contentful.BLOCKS.OL_LIST] = /*#__PURE__*/emotion.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);
|
|
3671
3725
|
|
|
3672
3726
|
function createList(Tag, block) {
|
|
@@ -3681,7 +3735,7 @@ var ListUL = /*#__PURE__*/createList('ul', Contentful.BLOCKS.UL_LIST);
|
|
|
3681
3735
|
var ListOL = /*#__PURE__*/createList('ol', Contentful.BLOCKS.OL_LIST);
|
|
3682
3736
|
|
|
3683
3737
|
var _templateObject$5;
|
|
3684
|
-
var style = /*#__PURE__*/emotion.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);
|
|
3738
|
+
var style = /*#__PURE__*/emotion.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);
|
|
3685
3739
|
function ListItem(props) {
|
|
3686
3740
|
return /*#__PURE__*/React.createElement("li", Object.assign({}, props.attributes, {
|
|
3687
3741
|
className: style
|
|
@@ -3749,66 +3803,285 @@ var insertParagraphAsChild = function insertParagraphAsChild(editor, _ref5) {
|
|
|
3749
3803
|
};
|
|
3750
3804
|
|
|
3751
3805
|
/**
|
|
3752
|
-
*
|
|
3753
|
-
* to support pasting any element
|
|
3806
|
+
* Build a new list item node while preserving marks
|
|
3754
3807
|
*/
|
|
3755
|
-
var getListInsertFragment = function getListInsertFragment(editor) {
|
|
3756
|
-
var insertFragment = editor.insertFragment;
|
|
3757
|
-
var li = plateCore.getPlugin(editor, plateList.ELEMENT_LI);
|
|
3758
|
-
var ul = plateCore.getPlugin(editor, plateList.ELEMENT_UL);
|
|
3759
|
-
var ol = plateCore.getPlugin(editor, plateList.ELEMENT_OL);
|
|
3760
3808
|
|
|
3761
|
-
|
|
3762
|
-
|
|
3809
|
+
var emptyListItemNode = function emptyListItemNode(editor, withChildren) {
|
|
3810
|
+
if (withChildren === void 0) {
|
|
3811
|
+
withChildren = false;
|
|
3812
|
+
}
|
|
3813
|
+
|
|
3814
|
+
var children = [];
|
|
3815
|
+
|
|
3816
|
+
if (withChildren) {
|
|
3817
|
+
var marks = slate.Editor.marks(editor) || {};
|
|
3818
|
+
children = [{
|
|
3819
|
+
type: Contentful.BLOCKS.PARAGRAPH,
|
|
3820
|
+
data: {},
|
|
3821
|
+
children: [_extends({
|
|
3822
|
+
text: ''
|
|
3823
|
+
}, marks)]
|
|
3824
|
+
}];
|
|
3825
|
+
}
|
|
3826
|
+
|
|
3827
|
+
return {
|
|
3828
|
+
type: Contentful.BLOCKS.LIST_ITEM,
|
|
3829
|
+
data: {},
|
|
3830
|
+
children: children
|
|
3763
3831
|
};
|
|
3832
|
+
};
|
|
3833
|
+
/**
|
|
3834
|
+
* Insert list item if selection is in li>p.
|
|
3835
|
+
*/
|
|
3764
3836
|
|
|
3765
|
-
var getFirstAncestorOfType = function getFirstAncestorOfType(root, entry, _ref) {
|
|
3766
|
-
var type = _ref.type;
|
|
3767
|
-
var ancestor = slate.Path.parent(entry[1]);
|
|
3768
3837
|
|
|
3769
|
-
|
|
3770
|
-
|
|
3838
|
+
var insertListItem = function insertListItem(editor) {
|
|
3839
|
+
if (!editor.selection) {
|
|
3840
|
+
return false;
|
|
3841
|
+
} // Naming it paragraph for simplicity but can be a heading as well
|
|
3842
|
+
|
|
3843
|
+
|
|
3844
|
+
var paragraph = plateCore.getAbove(editor, {
|
|
3845
|
+
match: {
|
|
3846
|
+
type: Contentful.TEXT_CONTAINERS
|
|
3771
3847
|
}
|
|
3848
|
+
});
|
|
3772
3849
|
|
|
3773
|
-
|
|
3774
|
-
|
|
3850
|
+
if (!paragraph) {
|
|
3851
|
+
return false;
|
|
3852
|
+
}
|
|
3853
|
+
|
|
3854
|
+
var paragraphPath = paragraph[1];
|
|
3855
|
+
var listItem = plateCore.getParent(editor, paragraphPath);
|
|
3856
|
+
|
|
3857
|
+
if (!listItem) {
|
|
3858
|
+
return false;
|
|
3859
|
+
}
|
|
3860
|
+
|
|
3861
|
+
var listItemNode = listItem[0],
|
|
3862
|
+
listItemPath = listItem[1];
|
|
3863
|
+
|
|
3864
|
+
if (listItemNode.type !== Contentful.BLOCKS.LIST_ITEM) {
|
|
3865
|
+
return false;
|
|
3866
|
+
} // We are in a li>p (or heading)
|
|
3867
|
+
|
|
3868
|
+
|
|
3869
|
+
slate.Editor.withoutNormalizing(editor, function () {
|
|
3870
|
+
if (!editor.selection) {
|
|
3871
|
+
return;
|
|
3872
|
+
} // Check the cursor position in the current paragraph
|
|
3873
|
+
|
|
3874
|
+
|
|
3875
|
+
var isAtStart = plateCore.isSelectionAtBlockStart(editor);
|
|
3876
|
+
var isAtEnd = plateCore.isSelectionAtBlockEnd(editor);
|
|
3877
|
+
var isAtStartOfListItem = isAtStart && plateCore.isFirstChild(paragraphPath);
|
|
3878
|
+
var shouldSplit = !isAtStart && !isAtEnd; // Split the current paragraph content if necessary
|
|
3879
|
+
|
|
3880
|
+
if (shouldSplit) {
|
|
3881
|
+
slate.Transforms.splitNodes(editor);
|
|
3882
|
+
} // Insert the new li
|
|
3883
|
+
|
|
3884
|
+
|
|
3885
|
+
var newListItemPath = isAtStartOfListItem ? listItemPath : slate.Path.next(listItemPath);
|
|
3886
|
+
plateCore.insertNodes(editor, // Add an empty paragraph to the new li if We will not move some
|
|
3887
|
+
// paragraphs over there.
|
|
3888
|
+
emptyListItemNode(editor, !shouldSplit), {
|
|
3889
|
+
at: newListItemPath
|
|
3890
|
+
}); // Move children *after* selection to the new li
|
|
3891
|
+
|
|
3892
|
+
var fromPath = isAtStart ? paragraphPath : slate.Path.next(paragraphPath);
|
|
3893
|
+
var fromStartIndex = fromPath[fromPath.length - 1] || 0; // On split we don't add paragraph to the new li so we move
|
|
3894
|
+
// content to the very beginning. Otherwise, account for the empty
|
|
3895
|
+
// paragraph at the beginning by moving the content after
|
|
3896
|
+
|
|
3897
|
+
var toPath = newListItemPath.concat([shouldSplit ? 0 : 1]);
|
|
3898
|
+
|
|
3899
|
+
if (!isAtStartOfListItem) {
|
|
3900
|
+
plateCore.moveChildren(editor, {
|
|
3901
|
+
at: listItemPath,
|
|
3902
|
+
to: toPath,
|
|
3903
|
+
fromStartIndex: fromStartIndex
|
|
3904
|
+
});
|
|
3905
|
+
} // Move cursor to the start of the new li
|
|
3906
|
+
|
|
3907
|
+
|
|
3908
|
+
slate.Transforms.select(editor, newListItemPath);
|
|
3909
|
+
slate.Transforms.collapse(editor, {
|
|
3910
|
+
edge: 'start'
|
|
3911
|
+
});
|
|
3912
|
+
}); // Returning True skips processing other editor.insertBreak handlers
|
|
3913
|
+
|
|
3914
|
+
return true;
|
|
3915
|
+
};
|
|
3916
|
+
|
|
3917
|
+
/**
|
|
3918
|
+
* Credit: Copied & modified version from Plate's list plugin to support
|
|
3919
|
+
* list items with multiple children.
|
|
3920
|
+
*
|
|
3921
|
+
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
3922
|
+
*/
|
|
3923
|
+
|
|
3924
|
+
var listBreak = function listBreak(editor) {
|
|
3925
|
+
if (!editor.selection) return false;
|
|
3926
|
+
var res = plateList.getListItemEntry(editor, {});
|
|
3927
|
+
var moved; // If selection is in a li
|
|
3928
|
+
|
|
3929
|
+
if (res) {
|
|
3930
|
+
var list = res.list,
|
|
3931
|
+
listItem = res.listItem;
|
|
3932
|
+
var childNode = listItem[0].children[0]; // If selected li is empty, move it up.
|
|
3933
|
+
|
|
3934
|
+
if (plateCore.isBlockAboveEmpty(editor) && listItem[0].children.length === 1 && Contentful.TEXT_CONTAINERS.includes(childNode.type)) {
|
|
3935
|
+
moved = plateList.moveListItemUp(editor, {
|
|
3936
|
+
list: list,
|
|
3937
|
+
listItem: listItem
|
|
3938
|
+
});
|
|
3939
|
+
if (moved) return true;
|
|
3940
|
+
}
|
|
3941
|
+
}
|
|
3942
|
+
|
|
3943
|
+
var didReset = plateResetNode.onKeyDownResetNode(editor, plateCore.mockPlugin({
|
|
3944
|
+
options: {
|
|
3945
|
+
rules: [{
|
|
3946
|
+
types: [plateCore.getPluginType(editor, plateList.ELEMENT_LI)],
|
|
3947
|
+
defaultType: plateCore.getPluginType(editor, plateCore.ELEMENT_DEFAULT),
|
|
3948
|
+
predicate: function predicate() {
|
|
3949
|
+
return !moved && plateCore.isBlockAboveEmpty(editor);
|
|
3950
|
+
},
|
|
3951
|
+
onReset: function onReset(_editor) {
|
|
3952
|
+
return plateList.unwrapList(_editor);
|
|
3953
|
+
}
|
|
3954
|
+
}]
|
|
3955
|
+
}
|
|
3956
|
+
}))(plateResetNode.SIMULATE_BACKSPACE);
|
|
3957
|
+
|
|
3958
|
+
if (didReset) {
|
|
3959
|
+
return true;
|
|
3960
|
+
}
|
|
3775
3961
|
/**
|
|
3776
|
-
*
|
|
3777
|
-
*
|
|
3778
|
-
* @returns If argument is not a list root, returns it, otherwise returns ul[] or li[].
|
|
3962
|
+
* If selection is in li > p, insert li.
|
|
3779
3963
|
*/
|
|
3780
3964
|
|
|
3781
3965
|
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3966
|
+
if (!moved) {
|
|
3967
|
+
var inserted = insertListItem(editor);
|
|
3968
|
+
if (inserted) return true;
|
|
3969
|
+
}
|
|
3970
|
+
|
|
3971
|
+
return false;
|
|
3972
|
+
};
|
|
3786
3973
|
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
return isListRoot(commonAncestorEntry[0]) ? commonAncestorEntry[0].children : [commonAncestorEntry[0]];
|
|
3974
|
+
var insertListBreak = function insertListBreak(editor) {
|
|
3975
|
+
var insertBreak = editor.insertBreak;
|
|
3976
|
+
return function () {
|
|
3977
|
+
if (listBreak(editor)) return;
|
|
3978
|
+
insertBreak();
|
|
3793
3979
|
};
|
|
3980
|
+
};
|
|
3794
3981
|
|
|
3982
|
+
/**
|
|
3983
|
+
* Credit: Modified version of Plate's list plugin
|
|
3984
|
+
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
3985
|
+
*/
|
|
3986
|
+
|
|
3987
|
+
var getFirstAncestorOfType = function getFirstAncestorOfType(root, entry) {
|
|
3988
|
+
var ancestor = slate.Path.parent(entry[1]);
|
|
3989
|
+
|
|
3990
|
+
while (slate.Node.get(root, ancestor).type !== Contentful.BLOCKS.LIST_ITEM) {
|
|
3991
|
+
ancestor = slate.Path.parent(ancestor);
|
|
3992
|
+
}
|
|
3993
|
+
|
|
3994
|
+
return [slate.Node.get(root, ancestor), ancestor];
|
|
3995
|
+
};
|
|
3996
|
+
|
|
3997
|
+
var isListRoot = function isListRoot(node) {
|
|
3998
|
+
return [Contentful.BLOCKS.UL_LIST, Contentful.BLOCKS.OL_LIST].includes(node.type);
|
|
3999
|
+
};
|
|
4000
|
+
/**
|
|
4001
|
+
* Removes the "empty" leading lis. Empty in this context means lis only with other lis as children.
|
|
4002
|
+
*
|
|
4003
|
+
* @returns If argument is not a list root, returns it, otherwise returns ul[] or li[].
|
|
4004
|
+
*/
|
|
4005
|
+
|
|
4006
|
+
|
|
4007
|
+
var trimList = function trimList(listRoot) {
|
|
4008
|
+
if (!isListRoot(listRoot)) {
|
|
4009
|
+
return [listRoot];
|
|
4010
|
+
}
|
|
4011
|
+
|
|
4012
|
+
var textEntries = Array.from(slate.Node.texts(listRoot));
|
|
4013
|
+
var commonAncestorEntry = textEntries.reduce(function (commonAncestor, textEntry) {
|
|
4014
|
+
return slate.Path.isAncestor(commonAncestor[1], textEntry[1]) ? commonAncestor : slate.Node.common(listRoot, textEntry[1], commonAncestor[1]);
|
|
4015
|
+
}, // any list item would do, we grab the first one
|
|
4016
|
+
getFirstAncestorOfType(listRoot, textEntries[0]));
|
|
4017
|
+
return isListRoot(commonAncestorEntry[0]) ? commonAncestorEntry[0].children : [commonAncestorEntry[0]];
|
|
4018
|
+
};
|
|
4019
|
+
/**
|
|
4020
|
+
* Removes leading li when pasting a single li with a single child.
|
|
4021
|
+
*/
|
|
4022
|
+
|
|
4023
|
+
|
|
4024
|
+
var trimLiWrapper = function trimLiWrapper(nodes) {
|
|
4025
|
+
if (nodes.length !== 1) {
|
|
4026
|
+
return nodes;
|
|
4027
|
+
}
|
|
4028
|
+
|
|
4029
|
+
var node = nodes[0];
|
|
4030
|
+
|
|
4031
|
+
if (node.type !== Contentful.BLOCKS.LIST_ITEM || node.children.length !== 1) {
|
|
4032
|
+
return nodes;
|
|
4033
|
+
}
|
|
4034
|
+
|
|
4035
|
+
return node.children;
|
|
4036
|
+
};
|
|
4037
|
+
|
|
4038
|
+
var unwrapTextContainerAtStart = function unwrapTextContainerAtStart(nodes) {
|
|
4039
|
+
var node = nodes[0];
|
|
4040
|
+
|
|
4041
|
+
if (Contentful.TEXT_CONTAINERS.includes(node.type)) {
|
|
4042
|
+
return [].concat(node.children, nodes.slice(1));
|
|
4043
|
+
}
|
|
4044
|
+
|
|
4045
|
+
return nodes;
|
|
4046
|
+
};
|
|
4047
|
+
|
|
4048
|
+
var insertListFragment = function insertListFragment(editor) {
|
|
4049
|
+
var insertFragment = editor.insertFragment;
|
|
3795
4050
|
return function (fragment) {
|
|
4051
|
+
if (!editor.selection) {
|
|
4052
|
+
return;
|
|
4053
|
+
}
|
|
4054
|
+
|
|
3796
4055
|
var liEntry = plateCore.findNode(editor, {
|
|
3797
4056
|
match: {
|
|
3798
|
-
type:
|
|
4057
|
+
type: Contentful.BLOCKS.LIST_ITEM
|
|
3799
4058
|
},
|
|
3800
4059
|
mode: 'lowest'
|
|
3801
4060
|
});
|
|
3802
4061
|
|
|
3803
4062
|
if (liEntry) {
|
|
3804
|
-
var
|
|
3805
|
-
// non-text elements
|
|
3806
|
-
|
|
3807
|
-
var nodes = fragment.flatMap(function (node) {
|
|
4063
|
+
var nodes = unwrapTextContainerAtStart(trimLiWrapper(fragment.flatMap(function (node) {
|
|
3808
4064
|
return trimList(node);
|
|
4065
|
+
})));
|
|
4066
|
+
var firstBlockIndex = nodes.findIndex(function (node) {
|
|
4067
|
+
return slate.Editor.isBlock(editor, node);
|
|
3809
4068
|
});
|
|
3810
|
-
|
|
3811
|
-
|
|
4069
|
+
|
|
4070
|
+
if (firstBlockIndex < 0) {
|
|
4071
|
+
firstBlockIndex = nodes.length;
|
|
4072
|
+
}
|
|
4073
|
+
|
|
4074
|
+
var inlines = nodes.slice(0, firstBlockIndex);
|
|
4075
|
+
var blocks = nodes.slice(firstBlockIndex); // Two calls to insertNodes are required here. Otherwise, all blocks
|
|
4076
|
+
// after a text or inline element occurrence will be unwrapped for
|
|
4077
|
+
// some reason.
|
|
4078
|
+
|
|
4079
|
+
slate.Transforms.insertNodes(editor, inlines, {
|
|
4080
|
+
at: editor.selection,
|
|
4081
|
+
select: true
|
|
4082
|
+
});
|
|
4083
|
+
return slate.Transforms.insertNodes(editor, blocks, {
|
|
4084
|
+
at: editor.selection,
|
|
3812
4085
|
select: true
|
|
3813
4086
|
});
|
|
3814
4087
|
}
|
|
@@ -3820,18 +4093,37 @@ var getListInsertFragment = function getListInsertFragment(editor) {
|
|
|
3820
4093
|
};
|
|
3821
4094
|
};
|
|
3822
4095
|
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
4096
|
+
/**
|
|
4097
|
+
* Credit: Modified version of Plate's list plugin
|
|
4098
|
+
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
4099
|
+
*/
|
|
4100
|
+
var validLiChildrenTypes = Contentful.LIST_ITEM_BLOCKS;
|
|
4101
|
+
var withList = function withList(editor) {
|
|
4102
|
+
var deleteBackward = editor.deleteBackward,
|
|
4103
|
+
deleteForward = editor.deleteForward,
|
|
4104
|
+
deleteFragment = editor.deleteFragment;
|
|
4105
|
+
|
|
4106
|
+
editor.deleteBackward = function (unit) {
|
|
4107
|
+
if (plateList.deleteBackwardList(editor, unit)) return;
|
|
4108
|
+
deleteBackward(unit);
|
|
4109
|
+
};
|
|
3831
4110
|
|
|
3832
|
-
editor.
|
|
4111
|
+
editor.deleteForward = function (unit) {
|
|
4112
|
+
if (plateList.deleteForwardList(editor)) return;
|
|
4113
|
+
deleteForward(unit);
|
|
4114
|
+
};
|
|
4115
|
+
|
|
4116
|
+
editor.deleteFragment = function () {
|
|
4117
|
+
if (plateList.deleteFragmentList(editor)) return;
|
|
4118
|
+
deleteFragment();
|
|
4119
|
+
};
|
|
4120
|
+
|
|
4121
|
+
editor.insertBreak = insertListBreak(editor);
|
|
4122
|
+
editor.insertFragment = insertListFragment(editor); // TODO: replace with Normalizer rules
|
|
3833
4123
|
|
|
3834
|
-
editor.
|
|
4124
|
+
editor.normalizeNode = plateList.normalizeList(editor, {
|
|
4125
|
+
validLiChildrenTypes: validLiChildrenTypes
|
|
4126
|
+
});
|
|
3835
4127
|
return editor;
|
|
3836
4128
|
};
|
|
3837
4129
|
|
|
@@ -3889,7 +4181,7 @@ function ToolbarListButton(props) {
|
|
|
3889
4181
|
plateList.toggleList(editor, {
|
|
3890
4182
|
type: type
|
|
3891
4183
|
});
|
|
3892
|
-
|
|
4184
|
+
focus(editor);
|
|
3893
4185
|
};
|
|
3894
4186
|
}
|
|
3895
4187
|
|
|
@@ -3917,7 +4209,7 @@ function ToolbarBoldButton(props) {
|
|
|
3917
4209
|
plateCore.toggleMark(editor, {
|
|
3918
4210
|
key: Contentful.MARKS.BOLD
|
|
3919
4211
|
});
|
|
3920
|
-
|
|
4212
|
+
focus(editor);
|
|
3921
4213
|
}
|
|
3922
4214
|
|
|
3923
4215
|
if (!editor) return null;
|
|
@@ -3976,7 +4268,7 @@ function ToolbarCodeButton(props) {
|
|
|
3976
4268
|
plateCore.toggleMark(editor, {
|
|
3977
4269
|
key: Contentful.MARKS.CODE
|
|
3978
4270
|
});
|
|
3979
|
-
|
|
4271
|
+
focus(editor);
|
|
3980
4272
|
}
|
|
3981
4273
|
|
|
3982
4274
|
if (!editor) return null;
|
|
@@ -4026,7 +4318,7 @@ function ToolbarItalicButton(props) {
|
|
|
4026
4318
|
plateCore.toggleMark(editor, {
|
|
4027
4319
|
key: Contentful.MARKS.ITALIC
|
|
4028
4320
|
});
|
|
4029
|
-
|
|
4321
|
+
focus(editor);
|
|
4030
4322
|
}
|
|
4031
4323
|
|
|
4032
4324
|
if (!editor) return null;
|
|
@@ -4080,7 +4372,7 @@ function ToolbarUnderlineButton(props) {
|
|
|
4080
4372
|
plateCore.toggleMark(editor, {
|
|
4081
4373
|
key: Contentful.MARKS.UNDERLINE
|
|
4082
4374
|
});
|
|
4083
|
-
|
|
4375
|
+
focus(editor);
|
|
4084
4376
|
}
|
|
4085
4377
|
|
|
4086
4378
|
if (!editor) return null;
|
|
@@ -4565,7 +4857,7 @@ function ToolbarQuoteButton(props) {
|
|
|
4565
4857
|
function handleOnClick() {
|
|
4566
4858
|
if (!editor) return;
|
|
4567
4859
|
toggleQuote(editor);
|
|
4568
|
-
|
|
4860
|
+
focus(editor);
|
|
4569
4861
|
}
|
|
4570
4862
|
|
|
4571
4863
|
if (!editor) return null;
|
|
@@ -4921,11 +5213,7 @@ var TableActions = function TableActions() {
|
|
|
4921
5213
|
|
|
4922
5214
|
var close = React__default.useCallback(function () {
|
|
4923
5215
|
setOpen(false);
|
|
4924
|
-
|
|
4925
|
-
// the dropdown menu
|
|
4926
|
-
|
|
4927
|
-
Slate.ReactEditor.focus(editor);
|
|
4928
|
-
}, [editor]);
|
|
5216
|
+
}, []);
|
|
4929
5217
|
React__default.useEffect(function () {
|
|
4930
5218
|
setHeaderEnabled(Boolean(editor && isTableHeaderEnabled(editor)));
|
|
4931
5219
|
}, [editor]);
|
|
@@ -5194,7 +5482,7 @@ function ToolbarTableButton(props) {
|
|
|
5194
5482
|
case 2:
|
|
5195
5483
|
onViewportAction('insertTable');
|
|
5196
5484
|
insertTableAndFocusFirstCell(editor);
|
|
5197
|
-
|
|
5485
|
+
focus(editor);
|
|
5198
5486
|
|
|
5199
5487
|
case 5:
|
|
5200
5488
|
case "end":
|
|
@@ -5221,36 +5509,49 @@ function createTextPlugin() {
|
|
|
5221
5509
|
return {
|
|
5222
5510
|
key: 'TextPlugin',
|
|
5223
5511
|
withOverrides: function withOverrides(editor) {
|
|
5224
|
-
|
|
5512
|
+
// Reverts the change made upstream that caused the cursor
|
|
5513
|
+
// to be trapped inside inline elements.
|
|
5514
|
+
//
|
|
5515
|
+
// Reverts https://github.com/ianstormtaylor/slate/pull/4578/
|
|
5516
|
+
// Related https://github.com/ianstormtaylor/slate/issues/4704
|
|
5517
|
+
var insertText = editor.insertText;
|
|
5518
|
+
|
|
5519
|
+
editor.insertText = function (text) {
|
|
5520
|
+
var selection = editor.selection; // If the cursor is at the end of an inline, move it outside
|
|
5521
|
+
// before inserting
|
|
5522
|
+
|
|
5523
|
+
if (selection && slate.Range.isCollapsed(selection)) {
|
|
5524
|
+
var _Editor$above;
|
|
5525
|
+
|
|
5526
|
+
var inlinePath = (_Editor$above = slate.Editor.above(editor, {
|
|
5527
|
+
match: function match(n) {
|
|
5528
|
+
return slate.Editor.isInline(editor, n);
|
|
5529
|
+
},
|
|
5530
|
+
mode: 'highest'
|
|
5531
|
+
})) == null ? void 0 : _Editor$above[1];
|
|
5532
|
+
|
|
5533
|
+
if (inlinePath && slate.Editor.isEnd(editor, selection.anchor, inlinePath)) {
|
|
5534
|
+
var point = slate.Editor.after(editor, inlinePath);
|
|
5535
|
+
slate.Transforms.setSelection(editor, {
|
|
5536
|
+
anchor: point,
|
|
5537
|
+
focus: point
|
|
5538
|
+
});
|
|
5539
|
+
}
|
|
5540
|
+
}
|
|
5225
5541
|
|
|
5226
|
-
|
|
5227
|
-
|
|
5542
|
+
return insertText(text);
|
|
5543
|
+
}; // When pressing delete instead of backspace
|
|
5228
5544
|
|
|
5229
|
-
var _Editor$nodes = slate.Editor.nodes(editor, {
|
|
5230
|
-
at: (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path,
|
|
5231
|
-
match: function match(node) {
|
|
5232
|
-
return Contentful.TEXT_CONTAINERS.includes(node.type);
|
|
5233
|
-
}
|
|
5234
|
-
}),
|
|
5235
|
-
nodes = _Editor$nodes[0];
|
|
5236
5545
|
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
path = nodes[1];
|
|
5240
|
-
var isTextEmpty = plateCore.isAncestorEmpty(editor, paragraphOrHeading); // We ignore paragraphs/headings that are children of ul, ol, blockquote, tables, etc
|
|
5546
|
+
var deleteForward = editor.deleteForward,
|
|
5547
|
+
deleteBackward = editor.deleteBackward;
|
|
5241
5548
|
|
|
5242
|
-
|
|
5549
|
+
editor.deleteBackward = function (unit) {
|
|
5550
|
+
deleteEmptyParagraph(unit, editor, deleteBackward);
|
|
5551
|
+
};
|
|
5243
5552
|
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
at: path
|
|
5247
|
-
});
|
|
5248
|
-
} else {
|
|
5249
|
-
deleteForward(unit);
|
|
5250
|
-
}
|
|
5251
|
-
} else {
|
|
5252
|
-
deleteForward(unit);
|
|
5253
|
-
}
|
|
5553
|
+
editor.deleteForward = function (unit) {
|
|
5554
|
+
deleteEmptyParagraph(unit, editor, deleteForward);
|
|
5254
5555
|
};
|
|
5255
5556
|
|
|
5256
5557
|
return editor;
|
|
@@ -5258,6 +5559,32 @@ function createTextPlugin() {
|
|
|
5258
5559
|
};
|
|
5259
5560
|
}
|
|
5260
5561
|
|
|
5562
|
+
function deleteEmptyParagraph(unit, editor, deleteFunction) {
|
|
5563
|
+
var entry = plateCore.getAbove(editor, {
|
|
5564
|
+
match: {
|
|
5565
|
+
type: Contentful.TEXT_CONTAINERS
|
|
5566
|
+
}
|
|
5567
|
+
});
|
|
5568
|
+
|
|
5569
|
+
if (entry) {
|
|
5570
|
+
var paragraphOrHeading = entry[0],
|
|
5571
|
+
path = entry[1];
|
|
5572
|
+
var isTextEmpty = plateCore.isAncestorEmpty(editor, paragraphOrHeading); // We ignore paragraphs/headings that are children of ul, ol, blockquote, tables, etc
|
|
5573
|
+
|
|
5574
|
+
var isRootLevel = path.length === 1;
|
|
5575
|
+
|
|
5576
|
+
if (isTextEmpty && isRootLevel) {
|
|
5577
|
+
slate.Transforms.removeNodes(editor, {
|
|
5578
|
+
at: path
|
|
5579
|
+
});
|
|
5580
|
+
} else {
|
|
5581
|
+
deleteFunction(unit);
|
|
5582
|
+
}
|
|
5583
|
+
} else {
|
|
5584
|
+
deleteFunction(unit);
|
|
5585
|
+
}
|
|
5586
|
+
}
|
|
5587
|
+
|
|
5261
5588
|
var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
|
|
5262
5589
|
return plateTrailingBlock.createTrailingBlockPlugin({
|
|
5263
5590
|
options: {
|
|
@@ -5293,8 +5620,9 @@ var transformVoid = function transformVoid(editor, _ref) {
|
|
|
5293
5620
|
var createVoidsPlugin = function createVoidsPlugin() {
|
|
5294
5621
|
return {
|
|
5295
5622
|
key: 'VoidsPlugin',
|
|
5296
|
-
exitBreak: [
|
|
5297
|
-
|
|
5623
|
+
exitBreak: [{
|
|
5624
|
+
// Inserts a new paragraph *before* a void element if it's the very first
|
|
5625
|
+
// node on the editor
|
|
5298
5626
|
hotkey: 'enter',
|
|
5299
5627
|
before: true,
|
|
5300
5628
|
query: {
|
|
@@ -5304,14 +5632,17 @@ var createVoidsPlugin = function createVoidsPlugin() {
|
|
|
5304
5632
|
return isRootLevel(path) && plateCore.isFirstChild(path) && !!node.isVoid;
|
|
5305
5633
|
}
|
|
5306
5634
|
}
|
|
5307
|
-
},
|
|
5308
|
-
|
|
5635
|
+
}, {
|
|
5636
|
+
// Inserts a new paragraph on enter when a void element is focused
|
|
5309
5637
|
hotkey: 'enter',
|
|
5638
|
+
// exploit the internal use of Array.slice(0, level + 1) by the exitBreak plugin
|
|
5639
|
+
// to stay in the parent element
|
|
5640
|
+
level: -2,
|
|
5310
5641
|
query: {
|
|
5311
5642
|
filter: function filter(_ref2) {
|
|
5312
5643
|
var node = _ref2[0],
|
|
5313
5644
|
path = _ref2[1];
|
|
5314
|
-
return !plateCore.isFirstChild(path) && !!node.isVoid;
|
|
5645
|
+
return !(isRootLevel(path) && plateCore.isFirstChild(path)) && !!node.isVoid;
|
|
5315
5646
|
}
|
|
5316
5647
|
}
|
|
5317
5648
|
}],
|
|
@@ -5340,8 +5671,8 @@ var getPlugins = function getPlugins(sdk, tracking) {
|
|
|
5340
5671
|
return [// AST must come after the HTML deserializer
|
|
5341
5672
|
plateCore.createDeserializeHtmlPlugin(), plateCore.createDeserializeAstPlugin(), plateSerializerDocx.createDeserializeDocxPlugin(), // Global shortcuts
|
|
5342
5673
|
createDragAndDropPlugin(), // Block Elements
|
|
5343
|
-
createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk), createEmbeddedAssetBlockPlugin(sdk), // Inline elements
|
|
5344
|
-
createHyperlinkPlugin(sdk), createEmbeddedEntityInlinePlugin(sdk), // Marks
|
|
5674
|
+
createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk, tracking), createEmbeddedAssetBlockPlugin(sdk, tracking), // Inline elements
|
|
5675
|
+
createHyperlinkPlugin(sdk, tracking), createEmbeddedEntityInlinePlugin(sdk, tracking), // Marks
|
|
5345
5676
|
createMarksPlugin(), // Other
|
|
5346
5677
|
createTrailingParagraphPlugin(), createTextPlugin(), createVoidsPlugin(), createSelectOnBackspacePlugin(), // Pasting content from other sources
|
|
5347
5678
|
createPasteHTMLPlugin(), // These plugins drive their configurations from the list of plugins
|
|
@@ -5612,13 +5943,9 @@ var StickyToolbarWrapper = function StickyToolbarWrapper(_ref) {
|
|
|
5612
5943
|
var _excluded = ["sdk", "isInitiallyDisabled", "onAction"];
|
|
5613
5944
|
var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
|
|
5614
5945
|
var tracking = useTrackingContext();
|
|
5615
|
-
var
|
|
5616
|
-
document: props.value || Contentful.EMPTY_DOCUMENT,
|
|
5617
|
-
schema: schema
|
|
5618
|
-
});
|
|
5619
|
-
var doc = sanitizeIncomingSlateDoc(docFromAdapter);
|
|
5946
|
+
var editor = useContentfulEditor();
|
|
5620
5947
|
|
|
5621
|
-
var _useState = React.useState(
|
|
5948
|
+
var _useState = React.useState([]),
|
|
5622
5949
|
value = _useState[0],
|
|
5623
5950
|
setValue = _useState[1];
|
|
5624
5951
|
|
|
@@ -5628,12 +5955,33 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
|
|
|
5628
5955
|
var plugins = React__default.useMemo(function () {
|
|
5629
5956
|
return getPlugins(props.sdk, tracking);
|
|
5630
5957
|
}, [props.sdk, tracking]);
|
|
5958
|
+
React__default.useEffect(function () {
|
|
5959
|
+
if (!editor) {
|
|
5960
|
+
return;
|
|
5961
|
+
}
|
|
5962
|
+
|
|
5963
|
+
var docFromAdapter = contentfulSlatejsAdapter.toSlatejsDocument({
|
|
5964
|
+
document: props.value || Contentful.EMPTY_DOCUMENT,
|
|
5965
|
+
schema: schema
|
|
5966
|
+
});
|
|
5967
|
+
var doc = sanitizeIncomingSlateDoc(docFromAdapter); // Slate throws an error if the value on the initial render is invalid
|
|
5968
|
+
// so we directly set the value on the editor in order
|
|
5969
|
+
// to be able to trigger normalization on the initial value before rendering
|
|
5970
|
+
// TODO: use https://plate.udecode.io/docs/Plate#normalizeinitialvalue when working
|
|
5971
|
+
|
|
5972
|
+
editor.children = doc;
|
|
5973
|
+
slate.Editor.normalize(editor, {
|
|
5974
|
+
force: true
|
|
5975
|
+
}); // We set the value so that the rendering can take over from here
|
|
5976
|
+
|
|
5977
|
+
setValue(editor.children);
|
|
5978
|
+
}, [props.value, editor]);
|
|
5631
5979
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
5632
5980
|
className: styles$j.root,
|
|
5633
5981
|
"data-test-id": "rich-text-editor"
|
|
5634
5982
|
}, /*#__PURE__*/React__default.createElement(plateCore.Plate, {
|
|
5635
5983
|
id: getContentfulEditorId(props.sdk),
|
|
5636
|
-
|
|
5984
|
+
value: value,
|
|
5637
5985
|
plugins: plugins,
|
|
5638
5986
|
disableCorePlugins: disableCorePlugins,
|
|
5639
5987
|
editableProps: {
|