@contentful/field-editor-rich-text 2.0.0-next.35 → 2.0.0-next.38

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.
@@ -451,7 +451,7 @@ function moveToTheNextLine(editor) {
451
451
  function moveToTheNextChar(editor) {
452
452
  Transforms.move(editor, {
453
453
  distance: 1,
454
- unit: 'character'
454
+ unit: 'offset'
455
455
  });
456
456
  }
457
457
  function insertEmptyParagraph(editor, options) {
@@ -6607,6 +6607,7 @@ function createTextPlugin() {
6607
6607
  deleteEmptyParagraph(unit, editor, deleteForward);
6608
6608
  };
6609
6609
 
6610
+ fixPasteAsPlainText(editor);
6610
6611
  return editor;
6611
6612
  }
6612
6613
  };
@@ -6657,6 +6658,45 @@ function deleteEmptyParagraph(unit, editor, deleteFunction) {
6657
6658
  deleteFunction(unit);
6658
6659
  }
6659
6660
  }
6661
+ /**
6662
+ * To be compatible with the old behavior we need to treat each 2 consecutive
6663
+ * line breaks as a new paragraph when pasting as plain text (also known as
6664
+ * paste and match style in macOS)
6665
+ */
6666
+
6667
+
6668
+ function fixPasteAsPlainText(editor) {
6669
+ editor.insertTextData = function (data) {
6670
+ var text = data.getData('text/plain');
6671
+
6672
+ if (!text) {
6673
+ return false;
6674
+ }
6675
+
6676
+ var lines = text.split(/\n{2}/);
6677
+ var split = false;
6678
+
6679
+ for (var _iterator = _createForOfIteratorHelperLoose(lines), _step; !(_step = _iterator()).done;) {
6680
+ var line = _step.value;
6681
+
6682
+ // empty lines
6683
+ if (/^(\r\n?|\n)$/.test(line)) {
6684
+ continue;
6685
+ }
6686
+
6687
+ if (split) {
6688
+ Transforms.splitNodes(editor, {
6689
+ always: true
6690
+ });
6691
+ }
6692
+
6693
+ editor.insertText(line);
6694
+ split = true;
6695
+ }
6696
+
6697
+ return true;
6698
+ };
6699
+ }
6660
6700
 
6661
6701
  var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
6662
6702
  return createTrailingBlockPlugin({
@@ -6887,26 +6927,11 @@ var EmbedEntityWidget = function EmbedEntityWidget(_ref) {
6887
6927
  return setEmbedDropdownOpen(!isEmbedDropdownOpen);
6888
6928
  };
6889
6929
 
6890
- var _useState2 = useState(false),
6891
- canAccessAssets = _useState2[0],
6892
- setCanAccessAssets = _useState2[1];
6893
-
6894
- React__default.useEffect(function () {
6895
- var subscribed = true;
6896
- sdk.access.can('read', 'Asset').then(function (can) {
6897
- if (!subscribed) {
6898
- return;
6899
- }
6900
-
6901
- setCanAccessAssets(can);
6902
- });
6903
- return function () {
6904
- subscribed = false;
6905
- };
6906
- }, [sdk]);
6907
6930
  var inlineEntryEmbedEnabled = isNodeTypeEnabled(sdk.field, INLINES.EMBEDDED_ENTRY);
6908
- var blockEntryEmbedEnabled = isNodeTypeEnabled(sdk.field, BLOCKS.EMBEDDED_ENTRY) && canInsertBlocks;
6909
- var blockAssetEmbedEnabled = canAccessAssets && isNodeTypeEnabled(sdk.field, BLOCKS.EMBEDDED_ASSET) && canInsertBlocks;
6931
+ var blockEntryEmbedEnabled = isNodeTypeEnabled(sdk.field, BLOCKS.EMBEDDED_ENTRY) && canInsertBlocks; // Removed access check following https://contentful.atlassian.net/browse/DANTE-486
6932
+ // TODO: refine permissions check in order to account for tags in rules and then readd access.can('read', 'Asset')
6933
+
6934
+ var blockAssetEmbedEnabled = isNodeTypeEnabled(sdk.field, BLOCKS.EMBEDDED_ASSET) && canInsertBlocks;
6910
6935
  var numEnabledEmbeds = [inlineEntryEmbedEnabled, blockEntryEmbedEnabled, blockAssetEmbedEnabled].filter(Boolean).length;
6911
6936
  var shouldDisplayDropdown = numEnabledEmbeds > 1 || isDisabled; // Avoids UI glitching when switching back and forth between
6912
6937
  // different layouts