@contentful/field-editor-rich-text 2.0.0-next.14 → 2.0.0-next.17

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.
@@ -539,17 +539,6 @@ function getAncestorPathFromSelection(editor) {
539
539
  return level.length === 1;
540
540
  });
541
541
  }
542
- function shouldUnwrapBlockquote(editor, type) {
543
- var isQuoteSelected = isBlockSelected(editor, Contentful.BLOCKS.QUOTE);
544
- var isValidType = [].concat(Contentful.HEADINGS, [Contentful.BLOCKS.OL_LIST, Contentful.BLOCKS.UL_LIST, Contentful.BLOCKS.HR]).includes(type);
545
- return isQuoteSelected && isValidType;
546
- }
547
- function unwrapFromRoot(editor) {
548
- var ancestorPath = getAncestorPathFromSelection(editor);
549
- slate.Transforms.unwrapNodes(editor, {
550
- at: ancestorPath
551
- });
552
- }
553
542
  var isAtEndOfTextSelection = function isAtEndOfTextSelection(editor) {
554
543
  var _editor$selection, _editor$selection2;
555
544
 
@@ -2506,11 +2495,6 @@ function ToolbarHeadingButton(props) {
2506
2495
  if (!(editor != null && editor.selection)) return;
2507
2496
  setSelected(type);
2508
2497
  setOpen(false);
2509
-
2510
- if (shouldUnwrapBlockquote(editor, type)) {
2511
- unwrapFromRoot(editor);
2512
- }
2513
-
2514
2498
  var prevOnChange = editor.onChange;
2515
2499
  /*
2516
2500
  The focus might happen at point in time when
@@ -2800,10 +2784,6 @@ function withHrEvents(editor) {
2800
2784
  pathToSelectedHr = _getNodeEntryFromSele[1];
2801
2785
 
2802
2786
  if (pathToSelectedHr) {
2803
- if (shouldUnwrapBlockquote(editor, Contentful.BLOCKS.HR)) {
2804
- unwrapFromRoot(editor);
2805
- }
2806
-
2807
2787
  var isBackspace = event.key === 'Backspace';
2808
2788
  var isDelete = event.key === 'Delete';
2809
2789
 
@@ -2821,11 +2801,6 @@ function ToolbarHrButton(props) {
2821
2801
 
2822
2802
  function handleOnClick() {
2823
2803
  if (!(editor != null && editor.selection)) return;
2824
-
2825
- if (shouldUnwrapBlockquote(editor, Contentful.BLOCKS.HR)) {
2826
- unwrapFromRoot(editor);
2827
- }
2828
-
2829
2804
  var hr = {
2830
2805
  type: Contentful.BLOCKS.HR,
2831
2806
  data: {},
@@ -3735,6 +3710,16 @@ var replaceNodeWithListItems = function replaceNodeWithListItems(editor, entry)
3735
3710
  at: path
3736
3711
  });
3737
3712
  };
3713
+ var isListTypeActive = function isListTypeActive(editor, type) {
3714
+ // Lists can be nested. Here, we take the list type at the lowest level
3715
+ var listNode = plateCore.getBlockAbove(editor, {
3716
+ match: {
3717
+ type: [Contentful.BLOCKS.OL_LIST, Contentful.BLOCKS.UL_LIST]
3718
+ },
3719
+ mode: 'lowest'
3720
+ });
3721
+ return (listNode == null ? void 0 : listNode[0].type) === type;
3722
+ };
3738
3723
 
3739
3724
  /**
3740
3725
  * Build a new list item node while preserving marks
@@ -4111,11 +4096,6 @@ function ToolbarListButton(props) {
4111
4096
  function handleClick(type) {
4112
4097
  return function () {
4113
4098
  if (!(editor != null && editor.selection)) return;
4114
-
4115
- if (shouldUnwrapBlockquote(editor, type)) {
4116
- unwrapFromRoot(editor);
4117
- }
4118
-
4119
4099
  plateList.toggleList(editor, {
4120
4100
  type: type
4121
4101
  });
@@ -4128,13 +4108,13 @@ function ToolbarListButton(props) {
4128
4108
  title: "UL",
4129
4109
  testId: "ul-toolbar-button",
4130
4110
  onClick: handleClick(Contentful.BLOCKS.UL_LIST),
4131
- isActive: isBlockSelected(editor, Contentful.BLOCKS.UL_LIST),
4111
+ isActive: isListTypeActive(editor, Contentful.BLOCKS.UL_LIST),
4132
4112
  isDisabled: props.isDisabled
4133
4113
  }, /*#__PURE__*/React.createElement(f36Icons.ListBulletedIcon, null)), isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.OL_LIST) && /*#__PURE__*/React.createElement(ToolbarButton, {
4134
4114
  title: "OL",
4135
4115
  testId: "ol-toolbar-button",
4136
4116
  onClick: handleClick(Contentful.BLOCKS.OL_LIST),
4137
- isActive: isBlockSelected(editor, Contentful.BLOCKS.OL_LIST),
4117
+ isActive: isListTypeActive(editor, Contentful.BLOCKS.OL_LIST),
4138
4118
  isDisabled: props.isDisabled
4139
4119
  }, /*#__PURE__*/React.createElement(f36Icons.ListNumberedIcon, null)));
4140
4120
  }
@@ -4701,11 +4681,54 @@ var sanitizeHTML = function sanitizeHTML(html) {
4701
4681
  return doc.body.innerHTML.replace(/>\s+</g, '><');
4702
4682
  };
4703
4683
 
4684
+ /**
4685
+ * Get x-slate-fragment attribute from data-slate-fragment
4686
+ */
4687
+
4688
+ var catchSlateFragment = /data-slate-fragment="(.+?)"/m;
4689
+ var getSlateFragmentAttribute = function getSlateFragmentAttribute(dataTransfer) {
4690
+ var htmlData = dataTransfer.getData('text/html');
4691
+
4692
+ var _ref = htmlData.match(catchSlateFragment) || [],
4693
+ fragment = _ref[1];
4694
+
4695
+ return fragment;
4696
+ };
4697
+ /**
4698
+ * Get the x-slate-fragment attribute that exist in text/html data
4699
+ * and append it to the DataTransfer object
4700
+ */
4701
+
4702
+ var ensureXSlateFragment = function ensureXSlateFragment(dataTransfer) {
4703
+ if (!dataTransfer.getData('application/x-slate-fragment')) {
4704
+ var fragment = getSlateFragmentAttribute(dataTransfer);
4705
+
4706
+ if (fragment) {
4707
+ var clipboardData = new DataTransfer();
4708
+ dataTransfer.types.forEach(function (type) {
4709
+ clipboardData.setData(type, dataTransfer.getData(type));
4710
+ });
4711
+ clipboardData.setData('application/x-slate-fragment', fragment);
4712
+ return clipboardData;
4713
+ }
4714
+ }
4715
+
4716
+ return dataTransfer;
4717
+ };
4704
4718
  var createPasteHTMLPlugin = function createPasteHTMLPlugin() {
4705
4719
  var _pluginsByKey;
4706
4720
 
4707
4721
  return {
4708
4722
  key: 'PasteHTMLPlugin',
4723
+ withOverrides: function withOverrides(editor) {
4724
+ var insertData = editor.insertData;
4725
+
4726
+ editor.insertData = function (data) {
4727
+ return insertData(ensureXSlateFragment(data));
4728
+ };
4729
+
4730
+ return editor;
4731
+ },
4709
4732
  inject: {
4710
4733
  pluginsByKey: (_pluginsByKey = {}, _pluginsByKey[plateCore.KEY_DESERIALIZE_HTML] = {
4711
4734
  editor: {
@@ -4724,10 +4747,7 @@ var style$1 = /*#__PURE__*/emotion.css({
4724
4747
  margin: '0 0 1.3125rem',
4725
4748
  borderLeft: "6px solid " + tokens.gray200,
4726
4749
  paddingLeft: '0.875rem',
4727
- fontStyle: 'normal',
4728
- '& a': {
4729
- color: 'inherit'
4730
- }
4750
+ fontStyle: 'normal'
4731
4751
  });
4732
4752
  function Quote(props) {
4733
4753
  return /*#__PURE__*/React.createElement("blockquote", Object.assign({}, props.attributes, {
@@ -4798,7 +4818,7 @@ function createQuotePlugin() {
4798
4818
  },
4799
4819
  normalizer: [{
4800
4820
  validChildren: Contentful.CONTAINERS[Contentful.BLOCKS.QUOTE],
4801
- transform: (_transform = {}, _transform[Contentful.BLOCKS.QUOTE] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_1] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_2] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_3] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_4] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_5] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_6] = transformUnwrap, _transform["default"] = transformLift, _transform)
4821
+ transform: (_transform = {}, _transform[Contentful.BLOCKS.QUOTE] = transformUnwrap, _transform["default"] = transformLift, _transform)
4802
4822
  }],
4803
4823
  withOverrides: function withOverrides(editor) {
4804
4824
  var insertFragment = editor.insertFragment;