@contentful/field-editor-rich-text 2.0.0-next.24 → 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.
- package/dist/field-editor-rich-text.cjs.development.js +94 -36
- 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 +95 -37
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/editor.d.ts +1 -1
- package/dist/plugins/Table/helpers.d.ts +2 -1
- package/dist/test-utils/jsx.d.ts +1 -1
- package/package.json +1 -1
- package/CHANGELOG.md +0 -410
|
@@ -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, onKeyDownTable } from '@udecode/plate-table';
|
|
29
|
+
import { ELEMENT_TABLE, ELEMENT_TR, getEmptyRowNode, ELEMENT_TD, ELEMENT_TH, getEmptyCellNode, insertTable, deleteRow, deleteColumn, deleteTable, createTablePlugin as createTablePlugin$1, withTable, onKeyDownTable } 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';
|
|
@@ -454,7 +454,7 @@ function moveToTheNextChar(editor) {
|
|
|
454
454
|
unit: 'character'
|
|
455
455
|
});
|
|
456
456
|
}
|
|
457
|
-
function insertEmptyParagraph(editor) {
|
|
457
|
+
function insertEmptyParagraph(editor, options) {
|
|
458
458
|
var emptyParagraph = {
|
|
459
459
|
type: BLOCKS.PARAGRAPH,
|
|
460
460
|
children: [{
|
|
@@ -463,7 +463,7 @@ function insertEmptyParagraph(editor) {
|
|
|
463
463
|
data: {},
|
|
464
464
|
isVoid: false
|
|
465
465
|
};
|
|
466
|
-
Transforms.insertNodes(editor, emptyParagraph);
|
|
466
|
+
Transforms.insertNodes(editor, emptyParagraph, options);
|
|
467
467
|
}
|
|
468
468
|
function getElementFromCurrentSelection(editor) {
|
|
469
469
|
if (!editor.selection) return [];
|
|
@@ -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
|
-
|
|
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
|
-
|
|
3880
|
+
// lift list items to the root level
|
|
3881
|
+
Transforms.liftNodes(editor, {
|
|
3872
3882
|
at: at,
|
|
3873
|
-
match: {
|
|
3874
|
-
type
|
|
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
|
-
|
|
3886
|
+
mode: 'lowest'
|
|
3884
3887
|
});
|
|
3885
|
-
} while (
|
|
3888
|
+
} while (!hasUnliftedListItems(editor, at)); // finally unwrap all lifted items
|
|
3889
|
+
|
|
3890
|
+
|
|
3891
|
+
unwrapNodes(editor, {
|
|
3892
|
+
at: at,
|
|
3886
3893
|
match: {
|
|
3887
|
-
type:
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
})
|
|
3894
|
+
type: BLOCKS.LIST_ITEM
|
|
3895
|
+
},
|
|
3896
|
+
split: false
|
|
3897
|
+
});
|
|
3891
3898
|
});
|
|
3892
3899
|
};
|
|
3893
3900
|
|
|
3894
|
-
var listTypes
|
|
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
|
|
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
|
|
3957
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
4014
|
+
if (listTypes.includes(n[0].type)) {
|
|
4002
4015
|
setNodes(editor, {
|
|
4003
4016
|
type: type
|
|
4004
4017
|
}, {
|
|
@@ -5214,9 +5227,9 @@ var sanitizeHTML = function sanitizeHTML(html) {
|
|
|
5214
5227
|
// Parse the HTML string and pipe it through our transformers
|
|
5215
5228
|
var doc = transformers.reduce(function (value, cb) {
|
|
5216
5229
|
return cb(value);
|
|
5217
|
-
}, new DOMParser().parseFromString(html, 'text/html'));
|
|
5218
|
-
|
|
5219
|
-
|
|
5230
|
+
}, new DOMParser().parseFromString(html, 'text/html'));
|
|
5231
|
+
return doc.body.innerHTML.replace(/>\s+</g, '><') // Remove whitespace between tags
|
|
5232
|
+
.replace(/(.*)<div.*>(<table.*<\/table>)<\/div>(.*)/g, '$1$2$3'); // remove div containers from tables
|
|
5220
5233
|
};
|
|
5221
5234
|
|
|
5222
5235
|
/**
|
|
@@ -5757,6 +5770,9 @@ var isNotEmpty = function isNotEmpty(editor, _ref4) {
|
|
|
5757
5770
|
var path = _ref4[1];
|
|
5758
5771
|
return Array.from(Node.children(editor, path)).length !== 0;
|
|
5759
5772
|
};
|
|
5773
|
+
var isTable = function isTable(node) {
|
|
5774
|
+
return Element.isElement(node) && node.type === BLOCKS.TABLE;
|
|
5775
|
+
};
|
|
5760
5776
|
|
|
5761
5777
|
var styles$i = {
|
|
5762
5778
|
topRight: /*#__PURE__*/css({
|
|
@@ -5900,9 +5916,11 @@ var Row = function Row(props) {
|
|
|
5900
5916
|
var _templateObject$a;
|
|
5901
5917
|
var style$5 = /*#__PURE__*/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);
|
|
5902
5918
|
var Table = function Table(props) {
|
|
5903
|
-
return /*#__PURE__*/createElement("
|
|
5919
|
+
return /*#__PURE__*/createElement("div", {
|
|
5920
|
+
"data-block-type": BLOCKS.TABLE
|
|
5921
|
+
}, /*#__PURE__*/createElement("table", Object.assign({
|
|
5904
5922
|
className: style$5
|
|
5905
|
-
}), /*#__PURE__*/createElement("tbody", null, props.children));
|
|
5923
|
+
}, props.attributes), /*#__PURE__*/createElement("tbody", null, props.children)));
|
|
5906
5924
|
};
|
|
5907
5925
|
|
|
5908
5926
|
var createTableOnKeyDown = function createTableOnKeyDown(editor, plugin) {
|
|
@@ -5915,6 +5933,38 @@ var createTableOnKeyDown = function createTableOnKeyDown(editor, plugin) {
|
|
|
5915
5933
|
event.preventDefault();
|
|
5916
5934
|
event.stopPropagation();
|
|
5917
5935
|
return;
|
|
5936
|
+
} // This fixes `Cannot resolve a Slate point from DOM point: [object HTMLDivElement]` when typing while the cursor is before table
|
|
5937
|
+
|
|
5938
|
+
|
|
5939
|
+
var windowSelection = window.getSelection();
|
|
5940
|
+
|
|
5941
|
+
if (windowSelection) {
|
|
5942
|
+
var _windowSelection$anch, _windowSelection$anch2;
|
|
5943
|
+
|
|
5944
|
+
// @ts-expect-error
|
|
5945
|
+
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`
|
|
5946
|
+
|
|
5947
|
+
var isBeforeTable = blockType === BLOCKS.TABLE;
|
|
5948
|
+
|
|
5949
|
+
if (isBeforeTable) {
|
|
5950
|
+
if (event.key === 'Enter') {
|
|
5951
|
+
var above = getAbove(editor, {
|
|
5952
|
+
match: {
|
|
5953
|
+
type: BLOCKS.TABLE
|
|
5954
|
+
}
|
|
5955
|
+
});
|
|
5956
|
+
if (!above) return;
|
|
5957
|
+
var tablePath = above[1];
|
|
5958
|
+
insertEmptyParagraph(editor, {
|
|
5959
|
+
at: tablePath,
|
|
5960
|
+
select: true
|
|
5961
|
+
});
|
|
5962
|
+
}
|
|
5963
|
+
|
|
5964
|
+
event.preventDefault();
|
|
5965
|
+
event.stopPropagation();
|
|
5966
|
+
return;
|
|
5967
|
+
}
|
|
5918
5968
|
}
|
|
5919
5969
|
|
|
5920
5970
|
defaultHandler(event);
|
|
@@ -5929,18 +5979,26 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
5929
5979
|
handlers: {
|
|
5930
5980
|
onKeyDown: createTableOnKeyDown
|
|
5931
5981
|
},
|
|
5932
|
-
withOverrides: function withOverrides(editor) {
|
|
5982
|
+
withOverrides: function withOverrides(editor, plugin) {
|
|
5983
|
+
// injects important fixes from plate's original table plugin
|
|
5984
|
+
withTable(editor, plugin);
|
|
5933
5985
|
addTableTrackingEvents(editor);
|
|
5934
5986
|
var insertFragment = editor.insertFragment;
|
|
5935
5987
|
|
|
5936
5988
|
editor.insertFragment = function (fragments) {
|
|
5989
|
+
var _editor$selection;
|
|
5990
|
+
|
|
5937
5991
|
// 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
|
|
5938
5992
|
// More info: https://github.com/ianstormtaylor/slate/pull/4489 and https://github.com/ianstormtaylor/slate/issues/4542
|
|
5939
|
-
var
|
|
5940
|
-
return fragment
|
|
5993
|
+
var isInsertingTable = fragments.some(function (fragment) {
|
|
5994
|
+
return isTable(fragment);
|
|
5941
5995
|
});
|
|
5996
|
+
var isTableFirstFragment = fragments.findIndex(function (fragment) {
|
|
5997
|
+
return isTable(fragment);
|
|
5998
|
+
}) === 0;
|
|
5999
|
+
var currentLineHasText = getText(editor, (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path) !== '';
|
|
5942
6000
|
|
|
5943
|
-
if (
|
|
6001
|
+
if (isInsertingTable && isTableFirstFragment && currentLineHasText) {
|
|
5944
6002
|
insertEmptyParagraph(editor);
|
|
5945
6003
|
}
|
|
5946
6004
|
|