bc518174
王天杨
提交两个项目文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
|
"use strict";
"use client";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/react/context-menu/src/index.ts
var src_exports = {};
__export(src_exports, {
Arrow: () => Arrow2,
CheckboxItem: () => CheckboxItem2,
Content: () => Content2,
ContextMenu: () => ContextMenu,
ContextMenuArrow: () => ContextMenuArrow,
ContextMenuCheckboxItem: () => ContextMenuCheckboxItem,
ContextMenuContent: () => ContextMenuContent,
ContextMenuGroup: () => ContextMenuGroup,
ContextMenuItem: () => ContextMenuItem,
ContextMenuItemIndicator: () => ContextMenuItemIndicator,
ContextMenuLabel: () => ContextMenuLabel,
ContextMenuPortal: () => ContextMenuPortal,
ContextMenuRadioGroup: () => ContextMenuRadioGroup,
ContextMenuRadioItem: () => ContextMenuRadioItem,
ContextMenuSeparator: () => ContextMenuSeparator,
ContextMenuSub: () => ContextMenuSub,
ContextMenuSubContent: () => ContextMenuSubContent,
ContextMenuSubTrigger: () => ContextMenuSubTrigger,
ContextMenuTrigger: () => ContextMenuTrigger,
Group: () => Group2,
Item: () => Item2,
ItemIndicator: () => ItemIndicator2,
Label: () => Label2,
Portal: () => Portal2,
RadioGroup: () => RadioGroup2,
RadioItem: () => RadioItem2,
Root: () => Root2,
Separator: () => Separator2,
Sub: () => Sub2,
SubContent: () => SubContent2,
SubTrigger: () => SubTrigger2,
Trigger: () => Trigger,
createContextMenuScope: () => createContextMenuScope
});
module.exports = __toCommonJS(src_exports);
// packages/react/context-menu/src/context-menu.tsx
var React = __toESM(require("react"));
var import_primitive = require("@radix-ui/primitive");
var import_react_context = require("@radix-ui/react-context");
var import_react_primitive = require("@radix-ui/react-primitive");
var MenuPrimitive = __toESM(require("@radix-ui/react-menu"));
var import_react_menu = require("@radix-ui/react-menu");
var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
var import_react_use_controllable_state = require("@radix-ui/react-use-controllable-state");
var import_jsx_runtime = require("react/jsx-runtime");
var CONTEXT_MENU_NAME = "ContextMenu";
var [createContextMenuContext, createContextMenuScope] = (0, import_react_context.createContextScope)(CONTEXT_MENU_NAME, [
import_react_menu.createMenuScope
]);
var useMenuScope = (0, import_react_menu.createMenuScope)();
var [ContextMenuProvider, useContextMenuContext] = createContextMenuContext(CONTEXT_MENU_NAME);
var ContextMenu = (props) => {
const { __scopeContextMenu, children, onOpenChange, dir, modal = true } = props;
const [open, setOpen] = React.useState(false);
const menuScope = useMenuScope(__scopeContextMenu);
const handleOpenChangeProp = (0, import_react_use_callback_ref.useCallbackRef)(onOpenChange);
const handleOpenChange = React.useCallback(
(open2) => {
setOpen(open2);
handleOpenChangeProp(open2);
},
[handleOpenChangeProp]
);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
ContextMenuProvider,
{
scope: __scopeContextMenu,
open,
onOpenChange: handleOpenChange,
modal,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
MenuPrimitive.Root,
{
...menuScope,
dir,
open,
onOpenChange: handleOpenChange,
modal,
children
}
)
}
);
};
ContextMenu.displayName = CONTEXT_MENU_NAME;
var TRIGGER_NAME = "ContextMenuTrigger";
var ContextMenuTrigger = React.forwardRef(
(props, forwardedRef) => {
const { __scopeContextMenu, disabled = false, ...triggerProps } = props;
const context = useContextMenuContext(TRIGGER_NAME, __scopeContextMenu);
const menuScope = useMenuScope(__scopeContextMenu);
const pointRef = React.useRef({ x: 0, y: 0 });
const virtualRef = React.useRef({
getBoundingClientRect: () => DOMRect.fromRect({ width: 0, height: 0, ...pointRef.current })
});
const longPressTimerRef = React.useRef(0);
const clearLongPress = React.useCallback(
() => window.clearTimeout(longPressTimerRef.current),
[]
);
const handleOpen = (event) => {
pointRef.current = { x: event.clientX, y: event.clientY };
context.onOpenChange(true);
};
React.useEffect(() => clearLongPress, [clearLongPress]);
React.useEffect(() => void (disabled && clearLongPress()), [disabled, clearLongPress]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Anchor, { ...menuScope, virtualRef }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_react_primitive.Primitive.span,
{
"data-state": context.open ? "open" : "closed",
"data-disabled": disabled ? "" : void 0,
...triggerProps,
ref: forwardedRef,
style: { WebkitTouchCallout: "none", ...props.style },
onContextMenu: disabled ? props.onContextMenu : (0, import_primitive.composeEventHandlers)(props.onContextMenu, (event) => {
clearLongPress();
handleOpen(event);
event.preventDefault();
}),
onPointerDown: disabled ? props.onPointerDown : (0, import_primitive.composeEventHandlers)(
props.onPointerDown,
whenTouchOrPen((event) => {
clearLongPress();
longPressTimerRef.current = window.setTimeout(() => handleOpen(event), 700);
})
),
onPointerMove: disabled ? props.onPointerMove : (0, import_primitive.composeEventHandlers)(props.onPointerMove, whenTouchOrPen(clearLongPress)),
onPointerCancel: disabled ? props.onPointerCancel : (0, import_primitive.composeEventHandlers)(props.onPointerCancel, whenTouchOrPen(clearLongPress)),
onPointerUp: disabled ? props.onPointerUp : (0, import_primitive.composeEventHandlers)(props.onPointerUp, whenTouchOrPen(clearLongPress))
}
)
] });
}
);
ContextMenuTrigger.displayName = TRIGGER_NAME;
var PORTAL_NAME = "ContextMenuPortal";
var ContextMenuPortal = (props) => {
const { __scopeContextMenu, ...portalProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Portal, { ...menuScope, ...portalProps });
};
ContextMenuPortal.displayName = PORTAL_NAME;
var CONTENT_NAME = "ContextMenuContent";
var ContextMenuContent = React.forwardRef(
(props, forwardedRef) => {
const { __scopeContextMenu, ...contentProps } = props;
const context = useContextMenuContext(CONTENT_NAME, __scopeContextMenu);
const menuScope = useMenuScope(__scopeContextMenu);
const hasInteractedOutsideRef = React.useRef(false);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
MenuPrimitive.Content,
{
...menuScope,
...contentProps,
ref: forwardedRef,
side: "right",
sideOffset: 2,
align: "start",
onCloseAutoFocus: (event) => {
props.onCloseAutoFocus?.(event);
if (!event.defaultPrevented && hasInteractedOutsideRef.current) {
event.preventDefault();
}
hasInteractedOutsideRef.current = false;
},
onInteractOutside: (event) => {
props.onInteractOutside?.(event);
if (!event.defaultPrevented && !context.modal) hasInteractedOutsideRef.current = true;
},
style: {
...props.style,
// re-namespace exposed content custom properties
...{
"--radix-context-menu-content-transform-origin": "var(--radix-popper-transform-origin)",
"--radix-context-menu-content-available-width": "var(--radix-popper-available-width)",
"--radix-context-menu-content-available-height": "var(--radix-popper-available-height)",
"--radix-context-menu-trigger-width": "var(--radix-popper-anchor-width)",
"--radix-context-menu-trigger-height": "var(--radix-popper-anchor-height)"
}
}
}
);
}
);
ContextMenuContent.displayName = CONTENT_NAME;
var GROUP_NAME = "ContextMenuGroup";
var ContextMenuGroup = React.forwardRef(
(props, forwardedRef) => {
const { __scopeContextMenu, ...groupProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Group, { ...menuScope, ...groupProps, ref: forwardedRef });
}
);
ContextMenuGroup.displayName = GROUP_NAME;
var LABEL_NAME = "ContextMenuLabel";
var ContextMenuLabel = React.forwardRef(
(props, forwardedRef) => {
const { __scopeContextMenu, ...labelProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Label, { ...menuScope, ...labelProps, ref: forwardedRef });
}
);
ContextMenuLabel.displayName = LABEL_NAME;
var ITEM_NAME = "ContextMenuItem";
var ContextMenuItem = React.forwardRef(
(props, forwardedRef) => {
const { __scopeContextMenu, ...itemProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Item, { ...menuScope, ...itemProps, ref: forwardedRef });
}
);
ContextMenuItem.displayName = ITEM_NAME;
var CHECKBOX_ITEM_NAME = "ContextMenuCheckboxItem";
var ContextMenuCheckboxItem = React.forwardRef((props, forwardedRef) => {
const { __scopeContextMenu, ...checkboxItemProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.CheckboxItem, { ...menuScope, ...checkboxItemProps, ref: forwardedRef });
});
ContextMenuCheckboxItem.displayName = CHECKBOX_ITEM_NAME;
var RADIO_GROUP_NAME = "ContextMenuRadioGroup";
var ContextMenuRadioGroup = React.forwardRef((props, forwardedRef) => {
const { __scopeContextMenu, ...radioGroupProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.RadioGroup, { ...menuScope, ...radioGroupProps, ref: forwardedRef });
});
ContextMenuRadioGroup.displayName = RADIO_GROUP_NAME;
var RADIO_ITEM_NAME = "ContextMenuRadioItem";
var ContextMenuRadioItem = React.forwardRef((props, forwardedRef) => {
const { __scopeContextMenu, ...radioItemProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.RadioItem, { ...menuScope, ...radioItemProps, ref: forwardedRef });
});
ContextMenuRadioItem.displayName = RADIO_ITEM_NAME;
var INDICATOR_NAME = "ContextMenuItemIndicator";
var ContextMenuItemIndicator = React.forwardRef((props, forwardedRef) => {
const { __scopeContextMenu, ...itemIndicatorProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.ItemIndicator, { ...menuScope, ...itemIndicatorProps, ref: forwardedRef });
});
ContextMenuItemIndicator.displayName = INDICATOR_NAME;
var SEPARATOR_NAME = "ContextMenuSeparator";
var ContextMenuSeparator = React.forwardRef((props, forwardedRef) => {
const { __scopeContextMenu, ...separatorProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Separator, { ...menuScope, ...separatorProps, ref: forwardedRef });
});
ContextMenuSeparator.displayName = SEPARATOR_NAME;
var ARROW_NAME = "ContextMenuArrow";
var ContextMenuArrow = React.forwardRef(
(props, forwardedRef) => {
const { __scopeContextMenu, ...arrowProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Arrow, { ...menuScope, ...arrowProps, ref: forwardedRef });
}
);
ContextMenuArrow.displayName = ARROW_NAME;
var SUB_NAME = "ContextMenuSub";
var ContextMenuSub = (props) => {
const { __scopeContextMenu, children, onOpenChange, open: openProp, defaultOpen } = props;
const menuScope = useMenuScope(__scopeContextMenu);
const [open, setOpen] = (0, import_react_use_controllable_state.useControllableState)({
prop: openProp,
defaultProp: defaultOpen,
onChange: onOpenChange
});
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Sub, { ...menuScope, open, onOpenChange: setOpen, children });
};
ContextMenuSub.displayName = SUB_NAME;
var SUB_TRIGGER_NAME = "ContextMenuSubTrigger";
var ContextMenuSubTrigger = React.forwardRef((props, forwardedRef) => {
const { __scopeContextMenu, ...triggerItemProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.SubTrigger, { ...menuScope, ...triggerItemProps, ref: forwardedRef });
});
ContextMenuSubTrigger.displayName = SUB_TRIGGER_NAME;
var SUB_CONTENT_NAME = "ContextMenuSubContent";
var ContextMenuSubContent = React.forwardRef((props, forwardedRef) => {
const { __scopeContextMenu, ...subContentProps } = props;
const menuScope = useMenuScope(__scopeContextMenu);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
MenuPrimitive.SubContent,
{
...menuScope,
...subContentProps,
ref: forwardedRef,
style: {
...props.style,
// re-namespace exposed content custom properties
...{
"--radix-context-menu-content-transform-origin": "var(--radix-popper-transform-origin)",
"--radix-context-menu-content-available-width": "var(--radix-popper-available-width)",
"--radix-context-menu-content-available-height": "var(--radix-popper-available-height)",
"--radix-context-menu-trigger-width": "var(--radix-popper-anchor-width)",
"--radix-context-menu-trigger-height": "var(--radix-popper-anchor-height)"
}
}
}
);
});
ContextMenuSubContent.displayName = SUB_CONTENT_NAME;
function whenTouchOrPen(handler) {
return (event) => event.pointerType !== "mouse" ? handler(event) : void 0;
}
var Root2 = ContextMenu;
var Trigger = ContextMenuTrigger;
var Portal2 = ContextMenuPortal;
var Content2 = ContextMenuContent;
var Group2 = ContextMenuGroup;
var Label2 = ContextMenuLabel;
var Item2 = ContextMenuItem;
var CheckboxItem2 = ContextMenuCheckboxItem;
var RadioGroup2 = ContextMenuRadioGroup;
var RadioItem2 = ContextMenuRadioItem;
var ItemIndicator2 = ContextMenuItemIndicator;
var Separator2 = ContextMenuSeparator;
var Arrow2 = ContextMenuArrow;
var Sub2 = ContextMenuSub;
var SubTrigger2 = ContextMenuSubTrigger;
var SubContent2 = ContextMenuSubContent;
//# sourceMappingURL=index.js.map
|