336 lines
15 KiB
JavaScript
336 lines
15 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/dropdown-menu/src/index.ts
|
|
var src_exports = {};
|
|
__export(src_exports, {
|
|
Arrow: () => Arrow2,
|
|
CheckboxItem: () => CheckboxItem2,
|
|
Content: () => Content2,
|
|
DropdownMenu: () => DropdownMenu,
|
|
DropdownMenuArrow: () => DropdownMenuArrow,
|
|
DropdownMenuCheckboxItem: () => DropdownMenuCheckboxItem,
|
|
DropdownMenuContent: () => DropdownMenuContent,
|
|
DropdownMenuGroup: () => DropdownMenuGroup,
|
|
DropdownMenuItem: () => DropdownMenuItem,
|
|
DropdownMenuItemIndicator: () => DropdownMenuItemIndicator,
|
|
DropdownMenuLabel: () => DropdownMenuLabel,
|
|
DropdownMenuPortal: () => DropdownMenuPortal,
|
|
DropdownMenuRadioGroup: () => DropdownMenuRadioGroup,
|
|
DropdownMenuRadioItem: () => DropdownMenuRadioItem,
|
|
DropdownMenuSeparator: () => DropdownMenuSeparator,
|
|
DropdownMenuSub: () => DropdownMenuSub,
|
|
DropdownMenuSubContent: () => DropdownMenuSubContent,
|
|
DropdownMenuSubTrigger: () => DropdownMenuSubTrigger,
|
|
DropdownMenuTrigger: () => DropdownMenuTrigger,
|
|
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,
|
|
createDropdownMenuScope: () => createDropdownMenuScope
|
|
});
|
|
module.exports = __toCommonJS(src_exports);
|
|
|
|
// packages/react/dropdown-menu/src/DropdownMenu.tsx
|
|
var React = __toESM(require("react"));
|
|
var import_primitive = require("@radix-ui/primitive");
|
|
var import_react_compose_refs = require("@radix-ui/react-compose-refs");
|
|
var import_react_context = require("@radix-ui/react-context");
|
|
var import_react_use_controllable_state = require("@radix-ui/react-use-controllable-state");
|
|
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_id = require("@radix-ui/react-id");
|
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
var DROPDOWN_MENU_NAME = "DropdownMenu";
|
|
var [createDropdownMenuContext, createDropdownMenuScope] = (0, import_react_context.createContextScope)(
|
|
DROPDOWN_MENU_NAME,
|
|
[import_react_menu.createMenuScope]
|
|
);
|
|
var useMenuScope = (0, import_react_menu.createMenuScope)();
|
|
var [DropdownMenuProvider, useDropdownMenuContext] = createDropdownMenuContext(DROPDOWN_MENU_NAME);
|
|
var DropdownMenu = (props) => {
|
|
const {
|
|
__scopeDropdownMenu,
|
|
children,
|
|
dir,
|
|
open: openProp,
|
|
defaultOpen,
|
|
onOpenChange,
|
|
modal = true
|
|
} = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
const triggerRef = React.useRef(null);
|
|
const [open = false, setOpen] = (0, import_react_use_controllable_state.useControllableState)({
|
|
prop: openProp,
|
|
defaultProp: defaultOpen,
|
|
onChange: onOpenChange
|
|
});
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
DropdownMenuProvider,
|
|
{
|
|
scope: __scopeDropdownMenu,
|
|
triggerId: (0, import_react_id.useId)(),
|
|
triggerRef,
|
|
contentId: (0, import_react_id.useId)(),
|
|
open,
|
|
onOpenChange: setOpen,
|
|
onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]),
|
|
modal,
|
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Root, { ...menuScope, open, onOpenChange: setOpen, dir, modal, children })
|
|
}
|
|
);
|
|
};
|
|
DropdownMenu.displayName = DROPDOWN_MENU_NAME;
|
|
var TRIGGER_NAME = "DropdownMenuTrigger";
|
|
var DropdownMenuTrigger = React.forwardRef(
|
|
(props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, disabled = false, ...triggerProps } = props;
|
|
const context = useDropdownMenuContext(TRIGGER_NAME, __scopeDropdownMenu);
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Anchor, { asChild: true, ...menuScope, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
import_react_primitive.Primitive.button,
|
|
{
|
|
type: "button",
|
|
id: context.triggerId,
|
|
"aria-haspopup": "menu",
|
|
"aria-expanded": context.open,
|
|
"aria-controls": context.open ? context.contentId : void 0,
|
|
"data-state": context.open ? "open" : "closed",
|
|
"data-disabled": disabled ? "" : void 0,
|
|
disabled,
|
|
...triggerProps,
|
|
ref: (0, import_react_compose_refs.composeRefs)(forwardedRef, context.triggerRef),
|
|
onPointerDown: (0, import_primitive.composeEventHandlers)(props.onPointerDown, (event) => {
|
|
if (!disabled && event.button === 0 && event.ctrlKey === false) {
|
|
context.onOpenToggle();
|
|
if (!context.open) event.preventDefault();
|
|
}
|
|
}),
|
|
onKeyDown: (0, import_primitive.composeEventHandlers)(props.onKeyDown, (event) => {
|
|
if (disabled) return;
|
|
if (["Enter", " "].includes(event.key)) context.onOpenToggle();
|
|
if (event.key === "ArrowDown") context.onOpenChange(true);
|
|
if (["Enter", " ", "ArrowDown"].includes(event.key)) event.preventDefault();
|
|
})
|
|
}
|
|
) });
|
|
}
|
|
);
|
|
DropdownMenuTrigger.displayName = TRIGGER_NAME;
|
|
var PORTAL_NAME = "DropdownMenuPortal";
|
|
var DropdownMenuPortal = (props) => {
|
|
const { __scopeDropdownMenu, ...portalProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Portal, { ...menuScope, ...portalProps });
|
|
};
|
|
DropdownMenuPortal.displayName = PORTAL_NAME;
|
|
var CONTENT_NAME = "DropdownMenuContent";
|
|
var DropdownMenuContent = React.forwardRef(
|
|
(props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...contentProps } = props;
|
|
const context = useDropdownMenuContext(CONTENT_NAME, __scopeDropdownMenu);
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
const hasInteractedOutsideRef = React.useRef(false);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
MenuPrimitive.Content,
|
|
{
|
|
id: context.contentId,
|
|
"aria-labelledby": context.triggerId,
|
|
...menuScope,
|
|
...contentProps,
|
|
ref: forwardedRef,
|
|
onCloseAutoFocus: (0, import_primitive.composeEventHandlers)(props.onCloseAutoFocus, (event) => {
|
|
if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();
|
|
hasInteractedOutsideRef.current = false;
|
|
event.preventDefault();
|
|
}),
|
|
onInteractOutside: (0, import_primitive.composeEventHandlers)(props.onInteractOutside, (event) => {
|
|
const originalEvent = event.detail.originalEvent;
|
|
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
if (!context.modal || isRightClick) hasInteractedOutsideRef.current = true;
|
|
}),
|
|
style: {
|
|
...props.style,
|
|
// re-namespace exposed content custom properties
|
|
...{
|
|
"--radix-dropdown-menu-content-transform-origin": "var(--radix-popper-transform-origin)",
|
|
"--radix-dropdown-menu-content-available-width": "var(--radix-popper-available-width)",
|
|
"--radix-dropdown-menu-content-available-height": "var(--radix-popper-available-height)",
|
|
"--radix-dropdown-menu-trigger-width": "var(--radix-popper-anchor-width)",
|
|
"--radix-dropdown-menu-trigger-height": "var(--radix-popper-anchor-height)"
|
|
}
|
|
}
|
|
}
|
|
);
|
|
}
|
|
);
|
|
DropdownMenuContent.displayName = CONTENT_NAME;
|
|
var GROUP_NAME = "DropdownMenuGroup";
|
|
var DropdownMenuGroup = React.forwardRef(
|
|
(props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...groupProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Group, { ...menuScope, ...groupProps, ref: forwardedRef });
|
|
}
|
|
);
|
|
DropdownMenuGroup.displayName = GROUP_NAME;
|
|
var LABEL_NAME = "DropdownMenuLabel";
|
|
var DropdownMenuLabel = React.forwardRef(
|
|
(props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...labelProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Label, { ...menuScope, ...labelProps, ref: forwardedRef });
|
|
}
|
|
);
|
|
DropdownMenuLabel.displayName = LABEL_NAME;
|
|
var ITEM_NAME = "DropdownMenuItem";
|
|
var DropdownMenuItem = React.forwardRef(
|
|
(props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...itemProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Item, { ...menuScope, ...itemProps, ref: forwardedRef });
|
|
}
|
|
);
|
|
DropdownMenuItem.displayName = ITEM_NAME;
|
|
var CHECKBOX_ITEM_NAME = "DropdownMenuCheckboxItem";
|
|
var DropdownMenuCheckboxItem = React.forwardRef((props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...checkboxItemProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.CheckboxItem, { ...menuScope, ...checkboxItemProps, ref: forwardedRef });
|
|
});
|
|
DropdownMenuCheckboxItem.displayName = CHECKBOX_ITEM_NAME;
|
|
var RADIO_GROUP_NAME = "DropdownMenuRadioGroup";
|
|
var DropdownMenuRadioGroup = React.forwardRef((props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...radioGroupProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.RadioGroup, { ...menuScope, ...radioGroupProps, ref: forwardedRef });
|
|
});
|
|
DropdownMenuRadioGroup.displayName = RADIO_GROUP_NAME;
|
|
var RADIO_ITEM_NAME = "DropdownMenuRadioItem";
|
|
var DropdownMenuRadioItem = React.forwardRef((props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...radioItemProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.RadioItem, { ...menuScope, ...radioItemProps, ref: forwardedRef });
|
|
});
|
|
DropdownMenuRadioItem.displayName = RADIO_ITEM_NAME;
|
|
var INDICATOR_NAME = "DropdownMenuItemIndicator";
|
|
var DropdownMenuItemIndicator = React.forwardRef((props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...itemIndicatorProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.ItemIndicator, { ...menuScope, ...itemIndicatorProps, ref: forwardedRef });
|
|
});
|
|
DropdownMenuItemIndicator.displayName = INDICATOR_NAME;
|
|
var SEPARATOR_NAME = "DropdownMenuSeparator";
|
|
var DropdownMenuSeparator = React.forwardRef((props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...separatorProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Separator, { ...menuScope, ...separatorProps, ref: forwardedRef });
|
|
});
|
|
DropdownMenuSeparator.displayName = SEPARATOR_NAME;
|
|
var ARROW_NAME = "DropdownMenuArrow";
|
|
var DropdownMenuArrow = React.forwardRef(
|
|
(props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...arrowProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Arrow, { ...menuScope, ...arrowProps, ref: forwardedRef });
|
|
}
|
|
);
|
|
DropdownMenuArrow.displayName = ARROW_NAME;
|
|
var DropdownMenuSub = (props) => {
|
|
const { __scopeDropdownMenu, children, open: openProp, onOpenChange, defaultOpen } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
const [open = false, 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 });
|
|
};
|
|
var SUB_TRIGGER_NAME = "DropdownMenuSubTrigger";
|
|
var DropdownMenuSubTrigger = React.forwardRef((props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...subTriggerProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.SubTrigger, { ...menuScope, ...subTriggerProps, ref: forwardedRef });
|
|
});
|
|
DropdownMenuSubTrigger.displayName = SUB_TRIGGER_NAME;
|
|
var SUB_CONTENT_NAME = "DropdownMenuSubContent";
|
|
var DropdownMenuSubContent = React.forwardRef((props, forwardedRef) => {
|
|
const { __scopeDropdownMenu, ...subContentProps } = props;
|
|
const menuScope = useMenuScope(__scopeDropdownMenu);
|
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
MenuPrimitive.SubContent,
|
|
{
|
|
...menuScope,
|
|
...subContentProps,
|
|
ref: forwardedRef,
|
|
style: {
|
|
...props.style,
|
|
// re-namespace exposed content custom properties
|
|
...{
|
|
"--radix-dropdown-menu-content-transform-origin": "var(--radix-popper-transform-origin)",
|
|
"--radix-dropdown-menu-content-available-width": "var(--radix-popper-available-width)",
|
|
"--radix-dropdown-menu-content-available-height": "var(--radix-popper-available-height)",
|
|
"--radix-dropdown-menu-trigger-width": "var(--radix-popper-anchor-width)",
|
|
"--radix-dropdown-menu-trigger-height": "var(--radix-popper-anchor-height)"
|
|
}
|
|
}
|
|
}
|
|
);
|
|
});
|
|
DropdownMenuSubContent.displayName = SUB_CONTENT_NAME;
|
|
var Root2 = DropdownMenu;
|
|
var Trigger = DropdownMenuTrigger;
|
|
var Portal2 = DropdownMenuPortal;
|
|
var Content2 = DropdownMenuContent;
|
|
var Group2 = DropdownMenuGroup;
|
|
var Label2 = DropdownMenuLabel;
|
|
var Item2 = DropdownMenuItem;
|
|
var CheckboxItem2 = DropdownMenuCheckboxItem;
|
|
var RadioGroup2 = DropdownMenuRadioGroup;
|
|
var RadioItem2 = DropdownMenuRadioItem;
|
|
var ItemIndicator2 = DropdownMenuItemIndicator;
|
|
var Separator2 = DropdownMenuSeparator;
|
|
var Arrow2 = DropdownMenuArrow;
|
|
var Sub2 = DropdownMenuSub;
|
|
var SubTrigger2 = DropdownMenuSubTrigger;
|
|
var SubContent2 = DropdownMenuSubContent;
|
|
//# sourceMappingURL=index.js.map
|