@contentful/field-editor-rich-text 2.0.0-next.23 → 2.0.0-next.24
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/field-editor-rich-text.cjs.development.js +61 -26
- 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 +61 -26
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/editor.d.ts +1 -1
- package/dist/plugins/Hyperlink/HyperlinkModal.d.ts +2 -1
- package/dist/test-utils/jsx.d.ts +1 -1
- package/package.json +1 -1
|
@@ -427,10 +427,12 @@ function isBlockSelected(editor, type) {
|
|
|
427
427
|
function isRootLevel(path) {
|
|
428
428
|
return path.length === 1;
|
|
429
429
|
}
|
|
430
|
-
function getNodeEntryFromSelection(editor, nodeTypeOrTypes) {
|
|
431
|
-
|
|
430
|
+
function getNodeEntryFromSelection(editor, nodeTypeOrTypes, path) {
|
|
431
|
+
var _path, _editor$selection;
|
|
432
|
+
|
|
433
|
+
path = (_path = path) != null ? _path : (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path;
|
|
434
|
+
if (!path) return [];
|
|
432
435
|
var nodeTypes = Array.isArray(nodeTypeOrTypes) ? nodeTypeOrTypes : [nodeTypeOrTypes];
|
|
433
|
-
var path = editor.selection.focus.path;
|
|
434
436
|
|
|
435
437
|
for (var i = 0; i < path.length; i++) {
|
|
436
438
|
var nodeEntry = slate.Editor.node(editor, path.slice(0, i + 1));
|
|
@@ -589,18 +591,18 @@ function getAncestorPathFromSelection(editor) {
|
|
|
589
591
|
});
|
|
590
592
|
}
|
|
591
593
|
var isAtEndOfTextSelection = function isAtEndOfTextSelection(editor) {
|
|
592
|
-
var _editor$
|
|
594
|
+
var _editor$selection2, _editor$selection3;
|
|
593
595
|
|
|
594
|
-
return ((_editor$
|
|
596
|
+
return ((_editor$selection2 = editor.selection) == null ? void 0 : _editor$selection2.focus.offset) === plateCore.getText(editor, (_editor$selection3 = editor.selection) == null ? void 0 : _editor$selection3.focus.path).length;
|
|
595
597
|
};
|
|
596
598
|
function currentSelectionStartsTableCell(editor) {
|
|
597
|
-
var _editor$
|
|
599
|
+
var _editor$selection4;
|
|
598
600
|
|
|
599
601
|
var _getNodeEntryFromSele2 = getNodeEntryFromSelection(editor, [Contentful.BLOCKS.TABLE_CELL, Contentful.BLOCKS.TABLE_HEADER_CELL]),
|
|
600
602
|
tableCellNode = _getNodeEntryFromSele2[0],
|
|
601
603
|
path = _getNodeEntryFromSele2[1];
|
|
602
604
|
|
|
603
|
-
return !!tableCellNode && (!plateCore.getText(editor, path) || ((_editor$
|
|
605
|
+
return !!tableCellNode && (!plateCore.getText(editor, path) || ((_editor$selection4 = editor.selection) == null ? void 0 : _editor$selection4.focus.offset) === 0);
|
|
604
606
|
}
|
|
605
607
|
/**
|
|
606
608
|
* This traversal strategy is unfortunately necessary because Slate doesn't
|
|
@@ -1063,6 +1065,9 @@ function FetchingWrappedEntryCard(props) {
|
|
|
1063
1065
|
var styles$3 = {
|
|
1064
1066
|
root: /*#__PURE__*/emotion.css({
|
|
1065
1067
|
marginBottom: '1.25rem !important',
|
|
1068
|
+
display: 'block'
|
|
1069
|
+
}),
|
|
1070
|
+
container: /*#__PURE__*/emotion.css({
|
|
1066
1071
|
// The next 2 properties ensure Entity card won't be aligned above
|
|
1067
1072
|
// a list item marker (i.e. bullet)
|
|
1068
1073
|
display: 'inline-block',
|
|
@@ -1107,7 +1112,8 @@ function LinkedEntityBlock(props) {
|
|
|
1107
1112
|
}), /*#__PURE__*/React__default.createElement("div", {
|
|
1108
1113
|
// COMPAT: This makes copy & paste work for Chromium/Blink browsers and Safari
|
|
1109
1114
|
contentEditable: HAS_BEFORE_INPUT_SUPPORT ? false : undefined,
|
|
1110
|
-
draggable: HAS_BEFORE_INPUT_SUPPORT ? true : undefined
|
|
1115
|
+
draggable: HAS_BEFORE_INPUT_SUPPORT ? true : undefined,
|
|
1116
|
+
className: styles$3.container
|
|
1111
1117
|
}, entityType === 'Entry' && /*#__PURE__*/React__default.createElement(FetchingWrappedEntryCard, {
|
|
1112
1118
|
sdk: sdk,
|
|
1113
1119
|
entryId: entityId,
|
|
@@ -3210,29 +3216,31 @@ function HyperlinkModal(props) {
|
|
|
3210
3216
|
testId: "confirm-cta"
|
|
3211
3217
|
}, props.linkType ? 'Update' : 'Insert'))));
|
|
3212
3218
|
}
|
|
3213
|
-
function addOrEditLink(_x, _x2, _x3) {
|
|
3219
|
+
function addOrEditLink(_x, _x2, _x3, _x4) {
|
|
3214
3220
|
return _addOrEditLink.apply(this, arguments);
|
|
3215
3221
|
}
|
|
3216
3222
|
|
|
3217
3223
|
function _addOrEditLink() {
|
|
3218
|
-
_addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk, logAction) {
|
|
3224
|
+
_addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk, logAction, targetPath) {
|
|
3219
3225
|
var _target$sys$linkType;
|
|
3220
3226
|
|
|
3221
|
-
var linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path,
|
|
3227
|
+
var selectionBeforeBlur, linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path, selectionAfterFocus, currentLinkText, isEditing, data, text, url, type, target;
|
|
3222
3228
|
|
|
3223
3229
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
3224
3230
|
while (1) {
|
|
3225
3231
|
switch (_context3.prev = _context3.next) {
|
|
3226
3232
|
case 0:
|
|
3227
|
-
|
|
3228
|
-
|
|
3233
|
+
selectionBeforeBlur = editor.selection ? _extends({}, editor.selection) : undefined;
|
|
3234
|
+
|
|
3235
|
+
if (!(!targetPath && !selectionBeforeBlur)) {
|
|
3236
|
+
_context3.next = 3;
|
|
3229
3237
|
break;
|
|
3230
3238
|
}
|
|
3231
3239
|
|
|
3232
3240
|
return _context3.abrupt("return");
|
|
3233
3241
|
|
|
3234
|
-
case
|
|
3235
|
-
_getNodeEntryFromSele = getNodeEntryFromSelection(editor, LINK_TYPES), node = _getNodeEntryFromSele[0], path = _getNodeEntryFromSele[1];
|
|
3242
|
+
case 3:
|
|
3243
|
+
_getNodeEntryFromSele = getNodeEntryFromSelection(editor, LINK_TYPES, targetPath), node = _getNodeEntryFromSele[0], path = _getNodeEntryFromSele[1];
|
|
3236
3244
|
|
|
3237
3245
|
if (node && path) {
|
|
3238
3246
|
linkType = node.type;
|
|
@@ -3241,11 +3249,11 @@ function _addOrEditLink() {
|
|
|
3241
3249
|
linkEntity = node.data.target;
|
|
3242
3250
|
}
|
|
3243
3251
|
|
|
3244
|
-
|
|
3245
|
-
currentLinkText = linkText || slate.Editor.string(editor, editor.selection);
|
|
3252
|
+
selectionAfterFocus = targetPath != null ? targetPath : selectionBeforeBlur;
|
|
3253
|
+
currentLinkText = linkText || (editor.selection ? slate.Editor.string(editor, editor.selection) : '');
|
|
3246
3254
|
isEditing = Boolean(node && path);
|
|
3247
3255
|
logAction(isEditing ? 'openEditHyperlinkDialog' : 'openCreateHyperlinkDialog');
|
|
3248
|
-
_context3.next =
|
|
3256
|
+
_context3.next = 11;
|
|
3249
3257
|
return fieldEditorShared.ModalDialogLauncher.openDialog({
|
|
3250
3258
|
title: isEditing ? 'Edit hyperlink' : 'Insert hyperlink',
|
|
3251
3259
|
width: 'large',
|
|
@@ -3264,20 +3272,21 @@ function _addOrEditLink() {
|
|
|
3264
3272
|
});
|
|
3265
3273
|
});
|
|
3266
3274
|
|
|
3267
|
-
case
|
|
3275
|
+
case 11:
|
|
3268
3276
|
data = _context3.sent;
|
|
3277
|
+
slate.Transforms.select(editor, selectionAfterFocus);
|
|
3269
3278
|
|
|
3270
3279
|
if (data) {
|
|
3271
|
-
_context3.next =
|
|
3280
|
+
_context3.next = 17;
|
|
3272
3281
|
break;
|
|
3273
3282
|
}
|
|
3274
3283
|
|
|
3284
|
+
focus(editor);
|
|
3275
3285
|
logAction(isEditing ? 'cancelEditHyperlinkDialog' : 'cancelCreateHyperlinkDialog');
|
|
3276
3286
|
return _context3.abrupt("return");
|
|
3277
3287
|
|
|
3278
|
-
case
|
|
3288
|
+
case 17:
|
|
3279
3289
|
text = data.linkText, url = data.linkTarget, type = data.linkType, target = data.linkEntity;
|
|
3280
|
-
slate.Transforms.select(editor, selectionBeforeBlur);
|
|
3281
3290
|
slate.Editor.withoutNormalizing(editor, function () {
|
|
3282
3291
|
insertLink(editor, {
|
|
3283
3292
|
text: text,
|
|
@@ -3293,7 +3302,7 @@ function _addOrEditLink() {
|
|
|
3293
3302
|
});
|
|
3294
3303
|
focus(editor);
|
|
3295
3304
|
|
|
3296
|
-
case
|
|
3305
|
+
case 21:
|
|
3297
3306
|
case "end":
|
|
3298
3307
|
return _context3.stop();
|
|
3299
3308
|
}
|
|
@@ -3547,7 +3556,11 @@ function EntityHyperlink(props) {
|
|
|
3547
3556
|
event.preventDefault();
|
|
3548
3557
|
event.stopPropagation();
|
|
3549
3558
|
if (!editor) return;
|
|
3550
|
-
|
|
3559
|
+
var p = Slate.ReactEditor.toSlatePoint(editor, [event.target, 0], {
|
|
3560
|
+
exactMatch: false,
|
|
3561
|
+
suppressThrow: false
|
|
3562
|
+
});
|
|
3563
|
+
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
|
|
3551
3564
|
}
|
|
3552
3565
|
|
|
3553
3566
|
return /*#__PURE__*/React.createElement(f36Components.Tooltip, {
|
|
@@ -3575,7 +3588,11 @@ function UrlHyperlink(props) {
|
|
|
3575
3588
|
event.preventDefault();
|
|
3576
3589
|
event.stopPropagation();
|
|
3577
3590
|
if (!editor) return;
|
|
3578
|
-
|
|
3591
|
+
var p = Slate.ReactEditor.toSlatePoint(editor, [event.target, 0], {
|
|
3592
|
+
exactMatch: false,
|
|
3593
|
+
suppressThrow: false
|
|
3594
|
+
});
|
|
3595
|
+
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
|
|
3579
3596
|
}
|
|
3580
3597
|
|
|
3581
3598
|
return /*#__PURE__*/React.createElement(f36Components.Tooltip, {
|
|
@@ -4139,7 +4156,25 @@ var replaceNodeWithListItems = function replaceNodeWithListItems(editor, entry)
|
|
|
4139
4156
|
});
|
|
4140
4157
|
};
|
|
4141
4158
|
var isListTypeActive = function isListTypeActive(editor, type) {
|
|
4142
|
-
|
|
4159
|
+
var selection = editor.selection;
|
|
4160
|
+
|
|
4161
|
+
if (!selection) {
|
|
4162
|
+
return false;
|
|
4163
|
+
}
|
|
4164
|
+
|
|
4165
|
+
if (slate.Range.isExpanded(selection)) {
|
|
4166
|
+
var _Range$edges = slate.Range.edges(selection),
|
|
4167
|
+
start = _Range$edges[0],
|
|
4168
|
+
end = _Range$edges[1];
|
|
4169
|
+
|
|
4170
|
+
var node = slate.Node.common(editor, start.path, end.path);
|
|
4171
|
+
|
|
4172
|
+
if (node[0].type === type) {
|
|
4173
|
+
return true;
|
|
4174
|
+
}
|
|
4175
|
+
} // Lists can be nested. Here, we take the list type at the lowest level
|
|
4176
|
+
|
|
4177
|
+
|
|
4143
4178
|
var listNode = plateCore.getBlockAbove(editor, {
|
|
4144
4179
|
match: {
|
|
4145
4180
|
type: [Contentful.BLOCKS.OL_LIST, Contentful.BLOCKS.UL_LIST]
|