@@ -21,56 +21,18 @@ struct NavigationLink<R: CustomRegistry>: View {
21
21
22
22
@ViewBuilder
23
23
public var body : some View {
24
- if let linkOpts = LinkOptions ( element: element) ,
25
- context. coordinator. session. config. navigationMode. supportsLinkState ( linkOpts. state) ,
26
- let url = linkOpts. url ( in: context)
27
- {
28
- SwiftUI . NavigationLink ( value: LiveNavigationEntry ( url: url, coordinator: context. coordinator) ) {
24
+ if let href = element. attributeValue ( for: " href " ) . flatMap ( {
25
+ URL ( string: $0, relativeTo: context. coordinator. url) ? . appending ( path: " " ) . absoluteURL
26
+ } ) {
27
+ SwiftUI . NavigationLink (
28
+ value: LiveNavigationEntry (
29
+ url: href,
30
+ coordinator: context. coordinator
31
+ )
32
+ ) {
29
33
context. buildChildren ( of: element)
30
34
}
31
35
. disabled ( element. attribute ( named: " disabled " ) != nil )
32
- } else {
33
- // if there are no link options, or the coordinator doesn't support the required navigation, we don't show anything
34
- }
35
- }
36
- }
37
-
38
- struct LinkOptions {
39
- let kind : LinkKind
40
- let state : LiveRedirect . Kind
41
- let href : String
42
-
43
- init ? ( element: ElementNode ) {
44
- guard let kindStr = element. attributeValue ( for: " data-phx-link " ) ,
45
- let kind = LinkKind ( rawValue: kindStr) ,
46
- let stateStr = element. attributeValue ( for: " data-phx-link-state " ) ,
47
- let state = LiveRedirect . Kind ( rawValue: stateStr) else {
48
- return nil
49
- }
50
- self . kind = kind
51
- self . state = state
52
- self . href = element. attributeValue ( for: " data-phx-href " ) !
53
- }
54
-
55
- @MainActor
56
- func url< R: CustomRegistry > ( in context: LiveContext < R > ) -> URL ? {
57
- . init( string: href, relativeTo: context. coordinator. url) ? . appending ( path: " / " ) . absoluteURL
58
- }
59
- }
60
-
61
- enum LinkKind : String {
62
- case redirect
63
- }
64
-
65
- extension LiveSessionConfiguration . NavigationMode {
66
- func supportsLinkState( _ state: LiveRedirect . Kind ) -> Bool {
67
- switch self {
68
- case . disabled:
69
- return false
70
- case . replaceOnly:
71
- return state == . replace
72
- case . enabled, . splitView:
73
- return true
74
36
}
75
37
}
76
38
}
0 commit comments