@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
|
@@ -1,54 +1,71 @@
|
|
|
1
|
-
/** @jsxImportSource @
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
2
|
import { registerElement } from '@nativescript-community/octane'
|
|
3
|
-
import type { Attributes } from '@
|
|
3
|
+
import type { Attributes } from '@octane-xplat/jsx/intrinsics'
|
|
4
4
|
import { SwiftUI, UIDataDriver, registerSwiftUI, SwiftUIManager } from '@nativescript/swift-ui'
|
|
5
5
|
import { GridLayout } from '@nativescript/core'
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
getSwiftUIHostLifecycle,
|
|
8
|
+
registerSwiftUIHost,
|
|
9
|
+
unregisterSwiftUIHost,
|
|
10
|
+
} from '@octane-xplat/lib'
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
createPortal as createUniversalPortal,
|
|
14
|
+
type UniversalRenderable,
|
|
15
|
+
} from 'octane/universal/native'
|
|
16
|
+
|
|
8
17
|
import { useEffect, useRef, useState } from 'octane'
|
|
9
18
|
import type { SwiftUIContextMenuProps } from './ios/types'
|
|
10
19
|
|
|
11
20
|
declare const XplatContextMenuProvider: any
|
|
12
21
|
declare const NativeScriptViewFactory: any
|
|
13
22
|
|
|
14
|
-
declare module '@
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
declare module '@octane-xplat/jsx/intrinsics' {
|
|
24
|
+
interface NativeElements<TElement> {
|
|
25
|
+
xplatioscontextmenu: Attributes<
|
|
26
|
+
TElement,
|
|
27
|
+
{
|
|
28
|
+
swiftId?: string
|
|
29
|
+
data?: Record<string, unknown>
|
|
30
|
+
onSwiftUIEvent?: (event: { data?: unknown }) => void
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
}
|
|
18
34
|
}
|
|
19
35
|
|
|
20
36
|
registerElement('xplatioscontextmenu', SwiftUI)
|
|
21
|
-
registerSwiftUI(
|
|
22
|
-
|
|
37
|
+
registerSwiftUI(
|
|
38
|
+
'xplat-swiftui-contextmenu',
|
|
39
|
+
(owner: any) => new UIDataDriver(new XplatContextMenuProvider(), owner),
|
|
23
40
|
)
|
|
24
41
|
|
|
25
42
|
function createPortal(children: unknown, target: unknown) {
|
|
26
|
-
|
|
43
|
+
return createUniversalPortal(children as UniversalRenderable, target)
|
|
27
44
|
}
|
|
28
45
|
|
|
29
46
|
function ensureNativeScriptViewFactory(): void {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
47
|
+
if (!NativeScriptViewFactory.shared) {
|
|
48
|
+
NativeScriptViewFactory.initShared()
|
|
49
|
+
}
|
|
33
50
|
}
|
|
34
51
|
|
|
35
52
|
function registerHosts(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
triggerId: string,
|
|
54
|
+
trigger: GridLayout,
|
|
55
|
+
previewId: string,
|
|
56
|
+
preview: GridLayout,
|
|
40
57
|
): void {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
ensureNativeScriptViewFactory()
|
|
59
|
+
registerSwiftUIHost(triggerId, { create: () => trigger })
|
|
60
|
+
registerSwiftUIHost(previewId, { create: () => preview })
|
|
61
|
+
SwiftUIManager.registerNativeScriptViews(
|
|
62
|
+
{ [triggerId]: true, [previewId]: true },
|
|
63
|
+
getSwiftUIHostLifecycle(),
|
|
64
|
+
)
|
|
48
65
|
}
|
|
49
66
|
|
|
50
67
|
function TriggerRoot(props: { render: () => any }) @{
|
|
51
|
-
|
|
68
|
+
<>{props.render()}</>
|
|
52
69
|
}
|
|
53
70
|
|
|
54
71
|
let seq = 0
|
|
@@ -56,62 +73,65 @@ let seq = 0
|
|
|
56
73
|
/** Renders a SwiftUI .contextMenu whose trigger and optional preview portal
|
|
57
74
|
* from the declaring Octane tree into NativeScript hosts. Menu items arrive
|
|
58
75
|
* as serialized data. */
|
|
59
|
-
export function SwiftUIContextMenu(props: SwiftUIContextMenuProps) @{
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
76
|
+
export function SwiftUIContextMenu(props: SwiftUIContextMenuProps): unknown @{
|
|
77
|
+
const triggerId = useRef<string>('')
|
|
78
|
+
|
|
79
|
+
if (!triggerId.current) {
|
|
80
|
+
triggerId.current = `ctxmenu${++seq}`
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const previewId = `${triggerId.current}preview`
|
|
84
|
+
const [portalHosts, setPortalHosts] = useState<{
|
|
85
|
+
trigger: GridLayout
|
|
86
|
+
preview: GridLayout
|
|
87
|
+
} | null>(null)
|
|
88
|
+
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
const trigger = new GridLayout()
|
|
91
|
+
const preview = new GridLayout()
|
|
92
|
+
|
|
93
|
+
registerHosts(triggerId.current, trigger, previewId, preview)
|
|
94
|
+
setPortalHosts({ trigger, preview })
|
|
95
|
+
|
|
96
|
+
return () => {
|
|
97
|
+
unregisterSwiftUIHost(triggerId.current)
|
|
98
|
+
unregisterSwiftUIHost(previewId)
|
|
99
|
+
}
|
|
100
|
+
}, [])
|
|
101
|
+
|
|
102
|
+
const items = props.items ?? []
|
|
103
|
+
|
|
104
|
+
<>
|
|
105
|
+
<xplatioscontextmenu
|
|
106
|
+
id={props.id}
|
|
107
|
+
className={props.className}
|
|
108
|
+
style={props.style}
|
|
109
|
+
accessibilityLabel={props.accessibilityLabel}
|
|
110
|
+
swiftId="xplat-swiftui-contextmenu"
|
|
111
|
+
data={{
|
|
112
|
+
triggerId: portalHosts ? triggerId.current : '',
|
|
113
|
+
previewId: portalHosts && props.preview ? previewId : '',
|
|
114
|
+
items: items.map((item) => ({
|
|
115
|
+
id: item.id,
|
|
116
|
+
title: item.title,
|
|
117
|
+
destructive: item.destructive ? 1 : 0,
|
|
118
|
+
disabled: item.disabled ? 1 : 0,
|
|
119
|
+
divider: item.divider ? 1 : 0,
|
|
120
|
+
})),
|
|
121
|
+
}}
|
|
122
|
+
onSwiftUIEvent={(event: any) => {
|
|
123
|
+
const item = event.data?.item
|
|
124
|
+
|
|
125
|
+
if (typeof item === 'string' && item) {
|
|
126
|
+
props.onItemSelected?.(item)
|
|
127
|
+
}
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
{portalHosts && props.trigger
|
|
131
|
+
? createPortal(<TriggerRoot render={props.trigger} />, portalHosts.trigger)
|
|
132
|
+
: null}
|
|
133
|
+
{portalHosts && props.preview
|
|
134
|
+
? createPortal(<TriggerRoot render={props.preview} />, portalHosts.preview)
|
|
135
|
+
: null}
|
|
136
|
+
</>
|
|
117
137
|
}
|
package/src/android/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { MaterialContextMenu } from '../MaterialContextMenu.android.tsrx'
|
|
2
2
|
export type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
MaterialContextMenuActivation,
|
|
4
|
+
MaterialContextMenuItem,
|
|
5
|
+
MaterialContextMenuProps,
|
|
6
6
|
} from './types'
|
package/src/android/types.ts
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
|
+
/** How the menu opens on Android. */
|
|
1
2
|
export type MaterialContextMenuActivation = 'longPress' | 'singlePress'
|
|
2
3
|
|
|
3
4
|
/** One row of serialized menu content carried over the bridge. */
|
|
4
5
|
export interface MaterialContextMenuItem {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
/** Stable id reported to `onItemSelected`. */
|
|
7
|
+
id: string
|
|
8
|
+
/** Item display text. */
|
|
9
|
+
title: string
|
|
10
|
+
/** Marks the action destructive (red styling where supported). */
|
|
11
|
+
destructive?: boolean
|
|
12
|
+
/** Greys the item; not selectable. */
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
/** Render a divider before this item. */
|
|
15
|
+
divider?: boolean
|
|
12
16
|
}
|
|
13
17
|
|
|
18
|
+
/** Android context-menu props. */
|
|
14
19
|
export interface MaterialContextMenuProps {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
/** Element id passed through to the host element. */
|
|
21
|
+
id?: string
|
|
22
|
+
/** Class list applied to the element. */
|
|
23
|
+
className?: any
|
|
24
|
+
/** Inline style (string CSS or object). */
|
|
25
|
+
style?: any
|
|
26
|
+
/** Activation gesture. @default 'longPress' */
|
|
27
|
+
activation?: MaterialContextMenuActivation
|
|
28
|
+
/** Menu entries in display order. */
|
|
29
|
+
items?: readonly MaterialContextMenuItem[]
|
|
30
|
+
/** Render fn producing the trigger subtree — portaled from the declaring
|
|
31
|
+
* Octane tree into the menu's AndroidView anchor. */
|
|
32
|
+
trigger: () => any
|
|
33
|
+
/** Fires with the selected item id. */
|
|
34
|
+
onItemSelected?: (id: string) => void
|
|
35
|
+
/** Spoken name for assistive tech. */
|
|
36
|
+
accessibilityLabel?: string
|
|
26
37
|
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type { AppKitContextMenuItem, AppKitContextMenuProps } from './macos/types'
|
|
2
|
+
|
|
3
|
+
export type ContextMenuAttach = (
|
|
4
|
+
view: object,
|
|
5
|
+
options: { items: readonly AppKitContextMenuItem[] },
|
|
6
|
+
onSelect: (id: string | undefined) => void,
|
|
7
|
+
) => (() => void) | null
|
|
8
|
+
|
|
9
|
+
export type ContextMenuStatus = 'ready' | 'empty' | 'invalid' | 'unavailable'
|
|
10
|
+
|
|
11
|
+
/** Copy primitive content so in-place item changes cannot rewrite an old menu. */
|
|
12
|
+
function menuSnapshot(
|
|
13
|
+
items: readonly AppKitContextMenuItem[] = [],
|
|
14
|
+
): AppKitContextMenuItem[] | null {
|
|
15
|
+
const ids = new Set<string>()
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
return items.map((item) => {
|
|
19
|
+
if (typeof item.id !== 'string' || typeof item.title !== 'string' || ids.has(item.id)) {
|
|
20
|
+
throw Error('invalid menu')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
ids.add(item.id)
|
|
24
|
+
return {
|
|
25
|
+
id: item.id,
|
|
26
|
+
title: item.title,
|
|
27
|
+
disabled: !!item.disabled,
|
|
28
|
+
divider: !!item.divider,
|
|
29
|
+
destructive: !!item.destructive,
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
} catch {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const sameMenuItems = (a: readonly AppKitContextMenuItem[], b: readonly AppKitContextMenuItem[]) =>
|
|
38
|
+
a.length === b.length &&
|
|
39
|
+
a.every((item, i) => {
|
|
40
|
+
const other = b[i]
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
item.id === other.id &&
|
|
44
|
+
item.title === other.title &&
|
|
45
|
+
item.disabled === other.disabled &&
|
|
46
|
+
item.divider === other.divider &&
|
|
47
|
+
item.destructive === other.destructive
|
|
48
|
+
)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
/** Current native menu session; callback-only renders preserve its tracking menu. */
|
|
52
|
+
export function createContextMenuOwner(deps: {
|
|
53
|
+
props(): AppKitContextMenuProps
|
|
54
|
+
attach(): ContextMenuAttach | undefined
|
|
55
|
+
status?(status: ContextMenuStatus): void
|
|
56
|
+
}): {
|
|
57
|
+
update: () => void
|
|
58
|
+
bind(next: object | null): void
|
|
59
|
+
dispose(): void
|
|
60
|
+
getStatus: () => ContextMenuStatus
|
|
61
|
+
} {
|
|
62
|
+
type Session = {
|
|
63
|
+
view: object
|
|
64
|
+
scope: string | undefined
|
|
65
|
+
items: AppKitContextMenuItem[]
|
|
66
|
+
ready: boolean
|
|
67
|
+
selecting: boolean
|
|
68
|
+
detach?: () => void
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let view: object | null = null,
|
|
72
|
+
session: Session | null = null,
|
|
73
|
+
disposed = false
|
|
74
|
+
|
|
75
|
+
let status: ContextMenuStatus = 'empty'
|
|
76
|
+
const report = (next: ContextMenuStatus) => {
|
|
77
|
+
if (!disposed && next !== status) {
|
|
78
|
+
status = next
|
|
79
|
+
deps.status?.(next)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const detach = () => {
|
|
84
|
+
const old = session
|
|
85
|
+
|
|
86
|
+
session = null
|
|
87
|
+
try {
|
|
88
|
+
old?.detach?.()
|
|
89
|
+
} catch {}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const update = () => {
|
|
93
|
+
if (disposed || !view) {
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const props = deps.props(),
|
|
98
|
+
items = menuSnapshot(props.items)
|
|
99
|
+
|
|
100
|
+
if (!items) {
|
|
101
|
+
detach()
|
|
102
|
+
report('invalid')
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!items.length) {
|
|
107
|
+
detach()
|
|
108
|
+
report('empty')
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (
|
|
113
|
+
session &&
|
|
114
|
+
session.view === view &&
|
|
115
|
+
session.scope === props.id &&
|
|
116
|
+
sameMenuItems(session.items, items)
|
|
117
|
+
) {
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
detach()
|
|
122
|
+
|
|
123
|
+
const attach = deps.attach()
|
|
124
|
+
|
|
125
|
+
if (!attach) {
|
|
126
|
+
report('unavailable')
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const owner: Session = { view, scope: props.id, items, ready: false, selecting: false }
|
|
131
|
+
|
|
132
|
+
session = owner
|
|
133
|
+
try {
|
|
134
|
+
const cleanup = attach(view, { items }, (id) => {
|
|
135
|
+
if (
|
|
136
|
+
disposed ||
|
|
137
|
+
session !== owner ||
|
|
138
|
+
!owner.ready ||
|
|
139
|
+
owner.selecting ||
|
|
140
|
+
typeof id !== 'string'
|
|
141
|
+
) {
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const current = deps.props(),
|
|
146
|
+
currentItems = menuSnapshot(current.items)
|
|
147
|
+
|
|
148
|
+
if (
|
|
149
|
+
!currentItems ||
|
|
150
|
+
current.id !== owner.scope ||
|
|
151
|
+
!sameMenuItems(owner.items, currentItems)
|
|
152
|
+
) {
|
|
153
|
+
update()
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const item = currentItems.find((item) => item.id === id)
|
|
158
|
+
|
|
159
|
+
if (!item || item.disabled) {
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
owner.selecting = true
|
|
164
|
+
try {
|
|
165
|
+
current.onItemSelected?.(id)
|
|
166
|
+
} finally {
|
|
167
|
+
owner.selecting = false
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
if (disposed || session !== owner) {
|
|
172
|
+
cleanup?.()
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (typeof cleanup !== 'function') {
|
|
177
|
+
session = null
|
|
178
|
+
report('unavailable')
|
|
179
|
+
return
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
owner.detach = cleanup
|
|
183
|
+
owner.ready = true
|
|
184
|
+
report('ready')
|
|
185
|
+
} catch {
|
|
186
|
+
if (session === owner) {
|
|
187
|
+
detach()
|
|
188
|
+
report('unavailable')
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
update,
|
|
195
|
+
bind(next: object | null) {
|
|
196
|
+
if (!disposed && next !== view) {
|
|
197
|
+
detach()
|
|
198
|
+
view = next
|
|
199
|
+
if (view) {
|
|
200
|
+
update()
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
dispose() {
|
|
205
|
+
if (!disposed) {
|
|
206
|
+
disposed = true
|
|
207
|
+
detach()
|
|
208
|
+
view = null
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
getStatus: () => status,
|
|
212
|
+
}
|
|
213
|
+
}
|
package/src/ios/types.ts
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
1
|
/** One row of serialized menu content carried over the bridge. */
|
|
2
2
|
export interface SwiftUIContextMenuItem {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
/** Stable id reported to `onItemSelected`. */
|
|
4
|
+
id: string
|
|
5
|
+
/** Item display text. */
|
|
6
|
+
title: string
|
|
7
|
+
/** Renders the item with .destructive role. */
|
|
8
|
+
destructive?: boolean
|
|
9
|
+
/** Greys the item; not selectable. */
|
|
10
|
+
disabled?: boolean
|
|
11
|
+
/** Render a divider before this item. */
|
|
12
|
+
divider?: boolean
|
|
11
13
|
}
|
|
12
14
|
|
|
15
|
+
/** iOS context-menu props (SwiftUI contextMenu). */
|
|
13
16
|
export interface SwiftUIContextMenuProps {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
/** Element id passed through to the host element. */
|
|
18
|
+
id?: string
|
|
19
|
+
/** Class list applied to the element. */
|
|
20
|
+
className?: any
|
|
21
|
+
/** Inline style (string CSS or object). */
|
|
22
|
+
style?: any
|
|
23
|
+
/** Menu entries in display order. */
|
|
24
|
+
items?: readonly SwiftUIContextMenuItem[]
|
|
25
|
+
/** Render fn producing the activation element — hosted inside the
|
|
26
|
+
* SwiftUI tree via the plugin's NativeScriptView-by-id factory. */
|
|
27
|
+
trigger: () => any
|
|
28
|
+
/** Optional preview shown while the menu opens (iOS 16+). */
|
|
29
|
+
preview?: () => any
|
|
30
|
+
/** Fires with the selected item id. */
|
|
31
|
+
onItemSelected?: (id: string) => void
|
|
32
|
+
/** Spoken name for assistive tech. */
|
|
33
|
+
accessibilityLabel?: string
|
|
25
34
|
}
|
package/src/macos/types.ts
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
/** One row of serialized menu content carried over the bridge. */
|
|
2
2
|
export interface AppKitContextMenuItem {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
/** Stable id reported to `onItemSelected`; unique within this menu. */
|
|
4
|
+
id: string
|
|
5
|
+
/** Item display text. */
|
|
6
|
+
title: string
|
|
7
|
+
/** No AppKit destructive role — kept in the contract for parity; the
|
|
8
|
+
* item renders as a normal menu row. */
|
|
9
|
+
destructive?: boolean
|
|
10
|
+
/** Greys the item; not selectable. */
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
/** Render a divider before this item. */
|
|
13
|
+
divider?: boolean
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
/** macOS context-menu props (NSMenu). */
|
|
14
17
|
export interface AppKitContextMenuProps {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
/** Native view identifier. Changing it retires this record's menu session. */
|
|
19
|
+
id?: string
|
|
20
|
+
/** Class list applied to the element. */
|
|
21
|
+
className?: any
|
|
22
|
+
/** Inline style (string CSS or object). */
|
|
23
|
+
style?: any
|
|
24
|
+
/** Menu entries in display order. */
|
|
25
|
+
items?: readonly AppKitContextMenuItem[]
|
|
26
|
+
/** Render fn producing the trigger element — rendered inline; the NSMenu
|
|
27
|
+
* attaches to the host's backing NSView. */
|
|
28
|
+
trigger: () => any
|
|
29
|
+
/** Current enabled item selections; retired/replaced menu actions are ignored. */
|
|
30
|
+
onItemSelected?: (id: string) => void
|
|
31
|
+
/** Spoken name for assistive tech. */
|
|
32
|
+
accessibilityLabel?: string
|
|
24
33
|
}
|
package/src/web/types.ts
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
|
+
/** How the menu opens (right-click/long-press variants). */
|
|
1
2
|
export type ContextMenuActivation = 'longPress' | 'singlePress'
|
|
2
3
|
|
|
4
|
+
/** One menu entry or separator. */
|
|
3
5
|
export interface ContextMenuItem {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/** Element id passed through to the host element. */
|
|
7
|
+
id: string
|
|
8
|
+
/** Item display text. */
|
|
9
|
+
title: string
|
|
10
|
+
/** Marks the action destructive (red styling where supported). */
|
|
11
|
+
destructive?: boolean
|
|
12
|
+
/** Greys the item; not selectable. */
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
/** Render as a separator instead of an item. */
|
|
15
|
+
divider?: boolean
|
|
9
16
|
}
|
|
10
17
|
|
|
18
|
+
/** Web context-menu props (composed web menu). */
|
|
11
19
|
export interface ContextMenuProps {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
/** Element id passed through to the host element. */
|
|
21
|
+
id?: string
|
|
22
|
+
/** Class list applied to the element. */
|
|
23
|
+
className?: any
|
|
24
|
+
/** Inline style (string CSS or object). */
|
|
25
|
+
style?: any
|
|
26
|
+
/** 'longPress' maps to right-click (contextmenu); 'singlePress' to click. */
|
|
27
|
+
activation?: ContextMenuActivation
|
|
28
|
+
/** Menu entries in display order. */
|
|
29
|
+
items?: readonly ContextMenuItem[]
|
|
30
|
+
/** Content that hosts the context menu (long-press/right-click). */
|
|
31
|
+
trigger: () => any
|
|
32
|
+
/** Fires with the selected item id. */
|
|
33
|
+
onItemSelected?: (id: string) => void
|
|
34
|
+
/** Spoken name for assistive tech. */
|
|
35
|
+
accessibilityLabel?: string
|
|
21
36
|
}
|