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