@contentful/field-editor-rich-text 2.0.0-next.25 → 2.0.0-next.26

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.
@@ -3861,37 +3861,44 @@ var moveListItems = function moveListItems(editor, _temp) {
3861
3861
  * Credit: Modified version of Plate's list plugin
3862
3862
  * See: https://github.com/udecode/plate/blob/main/packages/nodes/list
3863
3863
  */
3864
- var listTypes = [BLOCKS.UL_LIST, BLOCKS.OL_LIST];
3864
+
3865
+ function hasUnliftedListItems(editor, at) {
3866
+ return Editor.nodes(editor, {
3867
+ at: at,
3868
+ match: function match(node, path) {
3869
+ return Element.isElement(node) && node.type === BLOCKS.LIST_ITEM && path.length >= 2;
3870
+ }
3871
+ }).next().done;
3872
+ }
3873
+
3865
3874
  var unwrapList = function unwrapList(editor, _temp) {
3866
3875
  var _ref = _temp === void 0 ? {} : _temp,
3867
3876
  at = _ref.at;
3868
3877
 
3869
3878
  Editor.withoutNormalizing(editor, function () {
3870
3879
  do {
3871
- unwrapNodes(editor, {
3880
+ // lift list items to the root level
3881
+ Transforms.liftNodes(editor, {
3872
3882
  at: at,
3873
- match: {
3874
- type: BLOCKS.LIST_ITEM
3875
- },
3876
- split: true
3877
- });
3878
- unwrapNodes(editor, {
3879
- at: at,
3880
- match: {
3881
- type: listTypes
3883
+ match: function match(node) {
3884
+ return Element.isElement(node) && node.type === BLOCKS.LIST_ITEM;
3882
3885
  },
3883
- split: true
3886
+ mode: 'lowest'
3884
3887
  });
3885
- } while (getAbove(editor, {
3888
+ } while (!hasUnliftedListItems(editor, at)); // finally unwrap all lifted items
3889
+
3890
+
3891
+ unwrapNodes(editor, {
3892
+ at: at,
3886
3893
  match: {
3887
- type: listTypes,
3888
- at: at
3889
- }
3890
- }));
3894
+ type: BLOCKS.LIST_ITEM
3895
+ },
3896
+ split: false
3897
+ });
3891
3898
  });
3892
3899
  };
3893
3900
 
3894
- var listTypes$1 = [BLOCKS.UL_LIST, BLOCKS.OL_LIST];
3901
+ var listTypes = [BLOCKS.UL_LIST, BLOCKS.OL_LIST];
3895
3902
  var toggleList = function toggleList(editor, _ref) {
3896
3903
  var type = _ref.type;
3897
3904
  return Editor.withoutNormalizing(editor, function () {
@@ -3912,7 +3919,7 @@ var toggleList = function toggleList(editor, _ref) {
3912
3919
  }, {
3913
3920
  at: editor.selection,
3914
3921
  match: function match(n) {
3915
- return listTypes$1.includes(n.type);
3922
+ return listTypes.includes(n.type);
3916
3923
  },
3917
3924
  mode: 'lowest'
3918
3925
  });
@@ -3953,19 +3960,25 @@ var toggleList = function toggleList(editor, _ref) {
3953
3960
 
3954
3961
  var commonEntry = Node.common(editor, startPoint.path, endPoint.path);
3955
3962
 
3956
- if (listTypes$1.includes(commonEntry[0].type) || commonEntry[0].type === BLOCKS.LIST_ITEM) {
3957
- if (commonEntry[0].type !== type) {
3963
+ if (listTypes.includes(commonEntry[0].type) || commonEntry[0].type === BLOCKS.LIST_ITEM) {
3964
+ var listType = commonEntry[0].type;
3965
+
3966
+ if (commonEntry[0].type === BLOCKS.LIST_ITEM) {
3967
+ listType = Editor.parent(editor, commonEntry[1])[0].type;
3968
+ }
3969
+
3970
+ if (listType !== type) {
3958
3971
  var startList = findNode(editor, {
3959
3972
  at: Range.start(editor.selection),
3960
3973
  match: {
3961
- type: listTypes$1
3974
+ type: listTypes
3962
3975
  },
3963
3976
  mode: 'lowest'
3964
3977
  });
3965
3978
  var endList = findNode(editor, {
3966
3979
  at: Range.end(editor.selection),
3967
3980
  match: {
3968
- type: listTypes$1
3981
+ type: listTypes
3969
3982
  },
3970
3983
  mode: 'lowest'
3971
3984
  });
@@ -3980,7 +3993,7 @@ var toggleList = function toggleList(editor, _ref) {
3980
3993
  }, {
3981
3994
  at: editor.selection,
3982
3995
  match: function match(n, path) {
3983
- return listTypes$1.includes(n.type) && path.length >= rangeLength;
3996
+ return listTypes.includes(n.type) && path.length >= rangeLength;
3984
3997
  },
3985
3998
  mode: 'all'
3986
3999
  });
@@ -3998,7 +4011,7 @@ var toggleList = function toggleList(editor, _ref) {
3998
4011
  }).reverse();
3999
4012
 
4000
4013
  _nodes.forEach(function (n) {
4001
- if (listTypes$1.includes(n[0].type)) {
4014
+ if (listTypes.includes(n[0].type)) {
4002
4015
  setNodes(editor, {
4003
4016
  type: type
4004
4017
  }, {