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