diff --git a/.changeset/kind-hornets-thank.md b/.changeset/kind-hornets-thank.md new file mode 100644 index 0000000..0f682c2 --- /dev/null +++ b/.changeset/kind-hornets-thank.md @@ -0,0 +1,5 @@ +--- +"astro-portabletext": minor +--- + +Feat: Unhandled `style` in `Block` component and unhandled `markType` in `Mark` component now throws an error diff --git a/component/lib/components/Block.astro b/component/lib/components/Block.astro index 0896f2f..ef258f4 100644 --- a/component/lib/components/Block.astro +++ b/component/lib/components/Block.astro @@ -1,10 +1,12 @@ --- -import type { PtBlockComponentProps } from "../types"; -import UnknownBlockStyle from "./UnknownBlockStyle.astro"; +import type { BlockStyle, Props } from "../types"; +import { throwError } from "../internal"; +import { unknownBlockStyleWarning } from "../warnings"; -const { node, astroClass, ...props } = Astro.props as PtBlockComponentProps; +const { node, astroClass } = Astro.props as Props; const attrs = { class: astroClass }; const styleIs = (style: string) => style === node.style; +const err = unknownBlockStyleWarning(node.style); --- {styleIs("h1") ? ( @@ -24,5 +26,5 @@ const styleIs = (style: string) => style === node.style; ) : styleIs("normal") ? (

) : ( - + throwError(err) )} diff --git a/component/lib/components/Mark.astro b/component/lib/components/Mark.astro index b8561ba..8ad5194 100644 --- a/component/lib/components/Mark.astro +++ b/component/lib/components/Mark.astro @@ -1,9 +1,12 @@ --- -import UnknownMark from "./UnknownMark.astro"; +import { Mark, Props } from "../types"; +import { throwError } from "../internal"; +import { unknownMarkWarning } from "../warnings"; -const { node, astroClass, ...props } = Astro.props; +const { node, astroClass } = Astro.props as Props; const attrs = { class: astroClass }; const markTypeIs = (markType: string) => markType === node.markType; +const err = unknownMarkWarning(node.markType); --- {markTypeIs("code") ? ( @@ -11,7 +14,7 @@ const markTypeIs = (markType: string) => markType === node.markType; ) : markTypeIs("em") ? ( ) : markTypeIs("link") ? ( - + ).markDef.href} {...attrs}> ) : markTypeIs("strike-through") ? ( ) : markTypeIs("strong") ? ( @@ -19,5 +22,5 @@ const markTypeIs = (markType: string) => markType === node.markType; ) : markTypeIs("underline") ? ( ) : ( - + throwError(err) )}