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

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.
@@ -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 [];
@@ -5923,9 +5923,11 @@ var Row = function Row(props) {
5923
5923
  var _templateObject$a;
5924
5924
  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);
5925
5925
  var Table = function Table(props) {
5926
- return /*#__PURE__*/React.createElement("table", Object.assign({}, props.attributes, {
5926
+ return /*#__PURE__*/React.createElement("div", {
5927
+ "data-block-type": Contentful.BLOCKS.TABLE
5928
+ }, /*#__PURE__*/React.createElement("table", Object.assign({
5927
5929
  className: style$5
5928
- }), /*#__PURE__*/React.createElement("tbody", null, props.children));
5930
+ }, props.attributes), /*#__PURE__*/React.createElement("tbody", null, props.children)));
5929
5931
  };
5930
5932
 
5931
5933
  var createTableOnKeyDown = function createTableOnKeyDown(editor, plugin) {
@@ -5938,6 +5940,38 @@ var createTableOnKeyDown = function createTableOnKeyDown(editor, plugin) {
5938
5940
  event.preventDefault();
5939
5941
  event.stopPropagation();
5940
5942
  return;
5943
+ } // This fixes `Cannot resolve a Slate point from DOM point: [object HTMLDivElement]` when typing while the cursor is before table
5944
+
5945
+
5946
+ var windowSelection = window.getSelection();
5947
+
5948
+ if (windowSelection) {
5949
+ var _windowSelection$anch, _windowSelection$anch2;
5950
+
5951
+ // @ts-expect-error
5952
+ 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`
5953
+
5954
+ var isBeforeTable = blockType === Contentful.BLOCKS.TABLE;
5955
+
5956
+ if (isBeforeTable) {
5957
+ if (event.key === 'Enter') {
5958
+ var above = plateCore.getAbove(editor, {
5959
+ match: {
5960
+ type: Contentful.BLOCKS.TABLE
5961
+ }
5962
+ });
5963
+ if (!above) return;
5964
+ var tablePath = above[1];
5965
+ insertEmptyParagraph(editor, {
5966
+ at: tablePath,
5967
+ select: true
5968
+ });
5969
+ }
5970
+
5971
+ event.preventDefault();
5972
+ event.stopPropagation();
5973
+ return;
5974
+ }
5941
5975
  }
5942
5976
 
5943
5977
  defaultHandler(event);
@@ -5952,7 +5986,9 @@ var createTablePlugin = function createTablePlugin() {
5952
5986
  handlers: {
5953
5987
  onKeyDown: createTableOnKeyDown
5954
5988
  },
5955
- withOverrides: function withOverrides(editor) {
5989
+ withOverrides: function withOverrides(editor, plugin) {
5990
+ // injects important fixes from plate's original table plugin
5991
+ plateTable.withTable(editor, plugin);
5956
5992
  addTableTrackingEvents(editor);
5957
5993
  var insertFragment = editor.insertFragment;
5958
5994