17c366bb by Adam Heath

Add directly callable helper component that can be used to wrap nodes.

1 parent f7398eea
......@@ -4,8 +4,9 @@ import Match from './match.astro'
import Node from './node.astro'
import Replace from './replace.astro'
import External from './external.astro'
import WrapNode from './wrap-node.astro'
export { Children, Custom, Match, Node, Replace, External }
export { Children, Custom, Match, Node, Replace, External, WrapNode }
import type { NodeType } from 'ultrahtml'
type SlotHandler = (string, NodeType) => Promise<Any>
......
......@@ -22,7 +22,7 @@ const [ Component, componentArgs, componentContent ] = Array.isArray(slotName) ?
---
{
typeof Component === 'string' ? <Component {...node.attributes} {...componentArgs}>{componentContent}</Component>
: Component ? (<Component {...componentArgs} debug={nextDebug} replacers={replacers} slotHandler={slotHandler}/>)
: Component ? (<Component {...componentArgs} parent={parent} node={node} index={index} debug={nextDebug} replacers={replacers} slotHandler={slotHandler} special={special}>{componentContent}</Component>)
: slotName ? slotHandler(slotName, node, special)
: <Node parent={parent} node={node} index={index} debug={nextDebug} replacers={replacers} slotHandler={slotHandler} special={special}/>
}
......
---
import Node from './node.astro'
const { props: { Wrapped, args, ...rest } } = Astro
---
<Wrapped {...args}>
<Node {...rest}/>
</Wrapped>