UEA-PRODEM
This commit is contained in:
+1
@@ -7,6 +7,7 @@ type Direction = 'ltr' | 'rtl';
|
||||
declare const createContextMenuScope: _radix_ui_react_context.CreateScope;
|
||||
interface ContextMenuProps {
|
||||
children?: React.ReactNode;
|
||||
open?: boolean;
|
||||
onOpenChange?(open: boolean): void;
|
||||
dir?: Direction;
|
||||
modal?: boolean;
|
||||
|
||||
+1
@@ -7,6 +7,7 @@ type Direction = 'ltr' | 'rtl';
|
||||
declare const createContextMenuScope: _radix_ui_react_context.CreateScope;
|
||||
interface ContextMenuProps {
|
||||
children?: React.ReactNode;
|
||||
open?: boolean;
|
||||
onOpenChange?(open: boolean): void;
|
||||
dir?: Direction;
|
||||
modal?: boolean;
|
||||
|
||||
+26
-23
@@ -74,7 +74,6 @@ 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";
|
||||
@@ -84,35 +83,35 @@ var [createContextMenuContext, createContextMenuScope] = (0, import_react_contex
|
||||
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 { __scopeContextMenu, children, onOpenChange, open: openProp, dir, modal = true } = props;
|
||||
const hasInteractedRef = React.useRef(false);
|
||||
if (true) {
|
||||
const hasWarnedRef = React.useRef(false);
|
||||
React.useEffect(() => {
|
||||
if (openProp === true && !hasInteractedRef.current && !hasWarnedRef.current) {
|
||||
hasWarnedRef.current = true;
|
||||
console.warn(
|
||||
"ContextMenu: The `open` prop has been set to `true` before the user has interacted with the trigger, so its position is indeterminate. This is likely unintended and will result in the menu being anchored to the top-left corner of the viewport."
|
||||
);
|
||||
}
|
||||
}, [openProp]);
|
||||
}
|
||||
const [open, setOpen] = (0, import_react_use_controllable_state.useControllableState)({
|
||||
prop: openProp,
|
||||
defaultProp: false,
|
||||
onChange: onOpenChange,
|
||||
caller: CONTEXT_MENU_NAME
|
||||
});
|
||||
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,
|
||||
onOpenChange: setOpen,
|
||||
modal,
|
||||
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
||||
MenuPrimitive.Root,
|
||||
{
|
||||
...menuScope,
|
||||
dir,
|
||||
open,
|
||||
onOpenChange: handleOpenChange,
|
||||
modal,
|
||||
children
|
||||
}
|
||||
)
|
||||
hasInteractedRef,
|
||||
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPrimitive.Root, { ...menuScope, dir, open, onOpenChange: setOpen, modal, children })
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -133,6 +132,7 @@ var ContextMenuTrigger = React.forwardRef(
|
||||
[]
|
||||
);
|
||||
const handleOpen = (event) => {
|
||||
context.hasInteractedRef.current = true;
|
||||
pointRef.current = { x: event.clientX, y: event.clientY };
|
||||
context.onOpenChange(true);
|
||||
};
|
||||
@@ -157,6 +157,9 @@ var ContextMenuTrigger = React.forwardRef(
|
||||
props.onPointerDown,
|
||||
whenTouchOrPen((event) => {
|
||||
clearLongPress();
|
||||
if (context.open) {
|
||||
context.onOpenChange(false);
|
||||
}
|
||||
longPressTimerRef.current = window.setTimeout(() => handleOpen(event), 700);
|
||||
})
|
||||
),
|
||||
|
||||
+3
-3
File diff suppressed because one or more lines are too long
+26
-23
@@ -7,7 +7,6 @@ import { createContextScope } from "@radix-ui/react-context";
|
||||
import { Primitive } from "@radix-ui/react-primitive";
|
||||
import * as MenuPrimitive from "@radix-ui/react-menu";
|
||||
import { createMenuScope } from "@radix-ui/react-menu";
|
||||
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
||||
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
||||
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
||||
var CONTEXT_MENU_NAME = "ContextMenu";
|
||||
@@ -17,35 +16,35 @@ var [createContextMenuContext, createContextMenuScope] = createContextScope(CONT
|
||||
var useMenuScope = 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 { __scopeContextMenu, children, onOpenChange, open: openProp, dir, modal = true } = props;
|
||||
const hasInteractedRef = React.useRef(false);
|
||||
if (true) {
|
||||
const hasWarnedRef = React.useRef(false);
|
||||
React.useEffect(() => {
|
||||
if (openProp === true && !hasInteractedRef.current && !hasWarnedRef.current) {
|
||||
hasWarnedRef.current = true;
|
||||
console.warn(
|
||||
"ContextMenu: The `open` prop has been set to `true` before the user has interacted with the trigger, so its position is indeterminate. This is likely unintended and will result in the menu being anchored to the top-left corner of the viewport."
|
||||
);
|
||||
}
|
||||
}, [openProp]);
|
||||
}
|
||||
const [open, setOpen] = useControllableState({
|
||||
prop: openProp,
|
||||
defaultProp: false,
|
||||
onChange: onOpenChange,
|
||||
caller: CONTEXT_MENU_NAME
|
||||
});
|
||||
const menuScope = useMenuScope(__scopeContextMenu);
|
||||
const handleOpenChangeProp = useCallbackRef(onOpenChange);
|
||||
const handleOpenChange = React.useCallback(
|
||||
(open2) => {
|
||||
setOpen(open2);
|
||||
handleOpenChangeProp(open2);
|
||||
},
|
||||
[handleOpenChangeProp]
|
||||
);
|
||||
return /* @__PURE__ */ jsx(
|
||||
ContextMenuProvider,
|
||||
{
|
||||
scope: __scopeContextMenu,
|
||||
open,
|
||||
onOpenChange: handleOpenChange,
|
||||
onOpenChange: setOpen,
|
||||
modal,
|
||||
children: /* @__PURE__ */ jsx(
|
||||
MenuPrimitive.Root,
|
||||
{
|
||||
...menuScope,
|
||||
dir,
|
||||
open,
|
||||
onOpenChange: handleOpenChange,
|
||||
modal,
|
||||
children
|
||||
}
|
||||
)
|
||||
hasInteractedRef,
|
||||
children: /* @__PURE__ */ jsx(MenuPrimitive.Root, { ...menuScope, dir, open, onOpenChange: setOpen, modal, children })
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -66,6 +65,7 @@ var ContextMenuTrigger = React.forwardRef(
|
||||
[]
|
||||
);
|
||||
const handleOpen = (event) => {
|
||||
context.hasInteractedRef.current = true;
|
||||
pointRef.current = { x: event.clientX, y: event.clientY };
|
||||
context.onOpenChange(true);
|
||||
};
|
||||
@@ -90,6 +90,9 @@ var ContextMenuTrigger = React.forwardRef(
|
||||
props.onPointerDown,
|
||||
whenTouchOrPen((event) => {
|
||||
clearLongPress();
|
||||
if (context.open) {
|
||||
context.onOpenChange(false);
|
||||
}
|
||||
longPressTimerRef.current = window.setTimeout(() => handleOpen(event), 700);
|
||||
})
|
||||
),
|
||||
|
||||
+3
-3
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user