|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
treeNodeHeight = value path expanded \
|
|
|
|
|
lineH = 20;
|
|
|
|
|
|
|
|
|
|
valueLabel = v \ v
|
|
|
|
|
| NumberValue n \ Some n
|
|
|
|
|
| StringValue n \ Some n
|
|
|
|
|
@ -8,22 +9,22 @@ treeNodeHeight = value path expanded \
|
|
|
|
|
| _ \ None;
|
|
|
|
|
|
|
|
|
|
value
|
|
|
|
|
| RecordValue entries \
|
|
|
|
|
| RecordValue entries \ (
|
|
|
|
|
(contains path expanded)
|
|
|
|
|
| True \ lineH + (sum (map (entry \
|
|
|
|
|
(valueLabel entry.value)
|
|
|
|
|
| Some _ \ lineH
|
|
|
|
|
| None \ lineH + (treeNodeHeight entry.value (path & "." & entry.key) expanded)
|
|
|
|
|
) entries))
|
|
|
|
|
| False \ lineH
|
|
|
|
|
| ListValue items \
|
|
|
|
|
| False \ lineH)
|
|
|
|
|
| ListValue items \ (
|
|
|
|
|
(contains path expanded)
|
|
|
|
|
| True \ lineH + (sum (mapWithIndex (item i \
|
|
|
|
|
(valueLabel item)
|
|
|
|
|
| Some _ \ lineH
|
|
|
|
|
| None \ lineH + (treeNodeHeight item (path & "." & (show i)) expanded)
|
|
|
|
|
) items))
|
|
|
|
|
| False \ lineH
|
|
|
|
|
| False \ lineH)
|
|
|
|
|
| _ \ lineH;
|
|
|
|
|
|
|
|
|
|
treeNode = config \
|
|
|
|
|
@ -94,12 +95,18 @@ treeNode = config \
|
|
|
|
|
tree = config \
|
|
|
|
|
ui.stateful {
|
|
|
|
|
key = "tree-" & config.path,
|
|
|
|
|
init = { expanded = [] },
|
|
|
|
|
init = { expanded = [], scrollY = 0 },
|
|
|
|
|
|
|
|
|
|
update = state event \ event
|
|
|
|
|
| Toggle path \ ((contains path state.expanded)
|
|
|
|
|
| True \ { state = state.{ expanded = filter (p \ p != path) state.expanded }, emit = [] }
|
|
|
|
|
| False \ { state = state.{ expanded = [path, ...state.expanded] }, emit = [] })
|
|
|
|
|
|
|
|
|
|
| Scrolled delta \ (
|
|
|
|
|
totalH = treeNodeHeight config.value config.path state.expanded;
|
|
|
|
|
newY = max 0 (min (totalH - config.h) (state.scrollY + delta.deltaY));
|
|
|
|
|
{ state = state.{ scrollY = newY }, emit = [] })
|
|
|
|
|
|
|
|
|
|
| _ \ { state = state, emit = [] },
|
|
|
|
|
|
|
|
|
|
view = state emit \
|
|
|
|
|
@ -111,7 +118,9 @@ tree = config \
|
|
|
|
|
h = config.h,
|
|
|
|
|
totalWidth = config.w,
|
|
|
|
|
totalHeight = totalH,
|
|
|
|
|
onScroll = _ \ noOp,
|
|
|
|
|
scrollX = 0,
|
|
|
|
|
scrollY = state.scrollY,
|
|
|
|
|
onScroll = delta \ emit (Scrolled delta),
|
|
|
|
|
child = treeNode { value = config.value, path = config.path, depth = 0, expanded = state.expanded, onToggle = onToggle }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|