@@ -47,21 +47,14 @@ public struct LiveContext<R: CustomRegistry> {
47
47
return coordinator. builder. fromNodes ( element. children ( ) , context: self )
48
48
}
49
49
50
- public func buildChildren(
51
- of element: ElementNode ,
52
- `where` condition: ( NodeChildrenSequence . Element ) -> Bool
53
- ) -> some View {
54
- ForEach ( element. children ( ) . filter ( condition) . map ( { ( $0. id, $0. children ( ) ) } ) , id: \. 0 ) { subChildren in
55
- coordinator. builder. fromNodes ( subChildren. 1 , context: self )
56
- }
57
- }
58
-
59
50
public func buildChildren(
60
51
of element: ElementNode ,
61
52
withTagName tagName: String ,
62
- namespace: String ? = nil
53
+ namespace: String ? = nil ,
54
+ includeDefaultSlot: Bool = false
63
55
) -> some View {
64
- buildChildren ( of: element, where: { child in
56
+ let children = element. children ( )
57
+ let namedSlotChildren = children. filter ( { child in
65
58
if case let . element( element) = child. data,
66
59
element. namespace == namespace,
67
60
element. tag == tagName
@@ -71,15 +64,21 @@ public struct LiveContext<R: CustomRegistry> {
71
64
return false
72
65
}
73
66
} )
74
- }
75
-
76
- public func buildChildren( of element: ElementNode , defaultSlotFor tagName: String ) -> some View {
77
- buildChildren ( of: element, where: {
67
+ let defaultSlotChildren = children. filter ( {
78
68
if case let . element( element) = $0. data {
79
- return element. namespace != " menu "
69
+ return element. namespace != tagName
80
70
} else {
81
71
return true
82
72
}
83
73
} )
74
+ if namedSlotChildren. isEmpty && includeDefaultSlot {
75
+ return ForEach ( defaultSlotChildren. map ( { ( $0. id, $0. children ( ) ) } ) , id: \. 0 ) { subChildren in
76
+ coordinator. builder. fromNodes ( subChildren. 1 , context: self )
77
+ }
78
+ } else {
79
+ return ForEach ( namedSlotChildren. map ( { ( $0. id, $0. children ( ) ) } ) , id: \. 0 ) { subChildren in
80
+ coordinator. builder. fromNodes ( subChildren. 1 , context: self )
81
+ }
82
+ }
84
83
}
85
84
}
0 commit comments