Skip to content

Commit e914da0

Browse files
committed
refactor: clean up astroNode
1 parent 2dfc226 commit e914da0

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

packages/integrations/markdoc/components/astroNode.ts

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
1+
import type { ComponentInstance } from 'astro';
2+
import Markdoc from '@markdoc/markdoc';
13
import type { RenderableTreeNode, Tag } from '@markdoc/markdoc';
24
import { escape } from 'html-escaper';
35

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-
176
export type ComponentRenderer =
18-
| AstroComponentFactory
7+
| ComponentInstance['default']
198
| {
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>;
2511
};
2612

2713
export type AstroNode =
2814
| string
2915
| {
30-
component: AstroComponentFactory;
16+
component: ComponentInstance['default'];
3117
props: Record<string, any>;
3218
children: AstroNode[];
3319
}
@@ -43,7 +29,7 @@ export function createAstroNode(
4329
): AstroNode {
4430
if (typeof node === 'string' || typeof node === 'number') {
4531
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)) {
4733
return '';
4834
}
4935

0 commit comments

Comments
 (0)