mirror of
https://github.com/misode/misode.github.io.git
synced 2026-05-01 21:23:12 +00:00
Re-add context menu
This commit is contained in:
@@ -10,9 +10,11 @@ export function useFocus(): [boolean, () => unknown] {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (active) {
|
if (active) {
|
||||||
document.body.addEventListener('click', hider)
|
document.body.addEventListener('click', hider)
|
||||||
|
document.body.addEventListener('contextmenu', hider)
|
||||||
}
|
}
|
||||||
return () => {
|
return () => {
|
||||||
document.body.removeEventListener('click', hider)
|
document.body.removeEventListener('click', hider)
|
||||||
|
document.body.removeEventListener('contextmenu', hider)
|
||||||
}
|
}
|
||||||
}, [active])
|
}, [active])
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { BooleanHookParams, EnumOption, Hook, INode, NumberHookParams, StringHookParams, ValidationOption } from '@mcschema/core'
|
import type { BooleanHookParams, EnumOption, Hook, INode, NumberHookParams, StringHookParams, ValidationOption } from '@mcschema/core'
|
||||||
import { DataModel, MapNode, ModelPath, ObjectNode, Path, relativePath, StringNode } from '@mcschema/core'
|
import { DataModel, MapNode, ModelPath, ObjectNode, Path, relativePath, StringNode } from '@mcschema/core'
|
||||||
import type { ComponentChildren, JSX } from 'preact'
|
import type { ComponentChildren, JSX } from 'preact'
|
||||||
|
import { Btn } from '../components'
|
||||||
import { Octicon } from '../components/Octicon'
|
import { Octicon } from '../components/Octicon'
|
||||||
import { useFocus } from '../hooks'
|
import { useFocus } from '../hooks'
|
||||||
import { locale } from '../Locales'
|
import { locale } from '../Locales'
|
||||||
@@ -272,6 +273,14 @@ type TreeNodeProps = {
|
|||||||
function TreeNode({ label, schema, path, value, lang, states, children }: TreeNodeProps) {
|
function TreeNode({ label, schema, path, value, lang, states, children }: TreeNodeProps) {
|
||||||
const type = schema.type(path)
|
const type = schema.type(path)
|
||||||
const category = schema.category(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)
|
const [prefix, suffix, body] = schema.hook(renderHtml, path, value, lang, states)
|
||||||
return <div class={`node ${type}-node`} data-category={category}>
|
return <div class={`node ${type}-node`} data-category={category}>
|
||||||
<div class="node-header">
|
<div class="node-header">
|
||||||
@@ -279,7 +288,16 @@ function TreeNode({ label, schema, path, value, lang, states, children }: TreeNo
|
|||||||
<HelpPopup lang={lang} path={path} />
|
<HelpPopup lang={lang} path={path} />
|
||||||
{children}
|
{children}
|
||||||
{prefix}
|
{prefix}
|
||||||
<label>{label ?? pathLocale(lang, path, `${path.last()}`)}</label>
|
<label onContextMenu={onContextMenu}>
|
||||||
|
{label ?? pathLocale(lang, path, `${path.last()}`)}
|
||||||
|
{active && <div class="node-menu">
|
||||||
|
<div class="menu-item">
|
||||||
|
<Btn icon="clippy" onClick={() => navigator.clipboard.writeText(context)} />
|
||||||
|
Context:
|
||||||
|
<span class="menu-item-context">{context}</span>
|
||||||
|
</div>
|
||||||
|
</div>}
|
||||||
|
</label>
|
||||||
{suffix}
|
{suffix}
|
||||||
</div>
|
</div>
|
||||||
{body && <div class="node-body">{body}</div>}
|
{body && <div class="node-body">{body}</div>}
|
||||||
|
|||||||
Reference in New Issue
Block a user