forked from thompsonsj/slate-serializers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayload.ts
55 lines (53 loc) · 1.2 KB
/
payload.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Element, Text } from 'domhandler'
import { config as defaultConfig } from './default'
import { SlateToDomConfig } from '../..'
/**
* Configuration for Payload CMS
*
* Tested for v1.1.21
*/
export const config: SlateToDomConfig = {
...defaultConfig,
elementTransforms: {
...defaultConfig.elementTransforms,
link: ({ node, children = [] }) => {
const attrs: any = {}
if (node.linkType) {
attrs['data-link-type'] = node.linkType
}
if (node.newTab) {
attrs.target = '_blank'
}
return new Element(
'a',
{
href: node.url,
...attrs,
},
children,
)
},
upload: ({ node, children = [] }) => {
const attrs: any = {}
if (node.value?.mimeType && node.value?.url) {
if (node.value?.mimeType.match(/^image/)) {
return new Element(
'img',
{
src: node.value?.url,
},
)
} else {
return new Element(
'a',
{
href: node.value?.url,
},
[new Text(node.value?.filename)]
)
}
}
},
},
defaultTag: 'p',
}