@contentful/field-editor-rich-text 4.17.9 → 4.19.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 +5 -9
- package/dist/cjs/helpers/__tests__/toSlateDoc.test.js +436 -0
- package/dist/cjs/helpers/toSlateDoc.js +180 -0
- package/dist/cjs/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +2 -1
- package/dist/cjs/plugins/Hyperlink/HyperlinkModal.js +2 -1
- package/dist/cjs/plugins/shared/FetchingWrappedResourceCard.js +2 -1
- package/dist/esm/RichTextEditor.js +5 -9
- package/dist/esm/helpers/__tests__/toSlateDoc.test.js +432 -0
- package/dist/esm/helpers/toSlateDoc.js +170 -0
- package/dist/esm/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +2 -1
- package/dist/esm/plugins/Hyperlink/HyperlinkModal.js +2 -1
- package/dist/esm/plugins/shared/FetchingWrappedResourceCard.js +2 -1
- package/dist/types/helpers/__tests__/toSlateDoc.test.d.ts +1 -0
- package/dist/types/helpers/toSlateDoc.d.ts +3 -0
- package/package.json +5 -4
- package/dist/cjs/helpers/toSlateValue.js +0 -51
- package/dist/esm/helpers/toSlateValue.js +0 -36
- package/dist/types/helpers/toSlateValue.d.ts +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-rich-text",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.19.0",
|
|
4
4
|
"source": "./src/index.tsx",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@contentful/f36-icons": "^5.4.1",
|
|
45
45
|
"@contentful/f36-tokens": "^5.1.0",
|
|
46
46
|
"@contentful/f36-utils": "^5.1.0",
|
|
47
|
-
"@contentful/field-editor-reference": "^6.
|
|
47
|
+
"@contentful/field-editor-reference": "^6.19.0",
|
|
48
48
|
"@contentful/field-editor-shared": "^2.17.0",
|
|
49
49
|
"@contentful/rich-text-plain-text-renderer": "^17.0.0",
|
|
50
50
|
"@contentful/rich-text-types": "^17.2.5",
|
|
@@ -71,7 +71,8 @@
|
|
|
71
71
|
"slate": "0.94.1",
|
|
72
72
|
"slate-history": "0.100.0",
|
|
73
73
|
"slate-hyperscript": "0.77.0",
|
|
74
|
-
"slate-react": "0.102.0"
|
|
74
|
+
"slate-react": "0.102.0",
|
|
75
|
+
"use-deep-compare": "^1.3.0"
|
|
75
76
|
},
|
|
76
77
|
"peerDependencies": {
|
|
77
78
|
"@lingui/core": "^5.3.0",
|
|
@@ -90,5 +91,5 @@
|
|
|
90
91
|
"publishConfig": {
|
|
91
92
|
"registry": "https://npm.pkg.github.com/"
|
|
92
93
|
},
|
|
93
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "cfe222b9d0e4ca9d69e62697c48bbeaca1e52b51"
|
|
94
95
|
}
|
|
@@ -1,51 +0,0 @@
|
|
|
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 = /*#__PURE__*/ _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
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { toSlatejsDocument } from '@contentful/contentful-slatejs-adapter';
|
|
2
|
-
import { EMPTY_DOCUMENT } from '@contentful/rich-text-types';
|
|
3
|
-
import schema from '../constants/Schema';
|
|
4
|
-
const isTextElement = (node)=>'text' in node;
|
|
5
|
-
function sanitizeIncomingSlateDoc(nodes = []) {
|
|
6
|
-
return nodes.map((node)=>{
|
|
7
|
-
if (isTextElement(node)) {
|
|
8
|
-
return node;
|
|
9
|
-
}
|
|
10
|
-
if (node.children?.length === 0) {
|
|
11
|
-
return {
|
|
12
|
-
...node,
|
|
13
|
-
children: [
|
|
14
|
-
{
|
|
15
|
-
text: '',
|
|
16
|
-
data: {}
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
...node,
|
|
23
|
-
children: sanitizeIncomingSlateDoc(node?.children)
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
export const toSlateValue = (doc)=>{
|
|
28
|
-
const hasContent = (doc)=>{
|
|
29
|
-
return (doc?.content || []).length > 0;
|
|
30
|
-
};
|
|
31
|
-
const slateDoc = toSlatejsDocument({
|
|
32
|
-
document: doc && hasContent(doc) ? doc : EMPTY_DOCUMENT,
|
|
33
|
-
schema
|
|
34
|
-
});
|
|
35
|
-
return sanitizeIncomingSlateDoc(slateDoc);
|
|
36
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Document } from '@contentful/rich-text-types';
|
|
2
|
-
import { Element } from '../internal/types';
|
|
3
|
-
/**
|
|
4
|
-
* Converts a Contentful rich text document to the corresponding slate editor
|
|
5
|
-
* value
|
|
6
|
-
*/
|
|
7
|
-
export declare const toSlateValue: (doc?: Document) => Element[];
|