diff --git a/src/app/hooks/useFocus.ts b/src/app/hooks/useFocus.ts index 447d9965..0463f914 100644 --- a/src/app/hooks/useFocus.ts +++ b/src/app/hooks/useFocus.ts @@ -10,9 +10,11 @@ export function useFocus(): [boolean, () => unknown] { useEffect(() => { if (active) { document.body.addEventListener('click', hider) + document.body.addEventListener('contextmenu', hider) } return () => { document.body.removeEventListener('click', hider) + document.body.removeEventListener('contextmenu', hider) } }, [active]) diff --git a/src/app/schema/renderHtml.tsx b/src/app/schema/renderHtml.tsx index c1240ba8..d36459af 100644 --- a/src/app/schema/renderHtml.tsx +++ b/src/app/schema/renderHtml.tsx @@ -1,6 +1,7 @@ import type { BooleanHookParams, EnumOption, Hook, INode, NumberHookParams, StringHookParams, ValidationOption } from '@mcschema/core' import { DataModel, MapNode, ModelPath, ObjectNode, Path, relativePath, StringNode } from '@mcschema/core' import type { ComponentChildren, JSX } from 'preact' +import { Btn } from '../components' import { Octicon } from '../components/Octicon' import { useFocus } from '../hooks' import { locale } from '../Locales' @@ -272,6 +273,14 @@ type TreeNodeProps = { function TreeNode({ label, schema, path, value, lang, states, children }: TreeNodeProps) { const type = schema.type(path) const category = schema.category(path) + const context = path.getContext().join('.') + + const [active, setActive] = useFocus() + const onContextMenu = (evt: MouseEvent) => { + evt.preventDefault() + setActive() + } + const [prefix, suffix, body] = schema.hook(renderHtml, path, value, lang, states) return