render.astro
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
---
import { ELEMENT_NODE, TEXT_NODE } from 'ultrahtml'
import Children from './children.astro'
export const slotPassThrough = (Astro) => (slotName, node) => {
console.log('calling slot', { slotName, node, Astro })
return Astro.slots.render('default', [ slotName, node ])
}
const { props: { debug = false, parent = null, node, index = 0, replacers, slotHandler } } = Astro
const { name: Name, attributes } = node
if (debug) {
console.log('trying to match against', {node})
}
let slotName
for (const [ matcher, handler ] of replacers) {
if (debug) console.log('attempting matcher', matcher.toString())
if (matcher(node, parent, index, false)) {
if (debug) console.log('matched')
slotName = handler
}
}
//const slotCallback = slotPassThrough(Astro)
---
{
slotName ? slotHandler(slotName, node)
: node.type === TEXT_NODE ? <Fragment set:html={node.value}/>
: node.type === ELEMENT_NODE ? (
node.isSelfClosingTag ? <Name {...attributes}/>
: <Name {...attributes}>
<Children parent={node} children={node.children} replacers={replacers} slotHandler={slotHandler}/>
</Name>
) : (
<Children parent={node} children={node.children} replacers={replacers} slotHandler={slotHandler}/>
)
}