@contentful/field-editor-rich-text 2.0.0-next.25 → 2.0.0-next.28
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 +77 -89
- 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 +80 -92
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/editor.d.ts +1 -3
- package/package.json +1 -1
|
@@ -461,7 +461,7 @@ function moveToTheNextChar(editor) {
|
|
|
461
461
|
unit: 'character'
|
|
462
462
|
});
|
|
463
463
|
}
|
|
464
|
-
function insertEmptyParagraph(editor) {
|
|
464
|
+
function insertEmptyParagraph(editor, options) {
|
|
465
465
|
var emptyParagraph = {
|
|
466
466
|
type: Contentful.BLOCKS.PARAGRAPH,
|
|
467
467
|
children: [{
|
|
@@ -470,7 +470,7 @@ function insertEmptyParagraph(editor) {
|
|
|
470
470
|
data: {},
|
|
471
471
|
isVoid: false
|
|
472
472
|
};
|
|
473
|
-
slate.Transforms.insertNodes(editor, emptyParagraph);
|
|
473
|
+
slate.Transforms.insertNodes(editor, emptyParagraph, options);
|
|
474
474
|
}
|
|
475
475
|
function getElementFromCurrentSelection(editor) {
|
|
476
476
|
if (!editor.selection) return [];
|
|
@@ -590,58 +590,6 @@ function getAncestorPathFromSelection(editor) {
|
|
|
590
590
|
return level.length === 1;
|
|
591
591
|
});
|
|
592
592
|
}
|
|
593
|
-
var isAtEndOfTextSelection = function isAtEndOfTextSelection(editor) {
|
|
594
|
-
var _editor$selection2, _editor$selection3;
|
|
595
|
-
|
|
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;
|
|
597
|
-
};
|
|
598
|
-
function currentSelectionStartsTableCell(editor) {
|
|
599
|
-
var _editor$selection4;
|
|
600
|
-
|
|
601
|
-
var _getNodeEntryFromSele2 = getNodeEntryFromSelection(editor, [Contentful.BLOCKS.TABLE_CELL, Contentful.BLOCKS.TABLE_HEADER_CELL]),
|
|
602
|
-
tableCellNode = _getNodeEntryFromSele2[0],
|
|
603
|
-
path = _getNodeEntryFromSele2[1];
|
|
604
|
-
|
|
605
|
-
return !!tableCellNode && (!plateCore.getText(editor, path) || ((_editor$selection4 = editor.selection) == null ? void 0 : _editor$selection4.focus.offset) === 0);
|
|
606
|
-
}
|
|
607
|
-
/**
|
|
608
|
-
* This traversal strategy is unfortunately necessary because Slate doesn't
|
|
609
|
-
* expose something like Node.next(editor).
|
|
610
|
-
*/
|
|
611
|
-
|
|
612
|
-
function getNextNode(editor) {
|
|
613
|
-
if (!editor.selection) {
|
|
614
|
-
return null;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
var descendants = slate.Node.descendants(editor, {
|
|
618
|
-
from: editor.selection.focus.path
|
|
619
|
-
}); // eslint-disable-next-line no-constant-condition
|
|
620
|
-
|
|
621
|
-
while (true) {
|
|
622
|
-
var _descendants$next = descendants.next(),
|
|
623
|
-
done = _descendants$next.done,
|
|
624
|
-
value = _descendants$next.value;
|
|
625
|
-
|
|
626
|
-
if (done) {
|
|
627
|
-
return null;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
var node = value[0],
|
|
631
|
-
path = value[1];
|
|
632
|
-
|
|
633
|
-
if (slate.Path.isCommon(path, editor.selection.focus.path)) {
|
|
634
|
-
continue;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
return node;
|
|
638
|
-
}
|
|
639
|
-
} // TODO: move to table plugin
|
|
640
|
-
|
|
641
|
-
function currentSelectionPrecedesTableCell(editor) {
|
|
642
|
-
var nextNode = getNextNode(editor);
|
|
643
|
-
return !!nextNode && Contentful.TABLE_BLOCKS.includes(nextNode.type) && isAtEndOfTextSelection(editor);
|
|
644
|
-
}
|
|
645
593
|
var INLINE_TYPES = /*#__PURE__*/Object.values(Contentful.INLINES);
|
|
646
594
|
var isInlineOrText = function isInlineOrText(node) {
|
|
647
595
|
// either text or inline elements
|
|
@@ -3868,37 +3816,44 @@ var moveListItems = function moveListItems(editor, _temp) {
|
|
|
3868
3816
|
* Credit: Modified version of Plate's list plugin
|
|
3869
3817
|
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
3870
3818
|
*/
|
|
3871
|
-
|
|
3819
|
+
|
|
3820
|
+
function hasUnliftedListItems(editor, at) {
|
|
3821
|
+
return slate.Editor.nodes(editor, {
|
|
3822
|
+
at: at,
|
|
3823
|
+
match: function match(node, path) {
|
|
3824
|
+
return slate.Element.isElement(node) && node.type === Contentful.BLOCKS.LIST_ITEM && path.length >= 2;
|
|
3825
|
+
}
|
|
3826
|
+
}).next().done;
|
|
3827
|
+
}
|
|
3828
|
+
|
|
3872
3829
|
var unwrapList = function unwrapList(editor, _temp) {
|
|
3873
3830
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
3874
3831
|
at = _ref.at;
|
|
3875
3832
|
|
|
3876
3833
|
slate.Editor.withoutNormalizing(editor, function () {
|
|
3877
3834
|
do {
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
match: {
|
|
3881
|
-
type: Contentful.BLOCKS.LIST_ITEM
|
|
3882
|
-
},
|
|
3883
|
-
split: true
|
|
3884
|
-
});
|
|
3885
|
-
plateCore.unwrapNodes(editor, {
|
|
3835
|
+
// lift list items to the root level
|
|
3836
|
+
slate.Transforms.liftNodes(editor, {
|
|
3886
3837
|
at: at,
|
|
3887
|
-
match: {
|
|
3888
|
-
type
|
|
3838
|
+
match: function match(node) {
|
|
3839
|
+
return slate.Element.isElement(node) && node.type === Contentful.BLOCKS.LIST_ITEM;
|
|
3889
3840
|
},
|
|
3890
|
-
|
|
3841
|
+
mode: 'lowest'
|
|
3891
3842
|
});
|
|
3892
|
-
} while (
|
|
3843
|
+
} while (!hasUnliftedListItems(editor, at)); // finally unwrap all lifted items
|
|
3844
|
+
|
|
3845
|
+
|
|
3846
|
+
plateCore.unwrapNodes(editor, {
|
|
3847
|
+
at: at,
|
|
3893
3848
|
match: {
|
|
3894
|
-
type:
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
})
|
|
3849
|
+
type: Contentful.BLOCKS.LIST_ITEM
|
|
3850
|
+
},
|
|
3851
|
+
split: false
|
|
3852
|
+
});
|
|
3898
3853
|
});
|
|
3899
3854
|
};
|
|
3900
3855
|
|
|
3901
|
-
var listTypes
|
|
3856
|
+
var listTypes = [Contentful.BLOCKS.UL_LIST, Contentful.BLOCKS.OL_LIST];
|
|
3902
3857
|
var toggleList = function toggleList(editor, _ref) {
|
|
3903
3858
|
var type = _ref.type;
|
|
3904
3859
|
return slate.Editor.withoutNormalizing(editor, function () {
|
|
@@ -3919,7 +3874,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
3919
3874
|
}, {
|
|
3920
3875
|
at: editor.selection,
|
|
3921
3876
|
match: function match(n) {
|
|
3922
|
-
return listTypes
|
|
3877
|
+
return listTypes.includes(n.type);
|
|
3923
3878
|
},
|
|
3924
3879
|
mode: 'lowest'
|
|
3925
3880
|
});
|
|
@@ -3960,19 +3915,25 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
3960
3915
|
|
|
3961
3916
|
var commonEntry = slate.Node.common(editor, startPoint.path, endPoint.path);
|
|
3962
3917
|
|
|
3963
|
-
if (listTypes
|
|
3964
|
-
|
|
3918
|
+
if (listTypes.includes(commonEntry[0].type) || commonEntry[0].type === Contentful.BLOCKS.LIST_ITEM) {
|
|
3919
|
+
var listType = commonEntry[0].type;
|
|
3920
|
+
|
|
3921
|
+
if (commonEntry[0].type === Contentful.BLOCKS.LIST_ITEM) {
|
|
3922
|
+
listType = slate.Editor.parent(editor, commonEntry[1])[0].type;
|
|
3923
|
+
}
|
|
3924
|
+
|
|
3925
|
+
if (listType !== type) {
|
|
3965
3926
|
var startList = plateCore.findNode(editor, {
|
|
3966
3927
|
at: slate.Range.start(editor.selection),
|
|
3967
3928
|
match: {
|
|
3968
|
-
type: listTypes
|
|
3929
|
+
type: listTypes
|
|
3969
3930
|
},
|
|
3970
3931
|
mode: 'lowest'
|
|
3971
3932
|
});
|
|
3972
3933
|
var endList = plateCore.findNode(editor, {
|
|
3973
3934
|
at: slate.Range.end(editor.selection),
|
|
3974
3935
|
match: {
|
|
3975
|
-
type: listTypes
|
|
3936
|
+
type: listTypes
|
|
3976
3937
|
},
|
|
3977
3938
|
mode: 'lowest'
|
|
3978
3939
|
});
|
|
@@ -3987,7 +3948,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
3987
3948
|
}, {
|
|
3988
3949
|
at: editor.selection,
|
|
3989
3950
|
match: function match(n, path) {
|
|
3990
|
-
return listTypes
|
|
3951
|
+
return listTypes.includes(n.type) && path.length >= rangeLength;
|
|
3991
3952
|
},
|
|
3992
3953
|
mode: 'all'
|
|
3993
3954
|
});
|
|
@@ -4005,7 +3966,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
4005
3966
|
}).reverse();
|
|
4006
3967
|
|
|
4007
3968
|
_nodes.forEach(function (n) {
|
|
4008
|
-
if (listTypes
|
|
3969
|
+
if (listTypes.includes(n[0].type)) {
|
|
4009
3970
|
plateCore.setNodes(editor, {
|
|
4010
3971
|
type: type
|
|
4011
3972
|
}, {
|
|
@@ -5910,21 +5871,46 @@ var Row = function Row(props) {
|
|
|
5910
5871
|
var _templateObject$a;
|
|
5911
5872
|
var style$5 = /*#__PURE__*/emotion.css(_templateObject$a || (_templateObject$a = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-bottom: 1.5em;\n border-collapse: collapse;\n border-radius: 5px;\n border-style: hidden;\n box-shadow: 0 0 0 1px ", ";\n width: 100%;\n table-layout: fixed;\n overflow: hidden;\n"])), tokens.gray400);
|
|
5912
5873
|
var Table = function Table(props) {
|
|
5913
|
-
return /*#__PURE__*/React.createElement("
|
|
5874
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
5875
|
+
"data-block-type": Contentful.BLOCKS.TABLE
|
|
5876
|
+
}, /*#__PURE__*/React.createElement("table", Object.assign({
|
|
5914
5877
|
className: style$5
|
|
5915
|
-
}), /*#__PURE__*/React.createElement("tbody", null, props.children));
|
|
5878
|
+
}, props.attributes), /*#__PURE__*/React.createElement("tbody", null, props.children)));
|
|
5916
5879
|
};
|
|
5917
5880
|
|
|
5918
5881
|
var createTableOnKeyDown = function createTableOnKeyDown(editor, plugin) {
|
|
5919
5882
|
var defaultHandler = plateTable.onKeyDownTable(editor, plugin);
|
|
5920
5883
|
return function (event) {
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5884
|
+
// This fixes `Cannot resolve a Slate point from DOM point: [object HTMLDivElement]` when typing while the cursor is before table
|
|
5885
|
+
var windowSelection = window.getSelection();
|
|
5886
|
+
|
|
5887
|
+
if (windowSelection) {
|
|
5888
|
+
var _windowSelection$anch, _windowSelection$anch2;
|
|
5889
|
+
|
|
5890
|
+
// @ts-expect-error
|
|
5891
|
+
var blockType = (_windowSelection$anch = windowSelection.anchorNode.attributes) == null ? void 0 : (_windowSelection$anch2 = _windowSelection$anch['data-block-type']) == null ? void 0 : _windowSelection$anch2.value; // this attribute comes from `plugins/Table/components/Table.tsx`
|
|
5892
|
+
|
|
5893
|
+
var isBeforeTable = blockType === Contentful.BLOCKS.TABLE;
|
|
5894
|
+
|
|
5895
|
+
if (isBeforeTable) {
|
|
5896
|
+
if (event.key === 'Enter') {
|
|
5897
|
+
var above = plateCore.getAbove(editor, {
|
|
5898
|
+
match: {
|
|
5899
|
+
type: Contentful.BLOCKS.TABLE
|
|
5900
|
+
}
|
|
5901
|
+
});
|
|
5902
|
+
if (!above) return;
|
|
5903
|
+
var tablePath = above[1];
|
|
5904
|
+
insertEmptyParagraph(editor, {
|
|
5905
|
+
at: tablePath,
|
|
5906
|
+
select: true
|
|
5907
|
+
});
|
|
5908
|
+
}
|
|
5909
|
+
|
|
5910
|
+
event.preventDefault();
|
|
5911
|
+
event.stopPropagation();
|
|
5912
|
+
return;
|
|
5913
|
+
}
|
|
5928
5914
|
}
|
|
5929
5915
|
|
|
5930
5916
|
defaultHandler(event);
|
|
@@ -5939,7 +5925,9 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
5939
5925
|
handlers: {
|
|
5940
5926
|
onKeyDown: createTableOnKeyDown
|
|
5941
5927
|
},
|
|
5942
|
-
withOverrides: function withOverrides(editor) {
|
|
5928
|
+
withOverrides: function withOverrides(editor, plugin) {
|
|
5929
|
+
// injects important fixes from plate's original table plugin
|
|
5930
|
+
plateTable.withTable(editor, plugin);
|
|
5943
5931
|
addTableTrackingEvents(editor);
|
|
5944
5932
|
var insertFragment = editor.insertFragment;
|
|
5945
5933
|
|