@contentful/field-editor-rich-text 2.0.0-next.28 → 2.0.0-next.29
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/CHANGELOG.md +410 -0
- package/dist/field-editor-rich-text.cjs.development.js +83 -24
- 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 +85 -26
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/plugins/Table/insertTableFragment.d.ts +3 -0
- package/dist/plugins/Table/onKeyDownTable.d.ts +3 -0
- package/package.json +1 -1
|
@@ -26,7 +26,7 @@ import { createBoldPlugin as createBoldPlugin$1, createCodePlugin as createCodeP
|
|
|
26
26
|
import isPlainObject from 'is-plain-obj';
|
|
27
27
|
import { createParagraphPlugin as createParagraphPlugin$1 } from '@udecode/plate-paragraph';
|
|
28
28
|
import { createSelectOnBackspacePlugin as createSelectOnBackspacePlugin$1 } from '@udecode/plate-select';
|
|
29
|
-
import { ELEMENT_TABLE, ELEMENT_TR, getEmptyRowNode, ELEMENT_TD, ELEMENT_TH, getEmptyCellNode, insertTable, deleteRow, deleteColumn, deleteTable, createTablePlugin as createTablePlugin$1, withTable
|
|
29
|
+
import { ELEMENT_TABLE, ELEMENT_TR, getEmptyRowNode, ELEMENT_TD, ELEMENT_TH, getEmptyCellNode, insertTable, deleteRow, deleteColumn, deleteTable, onKeyDownTable as onKeyDownTable$1, getTableCellEntry, createTablePlugin as createTablePlugin$1, withTable } from '@udecode/plate-table';
|
|
30
30
|
import { toContentfulDocument, toSlatejsDocument } from '@contentful/contentful-slatejs-adapter';
|
|
31
31
|
import { documentToPlainTextString } from '@contentful/rich-text-plain-text-renderer';
|
|
32
32
|
import { createTrailingBlockPlugin } from '@udecode/plate-trailing-block';
|
|
@@ -5871,8 +5871,67 @@ var Table = function Table(props) {
|
|
|
5871
5871
|
}, props.attributes), /*#__PURE__*/createElement("tbody", null, props.children)));
|
|
5872
5872
|
};
|
|
5873
5873
|
|
|
5874
|
-
|
|
5875
|
-
|
|
5874
|
+
/**
|
|
5875
|
+
* Removes table wrappers when pasting a single table cell
|
|
5876
|
+
*
|
|
5877
|
+
* In Plate/Slate, copying the content of a table cell wraps
|
|
5878
|
+
* it in a <table><tr><td>{content}</td></tr></table> even
|
|
5879
|
+
* when copying partial cell content.
|
|
5880
|
+
*
|
|
5881
|
+
* That's really annoying as there is no way to remove the table
|
|
5882
|
+
* wrappers in that case.
|
|
5883
|
+
*/
|
|
5884
|
+
|
|
5885
|
+
var trimUnnecessaryTableWrapper = function trimUnnecessaryTableWrapper(node) {
|
|
5886
|
+
if (!Element.isElement(node)) {
|
|
5887
|
+
return [node];
|
|
5888
|
+
} // must be a table with a single row
|
|
5889
|
+
|
|
5890
|
+
|
|
5891
|
+
if (node.type !== BLOCKS.TABLE || node.children.length !== 1) {
|
|
5892
|
+
return [node];
|
|
5893
|
+
}
|
|
5894
|
+
|
|
5895
|
+
var row = node.children[0]; // the row must contain a single cell
|
|
5896
|
+
|
|
5897
|
+
if (row.children.length !== 1) {
|
|
5898
|
+
return [node];
|
|
5899
|
+
}
|
|
5900
|
+
|
|
5901
|
+
var cell = row.children[0];
|
|
5902
|
+
return cell.children;
|
|
5903
|
+
};
|
|
5904
|
+
|
|
5905
|
+
var insertTableFragment = function insertTableFragment(editor) {
|
|
5906
|
+
var insertFragment = editor.insertFragment;
|
|
5907
|
+
return function (fragments) {
|
|
5908
|
+
var _editor$selection;
|
|
5909
|
+
|
|
5910
|
+
if (!editor.selection) {
|
|
5911
|
+
return;
|
|
5912
|
+
}
|
|
5913
|
+
|
|
5914
|
+
fragments = fragments.flatMap(trimUnnecessaryTableWrapper); // We need to make sure we have a new, empty and clean paragraph in order to paste tables as-is due to how Slate behaves
|
|
5915
|
+
// More info: https://github.com/ianstormtaylor/slate/pull/4489 and https://github.com/ianstormtaylor/slate/issues/4542
|
|
5916
|
+
|
|
5917
|
+
var isInsertingTable = fragments.some(function (fragment) {
|
|
5918
|
+
return isTable(fragment);
|
|
5919
|
+
});
|
|
5920
|
+
var isTableFirstFragment = fragments.findIndex(function (fragment) {
|
|
5921
|
+
return isTable(fragment);
|
|
5922
|
+
}) === 0;
|
|
5923
|
+
var currentLineHasText = getText(editor, (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path) !== '';
|
|
5924
|
+
|
|
5925
|
+
if (isInsertingTable && isTableFirstFragment && currentLineHasText) {
|
|
5926
|
+
insertEmptyParagraph(editor);
|
|
5927
|
+
}
|
|
5928
|
+
|
|
5929
|
+
return insertFragment(fragments);
|
|
5930
|
+
};
|
|
5931
|
+
};
|
|
5932
|
+
|
|
5933
|
+
var onKeyDownTable = function onKeyDownTable(editor, plugin) {
|
|
5934
|
+
var defaultHandler = onKeyDownTable$1(editor, plugin);
|
|
5876
5935
|
return function (event) {
|
|
5877
5936
|
// This fixes `Cannot resolve a Slate point from DOM point: [object HTMLDivElement]` when typing while the cursor is before table
|
|
5878
5937
|
var windowSelection = window.getSelection();
|
|
@@ -5904,6 +5963,27 @@ var createTableOnKeyDown = function createTableOnKeyDown(editor, plugin) {
|
|
|
5904
5963
|
event.stopPropagation();
|
|
5905
5964
|
return;
|
|
5906
5965
|
}
|
|
5966
|
+
} // Pressing Tab on the last cell creates a new row
|
|
5967
|
+
// Otherwise, jumping between cells is handled in the defaultKeyDownTable
|
|
5968
|
+
|
|
5969
|
+
|
|
5970
|
+
if (event.key === 'Tab' && !event.shiftKey) {
|
|
5971
|
+
event.preventDefault();
|
|
5972
|
+
var res = getTableCellEntry(editor, {});
|
|
5973
|
+
|
|
5974
|
+
if (res) {
|
|
5975
|
+
var tableElement = res.tableElement,
|
|
5976
|
+
tableRow = res.tableRow,
|
|
5977
|
+
tableCell = res.tableCell;
|
|
5978
|
+
var isLastCell = isLastChild(tableRow, tableCell[1]);
|
|
5979
|
+
var isLastRow = isLastChild(tableElement, tableRow[1]);
|
|
5980
|
+
|
|
5981
|
+
if (isLastRow && isLastCell) {
|
|
5982
|
+
addRowBelow(editor); // skip default handler
|
|
5983
|
+
|
|
5984
|
+
return;
|
|
5985
|
+
}
|
|
5986
|
+
}
|
|
5907
5987
|
}
|
|
5908
5988
|
|
|
5909
5989
|
defaultHandler(event);
|
|
@@ -5916,34 +5996,13 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
5916
5996
|
return createTablePlugin$1({
|
|
5917
5997
|
type: BLOCKS.TABLE,
|
|
5918
5998
|
handlers: {
|
|
5919
|
-
onKeyDown:
|
|
5999
|
+
onKeyDown: onKeyDownTable
|
|
5920
6000
|
},
|
|
5921
6001
|
withOverrides: function withOverrides(editor, plugin) {
|
|
5922
6002
|
// injects important fixes from plate's original table plugin
|
|
5923
6003
|
withTable(editor, plugin);
|
|
5924
6004
|
addTableTrackingEvents(editor);
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
editor.insertFragment = function (fragments) {
|
|
5928
|
-
var _editor$selection;
|
|
5929
|
-
|
|
5930
|
-
// We need to make sure we have a new, empty and clean paragraph in order to paste tables as-is due to how Slate behaves
|
|
5931
|
-
// More info: https://github.com/ianstormtaylor/slate/pull/4489 and https://github.com/ianstormtaylor/slate/issues/4542
|
|
5932
|
-
var isInsertingTable = fragments.some(function (fragment) {
|
|
5933
|
-
return isTable(fragment);
|
|
5934
|
-
});
|
|
5935
|
-
var isTableFirstFragment = fragments.findIndex(function (fragment) {
|
|
5936
|
-
return isTable(fragment);
|
|
5937
|
-
}) === 0;
|
|
5938
|
-
var currentLineHasText = getText(editor, (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path) !== '';
|
|
5939
|
-
|
|
5940
|
-
if (isInsertingTable && isTableFirstFragment && currentLineHasText) {
|
|
5941
|
-
insertEmptyParagraph(editor);
|
|
5942
|
-
}
|
|
5943
|
-
|
|
5944
|
-
insertFragment(fragments);
|
|
5945
|
-
};
|
|
5946
|
-
|
|
6005
|
+
editor.insertFragment = insertTableFragment(editor);
|
|
5947
6006
|
return editor;
|
|
5948
6007
|
},
|
|
5949
6008
|
overrideByKey: (_overrideByKey = {}, _overrideByKey[ELEMENT_TABLE] = {
|