@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
|
@@ -25,14 +25,14 @@ const _emotion = require("emotion");
|
|
|
25
25
|
const _fastdeepequal = _interop_require_default(require("fast-deep-equal"));
|
|
26
26
|
const _noop = _interop_require_default(require("lodash/noop"));
|
|
27
27
|
const _ContentfulEditorProvider = require("./ContentfulEditorProvider");
|
|
28
|
-
const
|
|
28
|
+
const _callbacks = require("./helpers/callbacks");
|
|
29
|
+
const _toSlateValue = require("./helpers/toSlateValue");
|
|
29
30
|
const _plugins = require("./plugins");
|
|
30
|
-
const _prepareDocument = require("./prepareDocument");
|
|
31
31
|
const _RichTextEditorstyles = require("./RichTextEditor.styles");
|
|
32
32
|
const _SdkProvider = require("./SdkProvider");
|
|
33
|
+
const _SyncEditorValue = require("./SyncEditorValue");
|
|
33
34
|
const _Toolbar = _interop_require_default(require("./Toolbar"));
|
|
34
35
|
const _StickyToolbarWrapper = _interop_require_default(require("./Toolbar/components/StickyToolbarWrapper"));
|
|
35
|
-
const _useOnValueChanged = require("./useOnValueChanged");
|
|
36
36
|
function _interop_require_default(obj) {
|
|
37
37
|
return obj && obj.__esModule ? obj : {
|
|
38
38
|
default: obj
|
|
@@ -79,84 +79,73 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
79
79
|
}
|
|
80
80
|
const ConnectedRichTextEditor = (props)=>{
|
|
81
81
|
const id = (0, _ContentfulEditorProvider.getContentfulEditorId)(props.sdk);
|
|
82
|
-
const plugins = _react.
|
|
82
|
+
const plugins = _react.useMemo(()=>(0, _plugins.getPlugins)(props.sdk, props.onAction ?? _noop.default, props.restrictedMarks), [
|
|
83
83
|
props.sdk,
|
|
84
84
|
props.onAction,
|
|
85
85
|
props.restrictedMarks
|
|
86
86
|
]);
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
setPendingExternalUpdate(true);
|
|
102
|
-
(0, _prepareDocument.setEditorContent)(editor, (0, _prepareDocument.documentToEditorValue)(props.value));
|
|
87
|
+
const handleChange = props.onChange;
|
|
88
|
+
const isFirstRender = _react.useRef(true);
|
|
89
|
+
const value = (0, _toSlateValue.toSlateValue)(props.value);
|
|
90
|
+
const onChange = _react.useMemo(()=>(0, _callbacks.createOnChangeCallback)((document)=>{
|
|
91
|
+
if (!isFirstRender.current && handleChange) {
|
|
92
|
+
handleChange(document);
|
|
93
|
+
}
|
|
94
|
+
}), [
|
|
95
|
+
handleChange
|
|
96
|
+
]);
|
|
97
|
+
const firstInteractionHandler = _react.useCallback(()=>{
|
|
98
|
+
isFirstRender.current = false;
|
|
103
99
|
}, [
|
|
104
|
-
|
|
105
|
-
id
|
|
100
|
+
isFirstRender
|
|
106
101
|
]);
|
|
107
102
|
const classNames = (0, _emotion.cx)(_RichTextEditorstyles.styles.editor, props.minHeight !== undefined ? (0, _emotion.css)({
|
|
108
103
|
minHeight: props.minHeight
|
|
109
104
|
}) : undefined, props.isDisabled ? _RichTextEditorstyles.styles.disabled : _RichTextEditorstyles.styles.enabled, props.isToolbarHidden && _RichTextEditorstyles.styles.hiddenToolbar);
|
|
110
|
-
|
|
111
|
-
if (!isFirstRender) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
(0, _platecore.getPlateActions)(id).value((0, _prepareDocument.normalizeEditorValue)((0, _prepareDocument.documentToEditorValue)(props.value), {
|
|
115
|
-
plugins,
|
|
116
|
-
disableCorePlugins: _plugins.disableCorePlugins
|
|
117
|
-
}));
|
|
118
|
-
}, [
|
|
119
|
-
isFirstRender,
|
|
120
|
-
plugins,
|
|
121
|
-
id,
|
|
122
|
-
props.value
|
|
123
|
-
]);
|
|
124
|
-
return _react.default.createElement(_SdkProvider.SdkProvider, {
|
|
105
|
+
return _react.createElement(_SdkProvider.SdkProvider, {
|
|
125
106
|
sdk: props.sdk
|
|
126
|
-
}, _react.
|
|
107
|
+
}, _react.createElement(_ContentfulEditorProvider.ContentfulEditorIdProvider, {
|
|
127
108
|
value: id
|
|
128
|
-
}, _react.
|
|
109
|
+
}, _react.createElement("div", {
|
|
129
110
|
className: _RichTextEditorstyles.styles.root,
|
|
130
111
|
"data-test-id": "rich-text-editor"
|
|
131
|
-
}, _react.
|
|
112
|
+
}, _react.createElement(_platecore.PlateProvider, {
|
|
132
113
|
id: id,
|
|
114
|
+
initialValue: value,
|
|
115
|
+
normalizeInitialValue: true,
|
|
133
116
|
plugins: plugins,
|
|
134
117
|
disableCorePlugins: _plugins.disableCorePlugins,
|
|
118
|
+
onChange: onChange
|
|
119
|
+
}, !props.isToolbarHidden && _react.createElement(_StickyToolbarWrapper.default, {
|
|
120
|
+
isDisabled: props.isDisabled
|
|
121
|
+
}, _react.createElement(_Toolbar.default, {
|
|
122
|
+
isDisabled: props.isDisabled
|
|
123
|
+
})), _react.createElement(_SyncEditorValue.SyncEditorValue, {
|
|
124
|
+
incomingValue: value
|
|
125
|
+
}), _react.createElement(_platecore.Plate, {
|
|
126
|
+
id: id,
|
|
135
127
|
editableProps: {
|
|
136
128
|
className: classNames,
|
|
137
|
-
readOnly: props.isDisabled
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
isDisabled: props.isDisabled
|
|
144
|
-
}))
|
|
145
|
-
}))));
|
|
129
|
+
readOnly: props.isDisabled,
|
|
130
|
+
onKeyDown: firstInteractionHandler,
|
|
131
|
+
onChange: firstInteractionHandler,
|
|
132
|
+
onClick: firstInteractionHandler
|
|
133
|
+
}
|
|
134
|
+
})))));
|
|
146
135
|
};
|
|
147
136
|
const RichTextEditor = (props)=>{
|
|
148
137
|
const { sdk , isInitiallyDisabled , onAction , restrictedMarks , ...otherProps } = props;
|
|
149
|
-
const isEmptyValue =
|
|
138
|
+
const isEmptyValue = _react.useCallback((value)=>!value || (0, _fastdeepequal.default)(value, _richtexttypes.EMPTY_DOCUMENT), []);
|
|
150
139
|
const id = (0, _ContentfulEditorProvider.getContentfulEditorId)(props.sdk);
|
|
151
|
-
return _react.
|
|
140
|
+
return _react.createElement(_fieldeditorreference.EntityProvider, {
|
|
152
141
|
sdk: sdk
|
|
153
|
-
}, _react.
|
|
142
|
+
}, _react.createElement(_fieldeditorshared.FieldConnector, {
|
|
154
143
|
throttle: 0,
|
|
155
144
|
field: sdk.field,
|
|
156
145
|
isInitiallyDisabled: isInitiallyDisabled,
|
|
157
146
|
isEmptyValue: isEmptyValue,
|
|
158
147
|
isEqualValues: _fastdeepequal.default
|
|
159
|
-
}, ({ lastRemoteValue , disabled , setValue })=>_react.
|
|
148
|
+
}, ({ lastRemoteValue , disabled , setValue })=>_react.createElement(ConnectedRichTextEditor, {
|
|
160
149
|
...otherProps,
|
|
161
150
|
key: `rich-text-editor-${id}`,
|
|
162
151
|
value: lastRemoteValue,
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "SyncEditorValue", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return SyncEditorValue;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
const _fastdeepequal = _interop_require_default(require("fast-deep-equal"));
|
|
13
|
+
const _hooks = require("./internal/hooks");
|
|
14
|
+
const _misc = require("./internal/misc");
|
|
15
|
+
const _queries = require("./internal/queries");
|
|
16
|
+
const _transforms = require("./internal/transforms");
|
|
17
|
+
function _interop_require_default(obj) {
|
|
18
|
+
return obj && obj.__esModule ? obj : {
|
|
19
|
+
default: obj
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
23
|
+
if (typeof WeakMap !== "function") return null;
|
|
24
|
+
var cacheBabelInterop = new WeakMap();
|
|
25
|
+
var cacheNodeInterop = new WeakMap();
|
|
26
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
27
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
28
|
+
})(nodeInterop);
|
|
29
|
+
}
|
|
30
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
31
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
35
|
+
return {
|
|
36
|
+
default: obj
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
40
|
+
if (cache && cache.has(obj)) {
|
|
41
|
+
return cache.get(obj);
|
|
42
|
+
}
|
|
43
|
+
var newObj = {};
|
|
44
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
45
|
+
for(var key in obj){
|
|
46
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
47
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
48
|
+
if (desc && (desc.get || desc.set)) {
|
|
49
|
+
Object.defineProperty(newObj, key, desc);
|
|
50
|
+
} else {
|
|
51
|
+
newObj[key] = obj[key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
newObj.default = obj;
|
|
56
|
+
if (cache) {
|
|
57
|
+
cache.set(obj, newObj);
|
|
58
|
+
}
|
|
59
|
+
return newObj;
|
|
60
|
+
}
|
|
61
|
+
const setEditorContent = (editor, nodes)=>{
|
|
62
|
+
(0, _misc.withoutNormalizing)(editor, ()=>{
|
|
63
|
+
const children = [
|
|
64
|
+
...editor.children
|
|
65
|
+
];
|
|
66
|
+
children.forEach((node)=>editor.apply({
|
|
67
|
+
type: 'remove_node',
|
|
68
|
+
path: [
|
|
69
|
+
0
|
|
70
|
+
],
|
|
71
|
+
node
|
|
72
|
+
}));
|
|
73
|
+
if (nodes) {
|
|
74
|
+
const nodesArray = (0, _queries.isNode)(nodes) ? [
|
|
75
|
+
nodes
|
|
76
|
+
] : nodes;
|
|
77
|
+
nodesArray.forEach((node, i)=>{
|
|
78
|
+
editor.apply({
|
|
79
|
+
type: 'insert_node',
|
|
80
|
+
path: [
|
|
81
|
+
i
|
|
82
|
+
],
|
|
83
|
+
node
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const point = (0, _queries.getEndPoint)(editor, []);
|
|
88
|
+
if (point) {
|
|
89
|
+
(0, _transforms.select)(editor, point);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
const SyncEditorValue = ({ incomingValue })=>{
|
|
94
|
+
const editor = (0, _hooks.usePlateSelectors)().editor();
|
|
95
|
+
const lastIncomingValue = _react.useRef(incomingValue);
|
|
96
|
+
_react.useEffect(()=>{
|
|
97
|
+
if ((0, _fastdeepequal.default)(lastIncomingValue.current, incomingValue)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
lastIncomingValue.current = incomingValue;
|
|
101
|
+
setEditorContent(editor, incomingValue);
|
|
102
|
+
}, [
|
|
103
|
+
editor,
|
|
104
|
+
incomingValue
|
|
105
|
+
]);
|
|
106
|
+
return null;
|
|
107
|
+
};
|
|
@@ -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,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createOnChangeCallback", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createOnChangeCallback;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _contentfulslatejsadapter = require("@contentful/contentful-slatejs-adapter");
|
|
12
|
+
const _fastdeepequal = _interop_require_default(require("fast-deep-equal"));
|
|
13
|
+
const _debounce = _interop_require_default(require("lodash/debounce"));
|
|
14
|
+
const _Schema = _interop_require_default(require("../constants/Schema"));
|
|
15
|
+
const _removeInternalMarks = require("./removeInternalMarks");
|
|
16
|
+
function _interop_require_default(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : {
|
|
18
|
+
default: obj
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const createOnChangeCallback = (handler)=>{
|
|
22
|
+
let cache = null;
|
|
23
|
+
return (0, _debounce.default)((document)=>{
|
|
24
|
+
if ((0, _fastdeepequal.default)(document, cache)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
cache = document;
|
|
28
|
+
const doc = (0, _removeInternalMarks.removeInternalMarks)((0, _contentfulslatejsadapter.toContentfulDocument)({
|
|
29
|
+
document: document,
|
|
30
|
+
schema: _Schema.default
|
|
31
|
+
}));
|
|
32
|
+
const cleanedDocument = (0, _removeInternalMarks.removeInternalMarks)(doc);
|
|
33
|
+
handler?.(cleanedDocument);
|
|
34
|
+
}, 500);
|
|
35
|
+
};
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "toSlateValue", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return toSlateValue;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _contentfulslatejsadapter = require("@contentful/contentful-slatejs-adapter");
|
|
12
|
+
const _richtexttypes = require("@contentful/rich-text-types");
|
|
13
|
+
const _Schema = _interop_require_default(require("../constants/Schema"));
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const isTextElement = (node)=>'text' in node;
|
|
20
|
+
function sanitizeIncomingSlateDoc(nodes = []) {
|
|
21
|
+
return nodes.map((node)=>{
|
|
22
|
+
if (isTextElement(node)) {
|
|
23
|
+
return node;
|
|
24
|
+
}
|
|
25
|
+
if (node.children?.length === 0) {
|
|
26
|
+
return {
|
|
27
|
+
...node,
|
|
28
|
+
children: [
|
|
29
|
+
{
|
|
30
|
+
text: '',
|
|
31
|
+
data: {}
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
...node,
|
|
38
|
+
children: sanitizeIncomingSlateDoc(node?.children)
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const toSlateValue = (doc)=>{
|
|
43
|
+
const hasContent = (doc)=>{
|
|
44
|
+
return (doc?.content || []).length > 0;
|
|
45
|
+
};
|
|
46
|
+
const slateDoc = (0, _contentfulslatejsadapter.toSlatejsDocument)({
|
|
47
|
+
document: doc && hasContent(doc) ? doc : _richtexttypes.EMPTY_DOCUMENT,
|
|
48
|
+
schema: _Schema.default
|
|
49
|
+
});
|
|
50
|
+
return sanitizeIncomingSlateDoc(slateDoc);
|
|
51
|
+
};
|
|
@@ -17,6 +17,9 @@ _export(exports, {
|
|
|
17
17
|
},
|
|
18
18
|
usePlateEditorState: function() {
|
|
19
19
|
return usePlateEditorState;
|
|
20
|
+
},
|
|
21
|
+
usePlateSelectors: function() {
|
|
22
|
+
return usePlateSelectors;
|
|
20
23
|
}
|
|
21
24
|
});
|
|
22
25
|
const _platecore = _interop_require_wildcard(require("@udecode/plate-core"));
|
|
@@ -61,5 +64,12 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
61
64
|
return newObj;
|
|
62
65
|
}
|
|
63
66
|
const useReadOnly = _slatereact.useReadOnly;
|
|
64
|
-
const usePlateEditorRef =
|
|
65
|
-
|
|
67
|
+
const usePlateEditorRef = (id)=>{
|
|
68
|
+
return _platecore.usePlateEditorRef(id);
|
|
69
|
+
};
|
|
70
|
+
const usePlateEditorState = (id)=>{
|
|
71
|
+
return _platecore.usePlateEditorState(id);
|
|
72
|
+
};
|
|
73
|
+
const usePlateSelectors = (id)=>{
|
|
74
|
+
return _platecore.usePlateSelectors(id);
|
|
75
|
+
};
|
|
@@ -29,9 +29,6 @@ _export(exports, {
|
|
|
29
29
|
},
|
|
30
30
|
mockPlugin: function() {
|
|
31
31
|
return mockPlugin;
|
|
32
|
-
},
|
|
33
|
-
getPlateSelectors: function() {
|
|
34
|
-
return getPlateSelectors;
|
|
35
32
|
}
|
|
36
33
|
});
|
|
37
34
|
const _platecore = _interop_require_wildcard(require("@udecode/plate-core"));
|
|
@@ -98,6 +95,3 @@ const fromDOMPoint = (editor, domPoint, opts = {
|
|
|
98
95
|
const mockPlugin = (plugin)=>{
|
|
99
96
|
return _platecore.mockPlugin(plugin);
|
|
100
97
|
};
|
|
101
|
-
const getPlateSelectors = (id)=>{
|
|
102
|
-
return _platecore.getPlateSelectors(id);
|
|
103
|
-
};
|
|
@@ -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
|
}
|