@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.
@@ -420,10 +420,12 @@ function isBlockSelected(editor, type) {
420
420
  function isRootLevel(path) {
421
421
  return path.length === 1;
422
422
  }
423
- function getNodeEntryFromSelection(editor, nodeTypeOrTypes) {
424
- if (!editor.selection) return [];
423
+ function getNodeEntryFromSelection(editor, nodeTypeOrTypes, path) {
424
+ var _path, _editor$selection;
425
+
426
+ path = (_path = path) != null ? _path : (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path;
427
+ if (!path) return [];
425
428
  var nodeTypes = Array.isArray(nodeTypeOrTypes) ? nodeTypeOrTypes : [nodeTypeOrTypes];
426
- var path = editor.selection.focus.path;
427
429
 
428
430
  for (var i = 0; i < path.length; i++) {
429
431
  var nodeEntry = Editor.node(editor, path.slice(0, i + 1));
@@ -582,18 +584,18 @@ function getAncestorPathFromSelection(editor) {
582
584
  });
583
585
  }
584
586
  var isAtEndOfTextSelection = function isAtEndOfTextSelection(editor) {
585
- var _editor$selection, _editor$selection2;
587
+ var _editor$selection2, _editor$selection3;
586
588
 
587
- return ((_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.offset) === getText(editor, (_editor$selection2 = editor.selection) == null ? void 0 : _editor$selection2.focus.path).length;
589
+ return ((_editor$selection2 = editor.selection) == null ? void 0 : _editor$selection2.focus.offset) === getText(editor, (_editor$selection3 = editor.selection) == null ? void 0 : _editor$selection3.focus.path).length;
588
590
  };
589
591
  function currentSelectionStartsTableCell(editor) {
590
- var _editor$selection3;
592
+ var _editor$selection4;
591
593
 
592
594
  var _getNodeEntryFromSele2 = getNodeEntryFromSelection(editor, [BLOCKS.TABLE_CELL, BLOCKS.TABLE_HEADER_CELL]),
593
595
  tableCellNode = _getNodeEntryFromSele2[0],
594
596
  path = _getNodeEntryFromSele2[1];
595
597
 
596
- return !!tableCellNode && (!getText(editor, path) || ((_editor$selection3 = editor.selection) == null ? void 0 : _editor$selection3.focus.offset) === 0);
598
+ return !!tableCellNode && (!getText(editor, path) || ((_editor$selection4 = editor.selection) == null ? void 0 : _editor$selection4.focus.offset) === 0);
597
599
  }
598
600
  /**
599
601
  * This traversal strategy is unfortunately necessary because Slate doesn't
@@ -1056,6 +1058,9 @@ function FetchingWrappedEntryCard(props) {
1056
1058
  var styles$3 = {
1057
1059
  root: /*#__PURE__*/css({
1058
1060
  marginBottom: '1.25rem !important',
1061
+ display: 'block'
1062
+ }),
1063
+ container: /*#__PURE__*/css({
1059
1064
  // The next 2 properties ensure Entity card won't be aligned above
1060
1065
  // a list item marker (i.e. bullet)
1061
1066
  display: 'inline-block',
@@ -1100,7 +1105,8 @@ function LinkedEntityBlock(props) {
1100
1105
  }), /*#__PURE__*/React__default.createElement("div", {
1101
1106
  // COMPAT: This makes copy & paste work for Chromium/Blink browsers and Safari
1102
1107
  contentEditable: HAS_BEFORE_INPUT_SUPPORT ? false : undefined,
1103
- draggable: HAS_BEFORE_INPUT_SUPPORT ? true : undefined
1108
+ draggable: HAS_BEFORE_INPUT_SUPPORT ? true : undefined,
1109
+ className: styles$3.container
1104
1110
  }, entityType === 'Entry' && /*#__PURE__*/React__default.createElement(FetchingWrappedEntryCard, {
1105
1111
  sdk: sdk,
1106
1112
  entryId: entityId,
@@ -3203,29 +3209,31 @@ function HyperlinkModal(props) {
3203
3209
  testId: "confirm-cta"
3204
3210
  }, props.linkType ? 'Update' : 'Insert'))));
3205
3211
  }
3206
- function addOrEditLink(_x, _x2, _x3) {
3212
+ function addOrEditLink(_x, _x2, _x3, _x4) {
3207
3213
  return _addOrEditLink.apply(this, arguments);
3208
3214
  }
3209
3215
 
3210
3216
  function _addOrEditLink() {
3211
- _addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk, logAction) {
3217
+ _addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk, logAction, targetPath) {
3212
3218
  var _target$sys$linkType;
3213
3219
 
3214
- var linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path, selectionBeforeBlur, currentLinkText, isEditing, data, text, url, type, target;
3220
+ var selectionBeforeBlur, linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path, selectionAfterFocus, currentLinkText, isEditing, data, text, url, type, target;
3215
3221
 
3216
3222
  return runtime_1.wrap(function _callee3$(_context3) {
3217
3223
  while (1) {
3218
3224
  switch (_context3.prev = _context3.next) {
3219
3225
  case 0:
3220
- if (editor.selection) {
3221
- _context3.next = 2;
3226
+ selectionBeforeBlur = editor.selection ? _extends({}, editor.selection) : undefined;
3227
+
3228
+ if (!(!targetPath && !selectionBeforeBlur)) {
3229
+ _context3.next = 3;
3222
3230
  break;
3223
3231
  }
3224
3232
 
3225
3233
  return _context3.abrupt("return");
3226
3234
 
3227
- case 2:
3228
- _getNodeEntryFromSele = getNodeEntryFromSelection(editor, LINK_TYPES), node = _getNodeEntryFromSele[0], path = _getNodeEntryFromSele[1];
3235
+ case 3:
3236
+ _getNodeEntryFromSele = getNodeEntryFromSelection(editor, LINK_TYPES, targetPath), node = _getNodeEntryFromSele[0], path = _getNodeEntryFromSele[1];
3229
3237
 
3230
3238
  if (node && path) {
3231
3239
  linkType = node.type;
@@ -3234,11 +3242,11 @@ function _addOrEditLink() {
3234
3242
  linkEntity = node.data.target;
3235
3243
  }
3236
3244
 
3237
- selectionBeforeBlur = _extends({}, editor.selection);
3238
- currentLinkText = linkText || Editor.string(editor, editor.selection);
3245
+ selectionAfterFocus = targetPath != null ? targetPath : selectionBeforeBlur;
3246
+ currentLinkText = linkText || (editor.selection ? Editor.string(editor, editor.selection) : '');
3239
3247
  isEditing = Boolean(node && path);
3240
3248
  logAction(isEditing ? 'openEditHyperlinkDialog' : 'openCreateHyperlinkDialog');
3241
- _context3.next = 10;
3249
+ _context3.next = 11;
3242
3250
  return ModalDialogLauncher.openDialog({
3243
3251
  title: isEditing ? 'Edit hyperlink' : 'Insert hyperlink',
3244
3252
  width: 'large',
@@ -3257,20 +3265,21 @@ function _addOrEditLink() {
3257
3265
  });
3258
3266
  });
3259
3267
 
3260
- case 10:
3268
+ case 11:
3261
3269
  data = _context3.sent;
3270
+ Transforms.select(editor, selectionAfterFocus);
3262
3271
 
3263
3272
  if (data) {
3264
- _context3.next = 14;
3273
+ _context3.next = 17;
3265
3274
  break;
3266
3275
  }
3267
3276
 
3277
+ focus(editor);
3268
3278
  logAction(isEditing ? 'cancelEditHyperlinkDialog' : 'cancelCreateHyperlinkDialog');
3269
3279
  return _context3.abrupt("return");
3270
3280
 
3271
- case 14:
3281
+ case 17:
3272
3282
  text = data.linkText, url = data.linkTarget, type = data.linkType, target = data.linkEntity;
3273
- Transforms.select(editor, selectionBeforeBlur);
3274
3283
  Editor.withoutNormalizing(editor, function () {
3275
3284
  insertLink(editor, {
3276
3285
  text: text,
@@ -3286,7 +3295,7 @@ function _addOrEditLink() {
3286
3295
  });
3287
3296
  focus(editor);
3288
3297
 
3289
- case 19:
3298
+ case 21:
3290
3299
  case "end":
3291
3300
  return _context3.stop();
3292
3301
  }
@@ -3540,7 +3549,11 @@ function EntityHyperlink(props) {
3540
3549
  event.preventDefault();
3541
3550
  event.stopPropagation();
3542
3551
  if (!editor) return;
3543
- addOrEditLink(editor, sdk, editor.tracking.onViewportAction);
3552
+ var p = ReactEditor.toSlatePoint(editor, [event.target, 0], {
3553
+ exactMatch: false,
3554
+ suppressThrow: false
3555
+ });
3556
+ addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
3544
3557
  }
3545
3558
 
3546
3559
  return /*#__PURE__*/createElement(Tooltip, {
@@ -3568,7 +3581,11 @@ function UrlHyperlink(props) {
3568
3581
  event.preventDefault();
3569
3582
  event.stopPropagation();
3570
3583
  if (!editor) return;
3571
- addOrEditLink(editor, sdk, editor.tracking.onViewportAction);
3584
+ var p = ReactEditor.toSlatePoint(editor, [event.target, 0], {
3585
+ exactMatch: false,
3586
+ suppressThrow: false
3587
+ });
3588
+ addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
3572
3589
  }
3573
3590
 
3574
3591
  return /*#__PURE__*/createElement(Tooltip, {
@@ -4132,7 +4149,25 @@ var replaceNodeWithListItems = function replaceNodeWithListItems(editor, entry)
4132
4149
  });
4133
4150
  };
4134
4151
  var isListTypeActive = function isListTypeActive(editor, type) {
4135
- // Lists can be nested. Here, we take the list type at the lowest level
4152
+ var selection = editor.selection;
4153
+
4154
+ if (!selection) {
4155
+ return false;
4156
+ }
4157
+
4158
+ if (Range.isExpanded(selection)) {
4159
+ var _Range$edges = Range.edges(selection),
4160
+ start = _Range$edges[0],
4161
+ end = _Range$edges[1];
4162
+
4163
+ var node = Node.common(editor, start.path, end.path);
4164
+
4165
+ if (node[0].type === type) {
4166
+ return true;
4167
+ }
4168
+ } // Lists can be nested. Here, we take the list type at the lowest level
4169
+
4170
+
4136
4171
  var listNode = getBlockAbove(editor, {
4137
4172
  match: {
4138
4173
  type: [BLOCKS.OL_LIST, BLOCKS.UL_LIST]