-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Views.StateHookViews.fs
233 lines (212 loc) · 9.58 KB
/
Views.StateHookViews.fs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
namespace Avalonia.FuncUI.Diagnostics
open Avalonia.FuncUI
open Avalonia.FuncUI.Diagnostics
open Avalonia
open Avalonia.Controls
open Avalonia.FuncUI.DSL
open Avalonia.FuncUI.Types
open Avalonia.Layout
open Avalonia.Media
type internal StateHookViews =
static member private valuePresenterView (value: IReadable<obj>) =
Component.create ("value_presenter_view", fun ctx ->
let value = ctx.usePassedRead value
Border.create [
Border.background "#333333"
Border.cornerRadius 5.0
Border.padding 10.0
Border.contextMenu (
ContextMenu.create [
ContextMenu.viewItems [
MenuItem.create [
MenuItem.header "Copy"
MenuItem.onClick (fun args ->
Async.StartImmediate (
async {
let json = System.Text.Json.JsonSerializer.Serialize value.Current
do! Async.AwaitTask (TopLevel.GetTopLevel(args.Source :?> Visual).Clipboard.SetTextAsync json)
}
)
)
]
]
]
)
Border.child (
TextBlock.create [
TextBlock.foreground "#dddddd"
TextBlock.fontSize 12.0
TextBlock.fontFamily (FontFamily "Fira Code, monospace")
TextBlock.textWrapping TextWrapping.Wrap
TextBlock.text $"{value.Current}"
]
)
]
:> IView
)
static member private anyReadableView (name: string, readable: IAnyReadable) =
Component.create ($"any_readable_view_{readable.InstanceId}", fun ctx ->
let currentValue = ctx.useState (readable.CurrentAny, true)
ctx.useEffect(
handler = (fun _ ->
currentValue.Set readable.CurrentAny
),
triggers = [
EffectTrigger.AfterChange readable
]
)
StackPanel.create [
StackPanel.orientation Orientation.Vertical
StackPanel.spacing 5.0
StackPanel.children [
TextBlock.create [
TextBlock.foreground "#ecf0f1"
TextBlock.text $"{name}"
]
StateHookViews.valuePresenterView currentValue
]
]
:> IView
)
static member private stateHookSourcesView (hook: StateHook) =
Component.create ("state_hook_sources", fun _ctx ->
TreeView.create [
TreeView.itemTemplate (
DataTemplateView<_>.create (
(fun info -> Seq.ofList info.Source.InstanceType.Sources),
(fun info ->
StackPanel.create [
StackPanel.orientation Orientation.Vertical
StackPanel.spacing 5.0
StackPanel.children [
TextBlock.create [
TextBlock.foreground "#2ecc71"
TextBlock.text $"{Reflector.fullTypeName(info.Source.GetType())}"
]
StateHookViews.anyReadableView (info.Name, info.Source)
]
]
)
)
)
TreeView.dataItems hook.State.Value.InstanceType.Sources
]
:> IView
)
static member private stateHookHeader (hook: StateHook) =
Component.create ($"state_hook_details_header_{hook.Identity}", fun ctx ->
let currentValue = ctx.useState (hook.State.Value.CurrentAny, true)
ctx.useEffect(
handler = (fun _ ->
currentValue.Set hook.State.Value.CurrentAny
),
triggers = [
EffectTrigger.AfterChange hook.State.Value
]
)
StackPanel.create [
StackPanel.orientation Orientation.Vertical
StackPanel.spacing 5.0
StackPanel.children [
TextBlock.create [
TextBlock.foreground "#2ecc71"
TextBlock.text $"{Reflector.fullTypeName(hook.State.Value.GetType())}"
]
StackPanel.create [
StackPanel.orientation Orientation.Horizontal
StackPanel.spacing 5.0
StackPanel.children [
TextBlock.create [
TextBlock.opacity 0.8
TextBlock.text "Render on change:"
]
TextBlock.create [
TextBlock.foreground (if hook.RenderOnChange then "#1abc9c" else "#f39c12")
TextBlock.text $"{hook.RenderOnChange}"
]
TextBlock.create [
TextBlock.opacity 0.8
TextBlock.text "Hook Identity:"
]
TextBlock.create [
TextBlock.foreground "#1abc9c"
TextBlock.text $"{hook.Identity}"
]
]
]
StateHookViews.valuePresenterView currentValue
]
] :> IView
)
static member stateHookDetailsView (hook: StateHook) =
Component.create ($"state_hook_detail_view_{hook.Identity}", fun _ctx ->
StackPanel.create [
StackPanel.spacing 10.0
StackPanel.children [
StateHookViews.stateHookHeader hook
match hook.State.Value.InstanceType with
| InstanceType.Adapter _ ->
TextBlock.create [
TextBlock.text "Adapter sources:"
]
StackPanel.create [
StackPanel.orientation Orientation.Vertical
StackPanel.spacing 5.0
StackPanel.children [
StateHookViews.stateHookSourcesView hook
]
]
| _ ->
()
]
]
:> IView
)
static member stateHookView (hook: StateHook) =
Component.create ($"state_hook_detail_view_{hook.Identity}", fun _ctx ->
Border.create [
Border.padding 5.0
Border.child (
StackPanel.create [
StackPanel.spacing 10.0
StackPanel.children [
StateHookViews.stateHookHeader hook
if not hook.State.Value.InstanceType.Sources.IsEmpty then
Button.create [
Button.content (
StackPanel.create [
StackPanel.orientation Orientation.Horizontal
StackPanel.spacing 5.0
StackPanel.children [
IconView.create (Icons.openInNewWindow, 16)
TextBlock.create [
TextBlock.text "Details"
]
]
]
)
Button.onClick (fun _ ->
let childWindow =
ChildWindow (
title = "hook details",
comp = (
Component (fun _ctx ->
ScrollViewer.create [
ScrollViewer.padding 5.0
ScrollViewer.content (
StateHookViews.stateHookDetailsView hook
)
]
:> IView
)
)
)
childWindow.Show ()
)
]
]
]
)
]
:> IView
)