@octane-xplat/context-menu 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -163
- package/package.json +9 -9
- package/src/AppKitContextMenu.macos.tsrx +34 -32
- package/src/AppKitContextMenu.tsrx +2 -0
- package/src/ContextMenu.tsrx +2 -0
- package/src/ContextMenu.web.tsrx +165 -159
- package/src/MaterialContextMenu.android.tsrx +117 -113
- package/src/MaterialContextMenu.tsrx +2 -0
- package/src/SwiftUIContextMenu.ios.tsrx +93 -90
- package/src/SwiftUIContextMenu.tsrx +2 -0
- package/src/android/index.ts +3 -3
- package/src/android/types.ts +27 -27
- package/src/context-menu-owner.macos.ts +194 -171
- package/src/ios/types.ts +27 -27
- package/src/macos/types.ts +26 -26
- package/src/web/types.ts +26 -26
package/README.md
CHANGED
|
@@ -1,166 +1,5 @@
|
|
|
1
1
|
# `@octane-xplat/context-menu`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
`.contextMenu` on iOS, a Material 3 `DropdownMenu` anchored to a hosted
|
|
5
|
-
trigger on Android, an in-page right-click menu on web, and a real
|
|
6
|
-
experimental `NSMenu` source path on native macOS. Native macOS activation,
|
|
7
|
-
responder routing, keyboard/VoiceOver and installed-consumer qualification is
|
|
8
|
-
pending.
|
|
3
|
+
[Documentation](https://octane-xplat.goddardai.org/package-context-menu).
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
that renders a control, then import `SwiftUIContextMenu` from
|
|
12
|
-
`@octane-xplat/context-menu/ios`, `MaterialContextMenu` from
|
|
13
|
-
`@octane-xplat/context-menu/android`, `ContextMenu` from
|
|
14
|
-
`@octane-xplat/context-menu/web`, or `AppKitContextMenu` from
|
|
15
|
-
`@octane-xplat/context-menu/macos` in the matching platform-suffixed file.
|
|
16
|
-
|
|
17
|
-
Install in your existing app with Bun. The macOS entry requires a
|
|
18
|
-
[native AppKit app](https://octane-xplat.goddardai.org/macos-native); the renderer supplies
|
|
19
|
-
its native menu attachment.
|
|
20
|
-
|
|
21
|
-
```sh
|
|
22
|
-
bun add @octane-xplat/context-menu
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
```tsx
|
|
26
|
-
/** @jsxImportSource @octane-xplat/jsx */
|
|
27
|
-
// SwiftUIContextMenuExample.ios.tsx
|
|
28
|
-
import { SwiftUIContextMenu } from '@octane-xplat/context-menu/ios'
|
|
29
|
-
import { Text } from '@octane-xplat/ui'
|
|
30
|
-
|
|
31
|
-
export function Menu() {
|
|
32
|
-
return (
|
|
33
|
-
<SwiftUIContextMenu
|
|
34
|
-
trigger={() => <Text>Trip actions</Text>}
|
|
35
|
-
items={[{ id: 'rename', title: 'Rename' }]}
|
|
36
|
-
onItemSelected={(id) => console.log(id)}
|
|
37
|
-
/>
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
```tsx
|
|
43
|
-
/** @jsxImportSource @octane-xplat/jsx */
|
|
44
|
-
// MaterialContextMenuExample.android.tsx
|
|
45
|
-
import { MaterialContextMenu } from '@octane-xplat/context-menu/android'
|
|
46
|
-
import { Text } from '@octane-xplat/ui'
|
|
47
|
-
|
|
48
|
-
export function Menu() {
|
|
49
|
-
return (
|
|
50
|
-
<MaterialContextMenu
|
|
51
|
-
activation="singlePress"
|
|
52
|
-
trigger={() => <Text>Trip actions</Text>}
|
|
53
|
-
items={[{ id: 'rename', title: 'Rename' }]}
|
|
54
|
-
onItemSelected={(id) => console.log(id)}
|
|
55
|
-
/>
|
|
56
|
-
)
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
```tsx
|
|
61
|
-
// ContextMenuExample.web.tsx
|
|
62
|
-
import { ContextMenu } from '@octane-xplat/context-menu/web'
|
|
63
|
-
import { Text } from '@octane-xplat/ui'
|
|
64
|
-
|
|
65
|
-
export function Menu() {
|
|
66
|
-
return (
|
|
67
|
-
<ContextMenu
|
|
68
|
-
activation="singlePress"
|
|
69
|
-
trigger={() => <Text>Trip actions</Text>}
|
|
70
|
-
items={[{ id: 'rename', title: 'Rename' }]}
|
|
71
|
-
onItemSelected={(id) => console.log(id)}
|
|
72
|
-
/>
|
|
73
|
-
)
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
```tsx
|
|
78
|
-
// AppKitContextMenuExample.macos.tsx
|
|
79
|
-
import { useState } from 'octane'
|
|
80
|
-
import { AppKitContextMenu } from '@octane-xplat/context-menu/macos'
|
|
81
|
-
import { Text, VStack } from '@octane-xplat/ui'
|
|
82
|
-
|
|
83
|
-
export function Menu() {
|
|
84
|
-
const [last, setLast] = useState('none')
|
|
85
|
-
return (
|
|
86
|
-
<VStack gap={2}>
|
|
87
|
-
<AppKitContextMenu
|
|
88
|
-
id="trip-actions"
|
|
89
|
-
trigger={() => <Text>Trip actions</Text>}
|
|
90
|
-
items={[{ id: 'rename', title: 'Rename' }]}
|
|
91
|
-
onItemSelected={setLast}
|
|
92
|
-
/>
|
|
93
|
-
<Text>{`Last action: ${last}`}</Text>
|
|
94
|
-
</VStack>
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Menu items are plain data (`{id, title, destructive, disabled, divider}`),
|
|
100
|
-
reported back through `onItemSelected(id)`. The iOS entry also accepts an
|
|
101
|
-
optional `preview` render function (iOS 16+):
|
|
102
|
-
|
|
103
|
-
```tsx
|
|
104
|
-
/** @jsxImportSource @octane-xplat/jsx */
|
|
105
|
-
// Actions.ios.tsx
|
|
106
|
-
import { SwiftUIContextMenu } from '@octane-xplat/context-menu/ios'
|
|
107
|
-
import { Text } from '@octane-xplat/ui'
|
|
108
|
-
|
|
109
|
-
export function Actions() {
|
|
110
|
-
return (
|
|
111
|
-
<SwiftUIContextMenu
|
|
112
|
-
trigger={() => <Text>Trip actions</Text>}
|
|
113
|
-
preview={() => <Text>Kyoto trip</Text>}
|
|
114
|
-
items={[{ id: 'delete', title: 'Delete', destructive: true, divider: true }]}
|
|
115
|
-
onItemSelected={(id) => console.log(id)}
|
|
116
|
-
/>
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
- iOS: long-press activation (platform native); optional `preview` render fn
|
|
122
|
-
(iOS 16+).
|
|
123
|
-
- Android: `activation` prop — `'longPress'` (default) or `'singlePress'`,
|
|
124
|
-
detected at parent level so interactive children in the trigger keep
|
|
125
|
-
their own taps.
|
|
126
|
-
- Web: right-click (`longPress`) or click (`singlePress`) opens the menu at
|
|
127
|
-
the pointer.
|
|
128
|
-
- macOS: right-click — the NSMenu is the view's `menu`, so AppKit owns
|
|
129
|
-
activation and disabled-item dimming; the trigger renders inline.
|
|
130
|
-
|
|
131
|
-
On native macOS, item IDs must be unique strings and titles must be strings.
|
|
132
|
-
Changing menu content or its record `id` retires the old session; callback-only
|
|
133
|
-
renders preserve it and use the current handler. Empty items remove this
|
|
134
|
-
wrapper's menu. Invalid data or a missing native attachment shows a generic
|
|
135
|
-
unavailable message while the trigger remains inline. Native child editing menus
|
|
136
|
-
and nested wrappers keep their own menu slots. See the
|
|
137
|
-
[native macOS lifecycle and remaining limits](../../docs/platform/context-menu.md#native-macos-menus).
|
|
138
|
-
|
|
139
|
-
```tsx
|
|
140
|
-
// NoteActions.macos.tsx — use a record-specific identifier when reusing a row.
|
|
141
|
-
import { AppKitContextMenu } from '@octane-xplat/context-menu/macos'
|
|
142
|
-
import { Text } from '@octane-xplat/ui'
|
|
143
|
-
export function NoteActions({ noteID }: { noteID: string }) {
|
|
144
|
-
return <AppKitContextMenu id={`note-actions-${noteID}`} items={[{ id: 'rename', title: 'Rename' }]}
|
|
145
|
-
trigger={() => <Text>Right-click this note</Text>} onItemSelected={(id) => console.log(noteID, id)} />
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
## How the native menus work
|
|
150
|
-
|
|
151
|
-
On iOS and Android this leaf exercises subtree embedding: `trigger` is a render
|
|
152
|
-
fn whose octane output mounts into a
|
|
153
|
-
detached root, and the native menu wraps that subtree — SwiftUI resolves it
|
|
154
|
-
through `NativeScriptViewFactory` (the same factory the swift-ui plugin's
|
|
155
|
-
`NativeScriptView` uses), and Android through the leaf's
|
|
156
|
-
`XplatViewRegistry` + `AndroidView`.
|
|
157
|
-
The macOS trigger stays in its original tree, with the menu attached only at
|
|
158
|
-
its wrapper. AppKit's documented unhandled right-click propagation supplies
|
|
159
|
-
ancestor lookup; actual custom-host routing remains unqualified.
|
|
160
|
-
|
|
161
|
-
The native implementations are adapted from `@expo/ui` (MIT,
|
|
162
|
-
`packages/expo-ui` sdk-57): `ios/ContextMenu/ContextMenu.swift` and
|
|
163
|
-
`android/.../ui/menu/DropdownMenu*.kt`. Attribution headers sit on the
|
|
164
|
-
ported files.
|
|
165
|
-
|
|
166
|
-
Continue with [Platform context menus](https://octane-xplat.goddardai.org/context-menu).
|
|
5
|
+
[API reference](https://octane-xplat.goddardai.org/api-context-menu).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octane-xplat/context-menu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Platform-specific context menu controls for Octane xplat",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -48,24 +48,24 @@
|
|
|
48
48
|
"test:packed": "node tests/packed-consumer.mjs",
|
|
49
49
|
"pack:check": "tsrx-typegen --pack-check",
|
|
50
50
|
"typegen": "tsrx-typegen --target context-menu",
|
|
51
|
-
"typecheck": "
|
|
51
|
+
"typecheck": "tsc --runExternalCode --noEmit -p tsconfig.types.json"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@nativescript/jetpack-compose": "1.0.0-beta.0",
|
|
55
55
|
"@nativescript/swift-ui": "4.0.2",
|
|
56
|
-
"@octane-xplat/jsx": "0.
|
|
57
|
-
"@octane-xplat/lib": "0.
|
|
56
|
+
"@octane-xplat/jsx": "0.20.0",
|
|
57
|
+
"@octane-xplat/lib": "0.20.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@nativescript-community/octane": "0.2.5",
|
|
61
61
|
"@nativescript/core": "9.1.3",
|
|
62
|
-
"@octane-xplat/macos-
|
|
62
|
+
"@octane-xplat/macos-appkit": "0.20.0",
|
|
63
63
|
"@octanejs/vite-plugin": "0.5.0",
|
|
64
64
|
"octane": "0.16.3",
|
|
65
|
-
"tsrx-typegen": "0.
|
|
66
|
-
"typescript": "
|
|
67
|
-
"vite": "8.3.
|
|
68
|
-
"@tsrx/
|
|
65
|
+
"tsrx-typegen": "0.6.1",
|
|
66
|
+
"typescript": "7.1.0-beta",
|
|
67
|
+
"vite": "8.3.6",
|
|
68
|
+
"@tsrx/content-mapper": "0.1.2"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
@@ -13,38 +13,40 @@ const host = (): any => (globalThis as any).__xplatAppKit ?? {}
|
|
|
13
13
|
* so AppKit drives right-click activation and disabled items. Items are
|
|
14
14
|
* serialized data; selection reports through `onItemSelected`. */
|
|
15
15
|
export function AppKitContextMenu(props: AppKitContextMenuProps): unknown @{
|
|
16
|
-
|
|
17
|
-
latest.current = props
|
|
18
|
-
const [, rerender] = useState(0)
|
|
19
|
-
const owner = useMemo(
|
|
20
|
-
() =>
|
|
21
|
-
createContextMenuOwner({
|
|
22
|
-
props: () => latest.current,
|
|
23
|
-
attach: () =>
|
|
24
|
-
typeof host().attachContextMenu === 'function'
|
|
25
|
-
? (host().attachContextMenu as ContextMenuAttach)
|
|
26
|
-
: undefined,
|
|
27
|
-
status: () => rerender((n) => n + 1),
|
|
28
|
-
}),
|
|
29
|
-
[],
|
|
30
|
-
)
|
|
16
|
+
const latest = useRef(props)
|
|
31
17
|
|
|
32
|
-
|
|
33
|
-
useEffect(() => () => owner.dispose(), [])
|
|
18
|
+
latest.current = props
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
20
|
+
const [, rerender] = useState(0)
|
|
21
|
+
const owner = useMemo(
|
|
22
|
+
() =>
|
|
23
|
+
createContextMenuOwner({
|
|
24
|
+
props: () => latest.current,
|
|
25
|
+
attach: () =>
|
|
26
|
+
typeof host().attachContextMenu === 'function'
|
|
27
|
+
? (host().attachContextMenu as ContextMenuAttach)
|
|
28
|
+
: undefined,
|
|
29
|
+
status: () => rerender((n) => n + 1),
|
|
30
|
+
}),
|
|
31
|
+
[],
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
useLayoutEffect(() => owner.update(), null)
|
|
35
|
+
useEffect(() => () => owner.dispose(), [])
|
|
36
|
+
|
|
37
|
+
<masonview
|
|
38
|
+
ref={owner.bind}
|
|
39
|
+
id={props.id}
|
|
40
|
+
className={cx('xplat-appkit-context-menu', props.className)}
|
|
41
|
+
style={props.style}
|
|
42
|
+
accessibilityLabel={props.accessibilityLabel}
|
|
43
|
+
>
|
|
44
|
+
{props.trigger()}
|
|
45
|
+
@if (
|
|
46
|
+
owner.getStatus() === 'invalid' ||
|
|
47
|
+
owner.getStatus() === 'unavailable'
|
|
48
|
+
) {
|
|
49
|
+
<label text="Menu actions are unavailable." accessibilityLiveRegion="polite" />
|
|
50
|
+
}
|
|
51
|
+
</masonview>
|
|
50
52
|
}
|
package/src/ContextMenu.web.tsrx
CHANGED
|
@@ -7,164 +7,170 @@ import type { ContextMenuProps } from './web/types'
|
|
|
7
7
|
* long-press via the `activation` prop's 'singlePress' = click) opens an
|
|
8
8
|
* in-page menu at the pointer. */
|
|
9
9
|
export function ContextMenu(props: ContextMenuProps): JSX.Element @{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
10
|
+
const [menu, setMenu] = useState<{ x: number; y: number } | null>(null)
|
|
11
|
+
const [active, setActive] = useState(0)
|
|
12
|
+
const listRef = useRef<HTMLUListElement | null>(null)
|
|
13
|
+
const items = props.items ?? []
|
|
14
|
+
const enabled = items
|
|
15
|
+
.map((item, index) => (item.disabled ? -1 : index))
|
|
16
|
+
.filter((index) => index >= 0)
|
|
17
|
+
|
|
18
|
+
const openAt = (e: any) => {
|
|
19
|
+
e.preventDefault?.()
|
|
20
|
+
setActive(enabled[0] ?? 0)
|
|
21
|
+
setMenu({ x: e.clientX ?? 0, y: e.clientY ?? 0 })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const choose = (index: number) => {
|
|
25
|
+
const item = items[index]
|
|
26
|
+
|
|
27
|
+
if (!item || item.disabled) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setMenu(null)
|
|
32
|
+
props.onItemSelected?.(item.id)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Once the menu is mounted: clamp it into the viewport so every item
|
|
36
|
+
// stays reachable, then focus it so the keyboard contract works.
|
|
37
|
+
useLayoutEffect(() => {
|
|
38
|
+
const el = listRef.current
|
|
39
|
+
|
|
40
|
+
if (!menu || !el) {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const x = Math.max(0, Math.min(menu.x, window.innerWidth - el.offsetWidth - 8))
|
|
45
|
+
const y = Math.max(0, Math.min(menu.y, window.innerHeight - el.offsetHeight - 8))
|
|
46
|
+
|
|
47
|
+
if (x !== menu.x || y !== menu.y) {
|
|
48
|
+
setMenu({ x, y })
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
el.focus()
|
|
53
|
+
}, [menu])
|
|
54
|
+
|
|
55
|
+
const onMenuKeyDown = (e: any) => {
|
|
56
|
+
if (e.key === 'Escape') {
|
|
57
|
+
e.preventDefault?.()
|
|
58
|
+
e.stopPropagation?.()
|
|
59
|
+
setMenu(null)
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!enabled.length) {
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const at = Math.max(0, enabled.indexOf(active))
|
|
68
|
+
|
|
69
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
70
|
+
e.preventDefault?.()
|
|
71
|
+
|
|
72
|
+
const step = e.key === 'ArrowDown' ? 1 : -1
|
|
73
|
+
|
|
74
|
+
setActive(enabled[(at + step + enabled.length) % enabled.length])
|
|
75
|
+
} else if (e.key === 'Home') {
|
|
76
|
+
e.preventDefault?.()
|
|
77
|
+
setActive(enabled[0])
|
|
78
|
+
} else if (e.key === 'End') {
|
|
79
|
+
e.preventDefault?.()
|
|
80
|
+
setActive(enabled[enabled.length - 1])
|
|
81
|
+
} else if (e.key === 'Enter' || e.key === ' ') {
|
|
82
|
+
e.preventDefault?.()
|
|
83
|
+
choose(active)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
<span
|
|
88
|
+
id={props.id}
|
|
89
|
+
className={props.className}
|
|
90
|
+
style={{ display: 'inline-block', ...props.style }}
|
|
91
|
+
onContextMenu={props.activation === 'singlePress' ? undefined : openAt}
|
|
92
|
+
onClick={props.activation === 'singlePress' ? openAt : undefined}
|
|
93
|
+
aria-label={props.accessibilityLabel}
|
|
94
|
+
>
|
|
95
|
+
{props.trigger()}
|
|
96
|
+
{menu && (
|
|
97
|
+
<>
|
|
98
|
+
{/* Events from the backdrop and the menu must not bubble to the
|
|
93
99
|
opener handlers — dismissal stays final. */}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
100
|
+
<span
|
|
101
|
+
style={{ position: 'fixed', inset: 0, zIndex: 999 }}
|
|
102
|
+
onClick={(e: any) => {
|
|
103
|
+
e.stopPropagation?.()
|
|
104
|
+
setMenu(null)
|
|
105
|
+
}}
|
|
106
|
+
onContextMenu={(e: any) => {
|
|
107
|
+
e.preventDefault?.()
|
|
108
|
+
e.stopPropagation?.()
|
|
109
|
+
setMenu(null)
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
<ul
|
|
113
|
+
role="menu"
|
|
114
|
+
tabIndex={-1}
|
|
115
|
+
ref={(el: any) => {
|
|
116
|
+
listRef.current = el
|
|
117
|
+
}}
|
|
118
|
+
onClick={(e: any) => e.stopPropagation?.()}
|
|
119
|
+
onContextMenu={(e: any) => {
|
|
120
|
+
e.preventDefault?.()
|
|
121
|
+
e.stopPropagation?.()
|
|
122
|
+
}}
|
|
123
|
+
onKeyDown={onMenuKeyDown}
|
|
124
|
+
style={{
|
|
125
|
+
position: 'fixed',
|
|
126
|
+
left: menu.x,
|
|
127
|
+
top: menu.y,
|
|
128
|
+
zIndex: 1000,
|
|
129
|
+
margin: 0,
|
|
130
|
+
padding: '4px 0',
|
|
131
|
+
listStyle: 'none',
|
|
132
|
+
background: 'var(--menu-bg, Canvas)',
|
|
133
|
+
color: 'var(--menu-fg, CanvasText)',
|
|
134
|
+
border: '1px solid color-mix(in srgb, CanvasText 20%, transparent)',
|
|
135
|
+
borderRadius: 8,
|
|
136
|
+
boxShadow: '0 6px 24px rgb(0 0 0 / 0.18)',
|
|
137
|
+
minWidth: 160,
|
|
138
|
+
outline: 'none',
|
|
139
|
+
}}
|
|
140
|
+
>
|
|
141
|
+
{items.map((item, index) => (
|
|
142
|
+
<Fragment key={item.id}>
|
|
143
|
+
{item.divider && (
|
|
144
|
+
<li
|
|
145
|
+
aria-hidden="true"
|
|
146
|
+
style={{
|
|
147
|
+
borderTop: '1px solid color-mix(in srgb, CanvasText 15%, transparent)',
|
|
148
|
+
margin: '4px 0',
|
|
149
|
+
}}
|
|
150
|
+
/>
|
|
151
|
+
)}
|
|
152
|
+
<li
|
|
153
|
+
role="menuitem"
|
|
154
|
+
aria-disabled={item.disabled || undefined}
|
|
155
|
+
aria-current={index === active || undefined}
|
|
156
|
+
style={{
|
|
157
|
+
padding: '6px 12px',
|
|
158
|
+
cursor: item.disabled ? 'default' : 'pointer',
|
|
159
|
+
opacity: item.disabled ? 0.5 : 1,
|
|
160
|
+
color: item.destructive ? 'crimson' : undefined,
|
|
161
|
+
background:
|
|
162
|
+
index === active
|
|
163
|
+
? 'color-mix(in srgb, CanvasText 10%, transparent)'
|
|
164
|
+
: undefined,
|
|
165
|
+
}}
|
|
166
|
+
onClick={() => choose(index)}
|
|
167
|
+
>
|
|
168
|
+
{item.title}
|
|
169
|
+
</li>
|
|
170
|
+
</Fragment>
|
|
171
|
+
))}
|
|
172
|
+
</ul>
|
|
173
|
+
</>
|
|
174
|
+
)}
|
|
175
|
+
</span>
|
|
170
176
|
}
|