@contentful/field-editor-rich-text 3.12.6 → 3.13.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 -2
- package/dist/cjs/constants/Schema.js +3 -0
- package/dist/cjs/helpers/{newEntitySelectorConfigFromRichTextField.js → config.js} +19 -5
- package/dist/cjs/plugins/DragAndDrop/index.js +4 -2
- package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +1 -1
- package/dist/cjs/plugins/EmbeddedEntityInline/LinkedEntityInline.js +97 -0
- package/dist/cjs/plugins/EmbeddedEntityInline/index.js +27 -193
- package/dist/cjs/plugins/{shared/FetchingWrappedResourceCard.js → EmbeddedResourceBlock/FetchingWrappedResourceBlockCard.js} +3 -3
- package/dist/cjs/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +3 -3
- package/dist/cjs/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +102 -0
- package/dist/cjs/plugins/EmbeddedResourceInline/LinkedResourceInline.js +51 -0
- package/dist/cjs/plugins/EmbeddedResourceInline/index.js +56 -0
- package/dist/cjs/plugins/index.js +2 -0
- package/dist/cjs/plugins/shared/EmbeddedBlockToolbarIcon.js +2 -4
- package/dist/cjs/plugins/shared/EmbeddedBlockUtil.js +3 -4
- package/dist/cjs/plugins/shared/EmbeddedInlineToolbarIcon.js +105 -0
- package/dist/cjs/plugins/shared/EmbeddedInlineUtil.js +127 -0
- package/dist/cjs/plugins/shared/LinkedBlockWrapper.js +4 -5
- package/dist/cjs/plugins/shared/LinkedInlineWrapper.js +85 -0
- package/dist/cjs/plugins/shared/ResourceNewBadge.js +57 -0
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +2 -2
- package/dist/cjs/plugins/shared/utils.js +12 -0
- package/dist/esm/Toolbar/components/EmbedEntityWidget.js +8 -2
- package/dist/esm/constants/Schema.js +3 -0
- package/dist/esm/helpers/{newEntitySelectorConfigFromRichTextField.js → config.js} +8 -2
- package/dist/esm/plugins/DragAndDrop/index.js +4 -2
- package/dist/esm/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +1 -1
- package/dist/esm/plugins/EmbeddedEntityInline/LinkedEntityInline.js +48 -0
- package/dist/esm/plugins/EmbeddedEntityInline/index.js +24 -138
- package/dist/esm/plugins/{shared/FetchingWrappedResourceCard.js → EmbeddedResourceBlock/FetchingWrappedResourceBlockCard.js} +1 -1
- package/dist/esm/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +3 -3
- package/dist/esm/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +53 -0
- package/dist/esm/plugins/EmbeddedResourceInline/LinkedResourceInline.js +36 -0
- package/dist/esm/plugins/EmbeddedResourceInline/index.js +46 -0
- package/dist/esm/plugins/index.js +2 -0
- package/dist/esm/plugins/shared/EmbeddedBlockToolbarIcon.js +3 -5
- package/dist/esm/plugins/shared/EmbeddedBlockUtil.js +1 -2
- package/dist/esm/plugins/shared/EmbeddedInlineToolbarIcon.js +51 -0
- package/dist/esm/plugins/shared/EmbeddedInlineUtil.js +101 -0
- package/dist/esm/plugins/shared/LinkedBlockWrapper.js +4 -5
- package/dist/esm/plugins/shared/LinkedInlineWrapper.js +31 -0
- package/dist/esm/plugins/shared/ResourceNewBadge.js +8 -0
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +2 -2
- package/dist/esm/plugins/shared/utils.js +2 -0
- package/dist/types/constants/Schema.d.ts +3 -0
- package/dist/types/helpers/config.d.ts +33 -0
- package/dist/types/plugins/EmbeddedEntityBlock/LinkedEntityBlock.d.ts +2 -7
- package/dist/types/plugins/EmbeddedEntityInline/LinkedEntityInline.d.ts +14 -0
- package/dist/types/plugins/EmbeddedEntityInline/index.d.ts +0 -7
- package/dist/types/plugins/{shared/FetchingWrappedResourceCard.d.ts → EmbeddedResourceBlock/FetchingWrappedResourceBlockCard.d.ts} +2 -2
- package/dist/types/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.d.ts +13 -0
- package/dist/types/plugins/EmbeddedResourceInline/LinkedResourceInline.d.ts +13 -0
- package/dist/types/plugins/EmbeddedResourceInline/index.d.ts +3 -0
- package/dist/types/plugins/shared/EmbeddedInlineToolbarIcon.d.ts +8 -0
- package/dist/types/plugins/shared/EmbeddedInlineUtil.d.ts +8 -0
- package/dist/types/plugins/shared/LinkedBlockWrapper.d.ts +4 -19
- package/dist/types/plugins/shared/LinkedInlineWrapper.d.ts +10 -0
- package/dist/types/plugins/shared/ResourceNewBadge.d.ts +2 -0
- package/dist/types/plugins/shared/utils.d.ts +2 -0
- package/package.json +2 -2
- package/dist/cjs/helpers/newResourceEntitySelectorConfigFromRichTextField.js +0 -21
- package/dist/cjs/plugins/EmbeddedEntityInline/Util.js +0 -30
- package/dist/esm/helpers/newResourceEntitySelectorConfigFromRichTextField.js +0 -6
- package/dist/esm/plugins/EmbeddedEntityInline/Util.js +0 -20
- package/dist/types/helpers/newEntitySelectorConfigFromRichTextField.d.ts +0 -14
- package/dist/types/helpers/newResourceEntitySelectorConfigFromRichTextField.d.ts +0 -16
- package/dist/types/plugins/EmbeddedEntityInline/Util.d.ts +0 -16
|
@@ -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 _EmbeddedEntityInline = require("../../plugins/EmbeddedEntityInline");
|
|
17
16
|
const _EmbeddedBlockToolbarIcon = require("../../plugins/shared/EmbeddedBlockToolbarIcon");
|
|
17
|
+
const _EmbeddedInlineToolbarIcon = require("../../plugins/shared/EmbeddedInlineToolbarIcon");
|
|
18
18
|
const _SdkProvider = require("../../SdkProvider");
|
|
19
19
|
const _EmbeddedEntityDropdownButton = require("./EmbeddedEntityDropdownButton");
|
|
20
20
|
function _getRequireWildcardCache(nodeInterop) {
|
|
@@ -63,6 +63,7 @@ const EmbedEntityWidget = ({ isDisabled , canInsertBlocks })=>{
|
|
|
63
63
|
const onCloseEntityDropdown = ()=>setEmbedDropdownOpen(false);
|
|
64
64
|
const onToggleEntityDropdown = ()=>setEmbedDropdownOpen(!isEmbedDropdownOpen);
|
|
65
65
|
const inlineEntryEmbedEnabled = (0, _validations.isNodeTypeEnabled)(sdk.field, _richtexttypes.INLINES.EMBEDDED_ENTRY);
|
|
66
|
+
const inlineResourceEmbedEnabled = (0, _validations.isNodeTypeEnabled)(sdk.field, _richtexttypes.INLINES.EMBEDDED_RESOURCE);
|
|
66
67
|
const blockEntryEmbedEnabled = (0, _validations.isNodeTypeEnabled)(sdk.field, _richtexttypes.BLOCKS.EMBEDDED_ENTRY) && canInsertBlocks;
|
|
67
68
|
const blockResourceEmbedEnabled = (0, _validations.isNodeTypeEnabled)(sdk.field, _richtexttypes.BLOCKS.EMBEDDED_RESOURCE) && canInsertBlocks;
|
|
68
69
|
const blockAssetEmbedEnabled = (0, _validations.isNodeTypeEnabled)(sdk.field, _richtexttypes.BLOCKS.EMBEDDED_ASSET) && canInsertBlocks;
|
|
@@ -74,7 +75,12 @@ const EmbedEntityWidget = ({ isDisabled , canInsertBlocks })=>{
|
|
|
74
75
|
isDisabled: !!isDisabled,
|
|
75
76
|
nodeType: _richtexttypes.BLOCKS.EMBEDDED_RESOURCE,
|
|
76
77
|
onClose: onCloseEntityDropdown
|
|
77
|
-
}), inlineEntryEmbedEnabled && _react.default.createElement(
|
|
78
|
+
}), inlineEntryEmbedEnabled && _react.default.createElement(_EmbeddedInlineToolbarIcon.EmbeddedInlineToolbarIcon, {
|
|
79
|
+
nodeType: _richtexttypes.INLINES.EMBEDDED_ENTRY,
|
|
80
|
+
isDisabled: !!isDisabled || (0, _editor.isLinkActive)(editor),
|
|
81
|
+
onClose: onCloseEntityDropdown
|
|
82
|
+
}), inlineResourceEmbedEnabled && _react.default.createElement(_EmbeddedInlineToolbarIcon.EmbeddedInlineToolbarIcon, {
|
|
83
|
+
nodeType: _richtexttypes.INLINES.EMBEDDED_RESOURCE,
|
|
78
84
|
isDisabled: !!isDisabled || (0, _editor.isLinkActive)(editor),
|
|
79
85
|
onClose: onCloseEntityDropdown
|
|
80
86
|
}), blockAssetEmbedEnabled && _react.default.createElement(_EmbeddedBlockToolbarIcon.EmbeddedBlockToolbarIcon, {
|
|
@@ -2,25 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
newEntitySelectorConfigFromRichTextField: function() {
|
|
8
13
|
return newEntitySelectorConfigFromRichTextField;
|
|
14
|
+
},
|
|
15
|
+
newResourceEntitySelectorConfigFromRichTextField: function() {
|
|
16
|
+
return newResourceEntitySelectorConfigFromRichTextField;
|
|
9
17
|
}
|
|
10
18
|
});
|
|
19
|
+
const _getAllowedResourcesForNodeType = _interop_require_default(require("./getAllowedResourcesForNodeType"));
|
|
11
20
|
const _getLinkedContentTypeIdsForNodeType = _interop_require_default(require("./getLinkedContentTypeIdsForNodeType"));
|
|
12
21
|
function _interop_require_default(obj) {
|
|
13
22
|
return obj && obj.__esModule ? obj : {
|
|
14
23
|
default: obj
|
|
15
24
|
};
|
|
16
25
|
}
|
|
17
|
-
|
|
26
|
+
const newEntitySelectorConfigFromRichTextField = (field, nodeType)=>{
|
|
18
27
|
return {
|
|
19
28
|
entityType: getEntityTypeFromRichTextNode(nodeType),
|
|
20
29
|
locale: field.locale || null,
|
|
21
30
|
contentTypes: (0, _getLinkedContentTypeIdsForNodeType.default)(field, nodeType)
|
|
22
31
|
};
|
|
23
|
-
}
|
|
32
|
+
};
|
|
24
33
|
function getEntityTypeFromRichTextNode(nodeType) {
|
|
25
34
|
const words = nodeType.split('-');
|
|
26
35
|
if (words.indexOf('entry') !== -1) {
|
|
@@ -31,3 +40,8 @@ function getEntityTypeFromRichTextNode(nodeType) {
|
|
|
31
40
|
}
|
|
32
41
|
throw new Error(`RichText node type \`${nodeType}\` has no associated \`entityType\``);
|
|
33
42
|
}
|
|
43
|
+
const newResourceEntitySelectorConfigFromRichTextField = (field, nodeType)=>{
|
|
44
|
+
return {
|
|
45
|
+
allowedResources: (0, _getAllowedResourcesForNodeType.default)(field, nodeType)
|
|
46
|
+
};
|
|
47
|
+
};
|
|
@@ -16,11 +16,13 @@ function createDragAndDropPlugin() {
|
|
|
16
16
|
_richtexttypes.BLOCKS.EMBEDDED_ASSET,
|
|
17
17
|
_richtexttypes.BLOCKS.EMBEDDED_RESOURCE,
|
|
18
18
|
_richtexttypes.BLOCKS.HR,
|
|
19
|
-
_richtexttypes.INLINES.EMBEDDED_ENTRY
|
|
19
|
+
_richtexttypes.INLINES.EMBEDDED_ENTRY,
|
|
20
|
+
_richtexttypes.INLINES.EMBEDDED_RESOURCE
|
|
20
21
|
];
|
|
21
22
|
const ON_DROP_ALLOWED_TYPES = {
|
|
22
23
|
TABLE: [
|
|
23
|
-
_richtexttypes.INLINES.EMBEDDED_ENTRY
|
|
24
|
+
_richtexttypes.INLINES.EMBEDDED_ENTRY,
|
|
25
|
+
_richtexttypes.INLINES.EMBEDDED_RESOURCE
|
|
24
26
|
]
|
|
25
27
|
};
|
|
26
28
|
return {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LinkedEntityInline", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LinkedEntityInline;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
const _slatereact = require("slate-react");
|
|
13
|
+
const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
|
|
14
|
+
const _editor = require("../../helpers/editor");
|
|
15
|
+
const _queries = require("../../internal/queries");
|
|
16
|
+
const _transforms = require("../../internal/transforms");
|
|
17
|
+
const _SdkProvider = require("../../SdkProvider");
|
|
18
|
+
const _linkstracking = require("../links-tracking");
|
|
19
|
+
const _LinkedInlineWrapper = require("../shared/LinkedInlineWrapper");
|
|
20
|
+
const _FetchingWrappedInlineEntryCard = require("./FetchingWrappedInlineEntryCard");
|
|
21
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
22
|
+
if (typeof WeakMap !== "function") return null;
|
|
23
|
+
var cacheBabelInterop = new WeakMap();
|
|
24
|
+
var cacheNodeInterop = new WeakMap();
|
|
25
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
26
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
27
|
+
})(nodeInterop);
|
|
28
|
+
}
|
|
29
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
30
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
34
|
+
return {
|
|
35
|
+
default: obj
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
39
|
+
if (cache && cache.has(obj)) {
|
|
40
|
+
return cache.get(obj);
|
|
41
|
+
}
|
|
42
|
+
var newObj = {};
|
|
43
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
44
|
+
for(var key in obj){
|
|
45
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
46
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
47
|
+
if (desc && (desc.get || desc.set)) {
|
|
48
|
+
Object.defineProperty(newObj, key, desc);
|
|
49
|
+
} else {
|
|
50
|
+
newObj[key] = obj[key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
newObj.default = obj;
|
|
55
|
+
if (cache) {
|
|
56
|
+
cache.set(obj, newObj);
|
|
57
|
+
}
|
|
58
|
+
return newObj;
|
|
59
|
+
}
|
|
60
|
+
function LinkedEntityInline(props) {
|
|
61
|
+
const { attributes , children , element } = props;
|
|
62
|
+
const { onEntityFetchComplete } = (0, _linkstracking.useLinkTracking)();
|
|
63
|
+
const isSelected = (0, _slatereact.useSelected)();
|
|
64
|
+
const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
|
|
65
|
+
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
66
|
+
const isDisabled = (0, _slatereact.useReadOnly)();
|
|
67
|
+
const { id: entryId } = element.data.target.sys;
|
|
68
|
+
function handleEditClick() {
|
|
69
|
+
return sdk.navigator.openEntry(entryId, {
|
|
70
|
+
slideIn: {
|
|
71
|
+
waitForClose: true
|
|
72
|
+
}
|
|
73
|
+
}).then(()=>{
|
|
74
|
+
editor && (0, _editor.focus)(editor);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function handleRemoveClick() {
|
|
78
|
+
if (!editor) return;
|
|
79
|
+
const pathToElement = (0, _queries.findNodePath)(editor, element);
|
|
80
|
+
(0, _transforms.removeNodes)(editor, {
|
|
81
|
+
at: pathToElement
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return _react.createElement(_LinkedInlineWrapper.LinkedInlineWrapper, {
|
|
85
|
+
attributes: attributes,
|
|
86
|
+
card: _react.createElement(_FetchingWrappedInlineEntryCard.FetchingWrappedInlineEntryCard, {
|
|
87
|
+
sdk: sdk,
|
|
88
|
+
entryId: entryId,
|
|
89
|
+
isSelected: isSelected,
|
|
90
|
+
isDisabled: isDisabled,
|
|
91
|
+
onRemove: handleRemoveClick,
|
|
92
|
+
onEdit: handleEditClick,
|
|
93
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
94
|
+
}),
|
|
95
|
+
link: element.data.target
|
|
96
|
+
}, children);
|
|
97
|
+
}
|
|
@@ -2,202 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
ToolbarEmbeddedEntityInlineButton: function() {
|
|
13
|
-
return ToolbarEmbeddedEntityInlineButton;
|
|
14
|
-
},
|
|
15
|
-
createEmbeddedEntityInlinePlugin: function() {
|
|
5
|
+
Object.defineProperty(exports, "createEmbeddedEntityInlinePlugin", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
16
8
|
return createEmbeddedEntityInlinePlugin;
|
|
17
9
|
}
|
|
18
10
|
});
|
|
19
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
20
|
-
const _f36components = require("@contentful/f36-components");
|
|
21
|
-
const _f36icons = require("@contentful/f36-icons");
|
|
22
|
-
const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
|
|
23
11
|
const _richtexttypes = require("@contentful/rich-text-types");
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const _slatereact = require("slate-react");
|
|
27
|
-
const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
|
|
28
|
-
const _editor = require("../../helpers/editor");
|
|
29
|
-
const _environment = require("../../helpers/environment");
|
|
30
|
-
const _newEntitySelectorConfigFromRichTextField = _interop_require_default(require("../../helpers/newEntitySelectorConfigFromRichTextField"));
|
|
31
|
-
const _sdkNavigatorSlideIn = require("../../helpers/sdkNavigatorSlideIn");
|
|
32
|
-
const _queries = require("../../internal/queries");
|
|
33
|
-
const _transforms = require("../../internal/transforms");
|
|
34
|
-
const _SdkProvider = require("../../SdkProvider");
|
|
35
|
-
const _linkstracking = require("../links-tracking");
|
|
36
|
-
const _FetchingWrappedInlineEntryCard = require("./FetchingWrappedInlineEntryCard");
|
|
37
|
-
const _Util = require("./Util");
|
|
38
|
-
function _interop_require_default(obj) {
|
|
39
|
-
return obj && obj.__esModule ? obj : {
|
|
40
|
-
default: obj
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
44
|
-
if (typeof WeakMap !== "function") return null;
|
|
45
|
-
var cacheBabelInterop = new WeakMap();
|
|
46
|
-
var cacheNodeInterop = new WeakMap();
|
|
47
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
48
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
49
|
-
})(nodeInterop);
|
|
50
|
-
}
|
|
51
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
52
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
53
|
-
return obj;
|
|
54
|
-
}
|
|
55
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
56
|
-
return {
|
|
57
|
-
default: obj
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
61
|
-
if (cache && cache.has(obj)) {
|
|
62
|
-
return cache.get(obj);
|
|
63
|
-
}
|
|
64
|
-
var newObj = {};
|
|
65
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
66
|
-
for(var key in obj){
|
|
67
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
68
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
69
|
-
if (desc && (desc.get || desc.set)) {
|
|
70
|
-
Object.defineProperty(newObj, key, desc);
|
|
71
|
-
} else {
|
|
72
|
-
newObj[key] = obj[key];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
newObj.default = obj;
|
|
77
|
-
if (cache) {
|
|
78
|
-
cache.set(obj, newObj);
|
|
79
|
-
}
|
|
80
|
-
return newObj;
|
|
81
|
-
}
|
|
82
|
-
const styles = {
|
|
83
|
-
icon: (0, _emotion.css)({
|
|
84
|
-
marginRight: '10px'
|
|
85
|
-
}),
|
|
86
|
-
root: (0, _emotion.css)({
|
|
87
|
-
display: 'inline-block',
|
|
88
|
-
margin: `0 ${_f36tokens.default.spacing2Xs}`,
|
|
89
|
-
fontSize: 'inherit',
|
|
90
|
-
span: {
|
|
91
|
-
userSelect: 'none'
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
};
|
|
95
|
-
function EmbeddedEntityInline(props) {
|
|
96
|
-
const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
|
|
97
|
-
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
98
|
-
const isSelected = (0, _slatereact.useSelected)();
|
|
99
|
-
const { id: entryId } = props.element.data.target.sys;
|
|
100
|
-
const isDisabled = (0, _slatereact.useReadOnly)();
|
|
101
|
-
const { onEntityFetchComplete } = (0, _linkstracking.useLinkTracking)();
|
|
102
|
-
function handleEditClick() {
|
|
103
|
-
return sdk.navigator.openEntry(entryId, {
|
|
104
|
-
slideIn: {
|
|
105
|
-
waitForClose: true
|
|
106
|
-
}
|
|
107
|
-
}).then(()=>{
|
|
108
|
-
editor && (0, _editor.focus)(editor);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
function handleRemoveClick() {
|
|
112
|
-
if (!editor) return;
|
|
113
|
-
const pathToElement = (0, _queries.findNodePath)(editor, props.element);
|
|
114
|
-
(0, _transforms.removeNodes)(editor, {
|
|
115
|
-
at: pathToElement
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return _react.createElement("span", {
|
|
119
|
-
...props.attributes,
|
|
120
|
-
className: styles.root,
|
|
121
|
-
"data-embedded-entity-inline-id": entryId,
|
|
122
|
-
contentEditable: _environment.IS_CHROME ? undefined : false,
|
|
123
|
-
draggable: _environment.IS_CHROME ? true : undefined
|
|
124
|
-
}, _react.createElement("span", {
|
|
125
|
-
contentEditable: _environment.IS_CHROME ? false : undefined,
|
|
126
|
-
draggable: _environment.IS_CHROME ? true : undefined
|
|
127
|
-
}, _react.createElement(_FetchingWrappedInlineEntryCard.FetchingWrappedInlineEntryCard, {
|
|
128
|
-
sdk: sdk,
|
|
129
|
-
entryId: entryId,
|
|
130
|
-
isSelected: isSelected,
|
|
131
|
-
isDisabled: isDisabled,
|
|
132
|
-
onRemove: handleRemoveClick,
|
|
133
|
-
onEdit: handleEditClick,
|
|
134
|
-
onEntityFetchComplete: onEntityFetchComplete
|
|
135
|
-
})), props.children);
|
|
136
|
-
}
|
|
137
|
-
async function selectEntityAndInsert(editor, sdk, logAction) {
|
|
138
|
-
logAction('openCreateEmbedDialog', {
|
|
139
|
-
nodeType: _richtexttypes.INLINES.EMBEDDED_ENTRY
|
|
140
|
-
});
|
|
141
|
-
const config = {
|
|
142
|
-
...(0, _newEntitySelectorConfigFromRichTextField.default)(sdk.field, _richtexttypes.INLINES.EMBEDDED_ENTRY),
|
|
143
|
-
withCreate: true
|
|
144
|
-
};
|
|
145
|
-
const { selection } = editor;
|
|
146
|
-
const rteSlide = (0, _sdkNavigatorSlideIn.watchCurrentSlide)(sdk.navigator);
|
|
147
|
-
const entry = await sdk.dialogs.selectSingleEntry(config);
|
|
148
|
-
if (!entry) {
|
|
149
|
-
logAction('cancelCreateEmbedDialog', {
|
|
150
|
-
nodeType: _richtexttypes.INLINES.EMBEDDED_ENTRY
|
|
151
|
-
});
|
|
152
|
-
} else {
|
|
153
|
-
(0, _transforms.select)(editor, selection);
|
|
154
|
-
(0, _transforms.insertNodes)(editor, (0, _Util.createInlineEntryNode)(entry.sys.id));
|
|
155
|
-
logAction('insert', {
|
|
156
|
-
nodeType: _richtexttypes.INLINES.EMBEDDED_ENTRY
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
rteSlide.onActive(()=>{
|
|
160
|
-
rteSlide.unwatch();
|
|
161
|
-
(0, _editor.focus)(editor);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
function ToolbarEmbeddedEntityInlineButton(props) {
|
|
165
|
-
const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
|
|
166
|
-
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
167
|
-
async function handleClick(event) {
|
|
168
|
-
event.preventDefault();
|
|
169
|
-
if (!editor) return;
|
|
170
|
-
props.onClose();
|
|
171
|
-
await selectEntityAndInsert(editor, sdk, editor.tracking.onToolbarAction);
|
|
172
|
-
(0, _editor.moveToTheNextChar)(editor);
|
|
173
|
-
}
|
|
174
|
-
return _react.createElement(_f36components.Menu.Item, {
|
|
175
|
-
disabled: props.isDisabled,
|
|
176
|
-
className: "rich-text__entry-link-block-button",
|
|
177
|
-
testId: `toolbar-toggle-${_richtexttypes.INLINES.EMBEDDED_ENTRY}`,
|
|
178
|
-
onClick: handleClick
|
|
179
|
-
}, _react.createElement(_f36components.Flex, {
|
|
180
|
-
alignItems: "center",
|
|
181
|
-
flexDirection: "row"
|
|
182
|
-
}, _react.createElement(_f36icons.EmbeddedEntryInlineIcon, {
|
|
183
|
-
variant: "secondary",
|
|
184
|
-
className: `rich-text__embedded-entry-list-icon ${styles.icon}`
|
|
185
|
-
}), _react.createElement("span", null, "Inline entry")));
|
|
186
|
-
}
|
|
12
|
+
const _EmbeddedInlineUtil = require("../shared/EmbeddedInlineUtil");
|
|
13
|
+
const _LinkedEntityInline = require("./LinkedEntityInline");
|
|
187
14
|
function createEmbeddedEntityInlinePlugin(sdk) {
|
|
188
15
|
const htmlAttributeName = 'data-embedded-entity-inline-id';
|
|
16
|
+
const nodeType = _richtexttypes.INLINES.EMBEDDED_ENTRY;
|
|
189
17
|
return {
|
|
190
|
-
key:
|
|
191
|
-
type:
|
|
18
|
+
key: nodeType,
|
|
19
|
+
type: nodeType,
|
|
192
20
|
isElement: true,
|
|
193
21
|
isInline: true,
|
|
194
22
|
isVoid: true,
|
|
195
|
-
component:
|
|
23
|
+
component: _LinkedEntityInline.LinkedEntityInline,
|
|
196
24
|
options: {
|
|
197
25
|
hotkey: 'mod+shift+2'
|
|
198
26
|
},
|
|
199
27
|
handlers: {
|
|
200
|
-
onKeyDown: getWithEmbeddedEntryInlineEvents(sdk)
|
|
28
|
+
onKeyDown: (0, _EmbeddedInlineUtil.getWithEmbeddedEntryInlineEvents)(nodeType, sdk)
|
|
201
29
|
},
|
|
202
30
|
deserializeHtml: {
|
|
203
31
|
rules: [
|
|
@@ -206,17 +34,23 @@ function createEmbeddedEntityInlinePlugin(sdk) {
|
|
|
206
34
|
}
|
|
207
35
|
],
|
|
208
36
|
withoutChildren: true,
|
|
209
|
-
getNode: (el)=>(
|
|
37
|
+
getNode: (el)=>({
|
|
38
|
+
type: nodeType,
|
|
39
|
+
children: [
|
|
40
|
+
{
|
|
41
|
+
text: ''
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
data: {
|
|
45
|
+
target: {
|
|
46
|
+
sys: {
|
|
47
|
+
id: el.getAttribute('data-entity-id'),
|
|
48
|
+
type: 'Link',
|
|
49
|
+
linkType: el.getAttribute('data-entity-type')
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
})
|
|
210
54
|
}
|
|
211
55
|
};
|
|
212
56
|
}
|
|
213
|
-
function getWithEmbeddedEntryInlineEvents(sdk) {
|
|
214
|
-
return function withEmbeddedEntryInlineEvents(editor, { options: { hotkey } }) {
|
|
215
|
-
return function handleEvent(event) {
|
|
216
|
-
if (!editor) return;
|
|
217
|
-
if (hotkey && (0, _ishotkey.default)(hotkey, event)) {
|
|
218
|
-
selectEntityAndInsert(editor, sdk, editor.tracking.onShortcutAction);
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
};
|
|
222
|
-
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "FetchingWrappedResourceBlockCard", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return FetchingWrappedResourceBlockCard;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _react = _interop_require_wildcard(require("react"));
|
|
@@ -80,7 +80,7 @@ const InternalEntryCard = _react.memo((props)=>{
|
|
|
80
80
|
});
|
|
81
81
|
}, _fastdeepequal.default);
|
|
82
82
|
InternalEntryCard.displayName = 'ReferenceCard';
|
|
83
|
-
const
|
|
83
|
+
const FetchingWrappedResourceBlockCard = (props)=>{
|
|
84
84
|
const { link , onEntityFetchComplete } = props;
|
|
85
85
|
const { data , status , error } = (0, _fieldeditorreference.useResource)(link.linkType, link.urn);
|
|
86
86
|
_react.useEffect(()=>{
|
|
@@ -14,8 +14,8 @@ const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
|
|
|
14
14
|
const _internal = require("../../internal");
|
|
15
15
|
const _SdkProvider = require("../../SdkProvider");
|
|
16
16
|
const _linkstracking = require("../links-tracking");
|
|
17
|
-
const _FetchingWrappedResourceCard = require("../shared/FetchingWrappedResourceCard");
|
|
18
17
|
const _LinkedBlockWrapper = require("../shared/LinkedBlockWrapper");
|
|
18
|
+
const _FetchingWrappedResourceBlockCard = require("./FetchingWrappedResourceBlockCard");
|
|
19
19
|
function _interop_require_default(obj) {
|
|
20
20
|
return obj && obj.__esModule ? obj : {
|
|
21
21
|
default: obj
|
|
@@ -41,8 +41,8 @@ function LinkedResourceBlock(props) {
|
|
|
41
41
|
]);
|
|
42
42
|
return _react.default.createElement(_LinkedBlockWrapper.LinkedBlockWrapper, {
|
|
43
43
|
attributes: attributes,
|
|
44
|
-
|
|
45
|
-
card: _react.default.createElement(
|
|
44
|
+
link: element.data.target,
|
|
45
|
+
card: _react.default.createElement(_FetchingWrappedResourceBlockCard.FetchingWrappedResourceBlockCard, {
|
|
46
46
|
sdk: sdk,
|
|
47
47
|
link: link,
|
|
48
48
|
isDisabled: isDisabled,
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FetchingWrappedResourceInlineCard", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FetchingWrappedResourceInlineCard;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
const _f36components = require("@contentful/f36-components");
|
|
13
|
+
const _fieldeditorreference = require("@contentful/field-editor-reference");
|
|
14
|
+
const _fieldeditorshared = require("@contentful/field-editor-shared");
|
|
15
|
+
const _richtexttypes = require("@contentful/rich-text-types");
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
17
|
+
if (typeof WeakMap !== "function") return null;
|
|
18
|
+
var cacheBabelInterop = new WeakMap();
|
|
19
|
+
var cacheNodeInterop = new WeakMap();
|
|
20
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
21
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
22
|
+
})(nodeInterop);
|
|
23
|
+
}
|
|
24
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
25
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
29
|
+
return {
|
|
30
|
+
default: obj
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
34
|
+
if (cache && cache.has(obj)) {
|
|
35
|
+
return cache.get(obj);
|
|
36
|
+
}
|
|
37
|
+
var newObj = {};
|
|
38
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
39
|
+
for(var key in obj){
|
|
40
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
41
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
42
|
+
if (desc && (desc.get || desc.set)) {
|
|
43
|
+
Object.defineProperty(newObj, key, desc);
|
|
44
|
+
} else {
|
|
45
|
+
newObj[key] = obj[key];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
newObj.default = obj;
|
|
50
|
+
if (cache) {
|
|
51
|
+
cache.set(obj, newObj);
|
|
52
|
+
}
|
|
53
|
+
return newObj;
|
|
54
|
+
}
|
|
55
|
+
const { getEntryTitle , getEntryStatus } = _fieldeditorshared.entityHelpers;
|
|
56
|
+
function FetchingWrappedResourceInlineCard(props) {
|
|
57
|
+
const { link , onEntityFetchComplete } = props;
|
|
58
|
+
const { data , status: requestStatus } = (0, _fieldeditorreference.useResource)(link.linkType, link.urn);
|
|
59
|
+
_react.useEffect(()=>{
|
|
60
|
+
if (requestStatus === 'success') {
|
|
61
|
+
onEntityFetchComplete?.();
|
|
62
|
+
}
|
|
63
|
+
}, [
|
|
64
|
+
onEntityFetchComplete,
|
|
65
|
+
requestStatus
|
|
66
|
+
]);
|
|
67
|
+
if (requestStatus === 'error') {
|
|
68
|
+
return _react.createElement(_f36components.InlineEntryCard, {
|
|
69
|
+
title: "Entry missing or inaccessible",
|
|
70
|
+
testId: _richtexttypes.INLINES.EMBEDDED_RESOURCE,
|
|
71
|
+
isSelected: props.isSelected
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (requestStatus === 'loading' || data === undefined) {
|
|
75
|
+
return _react.createElement(_f36components.InlineEntryCard, {
|
|
76
|
+
isLoading: true
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const { resource: entry , contentType , defaultLocaleCode , space } = data;
|
|
80
|
+
const title = getEntryTitle({
|
|
81
|
+
entry,
|
|
82
|
+
contentType,
|
|
83
|
+
defaultLocaleCode,
|
|
84
|
+
localeCode: defaultLocaleCode,
|
|
85
|
+
defaultTitle: 'Untitled'
|
|
86
|
+
});
|
|
87
|
+
const status = getEntryStatus(entry?.sys);
|
|
88
|
+
return _react.createElement(_f36components.InlineEntryCard, {
|
|
89
|
+
testId: _richtexttypes.INLINES.EMBEDDED_RESOURCE,
|
|
90
|
+
isSelected: props.isSelected,
|
|
91
|
+
title: `${data.contentType.name}: ${title} (Space: ${space.name})`,
|
|
92
|
+
status: status,
|
|
93
|
+
actions: [
|
|
94
|
+
_react.createElement(_f36components.MenuItem, {
|
|
95
|
+
key: "remove",
|
|
96
|
+
onClick: props.onRemove,
|
|
97
|
+
disabled: props.isDisabled,
|
|
98
|
+
testId: "delete"
|
|
99
|
+
}, "Remove")
|
|
100
|
+
]
|
|
101
|
+
}, _react.createElement(_f36components.Text, null, title));
|
|
102
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LinkedResourceInline", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LinkedResourceInline;
|
|
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 _LinkedInlineWrapper = require("../shared/LinkedInlineWrapper");
|
|
18
|
+
const _FetchingWrappedResourceInlineCard = require("./FetchingWrappedResourceInlineCard");
|
|
19
|
+
function _interop_require_default(obj) {
|
|
20
|
+
return obj && obj.__esModule ? obj : {
|
|
21
|
+
default: obj
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function LinkedResourceInline(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
|
+
function handleRemoveClick() {
|
|
33
|
+
if (!editor) return;
|
|
34
|
+
const pathToElement = (0, _internal.findNodePath)(editor, element);
|
|
35
|
+
(0, _internal.removeNodes)(editor, {
|
|
36
|
+
at: pathToElement
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return _react.default.createElement(_LinkedInlineWrapper.LinkedInlineWrapper, {
|
|
40
|
+
attributes: attributes,
|
|
41
|
+
link: element.data.target,
|
|
42
|
+
card: _react.default.createElement(_FetchingWrappedResourceInlineCard.FetchingWrappedResourceInlineCard, {
|
|
43
|
+
sdk: sdk,
|
|
44
|
+
link: link,
|
|
45
|
+
isDisabled: isDisabled,
|
|
46
|
+
isSelected: isSelected,
|
|
47
|
+
onRemove: handleRemoveClick,
|
|
48
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
49
|
+
})
|
|
50
|
+
}, children);
|
|
51
|
+
}
|