@octane-xplat/context-menu 0.18.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 -124
- package/package.json +92 -86
- package/src/AppKitContextMenu.macos.css +1 -0
- package/src/AppKitContextMenu.macos.tsrx +41 -21
- package/src/AppKitContextMenu.tsrx +2 -0
- package/src/ContextMenu.tsrx +2 -0
- package/src/ContextMenu.web.tsrx +168 -149
- package/src/MaterialContextMenu.android.tsrx +128 -101
- package/src/MaterialContextMenu.tsrx +2 -0
- package/src/SwiftUIContextMenu.ios.tsrx +104 -84
- package/src/SwiftUIContextMenu.tsrx +2 -0
- package/src/android/index.ts +3 -3
- package/src/android/types.ts +29 -18
- package/src/context-menu-owner.macos.ts +213 -0
- package/src/ios/types.ts +28 -19
- package/src/macos/types.ts +27 -18
- package/src/web/types.ts +29 -14
- package/types/generated/.tsrx-typegen-manifest.json +19 -0
- package/types/generated/AppKitContextMenu.macos.d.ts +8 -0
- package/types/generated/ContextMenu.web.d.ts +7 -0
- package/types/generated/MaterialContextMenu.android.d.ts +16 -0
- package/types/generated/SwiftUIContextMenu.ios.d.ts +17 -0
- package/types/generated/android/index.d.ts +2 -0
- package/types/generated/android/types.d.ts +35 -0
- package/types/generated/context-menu-owner.macos.d.ts +16 -0
- package/types/generated/index.d.ts +1 -0
- package/types/generated/ios/index.d.ts +2 -0
- package/types/generated/ios/types.d.ts +33 -0
- package/types/generated/macos/index.d.ts +2 -0
- package/types/generated/macos/types.d.ts +32 -0
- package/types/generated/web/index.d.ts +2 -0
- package/types/generated/web/types.d.ts +34 -0
- package/LICENSE +0 -21
- package/types/android/index.d.ts +0 -22
- package/types/index.d.ts +0 -1
- package/types/ios/index.d.ts +0 -20
- package/types/macos/index.d.ts +0 -19
- package/types/web/index.d.ts +0 -22
package/README.md
CHANGED
|
@@ -1,127 +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
|
-
`NSMenu` on the backing view on macOS.
|
|
3
|
+
[Documentation](https://octane-xplat.goddardai.org/package-context-menu).
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
that renders a control, then import `SwiftUIContextMenu` from
|
|
10
|
-
`@octane-xplat/context-menu/ios`, `MaterialContextMenu` from
|
|
11
|
-
`@octane-xplat/context-menu/android`, `ContextMenu` from
|
|
12
|
-
`@octane-xplat/context-menu/web`, or `AppKitContextMenu` from
|
|
13
|
-
`@octane-xplat/context-menu/macos` in the matching platform-suffixed file.
|
|
14
|
-
|
|
15
|
-
```tsx
|
|
16
|
-
/** @jsxImportSource @nativescript-community/octane */
|
|
17
|
-
// SwiftUIContextMenuExample.ios.tsx
|
|
18
|
-
import { SwiftUIContextMenu } from '@octane-xplat/context-menu/ios'
|
|
19
|
-
import { Text } from '@octane-xplat/ui'
|
|
20
|
-
|
|
21
|
-
export function Menu() {
|
|
22
|
-
return (
|
|
23
|
-
<SwiftUIContextMenu
|
|
24
|
-
trigger={() => <Text>Trip actions</Text>}
|
|
25
|
-
items={[{ id: 'rename', title: 'Rename' }]}
|
|
26
|
-
onItemSelected={(id) => console.log(id)}
|
|
27
|
-
/>
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
```tsx
|
|
33
|
-
/** @jsxImportSource @nativescript-community/octane */
|
|
34
|
-
// MaterialContextMenuExample.android.tsx
|
|
35
|
-
import { MaterialContextMenu } from '@octane-xplat/context-menu/android'
|
|
36
|
-
import { Text } from '@octane-xplat/ui'
|
|
37
|
-
|
|
38
|
-
export function Menu() {
|
|
39
|
-
return (
|
|
40
|
-
<MaterialContextMenu
|
|
41
|
-
activation="singlePress"
|
|
42
|
-
trigger={() => <Text>Trip actions</Text>}
|
|
43
|
-
items={[{ id: 'rename', title: 'Rename' }]}
|
|
44
|
-
onItemSelected={(id) => console.log(id)}
|
|
45
|
-
/>
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
```tsx
|
|
51
|
-
// ContextMenuExample.web.tsx
|
|
52
|
-
import { ContextMenu } from '@octane-xplat/context-menu/web'
|
|
53
|
-
import { Text } from '@octane-xplat/ui'
|
|
54
|
-
|
|
55
|
-
export function Menu() {
|
|
56
|
-
return (
|
|
57
|
-
<ContextMenu
|
|
58
|
-
activation="singlePress"
|
|
59
|
-
trigger={() => <Text>Trip actions</Text>}
|
|
60
|
-
items={[{ id: 'rename', title: 'Rename' }]}
|
|
61
|
-
onItemSelected={(id) => console.log(id)}
|
|
62
|
-
/>
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
```tsx
|
|
68
|
-
// AppKitContextMenuExample.macos.tsx
|
|
69
|
-
import { AppKitContextMenu } from '@octane-xplat/context-menu/macos'
|
|
70
|
-
import { Text } from '@octane-xplat/ui'
|
|
71
|
-
|
|
72
|
-
export function Menu() {
|
|
73
|
-
return (
|
|
74
|
-
<AppKitContextMenu
|
|
75
|
-
trigger={() => <Text>Trip actions</Text>}
|
|
76
|
-
items={[{ id: 'rename', title: 'Rename' }]}
|
|
77
|
-
onItemSelected={(id) => console.log(id)}
|
|
78
|
-
/>
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
Menu items are plain data (`{id, title, destructive, disabled, divider}`),
|
|
84
|
-
reported back through `onItemSelected(id)`. The iOS entry also accepts an
|
|
85
|
-
optional `preview` render function (iOS 16+):
|
|
86
|
-
|
|
87
|
-
```tsx
|
|
88
|
-
/** @jsxImportSource @nativescript-community/octane */
|
|
89
|
-
// Actions.ios.tsx
|
|
90
|
-
import { SwiftUIContextMenu } from '@octane-xplat/context-menu/ios'
|
|
91
|
-
import { Text } from '@octane-xplat/ui'
|
|
92
|
-
|
|
93
|
-
export function Actions() {
|
|
94
|
-
return (
|
|
95
|
-
<SwiftUIContextMenu
|
|
96
|
-
trigger={() => <Text>Trip actions</Text>}
|
|
97
|
-
preview={() => <Text>Kyoto trip</Text>}
|
|
98
|
-
items={[{ id: 'delete', title: 'Delete', destructive: true, divider: true }]}
|
|
99
|
-
onItemSelected={(id) => console.log(id)}
|
|
100
|
-
/>
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
- iOS: long-press activation (platform native); optional `preview` render fn
|
|
106
|
-
(iOS 16+).
|
|
107
|
-
- Android: `activation` prop — `'longPress'` (default) or `'singlePress'`,
|
|
108
|
-
detected at parent level so interactive children in the trigger keep
|
|
109
|
-
their own taps.
|
|
110
|
-
- Web: right-click (`longPress`) or click (`singlePress`) opens the menu at
|
|
111
|
-
the pointer.
|
|
112
|
-
- macOS: right-click — the NSMenu is the view's `menu`, so AppKit owns
|
|
113
|
-
activation and disabled-item dimming; the trigger renders inline.
|
|
114
|
-
|
|
115
|
-
## How the native menus work
|
|
116
|
-
|
|
117
|
-
Unlike props-only leaves (picker, date-picker), this leaf exercises subtree
|
|
118
|
-
embedding: `trigger` is a render fn whose octane output mounts into a
|
|
119
|
-
detached root, and the native menu wraps that subtree — SwiftUI resolves it
|
|
120
|
-
through `NativeScriptViewFactory` (the same factory the swift-ui plugin's
|
|
121
|
-
`NativeScriptView` uses), and Android through the leaf's
|
|
122
|
-
`XplatViewRegistry` + `AndroidView`.
|
|
123
|
-
|
|
124
|
-
The native implementations are adapted from `@expo/ui` (MIT,
|
|
125
|
-
`packages/expo-ui` sdk-57): `ios/ContextMenu/ContextMenu.swift` and
|
|
126
|
-
`android/.../ui/menu/DropdownMenu*.kt`. Attribution headers sit on the
|
|
127
|
-
ported files.
|
|
5
|
+
[API reference](https://octane-xplat.goddardai.org/api-context-menu).
|
package/package.json
CHANGED
|
@@ -1,87 +1,93 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
2
|
+
"name": "@octane-xplat/context-menu",
|
|
3
|
+
"version": "0.20.0",
|
|
4
|
+
"description": "Platform-specific context menu controls for Octane xplat",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/octane-xplat/octane-xplat",
|
|
8
|
+
"directory": "packages/context-menu"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"types/generated",
|
|
12
|
+
"src",
|
|
13
|
+
"platforms",
|
|
14
|
+
"!src/**/*.test.*",
|
|
15
|
+
"!src/**/*.spec.*"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./types/generated/index.d.ts",
|
|
21
|
+
"web": "./src/index.ts",
|
|
22
|
+
"native": "./src/index.ts",
|
|
23
|
+
"default": "./src/index.ts"
|
|
24
|
+
},
|
|
25
|
+
"./ios": {
|
|
26
|
+
"types": "./types/generated/ios/index.d.ts",
|
|
27
|
+
"native": "./src/ios/index.ts"
|
|
28
|
+
},
|
|
29
|
+
"./android": {
|
|
30
|
+
"types": "./types/generated/android/index.d.ts",
|
|
31
|
+
"native": "./src/android/index.ts"
|
|
32
|
+
},
|
|
33
|
+
"./web": {
|
|
34
|
+
"types": "./types/generated/web/index.d.ts",
|
|
35
|
+
"web": "./src/web/index.ts"
|
|
36
|
+
},
|
|
37
|
+
"./macos": {
|
|
38
|
+
"types": "./types/generated/macos/index.d.ts",
|
|
39
|
+
"macos": "./src/macos/index.ts"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"prepack": "bun run typegen && tsrx-typegen --pack-check",
|
|
47
|
+
"test": "node --test tests/context-menu-owner.macos.test.mjs",
|
|
48
|
+
"test:packed": "node tests/packed-consumer.mjs",
|
|
49
|
+
"pack:check": "tsrx-typegen --pack-check",
|
|
50
|
+
"typegen": "tsrx-typegen --target context-menu",
|
|
51
|
+
"typecheck": "tsc --runExternalCode --noEmit -p tsconfig.types.json"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@nativescript/jetpack-compose": "1.0.0-beta.0",
|
|
55
|
+
"@nativescript/swift-ui": "4.0.2",
|
|
56
|
+
"@octane-xplat/jsx": "0.20.0",
|
|
57
|
+
"@octane-xplat/lib": "0.20.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@nativescript-community/octane": "0.2.5",
|
|
61
|
+
"@nativescript/core": "9.1.3",
|
|
62
|
+
"@octane-xplat/macos-appkit": "0.20.0",
|
|
63
|
+
"@octanejs/vite-plugin": "0.5.0",
|
|
64
|
+
"octane": "0.16.3",
|
|
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
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
72
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
73
|
+
"octane": ">=0.1.51 <1"
|
|
74
|
+
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"@nativescript-community/octane": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"@nativescript/core": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"octane": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"nativescript": {
|
|
87
|
+
"platforms": {
|
|
88
|
+
"android": "9.1.0",
|
|
89
|
+
"ios": "9.1.0"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"types": "./types/generated/index.d.ts"
|
|
93
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.xplat-appkit-context-menu { display: flex; }
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
/** @jsxImportSource @octane-xplat/
|
|
2
|
-
import
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
|
+
import './AppKitContextMenu.macos.css'
|
|
3
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'octane'
|
|
3
4
|
import type { AppKitContextMenuProps } from './macos/types'
|
|
5
|
+
import { createContextMenuOwner } from './context-menu-owner.macos'
|
|
6
|
+
import type { ContextMenuAttach } from './context-menu-owner.macos'
|
|
7
|
+
import { cx } from '@octane-xplat/lib'
|
|
4
8
|
|
|
5
9
|
const host = (): any => (globalThis as any).__xplatAppKit ?? {}
|
|
6
10
|
|
|
@@ -8,25 +12,41 @@ const host = (): any => (globalThis as any).__xplatAppKit ?? {}
|
|
|
8
12
|
* children and a real NSMenu is attached to the backing NSView's `menu`,
|
|
9
13
|
* so AppKit drives right-click activation and disabled items. Items are
|
|
10
14
|
* serialized data; selection reports through `onItemSelected`. */
|
|
11
|
-
export function AppKitContextMenu(props: AppKitContextMenuProps) @{
|
|
12
|
-
|
|
13
|
-
// Selection must reach the latest handler — re-attaching the NSMenu on
|
|
14
|
-
// every callback change would churn the view's `menu` subtree.
|
|
15
|
-
const latest = useRef(props)
|
|
16
|
-
latest.current = props
|
|
15
|
+
export function AppKitContextMenu(props: AppKitContextMenuProps): unknown @{
|
|
16
|
+
const latest = useRef(props)
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
const view = anchor.current
|
|
20
|
-
const attach = host().attachContextMenu
|
|
21
|
-
if (!view || typeof attach !== 'function') return
|
|
22
|
-
return attach(
|
|
23
|
-
view,
|
|
24
|
-
{ items: latest.current.items ?? [] },
|
|
25
|
-
(id: string) => latest.current.onItemSelected?.(id),
|
|
26
|
-
)
|
|
27
|
-
}, [props.items])
|
|
18
|
+
latest.current = props
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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>
|
|
32
52
|
}
|