1
+ import type { ComponentInstance } from 'astro' ;
2
+ import Markdoc from '@markdoc/markdoc' ;
1
3
import type { RenderableTreeNode , Tag } from '@markdoc/markdoc' ;
2
4
import { escape } from 'html-escaper' ;
3
5
4
- // TODO: expose `AstroComponentFactory` type from core
5
- type AstroComponentFactory = ( props : Record < string , any > ) => any & {
6
- isAstroComponentFactory : true ;
7
- } ;
8
-
9
- /**
10
- * Copied from Markdoc Tag.isTag implementation
11
- * to avoid dragging the whole 40kb Markdoc bundle into your build!
12
- */
13
- function isTag ( tag : any ) : tag is Tag {
14
- return ! ! ( tag ?. $$mdtype === 'Tag' ) ;
15
- }
16
-
17
6
export type ComponentRenderer =
18
- | AstroComponentFactory
7
+ | ComponentInstance [ 'default' ]
19
8
| {
20
- component : AstroComponentFactory ;
21
- props ?( params : {
22
- attributes : Record < string , any > ;
23
- getTreeNode ( ) : import ( '@markdoc/markdoc' ) . Tag ;
24
- } ) : Record < string , any > ;
9
+ component : ComponentInstance [ 'default' ] ;
10
+ props ?( params : { attributes : Record < string , any > ; getTreeNode ( ) : Tag } ) : Record < string , any > ;
25
11
} ;
26
12
27
13
export type AstroNode =
28
14
| string
29
15
| {
30
- component : AstroComponentFactory ;
16
+ component : ComponentInstance [ 'default' ] ;
31
17
props : Record < string , any > ;
32
18
children : AstroNode [ ] ;
33
19
}
@@ -43,7 +29,7 @@ export function createAstroNode(
43
29
) : AstroNode {
44
30
if ( typeof node === 'string' || typeof node === 'number' ) {
45
31
return escape ( String ( node ) ) ;
46
- } else if ( node === null || typeof node !== 'object' || ! isTag ( node ) ) {
32
+ } else if ( node === null || typeof node !== 'object' || ! Markdoc . Tag . isTag ( node ) ) {
47
33
return '' ;
48
34
}
49
35
0 commit comments