@contentful/field-editor-rich-text 3.5.0 → 3.6.1
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/cjs/RichTextEditor.js +42 -53
- package/dist/cjs/SyncEditorValue.js +107 -0
- package/dist/cjs/Toolbar/components/EmbedEntityWidget.js +8 -3
- package/dist/cjs/helpers/__tests__/removeInternalMarks.test.js +37 -21
- package/dist/cjs/helpers/callbacks.js +35 -0
- package/dist/cjs/helpers/getAllowedResourcesForNodeType.js +25 -0
- package/dist/cjs/helpers/newResourceEntitySelectorConfigFromRichTextField.js +21 -0
- package/dist/cjs/helpers/toSlateValue.js +51 -0
- package/dist/cjs/internal/hooks.js +12 -2
- package/dist/cjs/internal/misc.js +0 -6
- package/dist/cjs/plugins/DragAndDrop/index.js +1 -0
- package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +27 -44
- package/dist/cjs/plugins/EmbeddedEntityBlock/index.js +3 -35
- package/dist/cjs/plugins/EmbeddedEntityInline/index.js +3 -2
- package/dist/cjs/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +54 -0
- package/dist/cjs/plugins/EmbeddedResourceBlock/index.js +55 -0
- package/dist/cjs/plugins/Hyperlink/components/EntityHyperlink.js +2 -1
- package/dist/cjs/plugins/Hyperlink/createHyperlinkPlugin.js +2 -3
- package/dist/cjs/plugins/Table/onKeyDownTable.js +14 -0
- package/dist/cjs/plugins/Text/__tests__/createTextPlugin.test.js +5 -15
- package/dist/cjs/plugins/Text/createTextPlugin.js +1 -0
- package/dist/cjs/plugins/index.js +2 -5
- package/dist/cjs/plugins/links-tracking.js +8 -17
- package/dist/cjs/plugins/{EmbeddedEntityBlock/ToolbarIcon.js → shared/EmbeddedBlockToolbarIcon.js} +15 -7
- package/dist/cjs/plugins/shared/EmbeddedBlockUtil.js +170 -0
- package/dist/cjs/plugins/shared/FetchingWrappedResourceCard.js +110 -0
- package/dist/cjs/plugins/shared/LinkedBlockWrapper.js +45 -0
- package/dist/esm/RichTextEditor.js +37 -48
- package/dist/esm/SyncEditorValue.js +53 -0
- package/dist/esm/Toolbar/components/EmbedEntityWidget.js +8 -3
- package/dist/esm/helpers/__tests__/removeInternalMarks.test.js +37 -21
- package/dist/esm/helpers/callbacks.js +20 -0
- package/dist/esm/helpers/getAllowedResourcesForNodeType.js +10 -0
- package/dist/esm/helpers/newResourceEntitySelectorConfigFromRichTextField.js +6 -0
- package/dist/{cjs/helpers/sanitizeIncomingSlateDoc.js → esm/helpers/toSlateValue.js} +13 -10
- package/dist/esm/internal/hooks.js +9 -2
- package/dist/esm/internal/misc.js +0 -3
- package/dist/esm/plugins/DragAndDrop/index.js +1 -0
- package/dist/esm/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +27 -44
- package/dist/esm/plugins/EmbeddedEntityBlock/index.js +3 -27
- package/dist/esm/plugins/EmbeddedEntityInline/index.js +4 -3
- package/dist/esm/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +39 -0
- package/dist/esm/plugins/EmbeddedResourceBlock/index.js +45 -0
- package/dist/esm/plugins/Hyperlink/components/EntityHyperlink.js +2 -1
- package/dist/esm/plugins/Hyperlink/createHyperlinkPlugin.js +2 -3
- package/dist/esm/plugins/Table/onKeyDownTable.js +15 -1
- package/dist/esm/plugins/Text/__tests__/createTextPlugin.test.js +5 -15
- package/dist/esm/plugins/Text/createTextPlugin.js +1 -0
- package/dist/esm/plugins/index.js +2 -5
- package/dist/esm/plugins/links-tracking.js +6 -10
- package/dist/esm/plugins/{EmbeddedEntityBlock/ToolbarIcon.js → shared/EmbeddedBlockToolbarIcon.js} +14 -6
- package/dist/esm/plugins/shared/EmbeddedBlockUtil.js +144 -0
- package/dist/esm/plugins/shared/FetchingWrappedResourceCard.js +56 -0
- package/dist/esm/plugins/shared/LinkedBlockWrapper.js +30 -0
- package/dist/types/ContentfulEditorProvider.d.ts +2 -3
- package/dist/types/RichTextEditor.d.ts +2 -2
- package/dist/types/SyncEditorValue.d.ts +13 -0
- package/dist/types/dialogs/HypelinkDialog/HyperlinkDialog.d.ts +3 -3
- package/dist/types/helpers/callbacks.d.ts +3 -0
- package/dist/types/helpers/getAllowedResourcesForNodeType.d.ts +25 -0
- package/dist/types/helpers/newResourceEntitySelectorConfigFromRichTextField.d.ts +16 -0
- package/dist/types/helpers/toSlateValue.d.ts +7 -0
- package/dist/types/internal/hooks.d.ts +4 -2
- package/dist/types/internal/misc.d.ts +2 -2
- package/dist/types/plugins/EmbeddedEntityBlock/LinkedEntityBlock.d.ts +0 -1
- package/dist/types/plugins/EmbeddedEntityBlock/index.d.ts +1 -2
- package/dist/types/plugins/EmbeddedResourceBlock/LinkedResourceBlock.d.ts +18 -0
- package/dist/types/plugins/EmbeddedResourceBlock/index.d.ts +3 -0
- package/dist/types/plugins/links-tracking.d.ts +3 -3
- package/dist/types/plugins/shared/EmbeddedBlockToolbarIcon.d.ts +11 -0
- package/dist/types/plugins/shared/EmbeddedBlockUtil.d.ts +8 -0
- package/dist/types/plugins/shared/FetchingWrappedResourceCard.d.ts +14 -0
- package/dist/types/plugins/shared/LinkedBlockWrapper.d.ts +25 -0
- package/dist/types/test-utils/createEditor.d.ts +2 -0
- package/dist/types/test-utils/jsx.d.ts +1 -1
- package/package.json +18 -18
- package/dist/cjs/plugins/EmbeddedEntityBlock/Util.js +0 -108
- package/dist/cjs/prepareDocument.js +0 -86
- package/dist/cjs/useOnValueChanged.js +0 -58
- package/dist/esm/helpers/sanitizeIncomingSlateDoc.js +0 -23
- package/dist/esm/plugins/EmbeddedEntityBlock/Util.js +0 -85
- package/dist/esm/prepareDocument.js +0 -57
- package/dist/esm/useOnValueChanged.js +0 -43
- package/dist/types/helpers/sanitizeIncomingSlateDoc.d.ts +0 -6
- package/dist/types/plugins/EmbeddedEntityBlock/ToolbarIcon.d.ts +0 -11
- package/dist/types/plugins/EmbeddedEntityBlock/Util.d.ts +0 -4
- package/dist/types/prepareDocument.d.ts +0 -19
- package/dist/types/useOnValueChanged.d.ts +0 -8
|
@@ -9,9 +9,6 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
ToolbarIcon: function() {
|
|
13
|
-
return _ToolbarIcon.EmbeddedEntityBlockToolbarIcon;
|
|
14
|
-
},
|
|
15
12
|
createEmbeddedEntryBlockPlugin: function() {
|
|
16
13
|
return createEmbeddedEntryBlockPlugin;
|
|
17
14
|
},
|
|
@@ -20,52 +17,23 @@ _export(exports, {
|
|
|
20
17
|
}
|
|
21
18
|
});
|
|
22
19
|
const _richtexttypes = require("@contentful/rich-text-types");
|
|
23
|
-
const
|
|
24
|
-
const _editor = require("../../helpers/editor");
|
|
25
|
-
const _transforms = require("../../internal/transforms");
|
|
26
|
-
const _linkstracking = require("../links-tracking");
|
|
20
|
+
const _EmbeddedBlockUtil = require("../shared/EmbeddedBlockUtil");
|
|
27
21
|
const _LinkedEntityBlock = require("./LinkedEntityBlock");
|
|
28
|
-
const _Util = require("./Util");
|
|
29
|
-
const _ToolbarIcon = require("./ToolbarIcon");
|
|
30
|
-
function _interop_require_default(obj) {
|
|
31
|
-
return obj && obj.__esModule ? obj : {
|
|
32
|
-
default: obj
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
22
|
const entityTypes = {
|
|
36
23
|
[_richtexttypes.BLOCKS.EMBEDDED_ENTRY]: 'Entry',
|
|
37
24
|
[_richtexttypes.BLOCKS.EMBEDDED_ASSET]: 'Asset'
|
|
38
25
|
};
|
|
39
|
-
function getWithEmbeddedEntityEvents(nodeType, sdk) {
|
|
40
|
-
return (editor, { options: { hotkey } })=>(event)=>{
|
|
41
|
-
const [, pathToSelectedElement] = (0, _editor.getNodeEntryFromSelection)(editor, nodeType);
|
|
42
|
-
if (pathToSelectedElement) {
|
|
43
|
-
const isDelete = event.key === 'Delete';
|
|
44
|
-
const isBackspace = event.key === 'Backspace';
|
|
45
|
-
if (isDelete || isBackspace) {
|
|
46
|
-
event.preventDefault();
|
|
47
|
-
(0, _transforms.removeNodes)(editor, {
|
|
48
|
-
at: pathToSelectedElement
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (hotkey && (0, _ishotkey.default)(hotkey, event)) {
|
|
54
|
-
(0, _Util.selectEntityAndInsert)(nodeType, sdk, editor, editor.tracking.onShortcutAction);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
26
|
const createEmbeddedEntityPlugin = (nodeType, hotkey)=>(sdk)=>({
|
|
59
27
|
key: nodeType,
|
|
60
28
|
type: nodeType,
|
|
61
29
|
isElement: true,
|
|
62
30
|
isVoid: true,
|
|
63
|
-
component:
|
|
31
|
+
component: _LinkedEntityBlock.LinkedEntityBlock,
|
|
64
32
|
options: {
|
|
65
33
|
hotkey
|
|
66
34
|
},
|
|
67
35
|
handlers: {
|
|
68
|
-
onKeyDown:
|
|
36
|
+
onKeyDown: (0, _EmbeddedBlockUtil.getWithEmbeddedBlockEvents)(nodeType, sdk)
|
|
69
37
|
},
|
|
70
38
|
deserializeHtml: {
|
|
71
39
|
rules: [
|
|
@@ -98,6 +98,7 @@ function EmbeddedEntityInline(props) {
|
|
|
98
98
|
const isSelected = (0, _slatereact.useSelected)();
|
|
99
99
|
const { id: entryId } = props.element.data.target.sys;
|
|
100
100
|
const isDisabled = (0, _slatereact.useReadOnly)();
|
|
101
|
+
const { onEntityFetchComplete } = (0, _linkstracking.useLinkTracking)();
|
|
101
102
|
function handleEditClick() {
|
|
102
103
|
return sdk.navigator.openEntry(entryId, {
|
|
103
104
|
slideIn: {
|
|
@@ -130,7 +131,7 @@ function EmbeddedEntityInline(props) {
|
|
|
130
131
|
isDisabled: isDisabled,
|
|
131
132
|
onRemove: handleRemoveClick,
|
|
132
133
|
onEdit: handleEditClick,
|
|
133
|
-
onEntityFetchComplete:
|
|
134
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
134
135
|
})), props.children);
|
|
135
136
|
}
|
|
136
137
|
async function selectEntityAndInsert(editor, sdk, logAction) {
|
|
@@ -191,7 +192,7 @@ function createEmbeddedEntityInlinePlugin(sdk) {
|
|
|
191
192
|
isElement: true,
|
|
192
193
|
isInline: true,
|
|
193
194
|
isVoid: true,
|
|
194
|
-
component:
|
|
195
|
+
component: EmbeddedEntityInline,
|
|
195
196
|
options: {
|
|
196
197
|
hotkey: 'mod+shift+2'
|
|
197
198
|
},
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LinkedResourceBlock", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LinkedResourceBlock;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_default(require("react"));
|
|
12
|
+
const _slatereact = require("slate-react");
|
|
13
|
+
const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
|
|
14
|
+
const _internal = require("../../internal");
|
|
15
|
+
const _SdkProvider = require("../../SdkProvider");
|
|
16
|
+
const _linkstracking = require("../links-tracking");
|
|
17
|
+
const _FetchingWrappedResourceCard = require("../shared/FetchingWrappedResourceCard");
|
|
18
|
+
const _LinkedBlockWrapper = require("../shared/LinkedBlockWrapper");
|
|
19
|
+
function _interop_require_default(obj) {
|
|
20
|
+
return obj && obj.__esModule ? obj : {
|
|
21
|
+
default: obj
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function LinkedResourceBlock(props) {
|
|
25
|
+
const { attributes , children , element } = props;
|
|
26
|
+
const { onEntityFetchComplete } = (0, _linkstracking.useLinkTracking)();
|
|
27
|
+
const isSelected = (0, _slatereact.useSelected)();
|
|
28
|
+
const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
|
|
29
|
+
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
30
|
+
const isDisabled = (0, _slatereact.useReadOnly)();
|
|
31
|
+
const link = element.data.target.sys;
|
|
32
|
+
const handleRemoveClick = _react.default.useCallback(()=>{
|
|
33
|
+
if (!editor) return;
|
|
34
|
+
const pathToElement = (0, _internal.findNodePath)(editor, element);
|
|
35
|
+
(0, _internal.removeNodes)(editor, {
|
|
36
|
+
at: pathToElement
|
|
37
|
+
});
|
|
38
|
+
}, [
|
|
39
|
+
editor,
|
|
40
|
+
element
|
|
41
|
+
]);
|
|
42
|
+
return _react.default.createElement(_LinkedBlockWrapper.LinkedBlockWrapper, {
|
|
43
|
+
attributes: attributes,
|
|
44
|
+
element: element,
|
|
45
|
+
card: _react.default.createElement(_FetchingWrappedResourceCard.FetchingWrappedResourceCard, {
|
|
46
|
+
sdk: sdk,
|
|
47
|
+
link: link,
|
|
48
|
+
isDisabled: isDisabled,
|
|
49
|
+
isSelected: isSelected,
|
|
50
|
+
onRemove: handleRemoveClick,
|
|
51
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
52
|
+
})
|
|
53
|
+
}, children);
|
|
54
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createEmbeddedResourceBlockPlugin", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createEmbeddedResourceBlockPlugin;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _richtexttypes = require("@contentful/rich-text-types");
|
|
12
|
+
const _EmbeddedBlockUtil = require("../shared/EmbeddedBlockUtil");
|
|
13
|
+
const _LinkedResourceBlock = require("./LinkedResourceBlock");
|
|
14
|
+
const createEmbeddedResourcePlugin = (nodeType, hotkey)=>(sdk)=>({
|
|
15
|
+
key: nodeType,
|
|
16
|
+
type: nodeType,
|
|
17
|
+
isElement: true,
|
|
18
|
+
isVoid: true,
|
|
19
|
+
component: _LinkedResourceBlock.LinkedResourceBlock,
|
|
20
|
+
options: {
|
|
21
|
+
hotkey
|
|
22
|
+
},
|
|
23
|
+
handlers: {
|
|
24
|
+
onKeyDown: (0, _EmbeddedBlockUtil.getWithEmbeddedBlockEvents)(nodeType, sdk)
|
|
25
|
+
},
|
|
26
|
+
deserializeHtml: {
|
|
27
|
+
rules: [
|
|
28
|
+
{
|
|
29
|
+
validAttribute: {
|
|
30
|
+
'data-entity-type': 'Contentful:Entry'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
withoutChildren: true,
|
|
35
|
+
getNode: (el)=>({
|
|
36
|
+
type: nodeType,
|
|
37
|
+
children: [
|
|
38
|
+
{
|
|
39
|
+
text: ''
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
isVoid: true,
|
|
43
|
+
data: {
|
|
44
|
+
target: {
|
|
45
|
+
sys: {
|
|
46
|
+
urn: el.getAttribute('data-entity-id'),
|
|
47
|
+
linkType: el.getAttribute('data-entity-type'),
|
|
48
|
+
type: 'ResourceLink'
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
const createEmbeddedResourceBlockPlugin = createEmbeddedResourcePlugin(_richtexttypes.BLOCKS.EMBEDDED_RESOURCE, 'mod+shift+s');
|
|
@@ -13,6 +13,7 @@ const _f36components = require("@contentful/f36-components");
|
|
|
13
13
|
const _ContentfulEditorProvider = require("../../../ContentfulEditorProvider");
|
|
14
14
|
const _internal = require("../../../internal");
|
|
15
15
|
const _SdkProvider = require("../../../SdkProvider");
|
|
16
|
+
const _linkstracking = require("../../links-tracking");
|
|
16
17
|
const _HyperlinkModal = require("../HyperlinkModal");
|
|
17
18
|
const _useEntityInfo = require("../useEntityInfo");
|
|
18
19
|
const _styles = require("./styles");
|
|
@@ -59,7 +60,7 @@ function EntityHyperlink(props) {
|
|
|
59
60
|
const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
|
|
60
61
|
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
61
62
|
const { target } = props.element.data;
|
|
62
|
-
const { onEntityFetchComplete } =
|
|
63
|
+
const { onEntityFetchComplete } = (0, _linkstracking.useLinkTracking)();
|
|
63
64
|
const tooltipContent = (0, _useEntityInfo.useEntityInfo)({
|
|
64
65
|
target,
|
|
65
66
|
sdk,
|
|
@@ -13,7 +13,6 @@ const _richtexttypes = require("@contentful/rich-text-types");
|
|
|
13
13
|
const _ishotkey = _interop_require_default(require("is-hotkey"));
|
|
14
14
|
const _editor = require("../../helpers/editor");
|
|
15
15
|
const _transformers = require("../../helpers/transformers");
|
|
16
|
-
const _linkstracking = require("../links-tracking");
|
|
17
16
|
const _EntityHyperlink = require("./components/EntityHyperlink");
|
|
18
17
|
const _UrlHyperlink = require("./components/UrlHyperlink");
|
|
19
18
|
const _HyperlinkModal = require("./HyperlinkModal");
|
|
@@ -131,7 +130,7 @@ const createHyperlinkPlugin = (sdk)=>{
|
|
|
131
130
|
...common,
|
|
132
131
|
key: _richtexttypes.INLINES.ENTRY_HYPERLINK,
|
|
133
132
|
type: _richtexttypes.INLINES.ENTRY_HYPERLINK,
|
|
134
|
-
component:
|
|
133
|
+
component: _EntityHyperlink.EntityHyperlink,
|
|
135
134
|
deserializeHtml: {
|
|
136
135
|
rules: [
|
|
137
136
|
{
|
|
@@ -148,7 +147,7 @@ const createHyperlinkPlugin = (sdk)=>{
|
|
|
148
147
|
...common,
|
|
149
148
|
key: _richtexttypes.INLINES.ASSET_HYPERLINK,
|
|
150
149
|
type: _richtexttypes.INLINES.ASSET_HYPERLINK,
|
|
151
|
-
component:
|
|
150
|
+
component: _EntityHyperlink.EntityHyperlink,
|
|
152
151
|
deserializeHtml: {
|
|
153
152
|
rules: [
|
|
154
153
|
{
|
|
@@ -40,6 +40,20 @@ const onKeyDownTable = (editor, plugin)=>{
|
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
if (event.key === 'Backspace') {
|
|
44
|
+
const entry = (0, _platetable.getTableEntries)(editor, {});
|
|
45
|
+
if (entry) {
|
|
46
|
+
const { table , row , cell } = entry;
|
|
47
|
+
const cellText = (0, _queries.getText)(editor, cell[1]);
|
|
48
|
+
const isFirstCell = (0, _queries.isFirstChild)(row[1]);
|
|
49
|
+
const isFirstRow = (0, _queries.isFirstChild)(table[1]);
|
|
50
|
+
if (isFirstCell && isFirstRow && !cellText) {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
event.stopPropagation();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
43
57
|
if (event.key === 'Tab' && !event.shiftKey) {
|
|
44
58
|
event.preventDefault();
|
|
45
59
|
const entry = (0, _platetable.getTableEntries)(editor, {});
|
|
@@ -11,19 +11,9 @@ describe('delete backward', ()=>{
|
|
|
11
11
|
expected: (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, "p", (0, _testutils.jsx)("cursor", null))))
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
|
-
title: '
|
|
14
|
+
title: 'does not delete the very first paragraph',
|
|
15
15
|
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hp", null, "text")),
|
|
16
|
-
expected: (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "text")
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
title: 'deletes the empty paragraph at the beginning of the RTE followed by li',
|
|
20
|
-
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, "p1")))),
|
|
21
|
-
expected: (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "p1")))
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
title: 'deletes the empty paragraph at the beginning of the RTE followed by a blockquote',
|
|
25
|
-
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, "p1"))),
|
|
26
|
-
expected: (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "p1"))
|
|
16
|
+
expected: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hp", null, "text"))
|
|
27
17
|
}
|
|
28
18
|
];
|
|
29
19
|
const render = (children)=>(0, _testutils.jsx)("editor", null, children, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("htext", null)));
|
|
@@ -48,17 +38,17 @@ describe('delete forward', ()=>{
|
|
|
48
38
|
expected: (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "1")))
|
|
49
39
|
},
|
|
50
40
|
{
|
|
51
|
-
title: 'deletes the
|
|
41
|
+
title: 'deletes the first paragraph when followed by another paragraph',
|
|
52
42
|
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hp", null, "text")),
|
|
53
43
|
expected: (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "text")
|
|
54
44
|
},
|
|
55
45
|
{
|
|
56
|
-
title: 'deletes the
|
|
46
|
+
title: 'deletes the first paragraph when followed by li',
|
|
57
47
|
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, "p1")))),
|
|
58
48
|
expected: (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "p1")))
|
|
59
49
|
},
|
|
60
50
|
{
|
|
61
|
-
title: 'deletes the
|
|
51
|
+
title: 'deletes the first paragraph when followed by a blockquote',
|
|
62
52
|
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, "p1"))),
|
|
63
53
|
expected: (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "p1"))
|
|
64
54
|
}
|
|
@@ -16,7 +16,6 @@ _export(exports, {
|
|
|
16
16
|
return disableCorePlugins;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
const _platecore = require("@udecode/plate-core");
|
|
20
19
|
const _plateserializerdocx = require("@udecode/plate-serializer-docx");
|
|
21
20
|
const _Break = require("./Break");
|
|
22
21
|
const _CommandPalette = require("./CommandPalette");
|
|
@@ -24,6 +23,7 @@ const _useCommands = require("./CommandPalette/useCommands");
|
|
|
24
23
|
const _DragAndDrop = require("./DragAndDrop");
|
|
25
24
|
const _EmbeddedEntityBlock = require("./EmbeddedEntityBlock");
|
|
26
25
|
const _EmbeddedEntityInline = require("./EmbeddedEntityInline");
|
|
26
|
+
const _EmbeddedResourceBlock = require("./EmbeddedResourceBlock");
|
|
27
27
|
const _Heading = require("./Heading");
|
|
28
28
|
const _Hr = require("./Hr");
|
|
29
29
|
const _Hyperlink = require("./Hyperlink");
|
|
@@ -40,8 +40,6 @@ const _Tracking = require("./Tracking");
|
|
|
40
40
|
const _TrailingParagraph = require("./TrailingParagraph");
|
|
41
41
|
const _Voids = require("./Voids");
|
|
42
42
|
const getPlugins = (sdk, onAction, restrictedMarks)=>[
|
|
43
|
-
(0, _platecore.createDeserializeHtmlPlugin)(),
|
|
44
|
-
(0, _platecore.createDeserializeAstPlugin)(),
|
|
45
43
|
(0, _plateserializerdocx.createDeserializeDocxPlugin)(),
|
|
46
44
|
(0, _Tracking.createTrackingPlugin)(onAction),
|
|
47
45
|
(0, _DragAndDrop.createDragAndDropPlugin)(),
|
|
@@ -56,6 +54,7 @@ const getPlugins = (sdk, onAction, restrictedMarks)=>[
|
|
|
56
54
|
(0, _Table.createTablePlugin)(),
|
|
57
55
|
(0, _EmbeddedEntityBlock.createEmbeddedEntryBlockPlugin)(sdk),
|
|
58
56
|
(0, _EmbeddedEntityBlock.createEmbeddedAssetBlockPlugin)(sdk),
|
|
57
|
+
(0, _EmbeddedResourceBlock.createEmbeddedResourceBlockPlugin)(sdk),
|
|
59
58
|
(0, _Hyperlink.createHyperlinkPlugin)(sdk),
|
|
60
59
|
(0, _EmbeddedEntityInline.createEmbeddedEntityInlinePlugin)(sdk),
|
|
61
60
|
(0, _Marks.createMarksPlugin)(),
|
|
@@ -70,7 +69,5 @@ const getPlugins = (sdk, onAction, restrictedMarks)=>[
|
|
|
70
69
|
(0, _Normalizer.createNormalizerPlugin)()
|
|
71
70
|
];
|
|
72
71
|
const disableCorePlugins = {
|
|
73
|
-
deserializeAst: true,
|
|
74
|
-
deserializeHtml: true,
|
|
75
72
|
eventEditor: true
|
|
76
73
|
};
|
|
@@ -2,28 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "useLinkTracking", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return useLinkTracking;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react =
|
|
11
|
+
const _react = require("react");
|
|
12
12
|
const _ContentfulEditorProvider = require("../ContentfulEditorProvider");
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
function withLinkTracking(Component) {
|
|
19
|
-
return function ComponentWithTracking(props) {
|
|
20
|
-
const editor = (0, _ContentfulEditorProvider.useContentfulEditorRef)();
|
|
21
|
-
const onEntityFetchComplete = _react.default.useCallback(()=>editor?.tracking.onViewportAction('linkRendered'), [
|
|
13
|
+
function useLinkTracking() {
|
|
14
|
+
const editor = (0, _ContentfulEditorProvider.useContentfulEditorRef)();
|
|
15
|
+
return {
|
|
16
|
+
onEntityFetchComplete: (0, _react.useCallback)(()=>editor?.tracking.onViewportAction('linkRendered'), [
|
|
22
17
|
editor
|
|
23
|
-
])
|
|
24
|
-
return _react.default.createElement(Component, {
|
|
25
|
-
...props,
|
|
26
|
-
onEntityFetchComplete: onEntityFetchComplete
|
|
27
|
-
});
|
|
18
|
+
])
|
|
28
19
|
};
|
|
29
20
|
}
|
package/dist/cjs/plugins/{EmbeddedEntityBlock/ToolbarIcon.js → shared/EmbeddedBlockToolbarIcon.js}
RENAMED
|
@@ -12,17 +12,18 @@ _export(exports, {
|
|
|
12
12
|
styles: function() {
|
|
13
13
|
return styles;
|
|
14
14
|
},
|
|
15
|
-
|
|
16
|
-
return
|
|
15
|
+
EmbeddedBlockToolbarIcon: function() {
|
|
16
|
+
return EmbeddedBlockToolbarIcon;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
const _react = _interop_require_wildcard(require("react"));
|
|
20
20
|
const _f36components = require("@contentful/f36-components");
|
|
21
21
|
const _f36icons = require("@contentful/f36-icons");
|
|
22
|
+
const _richtexttypes = require("@contentful/rich-text-types");
|
|
22
23
|
const _emotion = require("emotion");
|
|
23
24
|
const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
|
|
24
25
|
const _SdkProvider = require("../../SdkProvider");
|
|
25
|
-
const
|
|
26
|
+
const _EmbeddedBlockUtil = require("../shared/EmbeddedBlockUtil");
|
|
26
27
|
function _getRequireWildcardCache(nodeInterop) {
|
|
27
28
|
if (typeof WeakMap !== "function") return null;
|
|
28
29
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -67,7 +68,7 @@ const styles = {
|
|
|
67
68
|
marginRight: '10px'
|
|
68
69
|
})
|
|
69
70
|
};
|
|
70
|
-
function
|
|
71
|
+
function EmbeddedBlockToolbarIcon({ isDisabled , nodeType , onClose }) {
|
|
71
72
|
const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
|
|
72
73
|
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
73
74
|
const handleClick = async (event)=>{
|
|
@@ -76,7 +77,11 @@ function EmbeddedEntityBlockToolbarIcon({ isDisabled , nodeType , onClose }) {
|
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
78
79
|
onClose();
|
|
79
|
-
|
|
80
|
+
if (nodeType == _richtexttypes.BLOCKS.EMBEDDED_RESOURCE) {
|
|
81
|
+
await (0, _EmbeddedBlockUtil.selectResourceEntityAndInsert)(sdk, editor, editor.tracking.onToolbarAction);
|
|
82
|
+
} else {
|
|
83
|
+
await (0, _EmbeddedBlockUtil.selectEntityAndInsert)(nodeType, sdk, editor, editor.tracking.onToolbarAction);
|
|
84
|
+
}
|
|
80
85
|
};
|
|
81
86
|
const type = getEntityTypeFromNodeType(nodeType);
|
|
82
87
|
const baseClass = `rich-text__${nodeType}`;
|
|
@@ -92,11 +97,14 @@ function EmbeddedEntityBlockToolbarIcon({ isDisabled , nodeType , onClose }) {
|
|
|
92
97
|
as: type === 'Asset' ? _f36icons.AssetIcon : _f36icons.EmbeddedEntryBlockIcon,
|
|
93
98
|
className: `rich-text__embedded-entry-list-icon ${styles.icon}`,
|
|
94
99
|
variant: "secondary"
|
|
95
|
-
}), _react.createElement("span", null, type)
|
|
100
|
+
}), _react.createElement("span", null, type, nodeType == _richtexttypes.BLOCKS.EMBEDDED_RESOURCE && _react.createElement(_react.Fragment, null, ' ', "(different space)", ' ', _react.createElement(_f36components.Badge, {
|
|
101
|
+
variant: "primary-filled",
|
|
102
|
+
size: "small"
|
|
103
|
+
}, "new")))));
|
|
96
104
|
}
|
|
97
105
|
function getEntityTypeFromNodeType(nodeType) {
|
|
98
106
|
const words = nodeType.toLowerCase().split('-');
|
|
99
|
-
if (words.includes('entry')) {
|
|
107
|
+
if (words.includes('entry') || words.includes('resource')) {
|
|
100
108
|
return 'Entry';
|
|
101
109
|
}
|
|
102
110
|
if (words.includes('asset')) {
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getWithEmbeddedBlockEvents: function() {
|
|
13
|
+
return getWithEmbeddedBlockEvents;
|
|
14
|
+
},
|
|
15
|
+
selectEntityAndInsert: function() {
|
|
16
|
+
return selectEntityAndInsert;
|
|
17
|
+
},
|
|
18
|
+
selectResourceEntityAndInsert: function() {
|
|
19
|
+
return selectResourceEntityAndInsert;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _richtexttypes = require("@contentful/rich-text-types");
|
|
23
|
+
const _ishotkey = _interop_require_default(require("is-hotkey"));
|
|
24
|
+
const _editor = require("../../helpers/editor");
|
|
25
|
+
const _newEntitySelectorConfigFromRichTextField = _interop_require_default(require("../../helpers/newEntitySelectorConfigFromRichTextField"));
|
|
26
|
+
const _newResourceEntitySelectorConfigFromRichTextField = _interop_require_default(require("../../helpers/newResourceEntitySelectorConfigFromRichTextField"));
|
|
27
|
+
const _sdkNavigatorSlideIn = require("../../helpers/sdkNavigatorSlideIn");
|
|
28
|
+
const _internal = require("../../internal");
|
|
29
|
+
function _interop_require_default(obj) {
|
|
30
|
+
return obj && obj.__esModule ? obj : {
|
|
31
|
+
default: obj
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function getWithEmbeddedBlockEvents(nodeType, sdk) {
|
|
35
|
+
return (editor, { options: { hotkey } })=>(event)=>{
|
|
36
|
+
const [, pathToSelectedElement] = (0, _editor.getNodeEntryFromSelection)(editor, nodeType);
|
|
37
|
+
if (pathToSelectedElement) {
|
|
38
|
+
const isDelete = event.key === 'Delete';
|
|
39
|
+
const isBackspace = event.key === 'Backspace';
|
|
40
|
+
if (isDelete || isBackspace) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
(0, _internal.removeNodes)(editor, {
|
|
43
|
+
at: pathToSelectedElement
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (hotkey && (0, _ishotkey.default)(hotkey, event)) {
|
|
49
|
+
if (nodeType === _richtexttypes.BLOCKS.EMBEDDED_RESOURCE) {
|
|
50
|
+
selectResourceEntityAndInsert(sdk, editor, editor.tracking.onShortcutAction);
|
|
51
|
+
} else {
|
|
52
|
+
selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onShortcutAction);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function selectEntityAndInsert(nodeType, sdk, editor, logAction) {
|
|
58
|
+
logAction('openCreateEmbedDialog', {
|
|
59
|
+
nodeType
|
|
60
|
+
});
|
|
61
|
+
const { field , dialogs } = sdk;
|
|
62
|
+
const baseConfig = (0, _newEntitySelectorConfigFromRichTextField.default)(field, nodeType);
|
|
63
|
+
const selectEntity = baseConfig.entityType === 'Asset' ? dialogs.selectSingleAsset : dialogs.selectSingleEntry;
|
|
64
|
+
const config = {
|
|
65
|
+
...baseConfig,
|
|
66
|
+
withCreate: true
|
|
67
|
+
};
|
|
68
|
+
const { selection } = editor;
|
|
69
|
+
const rteSlide = (0, _sdkNavigatorSlideIn.watchCurrentSlide)(sdk.navigator);
|
|
70
|
+
const entity = await selectEntity(config);
|
|
71
|
+
if (!entity) {
|
|
72
|
+
logAction('cancelCreateEmbedDialog', {
|
|
73
|
+
nodeType
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
(0, _internal.select)(editor, selection);
|
|
77
|
+
insertBlock(editor, nodeType, entity);
|
|
78
|
+
ensureFollowingParagraph(editor, [
|
|
79
|
+
_richtexttypes.BLOCKS.EMBEDDED_ASSET,
|
|
80
|
+
_richtexttypes.BLOCKS.EMBEDDED_ENTRY
|
|
81
|
+
]);
|
|
82
|
+
logAction('insert', {
|
|
83
|
+
nodeType
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
rteSlide.onActive(()=>{
|
|
87
|
+
rteSlide.unwatch();
|
|
88
|
+
(0, _editor.focus)(editor);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async function selectResourceEntityAndInsert(sdk, editor, logAction) {
|
|
92
|
+
logAction('openCreateEmbedDialog', {
|
|
93
|
+
nodeType: _richtexttypes.BLOCKS.EMBEDDED_RESOURCE
|
|
94
|
+
});
|
|
95
|
+
const { field , dialogs } = sdk;
|
|
96
|
+
const config = (0, _newResourceEntitySelectorConfigFromRichTextField.default)(field, _richtexttypes.BLOCKS.EMBEDDED_RESOURCE);
|
|
97
|
+
const { selection } = editor;
|
|
98
|
+
const entity = await dialogs.selectSingleResourceEntry(config);
|
|
99
|
+
if (!entity) {
|
|
100
|
+
logAction('cancelCreateEmbedDialog', {
|
|
101
|
+
nodeType: _richtexttypes.BLOCKS.EMBEDDED_RESOURCE
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
(0, _internal.select)(editor, selection);
|
|
105
|
+
insertBlock(editor, _richtexttypes.BLOCKS.EMBEDDED_RESOURCE, entity);
|
|
106
|
+
ensureFollowingParagraph(editor, [
|
|
107
|
+
_richtexttypes.BLOCKS.EMBEDDED_RESOURCE
|
|
108
|
+
]);
|
|
109
|
+
logAction('insert', {
|
|
110
|
+
nodeType: _richtexttypes.BLOCKS.EMBEDDED_RESOURCE
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function ensureFollowingParagraph(editor, nodeTypes) {
|
|
115
|
+
const entityBlock = (0, _internal.getAboveNode)(editor, {
|
|
116
|
+
match: {
|
|
117
|
+
type: nodeTypes
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
if (!entityBlock) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const level = entityBlock[1].length - 1;
|
|
124
|
+
const lastNode = (0, _internal.getLastNodeByLevel)(editor, level);
|
|
125
|
+
const isTextContainer = _richtexttypes.TEXT_CONTAINERS.includes(lastNode?.[0].type ?? '');
|
|
126
|
+
if (level !== 0 && !isTextContainer) {
|
|
127
|
+
(0, _editor.insertEmptyParagraph)(editor);
|
|
128
|
+
}
|
|
129
|
+
(0, _editor.moveToTheNextChar)(editor);
|
|
130
|
+
}
|
|
131
|
+
const getLink = (nodeType, entity)=>{
|
|
132
|
+
if (nodeType === _richtexttypes.BLOCKS.EMBEDDED_RESOURCE) {
|
|
133
|
+
return {
|
|
134
|
+
urn: entity.sys.urn,
|
|
135
|
+
type: 'ResourceLink',
|
|
136
|
+
linkType: 'Contentful:Entry'
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
id: entity.sys.id,
|
|
141
|
+
type: 'Link',
|
|
142
|
+
linkType: entity.sys.type
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
const createNode = (nodeType, entity)=>{
|
|
146
|
+
return {
|
|
147
|
+
type: nodeType,
|
|
148
|
+
data: {
|
|
149
|
+
target: {
|
|
150
|
+
sys: getLink(nodeType, entity)
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
children: [
|
|
154
|
+
{
|
|
155
|
+
text: ''
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
isVoid: true
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
function insertBlock(editor, nodeType, entity) {
|
|
162
|
+
if (!editor?.selection) return;
|
|
163
|
+
const linkedEntityBlock = createNode(nodeType, entity);
|
|
164
|
+
const hasText = editor.selection && !!(0, _internal.getText)(editor, editor.selection.focus.path);
|
|
165
|
+
if (hasText) {
|
|
166
|
+
(0, _internal.insertNodes)(editor, linkedEntityBlock);
|
|
167
|
+
} else {
|
|
168
|
+
(0, _internal.setNodes)(editor, linkedEntityBlock);
|
|
169
|
+
}
|
|
170
|
+
}
|