357 lines
16 KiB
JavaScript
357 lines
16 KiB
JavaScript
"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/ContextMenu.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
|