@contentful/field-editor-rich-text 4.18.0 → 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/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/types/helpers/__tests__/toSlateDoc.test.d.ts +1 -0
- package/dist/types/helpers/toSlateDoc.d.ts +3 -0
- package/package.json +4 -3
- 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
|
@@ -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[];
|