List add button

This commit is contained in:
Misode
2024-10-23 20:14:10 +02:00
parent 6ea2b7929c
commit 6151fbcea4
3 changed files with 162 additions and 27 deletions

View File

@@ -1,9 +1,10 @@
import type { DocAndNode } from '@spyglassmc/core'
import { JsonFileNode } from '@spyglassmc/json'
import { useCallback, useErrorBoundary } from 'preact/hooks'
import { useCallback, useErrorBoundary, useMemo } from 'preact/hooks'
import { useLocale } from '../../contexts/index.js'
import { useDocAndNode, useSpyglass } from '../../contexts/Spyglass.jsx'
import type { AstEdit } from '../../services/Spyglass.js'
import type { McdocContext } from './McdocRenderer.jsx'
import { McdocRoot } from './McdocRenderer.jsx'
type TreePanelProps = {
@@ -34,7 +35,14 @@ export function Tree({ docAndNode, onError }: TreePanelProps) {
service.applyEdit(docAndNode.doc.uri, edit)
}, [service, docAndNode])
const ctx = useMemo<McdocContext | undefined>(() => {
if (!service) {
return undefined
}
return { doc: docAndNode.doc, symbols: service.getSymbols() }
}, [docAndNode, service])
return <div class="tree node-root" data-cy="tree">
<McdocRoot node={fileChild.children[0]} makeEdit={makeEdit} />
{ctx && <McdocRoot node={fileChild.children[0]} makeEdit={makeEdit} ctx={ctx} />}
</div>
}