diff --git a/src/cg/06-inspector.cg b/src/cg/06-inspector.cg index 57d06ea..f394147 100644 --- a/src/cg/06-inspector.cg +++ b/src/cg/06-inspector.cg @@ -32,7 +32,7 @@ inspector = config \ # totalHeight = (len sourceLines) * lineHeight, totalHeight = 1000, onScroll = _ \ noOp, - child = tree { value = reflected, depth = 0 }, + child = tree { value = reflected, depth = 0, path = config.name }, # child = ui.column { # gap = 0, # children = map (line \ diff --git a/src/cg/06-tree.cg b/src/cg/06-tree.cg index b3364a0..f097634 100644 --- a/src/cg/06-tree.cg +++ b/src/cg/06-tree.cg @@ -20,16 +20,34 @@ tree = config \ | ConstructorValue { tag = tag } \ simple tag "#fc6" | FunctionValue _ \ simple "" "#888" | RecordValue entries \ - ui.column { - gap = 0, - children = map (entry \ - (valueLabel entry.value) - | Some label \ simple (entry.key & " = " & label) "#aaa" - | None \ ui.column { gap = 0, children = [ - simple entry.key "#aaa", - tree { value = entry.value, depth = depth + 1 } - ]} - ) entries + ui.stateful { + key = "tree-" & config.path, + init = { collapsed = True }, + + update = state event \ event + | Clicked _ \ ( + _ = debug "clicked on node" []; + { state = state.{ collapsed = (not state.collapsed) }, emit = [] } + ) + | _ \ { state = state, emit = [] }, + + view = state \ + ui.column { + gap = 0, + children = [ + simple ((state.collapsed | True \ "▶ " | False \ "▼ ") & (show (len entries)) & " fields") "#888", + ...(state.collapsed + | True \ [] + | False \ map (entry \ + (valueLabel entry.value) + | Some label \ simple (entry.key & " = " & label) "#aaa" + | None \ ui.column { gap = 0, children = [ + simple entry.key "#aaa", + tree { value = entry.value, depth = depth + 1, path = config.path & "." & entry.key } + ]} + ) entries) + ] + } } | ListValue items \ ui.column { diff --git a/src/runtime-compiled.ts b/src/runtime-compiled.ts index 616b9c7..d9c263d 100644 --- a/src/runtime-compiled.ts +++ b/src/runtime-compiled.ts @@ -93,15 +93,13 @@ export function runAppCompiled(canvas: HTMLCanvasElement, store: any) { } const viewResult = instance.view(instance.state); - let viewUI = viewResult; - - if (ui.focusable) { - viewUI = { - kind: 'clickable', - child: viewUI, - onClick: (coords: any) => ({ _tag: 'FocusAndClick', _0: fullKey, _1: coords }) - }; - } + const viewUI = { + kind: 'clickable', + child: viewResult, + onClick: ui.focusable + ? (coords: any) => ({ _tag: 'FocusAndClick', _0: fullKey, _1: coords }) + : (coords: any) => ({ _tag: 'ClickOnly', _0: fullKey, _1: coords }) + }; return expandStateful(viewUI, [...path, ui.key], renderedKeys); } @@ -191,6 +189,13 @@ export function runAppCompiled(canvas: HTMLCanvasElement, store: any) { return; } + if (event._tag === 'ClickOnly') { + const componentKey = event._0; + const coords = event._1; + handleComponentEvent(componentKey, { _tag: 'Clicked', _0: coords }); + return; + } + if (event._tag === 'Rebind') { store.rebind(event._0, event._1, event._2); return;