@contentful/field-editor-rich-text 3.5.0 → 3.6.0
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/Toolbar/components/EmbedEntityWidget.js +8 -3
- package/dist/cjs/helpers/__tests__/removeInternalMarks.test.js +37 -21
- package/dist/cjs/helpers/getAllowedResourcesForNodeType.js +25 -0
- package/dist/cjs/helpers/newResourceEntitySelectorConfigFromRichTextField.js +21 -0
- 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/Text/createTextPlugin.js +1 -0
- package/dist/cjs/plugins/index.js +2 -0
- 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/cjs/useOnValueChanged.js +1 -1
- package/dist/esm/Toolbar/components/EmbedEntityWidget.js +8 -3
- package/dist/esm/helpers/__tests__/removeInternalMarks.test.js +37 -21
- package/dist/esm/helpers/getAllowedResourcesForNodeType.js +10 -0
- package/dist/esm/helpers/newResourceEntitySelectorConfigFromRichTextField.js +6 -0
- 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/Text/createTextPlugin.js +1 -0
- package/dist/esm/plugins/index.js +2 -0
- 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/esm/useOnValueChanged.js +1 -1
- package/dist/types/dialogs/HypelinkDialog/HyperlinkDialog.d.ts +3 -3
- package/dist/types/helpers/getAllowedResourcesForNodeType.d.ts +25 -0
- package/dist/types/helpers/newResourceEntitySelectorConfigFromRichTextField.d.ts +16 -0
- 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/jsx.d.ts +1 -1
- package/package.json +7 -7
- package/dist/cjs/plugins/EmbeddedEntityBlock/Util.js +0 -108
- package/dist/esm/plugins/EmbeddedEntityBlock/Util.js +0 -85
- package/dist/types/plugins/EmbeddedEntityBlock/ToolbarIcon.d.ts +0 -11
- package/dist/types/plugins/EmbeddedEntityBlock/Util.d.ts +0 -4
|
@@ -13,8 +13,8 @@ const _richtexttypes = require("@contentful/rich-text-types");
|
|
|
13
13
|
const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
|
|
14
14
|
const _editor = require("../../helpers/editor");
|
|
15
15
|
const _validations = require("../../helpers/validations");
|
|
16
|
-
const _EmbeddedEntityBlock = require("../../plugins/EmbeddedEntityBlock");
|
|
17
16
|
const _EmbeddedEntityInline = require("../../plugins/EmbeddedEntityInline");
|
|
17
|
+
const _EmbeddedBlockToolbarIcon = require("../../plugins/shared/EmbeddedBlockToolbarIcon");
|
|
18
18
|
const _SdkProvider = require("../../SdkProvider");
|
|
19
19
|
const _EmbeddedEntityDropdownButton = require("./EmbeddedEntityDropdownButton");
|
|
20
20
|
function _getRequireWildcardCache(nodeInterop) {
|
|
@@ -64,15 +64,20 @@ const EmbedEntityWidget = ({ isDisabled , canInsertBlocks })=>{
|
|
|
64
64
|
const onToggleEntityDropdown = ()=>setEmbedDropdownOpen(!isEmbedDropdownOpen);
|
|
65
65
|
const inlineEntryEmbedEnabled = (0, _validations.isNodeTypeEnabled)(sdk.field, _richtexttypes.INLINES.EMBEDDED_ENTRY);
|
|
66
66
|
const blockEntryEmbedEnabled = (0, _validations.isNodeTypeEnabled)(sdk.field, _richtexttypes.BLOCKS.EMBEDDED_ENTRY) && canInsertBlocks;
|
|
67
|
+
const blockResourceEmbedEnabled = (0, _validations.isNodeTypeEnabled)(sdk.field, _richtexttypes.BLOCKS.EMBEDDED_RESOURCE) && canInsertBlocks;
|
|
67
68
|
const blockAssetEmbedEnabled = (0, _validations.isNodeTypeEnabled)(sdk.field, _richtexttypes.BLOCKS.EMBEDDED_ASSET) && canInsertBlocks;
|
|
68
|
-
const actions = _react.default.createElement(_react.default.Fragment, null, blockEntryEmbedEnabled && _react.default.createElement(
|
|
69
|
+
const actions = _react.default.createElement(_react.default.Fragment, null, blockEntryEmbedEnabled && _react.default.createElement(_EmbeddedBlockToolbarIcon.EmbeddedBlockToolbarIcon, {
|
|
69
70
|
isDisabled: !!isDisabled,
|
|
70
71
|
nodeType: _richtexttypes.BLOCKS.EMBEDDED_ENTRY,
|
|
71
72
|
onClose: onCloseEntityDropdown
|
|
73
|
+
}), blockResourceEmbedEnabled && _react.default.createElement(_EmbeddedBlockToolbarIcon.EmbeddedBlockToolbarIcon, {
|
|
74
|
+
isDisabled: !!isDisabled,
|
|
75
|
+
nodeType: _richtexttypes.BLOCKS.EMBEDDED_RESOURCE,
|
|
76
|
+
onClose: onCloseEntityDropdown
|
|
72
77
|
}), inlineEntryEmbedEnabled && _react.default.createElement(_EmbeddedEntityInline.ToolbarEmbeddedEntityInlineButton, {
|
|
73
78
|
isDisabled: !!isDisabled || (0, _editor.isLinkActive)(editor),
|
|
74
79
|
onClose: onCloseEntityDropdown
|
|
75
|
-
}), blockAssetEmbedEnabled && _react.default.createElement(
|
|
80
|
+
}), blockAssetEmbedEnabled && _react.default.createElement(_EmbeddedBlockToolbarIcon.EmbeddedBlockToolbarIcon, {
|
|
76
81
|
isDisabled: !!isDisabled,
|
|
77
82
|
nodeType: _richtexttypes.BLOCKS.EMBEDDED_ASSET,
|
|
78
83
|
onClose: onCloseEntityDropdown
|
|
@@ -11,36 +11,52 @@ describe('internal mark', ()=>{
|
|
|
11
11
|
const data = [
|
|
12
12
|
{
|
|
13
13
|
title: 'Paragraph mark is removed',
|
|
14
|
-
input: (0, _contentfulslatejsadapter.toContentfulDocument)(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
input: (0, _contentfulslatejsadapter.toContentfulDocument)({
|
|
15
|
+
document: (0, _testutils.jsx)("editor", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("htext", {
|
|
16
|
+
[_constants.COMMAND_PROMPT]: true
|
|
17
|
+
}))).children
|
|
18
|
+
}),
|
|
19
|
+
expected: (0, _contentfulslatejsadapter.toContentfulDocument)({
|
|
20
|
+
document: (0, _testutils.jsx)("editor", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("htext", null))).children
|
|
21
|
+
})
|
|
18
22
|
},
|
|
19
23
|
{
|
|
20
24
|
title: 'Heading mark is removed',
|
|
21
|
-
input: (0, _contentfulslatejsadapter.toContentfulDocument)(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
input: (0, _contentfulslatejsadapter.toContentfulDocument)({
|
|
26
|
+
document: (0, _testutils.jsx)("editor", null, (0, _testutils.jsx)("hh1", null, (0, _testutils.jsx)("htext", {
|
|
27
|
+
[_constants.COMMAND_PROMPT]: true
|
|
28
|
+
}))).children
|
|
29
|
+
}),
|
|
30
|
+
expected: (0, _contentfulslatejsadapter.toContentfulDocument)({
|
|
31
|
+
document: (0, _testutils.jsx)("editor", null, (0, _testutils.jsx)("hh1", null, (0, _testutils.jsx)("htext", null))).children
|
|
32
|
+
})
|
|
25
33
|
},
|
|
26
34
|
{
|
|
27
35
|
title: 'Block quote mark is removed',
|
|
28
|
-
input: (0, _contentfulslatejsadapter.toContentfulDocument)(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
input: (0, _contentfulslatejsadapter.toContentfulDocument)({
|
|
37
|
+
document: (0, _testutils.jsx)("editor", null, (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("htext", {
|
|
38
|
+
[_constants.COMMAND_PROMPT]: true
|
|
39
|
+
})))).children
|
|
40
|
+
}),
|
|
41
|
+
expected: (0, _contentfulslatejsadapter.toContentfulDocument)({
|
|
42
|
+
document: (0, _testutils.jsx)("editor", null, (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("htext", null)))).children
|
|
43
|
+
})
|
|
32
44
|
},
|
|
33
45
|
{
|
|
34
46
|
title: 'Other marks are not removed',
|
|
35
|
-
input: (0, _contentfulslatejsadapter.toContentfulDocument)(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
input: (0, _contentfulslatejsadapter.toContentfulDocument)({
|
|
48
|
+
document: (0, _testutils.jsx)("editor", null, (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("htext", {
|
|
49
|
+
bold: true,
|
|
50
|
+
underline: true,
|
|
51
|
+
[_constants.COMMAND_PROMPT]: true
|
|
52
|
+
})))).children
|
|
53
|
+
}),
|
|
54
|
+
expected: (0, _contentfulslatejsadapter.toContentfulDocument)({
|
|
55
|
+
document: (0, _testutils.jsx)("editor", null, (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("htext", {
|
|
56
|
+
bold: true,
|
|
57
|
+
underline: true
|
|
58
|
+
})))).children
|
|
59
|
+
})
|
|
44
60
|
}
|
|
45
61
|
];
|
|
46
62
|
for (const { input , expected , title } of data){
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getAllowedResourcesForNodeType;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _find = _interop_require_default(require("lodash/find"));
|
|
12
|
+
const _flow = _interop_require_default(require("lodash/flow"));
|
|
13
|
+
const _get = _interop_require_default(require("lodash/get"));
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function getAllowedResourcesForNodeType(field, nodeType) {
|
|
20
|
+
return (0, _flow.default)((validations)=>(0, _find.default)(validations, 'nodes'), (validations)=>(0, _get.default)(validations, [
|
|
21
|
+
'nodes',
|
|
22
|
+
nodeType,
|
|
23
|
+
'allowedResources'
|
|
24
|
+
], []))(field.validations);
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return newResourceEntitySelectorConfigFromRichTextField;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _getAllowedResourcesForNodeType = _interop_require_default(require("./getAllowedResourcesForNodeType"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function newResourceEntitySelectorConfigFromRichTextField(field, nodeType) {
|
|
18
|
+
return {
|
|
19
|
+
allowedResources: (0, _getAllowedResourcesForNodeType.default)(field, nodeType)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -14,6 +14,7 @@ function createDragAndDropPlugin() {
|
|
|
14
14
|
const DRAGGABLE_TYPES = [
|
|
15
15
|
_richtexttypes.BLOCKS.EMBEDDED_ENTRY,
|
|
16
16
|
_richtexttypes.BLOCKS.EMBEDDED_ASSET,
|
|
17
|
+
_richtexttypes.BLOCKS.EMBEDDED_RESOURCE,
|
|
17
18
|
_richtexttypes.BLOCKS.HR,
|
|
18
19
|
_richtexttypes.INLINES.EMBEDDED_ENTRY
|
|
19
20
|
];
|
|
@@ -9,15 +9,15 @@ Object.defineProperty(exports, "LinkedEntityBlock", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
-
const _emotion = require("emotion");
|
|
13
12
|
const _slatereact = require("slate-react");
|
|
14
13
|
const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
|
|
15
|
-
const _environment = require("../../helpers/environment");
|
|
16
14
|
const _queries = require("../../internal/queries");
|
|
17
15
|
const _transforms = require("../../internal/transforms");
|
|
18
16
|
const _SdkProvider = require("../../SdkProvider");
|
|
17
|
+
const _linkstracking = require("../links-tracking");
|
|
19
18
|
const _FetchingWrappedAssetCard = require("../shared/FetchingWrappedAssetCard");
|
|
20
19
|
const _FetchingWrappedEntryCard = require("../shared/FetchingWrappedEntryCard");
|
|
20
|
+
const _LinkedBlockWrapper = require("../shared/LinkedBlockWrapper");
|
|
21
21
|
function _getRequireWildcardCache(nodeInterop) {
|
|
22
22
|
if (typeof WeakMap !== "function") return null;
|
|
23
23
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -57,19 +57,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
57
57
|
}
|
|
58
58
|
return newObj;
|
|
59
59
|
}
|
|
60
|
-
const styles = {
|
|
61
|
-
root: (0, _emotion.css)({
|
|
62
|
-
marginBottom: '1.25rem !important',
|
|
63
|
-
display: 'block'
|
|
64
|
-
}),
|
|
65
|
-
container: (0, _emotion.css)({
|
|
66
|
-
display: 'inline-block',
|
|
67
|
-
verticalAlign: 'text-top',
|
|
68
|
-
width: '100%'
|
|
69
|
-
})
|
|
70
|
-
};
|
|
71
60
|
function LinkedEntityBlock(props) {
|
|
72
|
-
const { attributes , children , element
|
|
61
|
+
const { attributes , children , element } = props;
|
|
62
|
+
const { onEntityFetchComplete } = (0, _linkstracking.useLinkTracking)();
|
|
73
63
|
const isSelected = (0, _slatereact.useSelected)();
|
|
74
64
|
const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
|
|
75
65
|
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
@@ -95,34 +85,27 @@ function LinkedEntityBlock(props) {
|
|
|
95
85
|
editor,
|
|
96
86
|
element
|
|
97
87
|
]);
|
|
98
|
-
return _react.createElement(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
locale: sdk.field.locale,
|
|
122
|
-
isDisabled: isDisabled,
|
|
123
|
-
isSelected: isSelected,
|
|
124
|
-
onRemove: handleRemoveClick,
|
|
125
|
-
onEdit: handleEditClick,
|
|
126
|
-
onEntityFetchComplete: onEntityFetchComplete
|
|
127
|
-
})), children);
|
|
88
|
+
return _react.createElement(_LinkedBlockWrapper.LinkedBlockWrapper, {
|
|
89
|
+
attributes: attributes,
|
|
90
|
+
card: _react.createElement(_react.Fragment, null, entityType === 'Entry' && _react.createElement(_FetchingWrappedEntryCard.FetchingWrappedEntryCard, {
|
|
91
|
+
sdk: sdk,
|
|
92
|
+
entryId: entityId,
|
|
93
|
+
locale: sdk.field.locale,
|
|
94
|
+
isDisabled: isDisabled,
|
|
95
|
+
isSelected: isSelected,
|
|
96
|
+
onRemove: handleRemoveClick,
|
|
97
|
+
onEdit: handleEditClick,
|
|
98
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
99
|
+
}), entityType === 'Asset' && _react.createElement(_FetchingWrappedAssetCard.FetchingWrappedAssetCard, {
|
|
100
|
+
sdk: sdk,
|
|
101
|
+
assetId: entityId,
|
|
102
|
+
locale: sdk.field.locale,
|
|
103
|
+
isDisabled: isDisabled,
|
|
104
|
+
isSelected: isSelected,
|
|
105
|
+
onRemove: handleRemoveClick,
|
|
106
|
+
onEdit: handleEditClick,
|
|
107
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
108
|
+
})),
|
|
109
|
+
element: element
|
|
110
|
+
}, children);
|
|
128
111
|
}
|
|
@@ -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
|
{
|
|
@@ -24,6 +24,7 @@ const _useCommands = require("./CommandPalette/useCommands");
|
|
|
24
24
|
const _DragAndDrop = require("./DragAndDrop");
|
|
25
25
|
const _EmbeddedEntityBlock = require("./EmbeddedEntityBlock");
|
|
26
26
|
const _EmbeddedEntityInline = require("./EmbeddedEntityInline");
|
|
27
|
+
const _EmbeddedResourceBlock = require("./EmbeddedResourceBlock");
|
|
27
28
|
const _Heading = require("./Heading");
|
|
28
29
|
const _Hr = require("./Hr");
|
|
29
30
|
const _Hyperlink = require("./Hyperlink");
|
|
@@ -56,6 +57,7 @@ const getPlugins = (sdk, onAction, restrictedMarks)=>[
|
|
|
56
57
|
(0, _Table.createTablePlugin)(),
|
|
57
58
|
(0, _EmbeddedEntityBlock.createEmbeddedEntryBlockPlugin)(sdk),
|
|
58
59
|
(0, _EmbeddedEntityBlock.createEmbeddedAssetBlockPlugin)(sdk),
|
|
60
|
+
(0, _EmbeddedResourceBlock.createEmbeddedResourceBlockPlugin)(sdk),
|
|
59
61
|
(0, _Hyperlink.createHyperlinkPlugin)(sdk),
|
|
60
62
|
(0, _EmbeddedEntityInline.createEmbeddedEntityInlinePlugin)(sdk),
|
|
61
63
|
(0, _Marks.createMarksPlugin)(),
|
|
@@ -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')) {
|