@tamagui/context-menu 2.0.0-rc.4 → 2.0.0-rc.40

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