@tamagui/context-menu 2.7.7 → 3.0.0-beta.643.1

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.
Files changed (53) hide show
  1. package/dist/cjs/ContextMenu.cjs +152 -166
  2. package/dist/cjs/ContextMenu.native.cjs +178 -0
  3. package/dist/cjs/ContextMenu.native.js +157 -170
  4. package/dist/cjs/ContextMenu.native.js.map +1 -1
  5. package/dist/cjs/createNonNativeContextMenu.cjs +358 -422
  6. package/dist/cjs/createNonNativeContextMenu.native.cjs +405 -0
  7. package/dist/cjs/createNonNativeContextMenu.native.js +380 -443
  8. package/dist/cjs/createNonNativeContextMenu.native.js.map +1 -1
  9. package/dist/cjs/index.cjs +15 -29
  10. package/dist/cjs/index.native.cjs +29 -0
  11. package/dist/cjs/index.native.js +16 -29
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/esm/ContextMenu.mjs +136 -140
  14. package/dist/esm/ContextMenu.mjs.map +1 -1
  15. package/dist/esm/ContextMenu.native.js +141 -145
  16. package/dist/esm/ContextMenu.native.js.map +1 -1
  17. package/dist/esm/createNonNativeContextMenu.mjs +342 -398
  18. package/dist/esm/createNonNativeContextMenu.mjs.map +1 -1
  19. package/dist/esm/createNonNativeContextMenu.native.js +365 -421
  20. package/dist/esm/createNonNativeContextMenu.native.js.map +1 -1
  21. package/dist/esm/index.js +3 -12
  22. package/dist/esm/index.js.map +1 -1
  23. package/dist/esm/index.mjs +3 -12
  24. package/dist/esm/index.mjs.map +1 -1
  25. package/dist/esm/index.native.js +3 -12
  26. package/dist/esm/index.native.js.map +1 -1
  27. package/dist/jsx/ContextMenu.mjs +136 -140
  28. package/dist/jsx/ContextMenu.mjs.map +1 -1
  29. package/dist/jsx/ContextMenu.native.cjs +178 -0
  30. package/dist/jsx/ContextMenu.native.js +157 -170
  31. package/dist/jsx/ContextMenu.native.js.map +1 -1
  32. package/dist/jsx/createNonNativeContextMenu.mjs +342 -398
  33. package/dist/jsx/createNonNativeContextMenu.mjs.map +1 -1
  34. package/dist/jsx/createNonNativeContextMenu.native.cjs +405 -0
  35. package/dist/jsx/createNonNativeContextMenu.native.js +380 -443
  36. package/dist/jsx/createNonNativeContextMenu.native.js.map +1 -1
  37. package/dist/jsx/index.js +3 -12
  38. package/dist/jsx/index.js.map +1 -1
  39. package/dist/jsx/index.mjs +3 -12
  40. package/dist/jsx/index.mjs.map +1 -1
  41. package/dist/jsx/index.native.cjs +29 -0
  42. package/dist/jsx/index.native.js +16 -29
  43. package/dist/jsx/index.native.js.map +1 -1
  44. package/package.json +9 -7
  45. package/src/ContextMenu.tsx +2 -3
  46. package/src/createNonNativeContextMenu.tsx +131 -104
  47. package/src/index.tsx +1 -13
  48. package/types/ContextMenu.d.ts +85 -76
  49. package/types/ContextMenu.d.ts.map +1 -1
  50. package/types/createNonNativeContextMenu.d.ts +77 -107
  51. package/types/createNonNativeContextMenu.d.ts.map +1 -1
  52. package/types/index.d.ts +84 -74
  53. package/types/index.d.ts.map +1 -1
@@ -1,406 +1,350 @@
1
+ import { createRefComponent } from "@tamagui/compose-refs";
1
2
  import { createBaseMenu } from "@tamagui/create-menu";
2
3
  import { useControllableState } from "@tamagui/use-controllable-state";
3
- import { composeEventHandlers, composeRefs, createStyledContext, isAndroid, isWeb, Slot, View, withStaticProperties } from "@tamagui/web";
4
+ import { Slot, View, composeEventHandlers, composeRefs, createStyledContext, createStyledHOC, isAndroid, isWeb, withStaticProperties } from "@tamagui/web";
4
5
  import React, { useId } from "react";
5
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+
6
8
  const CONTEXTMENU_CONTEXT = "ContextMenuContext";
7
- function createNonNativeContextMenu(params) {
8
- const {
9
- Menu
10
- } = createBaseMenu(params);
11
- const CONTEXT_MENU_NAME = "ContextMenu";
12
- const {
13
- Provider: ContextMenuProvider,
14
- useStyledContext: useContextMenuContext
15
- } = createStyledContext();
16
- const ContextMenuComp = props => {
17
- const {
18
- scope,
19
- children,
20
- onOpenChange,
21
- dir,
22
- modal = true,
23
- ...rest
24
- } = props;
25
- const [open, setOpen] = React.useState(false);
26
- const triggerRef = React.useRef(null);
27
- const handleOpenChange = React.useCallback((open2, event) => {
28
- onOpenChange?.(open2, event);
29
- if (event?.defaultPrevented) return;
30
- setOpen(open2);
31
- }, [onOpenChange]);
32
- return /* @__PURE__ */jsx(ContextMenuProvider, {
33
- scope,
34
- triggerId: useId(),
35
- triggerRef,
36
- contentId: useId(),
37
- open,
38
- onOpenChange: handleOpenChange,
39
- modal,
40
- children: /* @__PURE__ */jsx(Menu, {
41
- scope: scope || CONTEXTMENU_CONTEXT,
42
- dir,
43
- open,
44
- onOpenChange: handleOpenChange,
45
- modal,
46
- ...rest,
47
- children
48
- })
49
- });
50
- };
51
- ContextMenuComp.displayName = CONTEXT_MENU_NAME;
52
- const TRIGGER_NAME = "ContextMenuTrigger";
53
- const ContextMenuTrigger = View.styleable((props, forwardedRef) => {
54
- const {
55
- scope,
56
- style,
57
- disabled = false,
58
- asChild,
59
- children,
60
- ...triggerProps
61
- } = props;
62
- const context = useContextMenuContext(scope);
63
- const pointRef = React.useRef({
64
- x: 0,
65
- y: 0
66
- });
67
- const virtualRef = React.useMemo(() => ({
68
- current: {
69
- getBoundingClientRect: () => {
70
- if (isWeb) {
71
- const scrollX = window.scrollX || document.documentElement.scrollLeft;
72
- const scrollY = window.scrollY || document.documentElement.scrollTop;
73
- return DOMRect.fromRect({
74
- width: 0,
75
- height: 0,
76
- x: pointRef.current.x - scrollX,
77
- y: pointRef.current.y - scrollY
78
- });
79
- }
80
- return {
81
- width: 0,
82
- height: 0,
83
- top: 0,
84
- left: 0,
85
- ...pointRef.current
86
- };
87
- },
88
- ...(!isWeb && {
89
- measure: c => c(pointRef.current.x, pointRef.current.y, 0, 0),
90
- measureInWindow: c => c(pointRef.current.x, pointRef.current.y, 0, 0)
91
- })
92
- }
93
- }), [pointRef.current.x, pointRef.current.y]);
94
- const longPressTimerRef = React.useRef(0);
95
- const clearLongPress = React.useCallback(() => window.clearTimeout(longPressTimerRef.current), []);
96
- const createOpenChangeEvent = () => {
97
- let defaultPrevented = false;
98
- return {
99
- get defaultPrevented() {
100
- return defaultPrevented;
101
- },
102
- preventDefault() {
103
- defaultPrevented = true;
104
- }
105
- };
106
- };
107
- const handleOpen = event => {
108
- if (isWeb && (event instanceof MouseEvent || event instanceof PointerEvent)) {
109
- pointRef.current = {
110
- x: event.clientX,
111
- y: event.clientY
112
- };
113
- } else {
114
- pointRef.current = {
115
- x: event.nativeEvent.pageX,
116
- y: event.nativeEvent.pageY
117
- };
118
- }
119
- const openChangeEvent = createOpenChangeEvent();
120
- context.onOpenChange(true, openChangeEvent);
121
- return openChangeEvent;
122
- };
123
- React.useEffect(() => clearLongPress, [clearLongPress]);
124
- React.useEffect(() => void (disabled && clearLongPress()), [disabled, clearLongPress]);
125
- const Comp = asChild ? Slot : View;
126
- return /* @__PURE__ */jsxs(Fragment, {
127
- children: [/* @__PURE__ */jsx(Menu.Anchor, {
128
- scope: scope || CONTEXTMENU_CONTEXT,
129
- virtualRef
130
- }), /* @__PURE__ */jsx(Comp, {
131
- render: "span",
132
- componentName: TRIGGER_NAME,
133
- id: context.triggerId,
134
- "data-state": context.open ? "open" : "closed",
135
- "data-disabled": disabled ? "" : void 0,
136
- ...triggerProps,
137
- ref: composeRefs(forwardedRef, context.triggerRef),
138
- style: isWeb ? {
139
- WebkitTouchCallout: "none",
140
- ...style
141
- } : null,
142
- ...(isWeb && {
143
- onContextMenu: disabled ? props.onContextMenu : composeEventHandlers(props.onContextMenu, event => {
144
- clearLongPress();
145
- const openChangeEvent = handleOpen(event);
146
- if (!openChangeEvent.defaultPrevented) {
147
- event.preventDefault();
148
- }
149
- }),
150
- onPointerDown: disabled ? props.onPointerDown : composeEventHandlers(props.onPointerDown, event => {
151
- if (event.pointerType === "mouse") return;
152
- clearLongPress();
153
- longPressTimerRef.current = window.setTimeout(() => handleOpen(event), 700);
154
- }),
155
- onPointerMove: disabled ? props.onPointerMove : composeEventHandlers(props.onPointerMove, event => {
156
- if (event.pointerType === "mouse") return;
157
- clearLongPress();
158
- }),
159
- onPointerCancel: disabled ? props.onPointerCancel : composeEventHandlers(props.onPointerCancel, event => {
160
- if (event.pointerType === "mouse") return;
161
- clearLongPress();
162
- }),
163
- onPointerUp: disabled ? props.onPointerUp : composeEventHandlers(props.onPointerUp, event => {
164
- if (event.pointerType === "mouse") return;
165
- clearLongPress();
166
- })
167
- }),
168
- ...(!isWeb && {
169
- onLongPress: disabled ? props.onLongPress : composeEventHandlers(props.onLongPress, event => {
170
- clearLongPress();
171
- const openChangeEvent = handleOpen(event);
172
- if (!openChangeEvent.defaultPrevented) {
173
- event.preventDefault();
174
- }
175
- })
176
- }),
177
- children
178
- })]
179
- });
180
- });
181
- ContextMenuTrigger.displayName = TRIGGER_NAME;
182
- const PORTAL_NAME = "ContextMenuPortal";
183
- const ContextMenuPortal = props => {
184
- const {
185
- scope,
186
- children,
187
- ...portalProps
188
- } = props;
189
- const context = isAndroid ? useContextMenuContext(scope) : null;
190
- const content = isAndroid ? /* @__PURE__ */jsx(ContextMenuProvider, {
191
- ...context,
192
- children
193
- }) : children;
194
- return /* @__PURE__ */jsx(Menu.Portal, {
195
- scope: scope || CONTEXTMENU_CONTEXT,
196
- ...portalProps,
197
- children: content
198
- });
199
- };
200
- ContextMenuPortal.displayName = PORTAL_NAME;
201
- const CONTENT_NAME = "ContextMenuContent";
202
- const ContextMenuContent = React.forwardRef((props, forwardedRef) => {
203
- const {
204
- scope,
205
- ...contentProps
206
- } = props;
207
- const context = useContextMenuContext(scope);
208
- const hasInteractedOutsideRef = React.useRef(false);
209
- return /* @__PURE__ */jsx(Menu.Content, {
210
- id: context.contentId,
211
- "aria-labelledby": context.triggerId,
212
- scope: scope || CONTEXTMENU_CONTEXT,
213
- ...contentProps,
214
- ref: forwardedRef,
215
- onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, event => {
216
- if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();
217
- hasInteractedOutsideRef.current = false;
218
- event.preventDefault();
219
- }),
220
- onInteractOutside: composeEventHandlers(props.onInteractOutside, event => {
221
- const originalEvent = event.detail.originalEvent;
222
- const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
223
- const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
224
- if (!context.modal || isRightClick) hasInteractedOutsideRef.current = true;
225
- })
226
- });
227
- });
228
- ContextMenuContent.displayName = CONTENT_NAME;
229
- const ITEM_NAME = "ContextMenuItem";
230
- const ContextMenuItem = React.forwardRef((props, forwardedRef) => {
231
- const {
232
- scope,
233
- ...itemProps
234
- } = props;
235
- return /* @__PURE__ */jsx(Menu.Item, {
236
- componentName: ITEM_NAME,
237
- scope: scope || CONTEXTMENU_CONTEXT,
238
- ...itemProps,
239
- ref: forwardedRef
240
- });
241
- });
242
- ContextMenuItem.displayName = ITEM_NAME;
243
- const CHECKBOX_ITEM_NAME = "ContextMenuCheckboxItem";
244
- const ContextMenuCheckboxItem = React.forwardRef((props, forwardedRef) => {
245
- const {
246
- scope,
247
- ...checkboxItemProps
248
- } = props;
249
- return /* @__PURE__ */jsx(Menu.CheckboxItem, {
250
- componentName: CHECKBOX_ITEM_NAME,
251
- scope: scope || CONTEXTMENU_CONTEXT,
252
- ...checkboxItemProps,
253
- ref: forwardedRef
254
- });
255
- });
256
- ContextMenuCheckboxItem.displayName = CHECKBOX_ITEM_NAME;
257
- const RADIO_GROUP_NAME = "ContextMenuRadioGroup";
258
- const ContextMenuRadioGroup = React.forwardRef((props, forwardedRef) => {
259
- const {
260
- scope,
261
- ...radioGroupProps
262
- } = props;
263
- return /* @__PURE__ */jsx(Menu.RadioGroup, {
264
- scope: scope || CONTEXTMENU_CONTEXT,
265
- ...radioGroupProps,
266
- ref: forwardedRef
267
- });
268
- });
269
- ContextMenuRadioGroup.displayName = RADIO_GROUP_NAME;
270
- const RADIO_ITEM_NAME = "ContextMenuRadioItem";
271
- const ContextMenuRadioItem = React.forwardRef((props, forwardedRef) => {
272
- const {
273
- scope,
274
- ...radioItemProps
275
- } = props;
276
- return /* @__PURE__ */jsx(Menu.RadioItem, {
277
- componentName: RADIO_ITEM_NAME,
278
- scope: scope || CONTEXTMENU_CONTEXT,
279
- ...radioItemProps,
280
- ref: forwardedRef
281
- });
282
- });
283
- ContextMenuRadioItem.displayName = RADIO_ITEM_NAME;
284
- const INDICATOR_NAME = "ContextMenuItemIndicator";
285
- const ContextMenuItemIndicator = Menu.ItemIndicator.styleable((props, forwardedRef) => {
286
- const {
287
- scope,
288
- ...itemIndicatorProps
289
- } = props;
290
- return /* @__PURE__ */jsx(Menu.ItemIndicator, {
291
- componentName: INDICATOR_NAME,
292
- scope: scope || CONTEXTMENU_CONTEXT,
293
- ...itemIndicatorProps,
294
- ref: forwardedRef
295
- });
296
- });
297
- ContextMenuItemIndicator.displayName = INDICATOR_NAME;
298
- const SUB_NAME = "ContextMenuSub";
299
- const ContextMenuSub = props => {
300
- const {
301
- scope,
302
- children,
303
- onOpenChange,
304
- open: openProp,
305
- defaultOpen,
306
- ...rest
307
- } = props;
308
- const [open, setOpen] = useControllableState({
309
- prop: openProp,
310
- defaultProp: defaultOpen,
311
- onChange: onOpenChange
312
- });
313
- return /* @__PURE__ */jsx(Menu.Sub, {
314
- scope: scope || CONTEXTMENU_CONTEXT,
315
- open,
316
- onOpenChange: setOpen,
317
- ...rest,
318
- children
319
- });
320
- };
321
- ContextMenuSub.displayName = SUB_NAME;
322
- const SUB_TRIGGER_NAME = "ContextMenuSubTrigger";
323
- const ContextMenuSubTrigger = View.styleable((props, forwardedRef) => {
324
- const {
325
- scope,
326
- ...subTriggerProps
327
- } = props;
328
- return /* @__PURE__ */jsx(Menu.SubTrigger, {
329
- componentName: SUB_TRIGGER_NAME,
330
- scope: scope || CONTEXTMENU_CONTEXT,
331
- ...subTriggerProps,
332
- ref: forwardedRef
333
- });
334
- });
335
- ContextMenuSubTrigger.displayName = SUB_TRIGGER_NAME;
336
- const SUB_CONTENT_NAME = "ContextMenuSubContent";
337
- const ContextMenuSubContent = React.forwardRef((props, forwardedRef) => {
338
- const {
339
- scope,
340
- ...subContentProps
341
- } = props;
342
- return /* @__PURE__ */jsx(Menu.SubContent, {
343
- scope: scope || CONTEXTMENU_CONTEXT,
344
- ...subContentProps,
345
- ref: forwardedRef,
346
- style: isWeb ? {
347
- ...props.style,
348
- ...{
349
- "--tamagui-context-menu-content-transform-origin": "var(--tamagui-popper-transform-origin)",
350
- "--tamagui-context-menu-content-available-width": "var(--tamagui-popper-available-width)",
351
- "--tamagui-context-menu-content-available-height": "var(--tamagui-popper-available-height)",
352
- "--tamagui-context-menu-trigger-width": "var(--tamagui-popper-anchor-width)",
353
- "--tamagui-context-menu-trigger-height": "var(--tamagui-popper-anchor-height)"
354
- }
355
- } : null
356
- });
357
- });
358
- ContextMenuSubContent.displayName = SUB_CONTENT_NAME;
359
- const ARROW_NAME = "ContextMenuArrow";
360
- const ContextMenuArrow = React.forwardRef((props, forwardedRef) => {
361
- const {
362
- scope,
363
- ...arrowProps
364
- } = props;
365
- return /* @__PURE__ */jsx(Menu.Arrow, {
366
- componentName: ARROW_NAME,
367
- scope: scope || CONTEXTMENU_CONTEXT,
368
- ...arrowProps,
369
- ref: forwardedRef
370
- });
371
- });
372
- ContextMenuArrow.displayName = ARROW_NAME;
373
- const ContextMenuGroup = Menu.Group;
374
- const ContextMenuLabel = Menu.Label;
375
- const ContextMenuSeparator = Menu.Separator;
376
- const ContextMenuItemTitle = Menu.ItemTitle;
377
- const ContextMenuItemSubTitle = Menu.ItemSubtitle;
378
- const ContextMenuItemImage = Menu.ItemImage;
379
- const ContextMenuItemIcon = Menu.ItemIcon;
380
- const ContextMenuPreview = () => null;
381
- return withStaticProperties(ContextMenuComp, {
382
- Root: ContextMenuComp,
383
- Trigger: ContextMenuTrigger,
384
- Portal: ContextMenuPortal,
385
- Content: ContextMenuContent,
386
- Group: ContextMenuGroup,
387
- Label: ContextMenuLabel,
388
- Item: ContextMenuItem,
389
- CheckboxItem: ContextMenuCheckboxItem,
390
- RadioGroup: ContextMenuRadioGroup,
391
- RadioItem: ContextMenuRadioItem,
392
- ItemIndicator: ContextMenuItemIndicator,
393
- Separator: ContextMenuSeparator,
394
- Arrow: ContextMenuArrow,
395
- Sub: ContextMenuSub,
396
- SubTrigger: ContextMenuSubTrigger,
397
- SubContent: ContextMenuSubContent,
398
- ItemTitle: ContextMenuItemTitle,
399
- ItemSubtitle: ContextMenuItemSubTitle,
400
- ItemIcon: ContextMenuItemIcon,
401
- ItemImage: ContextMenuItemImage,
402
- Preview: ContextMenuPreview
403
- });
9
+ function createNonNativeContextMenu() {
10
+ const { Menu } = createBaseMenu();
11
+ const CONTEXT_MENU_NAME = "ContextMenu";
12
+ const { Provider: ContextMenuProvider, useStyledContext: useContextMenuContext } = createStyledContext();
13
+ const ContextMenuComp = (props) => {
14
+ const { scope, children, onOpenChange, open: openProp, defaultOpen, dir, modal = true, ...rest } = props;
15
+ const [open, setOpen] = useControllableState({
16
+ prop: openProp,
17
+ defaultProp: defaultOpen ?? false
18
+ });
19
+ const triggerRef = React.useRef(null);
20
+ const handleOpenChange = React.useCallback((open2, event) => {
21
+ onOpenChange?.(open2, event);
22
+ if (event?.defaultPrevented) return;
23
+ setOpen(open2);
24
+ }, [onOpenChange, setOpen]);
25
+ return /* @__PURE__ */ jsx(ContextMenuProvider, {
26
+ scope,
27
+ triggerId: useId(),
28
+ triggerRef,
29
+ contentId: useId(),
30
+ open,
31
+ onOpenChange: handleOpenChange,
32
+ modal,
33
+ children: /* @__PURE__ */ jsx(Menu, {
34
+ scope: scope || "ContextMenuContext",
35
+ dir,
36
+ open,
37
+ onOpenChange: handleOpenChange,
38
+ modal,
39
+ ...rest,
40
+ children
41
+ })
42
+ });
43
+ };
44
+ ContextMenuComp.displayName = CONTEXT_MENU_NAME;
45
+ const TRIGGER_NAME = "ContextMenuTrigger";
46
+ const ContextMenuTrigger = createStyledHOC(View, (props, forwardedRef) => {
47
+ const { scope, style, className, disabled = false, asChild, children, ...triggerProps } = props;
48
+ const context = useContextMenuContext(scope);
49
+ const pointRef = React.useRef({
50
+ x: 0,
51
+ y: 0
52
+ });
53
+ const virtualRef = React.useMemo(() => ({ current: {
54
+ getBoundingClientRect: () => {
55
+ if (isWeb) {
56
+ const scrollX = window.scrollX || document.documentElement.scrollLeft;
57
+ const scrollY = window.scrollY || document.documentElement.scrollTop;
58
+ return DOMRect.fromRect({
59
+ width: 0,
60
+ height: 0,
61
+ x: pointRef.current.x - scrollX,
62
+ y: pointRef.current.y - scrollY
63
+ });
64
+ }
65
+ return {
66
+ width: 0,
67
+ height: 0,
68
+ top: 0,
69
+ left: 0,
70
+ ...pointRef.current
71
+ };
72
+ },
73
+ ...!isWeb && {
74
+ measure: (c) => c(pointRef.current.x, pointRef.current.y, 0, 0),
75
+ measureInWindow: (c) => c(pointRef.current.x, pointRef.current.y, 0, 0)
76
+ }
77
+ } }), [pointRef.current.x, pointRef.current.y]);
78
+ const longPressTimerRef = React.useRef(0);
79
+ const clearLongPress = React.useCallback(() => window.clearTimeout(longPressTimerRef.current), []);
80
+ const createOpenChangeEvent = () => {
81
+ let defaultPrevented = false;
82
+ return {
83
+ get defaultPrevented() {
84
+ return defaultPrevented;
85
+ },
86
+ preventDefault() {
87
+ defaultPrevented = true;
88
+ }
89
+ };
90
+ };
91
+ const handleOpen = (event) => {
92
+ if (isWeb && (event instanceof MouseEvent || event instanceof PointerEvent)) {
93
+ pointRef.current = {
94
+ x: event.clientX,
95
+ y: event.clientY
96
+ };
97
+ } else {
98
+ pointRef.current = {
99
+ x: event.nativeEvent.pageX,
100
+ y: event.nativeEvent.pageY
101
+ };
102
+ }
103
+ const openChangeEvent = createOpenChangeEvent();
104
+ context.onOpenChange(true, openChangeEvent);
105
+ return openChangeEvent;
106
+ };
107
+ React.useEffect(() => clearLongPress, [clearLongPress]);
108
+ React.useEffect(() => void (disabled && clearLongPress()), [disabled, clearLongPress]);
109
+ const Comp = asChild ? Slot : View;
110
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Menu.Anchor, {
111
+ scope: scope || "ContextMenuContext",
112
+ virtualRef
113
+ }), /* @__PURE__ */ jsx(Comp, {
114
+ render: "span",
115
+ className: `is_${TRIGGER_NAME} ${className || ""}`.trim(),
116
+ id: context.triggerId,
117
+ "data-state": context.open ? "open" : "closed",
118
+ "data-disabled": disabled ? "" : void 0,
119
+ ...triggerProps,
120
+ ref: composeRefs(forwardedRef, context.triggerRef),
121
+ style: isWeb ? {
122
+ WebkitTouchCallout: "none",
123
+ ...style
124
+ } : null,
125
+ ...isWeb && {
126
+ onContextMenu: disabled ? props.onContextMenu : composeEventHandlers(props.onContextMenu, (event) => {
127
+ clearLongPress();
128
+ const openChangeEvent = handleOpen(event);
129
+ if (!openChangeEvent.defaultPrevented) {
130
+ event.preventDefault();
131
+ }
132
+ }),
133
+ onPointerDown: disabled ? props.onPointerDown : composeEventHandlers(props.onPointerDown, (event) => {
134
+ if (event.pointerType === "mouse") return;
135
+ clearLongPress();
136
+ longPressTimerRef.current = window.setTimeout(() => handleOpen(event), 700);
137
+ }),
138
+ onPointerMove: disabled ? props.onPointerMove : composeEventHandlers(props.onPointerMove, (event) => {
139
+ if (event.pointerType === "mouse") return;
140
+ clearLongPress();
141
+ }),
142
+ onPointerCancel: disabled ? props.onPointerCancel : composeEventHandlers(props.onPointerCancel, (event) => {
143
+ if (event.pointerType === "mouse") return;
144
+ clearLongPress();
145
+ }),
146
+ onPointerUp: disabled ? props.onPointerUp : composeEventHandlers(props.onPointerUp, (event) => {
147
+ if (event.pointerType === "mouse") return;
148
+ clearLongPress();
149
+ })
150
+ },
151
+ ...!isWeb && { onLongPress: disabled ? props.onLongPress : composeEventHandlers(props.onLongPress, (event) => {
152
+ clearLongPress();
153
+ const openChangeEvent = handleOpen(event);
154
+ if (!openChangeEvent.defaultPrevented) {
155
+ event.preventDefault();
156
+ }
157
+ }) },
158
+ children
159
+ })] });
160
+ });
161
+ ContextMenuTrigger.displayName = TRIGGER_NAME;
162
+ const PORTAL_NAME = "ContextMenuPortal";
163
+ const ContextMenuPortal = (props) => {
164
+ const { scope, children, ...portalProps } = props;
165
+ const context = isAndroid ? useContextMenuContext(scope) : null;
166
+ const content = isAndroid ? /* @__PURE__ */ jsx(ContextMenuProvider, {
167
+ ...context,
168
+ children
169
+ }) : children;
170
+ return /* @__PURE__ */ jsx(Menu.Portal, {
171
+ scope: scope || "ContextMenuContext",
172
+ ...portalProps,
173
+ children: content
174
+ });
175
+ };
176
+ ContextMenuPortal.displayName = PORTAL_NAME;
177
+ const CONTENT_NAME = "ContextMenuContent";
178
+ const ContextMenuContent = createStyledHOC(Menu.Content, (props, forwardedRef) => {
179
+ const { scope, ...contentProps } = props;
180
+ const context = useContextMenuContext(scope);
181
+ const hasInteractedOutsideRef = React.useRef(false);
182
+ return /* @__PURE__ */ jsx(Menu.Content, {
183
+ id: context.contentId,
184
+ "aria-labelledby": context.triggerId,
185
+ scope: scope || "ContextMenuContext",
186
+ ...contentProps,
187
+ ref: forwardedRef,
188
+ onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, (event) => {
189
+ if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();
190
+ hasInteractedOutsideRef.current = false;
191
+ event.cancel();
192
+ }),
193
+ onInteractOutside: composeEventHandlers(props.onInteractOutside, (event) => {
194
+ if (event.interaction !== "pointer" || !event.event) return;
195
+ const originalEvent = event.event;
196
+ const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
197
+ const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
198
+ if (!context.modal || isRightClick) hasInteractedOutsideRef.current = true;
199
+ })
200
+ });
201
+ });
202
+ ContextMenuContent.displayName = CONTENT_NAME;
203
+ const ITEM_NAME = "ContextMenuItem";
204
+ const ContextMenuItem = createRefComponent((props, forwardedRef) => {
205
+ const { scope, className, ...itemProps } = props;
206
+ return /* @__PURE__ */ jsx(Menu.Item, {
207
+ className: `is_${ITEM_NAME} ${className || ""}`.trim(),
208
+ scope: scope || "ContextMenuContext",
209
+ ...itemProps,
210
+ ref: forwardedRef
211
+ });
212
+ });
213
+ ContextMenuItem.displayName = ITEM_NAME;
214
+ const CHECKBOX_ITEM_NAME = "ContextMenuCheckboxItem";
215
+ const ContextMenuCheckboxItem = createRefComponent((props, forwardedRef) => {
216
+ const { scope, className, ...checkboxItemProps } = props;
217
+ return /* @__PURE__ */ jsx(Menu.CheckboxItem, {
218
+ className: `is_${CHECKBOX_ITEM_NAME} ${className || ""}`.trim(),
219
+ scope: scope || "ContextMenuContext",
220
+ ...checkboxItemProps,
221
+ ref: forwardedRef
222
+ });
223
+ });
224
+ ContextMenuCheckboxItem.displayName = CHECKBOX_ITEM_NAME;
225
+ const RADIO_GROUP_NAME = "ContextMenuRadioGroup";
226
+ const ContextMenuRadioGroup = createRefComponent((props, forwardedRef) => {
227
+ const { scope, ...radioGroupProps } = props;
228
+ return /* @__PURE__ */ jsx(Menu.RadioGroup, {
229
+ scope: scope || "ContextMenuContext",
230
+ ...radioGroupProps,
231
+ ref: forwardedRef
232
+ });
233
+ });
234
+ ContextMenuRadioGroup.displayName = RADIO_GROUP_NAME;
235
+ const RADIO_ITEM_NAME = "ContextMenuRadioItem";
236
+ const ContextMenuRadioItem = createRefComponent((props, forwardedRef) => {
237
+ const { scope, className, ...radioItemProps } = props;
238
+ return /* @__PURE__ */ jsx(Menu.RadioItem, {
239
+ className: `is_${RADIO_ITEM_NAME} ${className || ""}`.trim(),
240
+ scope: scope || "ContextMenuContext",
241
+ ...radioItemProps,
242
+ ref: forwardedRef
243
+ });
244
+ });
245
+ ContextMenuRadioItem.displayName = RADIO_ITEM_NAME;
246
+ const INDICATOR_NAME = "ContextMenuItemIndicator";
247
+ const ContextMenuItemIndicator = createStyledHOC(Menu.ItemIndicator, (props, forwardedRef) => {
248
+ const { scope, className, ...itemIndicatorProps } = props;
249
+ return /* @__PURE__ */ jsx(Menu.ItemIndicator, {
250
+ className: `is_${INDICATOR_NAME} ${className || ""}`.trim(),
251
+ scope: scope || "ContextMenuContext",
252
+ ...itemIndicatorProps,
253
+ ref: forwardedRef
254
+ });
255
+ });
256
+ ContextMenuItemIndicator.displayName = INDICATOR_NAME;
257
+ const SUB_NAME = "ContextMenuSub";
258
+ const ContextMenuSub = (props) => {
259
+ const { scope, children, onOpenChange, open: openProp, defaultOpen, ...rest } = props;
260
+ const [open, setOpen] = useControllableState({
261
+ prop: openProp,
262
+ defaultProp: defaultOpen,
263
+ onChange: onOpenChange
264
+ });
265
+ return /* @__PURE__ */ jsx(Menu.Sub, {
266
+ scope: scope || "ContextMenuContext",
267
+ open,
268
+ onOpenChange: setOpen,
269
+ ...rest,
270
+ children
271
+ });
272
+ };
273
+ ContextMenuSub.displayName = SUB_NAME;
274
+ const SUB_TRIGGER_NAME = "ContextMenuSubTrigger";
275
+ const ContextMenuSubTrigger = createStyledHOC(View, (props, forwardedRef) => {
276
+ const { scope, className, ...subTriggerProps } = props;
277
+ return /* @__PURE__ */ jsx(Menu.SubTrigger, {
278
+ className: `is_${SUB_TRIGGER_NAME} ${className || ""}`.trim(),
279
+ scope: scope || "ContextMenuContext",
280
+ ...subTriggerProps,
281
+ ref: forwardedRef
282
+ });
283
+ });
284
+ ContextMenuSubTrigger.displayName = SUB_TRIGGER_NAME;
285
+ const SUB_CONTENT_NAME = "ContextMenuSubContent";
286
+ const ContextMenuSubContent = createStyledHOC(Menu.SubContent, (props, forwardedRef) => {
287
+ const { scope, ...subContentProps } = props;
288
+ return /* @__PURE__ */ jsx(Menu.SubContent, {
289
+ scope: scope || "ContextMenuContext",
290
+ ...subContentProps,
291
+ ref: forwardedRef,
292
+ style: isWeb ? {
293
+ ...props.style,
294
+ ...{
295
+ "--tamagui-context-menu-content-transform-origin": "var(--tamagui-popper-transform-origin)",
296
+ "--tamagui-context-menu-content-available-width": "var(--tamagui-popper-available-width)",
297
+ "--tamagui-context-menu-content-available-height": "var(--tamagui-popper-available-height)",
298
+ "--tamagui-context-menu-trigger-width": "var(--tamagui-popper-anchor-width)",
299
+ "--tamagui-context-menu-trigger-height": "var(--tamagui-popper-anchor-height)"
300
+ }
301
+ } : null
302
+ });
303
+ });
304
+ ContextMenuSubContent.displayName = SUB_CONTENT_NAME;
305
+ const ARROW_NAME = "ContextMenuArrow";
306
+ const ContextMenuArrow = createRefComponent((props, forwardedRef) => {
307
+ const { scope, className, ...arrowProps } = props;
308
+ return /* @__PURE__ */ jsx(Menu.Arrow, {
309
+ className: `is_${ARROW_NAME} ${className || ""}`.trim(),
310
+ scope: scope || "ContextMenuContext",
311
+ ...arrowProps,
312
+ ref: forwardedRef
313
+ });
314
+ });
315
+ ContextMenuArrow.displayName = ARROW_NAME;
316
+ const ContextMenuGroup = Menu.Group;
317
+ const ContextMenuLabel = Menu.Label;
318
+ const ContextMenuSeparator = Menu.Separator;
319
+ const ContextMenuItemTitle = Menu.ItemTitle;
320
+ const ContextMenuItemSubTitle = Menu.ItemSubtitle;
321
+ const ContextMenuItemImage = Menu.ItemImage;
322
+ const ContextMenuItemIcon = Menu.ItemIcon;
323
+ const ContextMenuPreview = () => null;
324
+ return withStaticProperties(ContextMenuComp, {
325
+ Root: ContextMenuComp,
326
+ Trigger: ContextMenuTrigger,
327
+ Portal: ContextMenuPortal,
328
+ Content: ContextMenuContent,
329
+ Group: ContextMenuGroup,
330
+ Label: ContextMenuLabel,
331
+ Item: ContextMenuItem,
332
+ CheckboxItem: ContextMenuCheckboxItem,
333
+ RadioGroup: ContextMenuRadioGroup,
334
+ RadioItem: ContextMenuRadioItem,
335
+ ItemIndicator: ContextMenuItemIndicator,
336
+ Separator: ContextMenuSeparator,
337
+ Arrow: ContextMenuArrow,
338
+ Sub: ContextMenuSub,
339
+ SubTrigger: ContextMenuSubTrigger,
340
+ SubContent: ContextMenuSubContent,
341
+ ItemTitle: ContextMenuItemTitle,
342
+ ItemSubtitle: ContextMenuItemSubTitle,
343
+ ItemIcon: ContextMenuItemIcon,
344
+ ItemImage: ContextMenuItemImage,
345
+ Preview: ContextMenuPreview
346
+ });
404
347
  }
348
+
405
349
  export { CONTEXTMENU_CONTEXT, createNonNativeContextMenu };
406
350
  //# sourceMappingURL=createNonNativeContextMenu.mjs.map