@contentful/field-editor-rich-text 3.6.0 → 3.7.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/RichTextEditor.js +42 -53
- package/dist/cjs/SyncEditorValue.js +107 -0
- package/dist/cjs/helpers/callbacks.js +35 -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/Table/onKeyDownTable.js +14 -0
- package/dist/cjs/plugins/Text/__tests__/createTextPlugin.test.js +5 -15
- package/dist/cjs/plugins/index.js +0 -5
- package/dist/cjs/plugins/shared/FetchingWrappedResourceCard.js +11 -9
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +146 -0
- package/dist/esm/RichTextEditor.js +37 -48
- package/dist/esm/SyncEditorValue.js +53 -0
- package/dist/esm/helpers/callbacks.js +20 -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/Table/onKeyDownTable.js +15 -1
- package/dist/esm/plugins/Text/__tests__/createTextPlugin.test.js +5 -15
- package/dist/esm/plugins/index.js +0 -5
- package/dist/esm/plugins/shared/FetchingWrappedResourceCard.js +12 -10
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +98 -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/helpers/callbacks.d.ts +3 -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/shared/__tests__/FetchingWrappedResourceCard.test.d.ts +1 -0
- package/dist/types/test-utils/createEditor.d.ts +2 -0
- package/package.json +14 -14
- 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/prepareDocument.js +0 -57
- package/dist/esm/useOnValueChanged.js +0 -43
- package/dist/types/helpers/sanitizeIncomingSlateDoc.d.ts +0 -6
- 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
|
+
};
|
|
@@ -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,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
|
-
};
|
|
@@ -40,6 +40,20 @@ const onKeyDownTable = (editor, plugin)=>{
|
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
if (event.key === 'Backspace') {
|
|
44
|
+
const entry = (0, _platetable.getTableEntries)(editor, {});
|
|
45
|
+
if (entry) {
|
|
46
|
+
const { table , row , cell } = entry;
|
|
47
|
+
const cellText = (0, _queries.getText)(editor, cell[1]);
|
|
48
|
+
const isFirstCell = (0, _queries.isFirstChild)(row[1]);
|
|
49
|
+
const isFirstRow = (0, _queries.isFirstChild)(table[1]);
|
|
50
|
+
if (isFirstCell && isFirstRow && !cellText) {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
event.stopPropagation();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
43
57
|
if (event.key === 'Tab' && !event.shiftKey) {
|
|
44
58
|
event.preventDefault();
|
|
45
59
|
const entry = (0, _platetable.getTableEntries)(editor, {});
|
|
@@ -11,19 +11,9 @@ describe('delete backward', ()=>{
|
|
|
11
11
|
expected: (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, "p", (0, _testutils.jsx)("cursor", null))))
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
|
-
title: '
|
|
14
|
+
title: 'does not delete the very first paragraph',
|
|
15
15
|
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hp", null, "text")),
|
|
16
|
-
expected: (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "text")
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
title: 'deletes the empty paragraph at the beginning of the RTE followed by li',
|
|
20
|
-
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, "p1")))),
|
|
21
|
-
expected: (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "p1")))
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
title: 'deletes the empty paragraph at the beginning of the RTE followed by a blockquote',
|
|
25
|
-
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, "p1"))),
|
|
26
|
-
expected: (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "p1"))
|
|
16
|
+
expected: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hp", null, "text"))
|
|
27
17
|
}
|
|
28
18
|
];
|
|
29
19
|
const render = (children)=>(0, _testutils.jsx)("editor", null, children, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("htext", null)));
|
|
@@ -48,17 +38,17 @@ describe('delete forward', ()=>{
|
|
|
48
38
|
expected: (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "1")))
|
|
49
39
|
},
|
|
50
40
|
{
|
|
51
|
-
title: 'deletes the
|
|
41
|
+
title: 'deletes the first paragraph when followed by another paragraph',
|
|
52
42
|
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hp", null, "text")),
|
|
53
43
|
expected: (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "text")
|
|
54
44
|
},
|
|
55
45
|
{
|
|
56
|
-
title: 'deletes the
|
|
46
|
+
title: 'deletes the first paragraph when followed by li',
|
|
57
47
|
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, "p1")))),
|
|
58
48
|
expected: (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "p1")))
|
|
59
49
|
},
|
|
60
50
|
{
|
|
61
|
-
title: 'deletes the
|
|
51
|
+
title: 'deletes the first paragraph when followed by a blockquote',
|
|
62
52
|
input: (0, _testutils.jsx)("fragment", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)), (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, "p1"))),
|
|
63
53
|
expected: (0, _testutils.jsx)("hquote", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null), "p1"))
|
|
64
54
|
}
|
|
@@ -16,7 +16,6 @@ _export(exports, {
|
|
|
16
16
|
return disableCorePlugins;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
const _platecore = require("@udecode/plate-core");
|
|
20
19
|
const _plateserializerdocx = require("@udecode/plate-serializer-docx");
|
|
21
20
|
const _Break = require("./Break");
|
|
22
21
|
const _CommandPalette = require("./CommandPalette");
|
|
@@ -41,8 +40,6 @@ const _Tracking = require("./Tracking");
|
|
|
41
40
|
const _TrailingParagraph = require("./TrailingParagraph");
|
|
42
41
|
const _Voids = require("./Voids");
|
|
43
42
|
const getPlugins = (sdk, onAction, restrictedMarks)=>[
|
|
44
|
-
(0, _platecore.createDeserializeHtmlPlugin)(),
|
|
45
|
-
(0, _platecore.createDeserializeAstPlugin)(),
|
|
46
43
|
(0, _plateserializerdocx.createDeserializeDocxPlugin)(),
|
|
47
44
|
(0, _Tracking.createTrackingPlugin)(onAction),
|
|
48
45
|
(0, _DragAndDrop.createDragAndDropPlugin)(),
|
|
@@ -72,7 +69,5 @@ const getPlugins = (sdk, onAction, restrictedMarks)=>[
|
|
|
72
69
|
(0, _Normalizer.createNormalizerPlugin)()
|
|
73
70
|
];
|
|
74
71
|
const disableCorePlugins = {
|
|
75
|
-
deserializeAst: true,
|
|
76
|
-
deserializeHtml: true,
|
|
77
72
|
eventEditor: true
|
|
78
73
|
};
|
|
@@ -57,18 +57,11 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
57
57
|
return newObj;
|
|
58
58
|
}
|
|
59
59
|
const InternalEntryCard = _react.memo((props)=>{
|
|
60
|
-
if (props.status === 'loading') {
|
|
60
|
+
if (props.data === undefined || props.status === 'loading') {
|
|
61
61
|
return _react.createElement(_f36components.EntryCard, {
|
|
62
62
|
isLoading: true
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
if (!props.data || props.status === 'error') {
|
|
66
|
-
return _react.createElement(_fieldeditorreference.MissingEntityCard, {
|
|
67
|
-
entityType: "Entry",
|
|
68
|
-
isDisabled: props.isDisabled,
|
|
69
|
-
onRemove: props.onRemove
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
65
|
const { contentType , resource: entry , space } = props.data;
|
|
73
66
|
return _react.createElement(_fieldeditorreference.WrappedEntryCard, {
|
|
74
67
|
size: "default",
|
|
@@ -89,7 +82,7 @@ const InternalEntryCard = _react.memo((props)=>{
|
|
|
89
82
|
InternalEntryCard.displayName = 'ReferenceCard';
|
|
90
83
|
const FetchingWrappedResourceCard = (props)=>{
|
|
91
84
|
const { link , onEntityFetchComplete } = props;
|
|
92
|
-
const { data , status } = (0, _fieldeditorreference.useResource)(link.linkType, link.urn);
|
|
85
|
+
const { data , status , error } = (0, _fieldeditorreference.useResource)(link.linkType, link.urn);
|
|
93
86
|
_react.useEffect(()=>{
|
|
94
87
|
if (status === 'success') {
|
|
95
88
|
onEntityFetchComplete?.();
|
|
@@ -98,6 +91,15 @@ const FetchingWrappedResourceCard = (props)=>{
|
|
|
98
91
|
onEntityFetchComplete,
|
|
99
92
|
status
|
|
100
93
|
]);
|
|
94
|
+
if (status === 'error') {
|
|
95
|
+
return _react.createElement(_fieldeditorreference.ResourceEntityErrorCard, {
|
|
96
|
+
error: error,
|
|
97
|
+
linkType: link.linkType,
|
|
98
|
+
isSelected: props.isSelected,
|
|
99
|
+
isDisabled: props.isDisabled,
|
|
100
|
+
onRemove: props.onRemove
|
|
101
|
+
});
|
|
102
|
+
}
|
|
101
103
|
return _react.createElement(InternalEntryCard, {
|
|
102
104
|
data: data,
|
|
103
105
|
status: status,
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
6
|
+
require("@testing-library/jest-dom/extend-expect");
|
|
7
|
+
const _fieldeditorreference = require("@contentful/field-editor-reference");
|
|
8
|
+
const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
|
|
9
|
+
const _react1 = require("@testing-library/react");
|
|
10
|
+
const _published_content_typejson = _interop_require_default(require("../__fixtures__/published_content_type.json"));
|
|
11
|
+
const _published_entryjson = _interop_require_default(require("../__fixtures__/published_entry.json"));
|
|
12
|
+
const _spacejson = _interop_require_default(require("../__fixtures__/space.json"));
|
|
13
|
+
const _FetchingWrappedResourceCard = require("../FetchingWrappedResourceCard");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
20
|
+
if (typeof WeakMap !== "function") return null;
|
|
21
|
+
var cacheBabelInterop = new WeakMap();
|
|
22
|
+
var cacheNodeInterop = new WeakMap();
|
|
23
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
24
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
25
|
+
})(nodeInterop);
|
|
26
|
+
}
|
|
27
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
28
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
32
|
+
return {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
37
|
+
if (cache && cache.has(obj)) {
|
|
38
|
+
return cache.get(obj);
|
|
39
|
+
}
|
|
40
|
+
var newObj = {};
|
|
41
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
42
|
+
for(var key in obj){
|
|
43
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
44
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
45
|
+
if (desc && (desc.get || desc.set)) {
|
|
46
|
+
Object.defineProperty(newObj, key, desc);
|
|
47
|
+
} else {
|
|
48
|
+
newObj[key] = obj[key];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
newObj.default = obj;
|
|
53
|
+
if (cache) {
|
|
54
|
+
cache.set(obj, newObj);
|
|
55
|
+
}
|
|
56
|
+
return newObj;
|
|
57
|
+
}
|
|
58
|
+
(0, _react1.configure)({
|
|
59
|
+
testIdAttribute: 'data-test-id'
|
|
60
|
+
});
|
|
61
|
+
let sdk;
|
|
62
|
+
const resolvableEntryUrn = 'crn:contentful:::content:spaces/space-id/entries/linked-entry-urn';
|
|
63
|
+
const unknownEntryUrn = 'crn:contentful:::content:spaces/space-id/entries/unknown-entry-urn';
|
|
64
|
+
beforeEach(()=>{
|
|
65
|
+
sdk = {
|
|
66
|
+
locales: {
|
|
67
|
+
default: 'en-US'
|
|
68
|
+
},
|
|
69
|
+
cmaAdapter: (0, _fieldeditortestutils.createFakeCMAAdapter)({
|
|
70
|
+
ContentType: {
|
|
71
|
+
get: jest.fn().mockReturnValue(_published_content_typejson.default)
|
|
72
|
+
},
|
|
73
|
+
Entry: {
|
|
74
|
+
get: jest.fn().mockImplementation(({ entryId })=>{
|
|
75
|
+
if (entryId === 'linked-entry-urn') {
|
|
76
|
+
return Promise.resolve(_published_entryjson.default);
|
|
77
|
+
}
|
|
78
|
+
return Promise.reject(new Error());
|
|
79
|
+
})
|
|
80
|
+
},
|
|
81
|
+
Locale: {
|
|
82
|
+
getMany: jest.fn().mockResolvedValue({
|
|
83
|
+
items: [
|
|
84
|
+
{
|
|
85
|
+
default: true,
|
|
86
|
+
code: 'en'
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
})
|
|
90
|
+
},
|
|
91
|
+
ScheduledAction: {
|
|
92
|
+
getMany: jest.fn().mockResolvedValue({
|
|
93
|
+
items: [],
|
|
94
|
+
total: 0
|
|
95
|
+
})
|
|
96
|
+
},
|
|
97
|
+
Space: {
|
|
98
|
+
get: jest.fn().mockResolvedValue(_spacejson.default)
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
space: {
|
|
102
|
+
onEntityChanged: jest.fn()
|
|
103
|
+
},
|
|
104
|
+
navigator: {},
|
|
105
|
+
ids: {
|
|
106
|
+
space: 'space-id',
|
|
107
|
+
environment: 'environment-id'
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
function renderResourceCard({ linkType ='Contentful:Entry' , entryUrn =resolvableEntryUrn } = {}) {
|
|
112
|
+
return (0, _react1.render)(_react.createElement(_fieldeditorreference.EntityProvider, {
|
|
113
|
+
sdk: sdk
|
|
114
|
+
}, _react.createElement(_FetchingWrappedResourceCard.FetchingWrappedResourceCard, {
|
|
115
|
+
isDisabled: false,
|
|
116
|
+
isSelected: false,
|
|
117
|
+
sdk: sdk,
|
|
118
|
+
link: {
|
|
119
|
+
type: 'ResourceLink',
|
|
120
|
+
linkType: linkType,
|
|
121
|
+
urn: entryUrn
|
|
122
|
+
}
|
|
123
|
+
})));
|
|
124
|
+
}
|
|
125
|
+
test('renders entry card', async ()=>{
|
|
126
|
+
const { getByTestId , getByText } = renderResourceCard();
|
|
127
|
+
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-entry-card')).toBeDefined());
|
|
128
|
+
expect(getByText(_published_entryjson.default.fields.exField.en)).toBeDefined();
|
|
129
|
+
expect(getByText(_spacejson.default.name)).toBeDefined();
|
|
130
|
+
});
|
|
131
|
+
test('renders skeleton when no data is provided', ()=>{
|
|
132
|
+
const { getByTestId } = renderResourceCard();
|
|
133
|
+
expect(getByTestId('cf-ui-skeleton-form')).toBeDefined();
|
|
134
|
+
});
|
|
135
|
+
test('renders unsupported entity card when unsupported link is passed', async ()=>{
|
|
136
|
+
const { getByText } = renderResourceCard({
|
|
137
|
+
linkType: 'Contentful:UnsupportedLink'
|
|
138
|
+
});
|
|
139
|
+
await (0, _react1.waitFor)(()=>expect(getByText('Resource type Contentful:UnsupportedLink is currently not supported')).toBeDefined());
|
|
140
|
+
});
|
|
141
|
+
test('renders missing entity card when unknown error is returned', async ()=>{
|
|
142
|
+
const { getByTestId } = renderResourceCard({
|
|
143
|
+
entryUrn: unknownEntryUrn
|
|
144
|
+
});
|
|
145
|
+
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-missing-entry-card')).toBeDefined());
|
|
146
|
+
});
|