From 36025cdb66a6e4a9eb62a40bc4bc357fd22e250e Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Tue, 14 Feb 2023 09:25:38 -0500 Subject: [PATCH] refactor: clean up astroNode --- .../markdoc/components/astroNode.ts | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/packages/integrations/markdoc/components/astroNode.ts b/packages/integrations/markdoc/components/astroNode.ts index 3d359a9c1..58a800fa4 100644 --- a/packages/integrations/markdoc/components/astroNode.ts +++ b/packages/integrations/markdoc/components/astroNode.ts @@ -1,33 +1,19 @@ +import type { ComponentInstance } from 'astro'; +import Markdoc from '@markdoc/markdoc'; import type { RenderableTreeNode, Tag } from '@markdoc/markdoc'; import { escape } from 'html-escaper'; -// TODO: expose `AstroComponentFactory` type from core -type AstroComponentFactory = (props: Record) => any & { - isAstroComponentFactory: true; -}; - -/** - * Copied from Markdoc Tag.isTag implementation - * to avoid dragging the whole 40kb Markdoc bundle into your build! - */ -function isTag(tag: any): tag is Tag { - return !!(tag?.$$mdtype === 'Tag'); -} - export type ComponentRenderer = - | AstroComponentFactory + | ComponentInstance['default'] | { - component: AstroComponentFactory; - props?(params: { - attributes: Record; - getTreeNode(): import('@markdoc/markdoc').Tag; - }): Record; + component: ComponentInstance['default']; + props?(params: { attributes: Record; getTreeNode(): Tag }): Record; }; export type AstroNode = | string | { - component: AstroComponentFactory; + component: ComponentInstance['default']; props: Record; children: AstroNode[]; } @@ -43,7 +29,7 @@ export function createAstroNode( ): AstroNode { if (typeof node === 'string' || typeof node === 'number') { return escape(String(node)); - } else if (node === null || typeof node !== 'object' || !isTag(node)) { + } else if (node === null || typeof node !== 'object' || !Markdoc.Tag.isTag(node)) { return ''; }