MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / DisplayStructureTree

Function DisplayStructureTree

packages/frontend/src/structure.tsx:500–826  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

498}
499
500const DisplayStructureTree: s.Component = () => {
501
502 const [containerScroll, setContainerScroll] = s.createSignal({
503 top: 0,
504 height: 0,
505 }, {
506 equals: (a, b) => a.top === b.top && a.height === b.height
507 })
508
509 const remSize = useRemSize()
510 const getContainerTopMargin = () => remSize() * v_margin_in_rem
511 const getRowHeight = () => remSize() * row_height_in_rem
512
513 const updateScrollData = (el: HTMLElement): void => {
514 setContainerScroll({
515 top: Math.max(el.scrollTop - getContainerTopMargin(), 0),
516 height: el.clientHeight,
517 })
518 }
519
520 const [collapsed, setCollapsed] = s.createSignal(new WeakSet<Node>(), {equals: false})
521
522 const isCollapsed = (node: Node): boolean => collapsed().has(node)
523
524 const toggleCollapsed = (node: Node): void => {
525 setCollapsed(set => {
526 set.delete(node) || set.add(node)
527 return set
528 })
529 }
530
531 const ctx = useAppCtx()
532 const {inspector, hovered} = ctx
533 const structure = useStructure()
534
535 let lastVirtualStart = 0
536 let lastVirtualEnd = 0
537 let lastInspectedIndex = 0
538 let lastFocusedNodeData: ReturnType<typeof getFocusedNodeData>
539
540 s.createEffect(() => {
541 ;({start: lastVirtualStart, end: lastVirtualEnd} = virtual())
542 lastInspectedIndex = inspectedIndex()
543 })
544
545 const collapsedList = s.createMemo((prev: Node[] = []) => {
546 // position of focused component needs to be calculated right before the collapsed list is recalculated
547 // to be compated with it after the changes
548 // `list data` has to be updated in an effect, so that this memo can run before it, instead of reading it here
549 // because of solid's pull-based memo behavior (reading from a memo invalidates it, and it's dependencies)
550 lastFocusedNodeData = getFocusedNodeData(
551 prev,
552 lastVirtualStart,
553 lastVirtualEnd,
554 lastInspectedIndex,
555 )
556
557 const all_nodes_list = structure.state().nodeList

Callers

nothing calls this directly

Calls 11

useAppCtxFunction · 0.90
atomFunction · 0.90
useStructureFunction · 0.85
getFocusedNodeDataFunction · 0.85
getVirtualVarsFunction · 0.85
getRowHeightFunction · 0.85
getNodeIndexByIdFunction · 0.85
getContainerTopMarginFunction · 0.85
isCollapsedFunction · 0.85
toggleCollapsedFunction · 0.85
updateScrollDataFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…