@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React__default, { createContext, useContext, useMemo, createElement, useEffect, useState, memo, Fragment, useCallback } from 'react';
|
|
2
2
|
import { useEntities, ScheduledIconWithTooltip, MissingEntityCard, AssetThumbnail, EntityProvider, getScheduleTooltipContent } from '@contentful/field-editor-reference';
|
|
3
3
|
import { entityHelpers, shortenStorageUnit, isValidImage, ModalDialogLauncher, FieldConnector } from '@contentful/field-editor-shared';
|
|
4
|
-
import { BLOCKS, INLINES,
|
|
4
|
+
import { BLOCKS, INLINES, TEXT_CONTAINERS, HEADINGS, LIST_ITEM_BLOCKS, MARKS, CONTAINERS, TOP_LEVEL_BLOCKS, VOID_BLOCKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
|
|
5
5
|
import { usePlateEditorRef, usePlateEditorState, getNodes, toggleNodeType, getText, getAbove, setNodes, isAncestorEmpty, match, getLastChildPath, wrapNodes, getPluginType, unwrapNodes, isCollapsed, isRangeAcrossBlocks, ELEMENT_DEFAULT, findNode, getParent, getBlockAbove, isSelectionAtBlockStart, isSelectionAtBlockEnd, isFirstChild, insertNodes, moveChildren, isBlockAboveEmpty, mockPlugin, deleteFragment, isMarkActive, toggleMark, someHtmlElement, KEY_DESERIALIZE_HTML, hasSingleChild, isLastChild, someNode, getChildren as getChildren$1, createDeserializeHtmlPlugin, createDeserializeAstPlugin, createPlateEditor, getPlateSelectors, getPlateActions, Plate } from '@udecode/plate-core';
|
|
6
6
|
import { css, cx } from 'emotion';
|
|
7
7
|
import deepEquals from 'fast-deep-equal';
|
|
@@ -10,7 +10,7 @@ import { createDeserializeDocxPlugin } from '@udecode/plate-serializer-docx';
|
|
|
10
10
|
import { createSoftBreakPlugin as createSoftBreakPlugin$1, createExitBreakPlugin as createExitBreakPlugin$1 } from '@udecode/plate-break';
|
|
11
11
|
import { createResetNodePlugin as createResetNodePlugin$1, onKeyDownResetNode, SIMULATE_BACKSPACE } from '@udecode/plate-reset-node';
|
|
12
12
|
import isHotkey from 'is-hotkey';
|
|
13
|
-
import { Text, Element, Editor, Transforms, Range,
|
|
13
|
+
import { Text, Element, Editor, Transforms, Range, Path, Node, Point } from 'slate';
|
|
14
14
|
import { ReactEditor, useSelected, useReadOnly, useFocused } from 'slate-react';
|
|
15
15
|
import constate from 'constate';
|
|
16
16
|
import { AssetCard, Menu, Text as Text$1, Notification, EntryCard, MenuItem, Button, Flex, Icon, InlineEntryCard, Tooltip, ModalContent, Form, FormControl, TextInput, Select, FormLabel, TextLink, ModalControls, IconButton } from '@contentful/f36-components';
|
|
@@ -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 [];
|
|
@@ -583,58 +583,6 @@ function getAncestorPathFromSelection(editor) {
|
|
|
583
583
|
return level.length === 1;
|
|
584
584
|
});
|
|
585
585
|
}
|
|
586
|
-
var isAtEndOfTextSelection = function isAtEndOfTextSelection(editor) {
|
|
587
|
-
var _editor$selection2, _editor$selection3;
|
|
588
|
-
|
|
589
|
-
return ((_editor$selection2 = editor.selection) == null ? void 0 : _editor$selection2.focus.offset) === getText(editor, (_editor$selection3 = editor.selection) == null ? void 0 : _editor$selection3.focus.path).length;
|
|
590
|
-
};
|
|
591
|
-
function currentSelectionStartsTableCell(editor) {
|
|
592
|
-
var _editor$selection4;
|
|
593
|
-
|
|
594
|
-
var _getNodeEntryFromSele2 = getNodeEntryFromSelection(editor, [BLOCKS.TABLE_CELL, BLOCKS.TABLE_HEADER_CELL]),
|
|
595
|
-
tableCellNode = _getNodeEntryFromSele2[0],
|
|
596
|
-
path = _getNodeEntryFromSele2[1];
|
|
597
|
-
|
|
598
|
-
return !!tableCellNode && (!getText(editor, path) || ((_editor$selection4 = editor.selection) == null ? void 0 : _editor$selection4.focus.offset) === 0);
|
|
599
|
-
}
|
|
600
|
-
/**
|
|
601
|
-
* This traversal strategy is unfortunately necessary because Slate doesn't
|
|
602
|
-
* expose something like Node.next(editor).
|
|
603
|
-
*/
|
|
604
|
-
|
|
605
|
-
function getNextNode(editor) {
|
|
606
|
-
if (!editor.selection) {
|
|
607
|
-
return null;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
var descendants = Node.descendants(editor, {
|
|
611
|
-
from: editor.selection.focus.path
|
|
612
|
-
}); // eslint-disable-next-line no-constant-condition
|
|
613
|
-
|
|
614
|
-
while (true) {
|
|
615
|
-
var _descendants$next = descendants.next(),
|
|
616
|
-
done = _descendants$next.done,
|
|
617
|
-
value = _descendants$next.value;
|
|
618
|
-
|
|
619
|
-
if (done) {
|
|
620
|
-
return null;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
var node = value[0],
|
|
624
|
-
path = value[1];
|
|
625
|
-
|
|
626
|
-
if (Path.isCommon(path, editor.selection.focus.path)) {
|
|
627
|
-
continue;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
return node;
|
|
631
|
-
}
|
|
632
|
-
} // TODO: move to table plugin
|
|
633
|
-
|
|
634
|
-
function currentSelectionPrecedesTableCell(editor) {
|
|
635
|
-
var nextNode = getNextNode(editor);
|
|
636
|
-
return !!nextNode && TABLE_BLOCKS.includes(nextNode.type) && isAtEndOfTextSelection(editor);
|
|
637
|
-
}
|
|
638
586
|
var INLINE_TYPES = /*#__PURE__*/Object.values(INLINES);
|
|
639
587
|
var isInlineOrText = function isInlineOrText(node) {
|
|
640
588
|
// either text or inline elements
|
|
@@ -3861,37 +3809,44 @@ var moveListItems = function moveListItems(editor, _temp) {
|
|
|
3861
3809
|
* Credit: Modified version of Plate's list plugin
|
|
3862
3810
|
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
3863
3811
|
*/
|
|
3864
|
-
|
|
3812
|
+
|
|
3813
|
+
function hasUnliftedListItems(editor, at) {
|
|
3814
|
+
return Editor.nodes(editor, {
|
|
3815
|
+
at: at,
|
|
3816
|
+
match: function match(node, path) {
|
|
3817
|
+
return Element.isElement(node) && node.type === BLOCKS.LIST_ITEM && path.length >= 2;
|
|
3818
|
+
}
|
|
3819
|
+
}).next().done;
|
|
3820
|
+
}
|
|
3821
|
+
|
|
3865
3822
|
var unwrapList = function unwrapList(editor, _temp) {
|
|
3866
3823
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
3867
3824
|
at = _ref.at;
|
|
3868
3825
|
|
|
3869
3826
|
Editor.withoutNormalizing(editor, function () {
|
|
3870
3827
|
do {
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
match: {
|
|
3874
|
-
type: BLOCKS.LIST_ITEM
|
|
3875
|
-
},
|
|
3876
|
-
split: true
|
|
3877
|
-
});
|
|
3878
|
-
unwrapNodes(editor, {
|
|
3828
|
+
// lift list items to the root level
|
|
3829
|
+
Transforms.liftNodes(editor, {
|
|
3879
3830
|
at: at,
|
|
3880
|
-
match: {
|
|
3881
|
-
type
|
|
3831
|
+
match: function match(node) {
|
|
3832
|
+
return Element.isElement(node) && node.type === BLOCKS.LIST_ITEM;
|
|
3882
3833
|
},
|
|
3883
|
-
|
|
3834
|
+
mode: 'lowest'
|
|
3884
3835
|
});
|
|
3885
|
-
} while (
|
|
3836
|
+
} while (!hasUnliftedListItems(editor, at)); // finally unwrap all lifted items
|
|
3837
|
+
|
|
3838
|
+
|
|
3839
|
+
unwrapNodes(editor, {
|
|
3840
|
+
at: at,
|
|
3886
3841
|
match: {
|
|
3887
|
-
type:
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
})
|
|
3842
|
+
type: BLOCKS.LIST_ITEM
|
|
3843
|
+
},
|
|
3844
|
+
split: false
|
|
3845
|
+
});
|
|
3891
3846
|
});
|
|
3892
3847
|
};
|
|
3893
3848
|
|
|
3894
|
-
var listTypes
|
|
3849
|
+
var listTypes = [BLOCKS.UL_LIST, BLOCKS.OL_LIST];
|
|
3895
3850
|
var toggleList = function toggleList(editor, _ref) {
|
|
3896
3851
|
var type = _ref.type;
|
|
3897
3852
|
return Editor.withoutNormalizing(editor, function () {
|
|
@@ -3912,7 +3867,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
3912
3867
|
}, {
|
|
3913
3868
|
at: editor.selection,
|
|
3914
3869
|
match: function match(n) {
|
|
3915
|
-
return listTypes
|
|
3870
|
+
return listTypes.includes(n.type);
|
|
3916
3871
|
},
|
|
3917
3872
|
mode: 'lowest'
|
|
3918
3873
|
});
|
|
@@ -3953,19 +3908,25 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
3953
3908
|
|
|
3954
3909
|
var commonEntry = Node.common(editor, startPoint.path, endPoint.path);
|
|
3955
3910
|
|
|
3956
|
-
if (listTypes
|
|
3957
|
-
|
|
3911
|
+
if (listTypes.includes(commonEntry[0].type) || commonEntry[0].type === BLOCKS.LIST_ITEM) {
|
|
3912
|
+
var listType = commonEntry[0].type;
|
|
3913
|
+
|
|
3914
|
+
if (commonEntry[0].type === BLOCKS.LIST_ITEM) {
|
|
3915
|
+
listType = Editor.parent(editor, commonEntry[1])[0].type;
|
|
3916
|
+
}
|
|
3917
|
+
|
|
3918
|
+
if (listType !== type) {
|
|
3958
3919
|
var startList = findNode(editor, {
|
|
3959
3920
|
at: Range.start(editor.selection),
|
|
3960
3921
|
match: {
|
|
3961
|
-
type: listTypes
|
|
3922
|
+
type: listTypes
|
|
3962
3923
|
},
|
|
3963
3924
|
mode: 'lowest'
|
|
3964
3925
|
});
|
|
3965
3926
|
var endList = findNode(editor, {
|
|
3966
3927
|
at: Range.end(editor.selection),
|
|
3967
3928
|
match: {
|
|
3968
|
-
type: listTypes
|
|
3929
|
+
type: listTypes
|
|
3969
3930
|
},
|
|
3970
3931
|
mode: 'lowest'
|
|
3971
3932
|
});
|
|
@@ -3980,7 +3941,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
3980
3941
|
}, {
|
|
3981
3942
|
at: editor.selection,
|
|
3982
3943
|
match: function match(n, path) {
|
|
3983
|
-
return listTypes
|
|
3944
|
+
return listTypes.includes(n.type) && path.length >= rangeLength;
|
|
3984
3945
|
},
|
|
3985
3946
|
mode: 'all'
|
|
3986
3947
|
});
|
|
@@ -3998,7 +3959,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
3998
3959
|
}).reverse();
|
|
3999
3960
|
|
|
4000
3961
|
_nodes.forEach(function (n) {
|
|
4001
|
-
if (listTypes
|
|
3962
|
+
if (listTypes.includes(n[0].type)) {
|
|
4002
3963
|
setNodes(editor, {
|
|
4003
3964
|
type: type
|
|
4004
3965
|
}, {
|
|
@@ -5903,21 +5864,46 @@ var Row = function Row(props) {
|
|
|
5903
5864
|
var _templateObject$a;
|
|
5904
5865
|
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);
|
|
5905
5866
|
var Table = function Table(props) {
|
|
5906
|
-
return /*#__PURE__*/createElement("
|
|
5867
|
+
return /*#__PURE__*/createElement("div", {
|
|
5868
|
+
"data-block-type": BLOCKS.TABLE
|
|
5869
|
+
}, /*#__PURE__*/createElement("table", Object.assign({
|
|
5907
5870
|
className: style$5
|
|
5908
|
-
}), /*#__PURE__*/createElement("tbody", null, props.children));
|
|
5871
|
+
}, props.attributes), /*#__PURE__*/createElement("tbody", null, props.children)));
|
|
5909
5872
|
};
|
|
5910
5873
|
|
|
5911
5874
|
var createTableOnKeyDown = function createTableOnKeyDown(editor, plugin) {
|
|
5912
5875
|
var defaultHandler = onKeyDownTable(editor, plugin);
|
|
5913
5876
|
return function (event) {
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5877
|
+
// This fixes `Cannot resolve a Slate point from DOM point: [object HTMLDivElement]` when typing while the cursor is before table
|
|
5878
|
+
var windowSelection = window.getSelection();
|
|
5879
|
+
|
|
5880
|
+
if (windowSelection) {
|
|
5881
|
+
var _windowSelection$anch, _windowSelection$anch2;
|
|
5882
|
+
|
|
5883
|
+
// @ts-expect-error
|
|
5884
|
+
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`
|
|
5885
|
+
|
|
5886
|
+
var isBeforeTable = blockType === BLOCKS.TABLE;
|
|
5887
|
+
|
|
5888
|
+
if (isBeforeTable) {
|
|
5889
|
+
if (event.key === 'Enter') {
|
|
5890
|
+
var above = getAbove(editor, {
|
|
5891
|
+
match: {
|
|
5892
|
+
type: BLOCKS.TABLE
|
|
5893
|
+
}
|
|
5894
|
+
});
|
|
5895
|
+
if (!above) return;
|
|
5896
|
+
var tablePath = above[1];
|
|
5897
|
+
insertEmptyParagraph(editor, {
|
|
5898
|
+
at: tablePath,
|
|
5899
|
+
select: true
|
|
5900
|
+
});
|
|
5901
|
+
}
|
|
5902
|
+
|
|
5903
|
+
event.preventDefault();
|
|
5904
|
+
event.stopPropagation();
|
|
5905
|
+
return;
|
|
5906
|
+
}
|
|
5921
5907
|
}
|
|
5922
5908
|
|
|
5923
5909
|
defaultHandler(event);
|
|
@@ -5932,7 +5918,9 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
5932
5918
|
handlers: {
|
|
5933
5919
|
onKeyDown: createTableOnKeyDown
|
|
5934
5920
|
},
|
|
5935
|
-
withOverrides: function withOverrides(editor) {
|
|
5921
|
+
withOverrides: function withOverrides(editor, plugin) {
|
|
5922
|
+
// injects important fixes from plate's original table plugin
|
|
5923
|
+
withTable(editor, plugin);
|
|
5936
5924
|
addTableTrackingEvents(editor);
|
|
5937
5925
|
var insertFragment = editor.insertFragment;
|
|
5938
5926
|
|