@zealakit/overlay-react 1.0.1 → 1.1.0
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/README.md +1 -0
- package/dist/animation/presence.js +3 -2
- package/dist/components/arrow.js +2 -0
- package/dist/components/context-menu/content.js +1 -1
- package/dist/components/context-menu/context-menu.js +2 -12
- package/dist/components/context-menu/index.d.ts +4 -4
- package/dist/components/context-menu/index.js +2 -2
- package/dist/components/context-menu/items.js +3 -3
- package/dist/components/context-menu/menu-navigation.js +22 -6
- package/dist/components/context-menu/menu-surface.d.ts +4 -4
- package/dist/components/context-menu/menu-surface.js +10 -11
- package/dist/components/context-menu/sub.d.ts +1 -1
- package/dist/components/context-menu/sub.js +3 -13
- package/dist/components/context-menu/trigger.js +0 -1
- package/dist/components/dialog/content.d.ts +3 -3
- package/dist/components/dialog/content.js +13 -15
- package/dist/components/dialog/dialog.js +1 -1
- package/dist/components/dialog/helpers.js +1 -0
- package/dist/components/dialog/index.d.ts +1 -1
- package/dist/components/dialog/trigger.js +2 -0
- package/dist/components/popover/content.d.ts +24 -24
- package/dist/components/popover/content.js +13 -17
- package/dist/components/popover/helpers.js +1 -0
- package/dist/components/popover/index.d.ts +2 -2
- package/dist/components/popover/index.js +1 -1
- package/dist/components/popover/popover.js +3 -1
- package/dist/components/portal.d.ts +1 -1
- package/dist/components/slot.js +1 -4
- package/dist/components/tooltip/content.d.ts +2 -2
- package/dist/components/tooltip/content.js +1 -3
- package/dist/components/tooltip/index.d.ts +5 -5
- package/dist/components/tooltip/index.js +4 -4
- package/dist/components/tooltip/provider.js +2 -2
- package/dist/components/tooltip/tooltip.js +19 -28
- package/dist/hooks/use-layer.js +4 -4
- package/dist/hooks/use-overlay.js +4 -4
- package/dist/hooks/use-positioner.js +3 -12
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/vendor/core/animation/keyframes.js +3 -15
- package/dist/vendor/core/animation/run-animation.d.ts +1 -1
- package/dist/vendor/core/animation/run-animation.js +5 -10
- package/dist/vendor/core/controller/animator.js +2 -2
- package/dist/vendor/core/controller/context-menu-behavior.js +48 -37
- package/dist/vendor/core/controller/overlay-controller.d.ts +1 -1
- package/dist/vendor/core/controller/overlay-controller.js +52 -72
- package/dist/vendor/core/controller/tooltip-behavior.js +1 -3
- package/dist/vendor/core/controller/types.d.ts +15 -1
- package/dist/vendor/core/events/outside.d.ts +6 -3
- package/dist/vendor/core/events/outside.js +12 -25
- package/dist/vendor/core/events/pointer.d.ts +7 -7
- package/dist/vendor/core/events/pointer.js +7 -9
- package/dist/vendor/core/focus/focus.js +45 -105
- package/dist/vendor/core/layer/create-layer-stack.d.ts +14 -12
- package/dist/vendor/core/layer/create-layer-stack.js +114 -158
- package/dist/vendor/core/layer/create-layer.js +1 -2
- package/dist/vendor/core/layer/index.d.ts +1 -2
- package/dist/vendor/core/layer/index.js +1 -2
- package/dist/vendor/core/menu/index.d.ts +1 -1
- package/dist/vendor/core/menu/index.js +1 -1
- package/dist/vendor/core/menu/navigation.d.ts +0 -12
- package/dist/vendor/core/menu/navigation.js +0 -42
- package/dist/vendor/core/modal/background.js +13 -5
- package/dist/vendor/core/portal/index.d.ts +1 -1
- package/dist/vendor/core/portal/index.js +1 -1
- package/dist/vendor/core/positioning/compute.js +3 -3
- package/dist/vendor/core/positioning/coordinates.js +1 -1
- package/dist/vendor/core/positioning/create-positioner.d.ts +6 -3
- package/dist/vendor/core/positioning/create-positioner.js +86 -76
- package/dist/vendor/core/positioning/placement.js +1 -3
- package/dist/vendor/core/scroll-lock/scroll-lock.d.ts +8 -6
- package/dist/vendor/core/scroll-lock/scroll-lock.js +14 -60
- package/dist/vendor/core/types/animation.d.ts +10 -18
- package/dist/vendor/core/types/animation.js +3 -5
- package/dist/vendor/core/types/dismissal.d.ts +15 -2
- package/dist/vendor/core/types/geometry.d.ts +14 -5
- package/dist/vendor/core/types/layer.d.ts +2 -0
- package/dist/vendor/core/types/positioner.d.ts +8 -1
- package/dist/vendor/core/utils/global-state.js +6 -0
- package/package.json +4 -13
- package/dist/vendor/core/layer/manager.d.ts +0 -9
- package/dist/vendor/core/layer/manager.js +0 -157
|
@@ -67,7 +67,7 @@ export function Popover({ children, open: controlledOpen, defaultOpen = false, o
|
|
|
67
67
|
toggle,
|
|
68
68
|
triggerElement,
|
|
69
69
|
]);
|
|
70
|
-
return
|
|
70
|
+
return _jsx(PopoverContext.Provider, { value: contextValue, children: children });
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Trigger button. Renders a native button by default. With `asChild`, the
|
|
@@ -94,5 +94,7 @@ export const PopoverTrigger = forwardRef(function PopoverTrigger({ asChild = fal
|
|
|
94
94
|
if (asChild) {
|
|
95
95
|
return (_jsx(Slot, { ...shared, ...(disabled ? { disabled: true, "aria-disabled": true } : {}), ref: refs, children: children }));
|
|
96
96
|
}
|
|
97
|
+
// oxlint-disable react/button-has-type -- `type` is a literal union with a "button" fallback
|
|
97
98
|
return (_jsx("button", { ...shared, ref: refs, type: type ?? "button", disabled: disabled, children: children }));
|
|
99
|
+
// oxlint-enable react/button-has-type
|
|
98
100
|
});
|
package/dist/components/slot.js
CHANGED
|
@@ -33,10 +33,7 @@ export const Slot = forwardRef(function Slot({ children, ...rest }, forwardedRef
|
|
|
33
33
|
const merged = { ...childProps, ...rest };
|
|
34
34
|
const childClassName = typeof childProps.className === "string" ? childProps.className : "";
|
|
35
35
|
const slotClassName = typeof rest.className === "string" ? rest.className : "";
|
|
36
|
-
const className = [childClassName, slotClassName]
|
|
37
|
-
.filter(Boolean)
|
|
38
|
-
.join(" ")
|
|
39
|
-
.trim();
|
|
36
|
+
const className = [childClassName, slotClassName].filter(Boolean).join(" ").trim();
|
|
40
37
|
if (className) {
|
|
41
38
|
merged.className = className;
|
|
42
39
|
}
|
|
@@ -6,7 +6,7 @@ export type TooltipContentProps = Omit<PopoverPositionerProps, "anchor" | "child
|
|
|
6
6
|
/** `true`/omitted portals to document.body; `false` renders inline. */
|
|
7
7
|
portal?: boolean | Element | null;
|
|
8
8
|
/** Fade/custom enter and exit animation. Disabled by default; pass true or a config. */
|
|
9
|
-
animation?: AnimationSetting;
|
|
9
|
+
animation?: AnimationSetting | undefined;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Convenient Tooltip content: Portal -> Positioner -> Popup. The popup has
|
|
@@ -17,5 +17,5 @@ export declare const TooltipContent: import("react").ForwardRefExoticComponent<O
|
|
|
17
17
|
/** `true`/omitted portals to document.body; `false` renders inline. */
|
|
18
18
|
portal?: boolean | Element | null;
|
|
19
19
|
/** Fade/custom enter and exit animation. Disabled by default; pass true or a config. */
|
|
20
|
-
animation?: AnimationSetting;
|
|
20
|
+
animation?: AnimationSetting | undefined;
|
|
21
21
|
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -37,9 +37,7 @@ const TooltipPopup = forwardRef(function TooltipPopup({ onPointerEnter, onPointe
|
|
|
37
37
|
}
|
|
38
38
|
const rect = reference.getBoundingClientRect();
|
|
39
39
|
const next = { width: rect.width, height: rect.height };
|
|
40
|
-
setAnchorSize((previous) => previous !== null &&
|
|
41
|
-
previous.width === next.width &&
|
|
42
|
-
previous.height === next.height
|
|
40
|
+
setAnchorSize((previous) => previous !== null && previous.width === next.width && previous.height === next.height
|
|
43
41
|
? previous
|
|
44
42
|
: next);
|
|
45
43
|
}, [positioner.referenceElement, positioner.result]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { TooltipProvider, type TooltipProviderProps
|
|
2
|
-
export { Tooltip, type TooltipProps
|
|
3
|
-
export { TooltipTrigger, type TooltipTriggerProps
|
|
4
|
-
export { TooltipContent, type TooltipContentProps
|
|
5
|
-
export type { TooltipChangeReason, TooltipDirection
|
|
1
|
+
export { TooltipProvider, type TooltipProviderProps } from "./provider.js";
|
|
2
|
+
export { Tooltip, type TooltipProps } from "./tooltip.js";
|
|
3
|
+
export { TooltipTrigger, type TooltipTriggerProps } from "./trigger.js";
|
|
4
|
+
export { TooltipContent, type TooltipContentProps } from "./content.js";
|
|
5
|
+
export type { TooltipChangeReason, TooltipDirection } from "./context.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export { TooltipProvider
|
|
3
|
-
export { Tooltip
|
|
4
|
-
export { TooltipTrigger
|
|
5
|
-
export { TooltipContent
|
|
2
|
+
export { TooltipProvider } from "./provider.js";
|
|
3
|
+
export { Tooltip } from "./tooltip.js";
|
|
4
|
+
export { TooltipTrigger } from "./trigger.js";
|
|
5
|
+
export { TooltipContent } from "./content.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useMemo, useRef
|
|
3
|
+
import { createContext, useContext, useMemo, useRef } from "react";
|
|
4
4
|
export const TOOLTIP_DEFAULT_DELAY = 500;
|
|
5
5
|
export const TOOLTIP_DEFAULT_CLOSE_DELAY = 100;
|
|
6
6
|
export const TOOLTIP_DEFAULT_SKIP_DELAY = 300;
|
|
@@ -22,7 +22,7 @@ export function TooltipProvider({ children, delay = TOOLTIP_DEFAULT_DELAY, close
|
|
|
22
22
|
skipUntilRef.current = Date.now() + skipDelayDuration;
|
|
23
23
|
},
|
|
24
24
|
}), [closeDelay, delay, disableHoverableContent, skipDelayDuration]);
|
|
25
|
-
return
|
|
25
|
+
return _jsx(TooltipTimingContext.Provider, { value: value, children: children });
|
|
26
26
|
}
|
|
27
27
|
export function useTooltipTiming() {
|
|
28
28
|
return useContext(TooltipTimingContext);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback, useEffect, useMemo, useRef, useState
|
|
4
|
-
import {
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { acquireSharedLayerStack } from "../../vendor/core/index.js";
|
|
5
5
|
import { Popover } from "../popover/popover.js";
|
|
6
6
|
import { TooltipContext, } from "./context.js";
|
|
7
7
|
import { TOOLTIP_DEFAULT_CLOSE_DELAY, TOOLTIP_DEFAULT_DELAY, TOOLTIP_DEFAULT_SKIP_DELAY, useTooltipTiming, } from "./provider.js";
|
|
@@ -19,7 +19,7 @@ export function Tooltip({ children, open: controlledOpen, defaultOpen = false, o
|
|
|
19
19
|
delay: TOOLTIP_DEFAULT_DELAY,
|
|
20
20
|
closeDelay: TOOLTIP_DEFAULT_CLOSE_DELAY,
|
|
21
21
|
disableHoverableContent: false,
|
|
22
|
-
getOpenDelay: (nextDelay) => Date.now() < localSkipUntilRef.current ? 0 : nextDelay,
|
|
22
|
+
getOpenDelay: (nextDelay) => (Date.now() < localSkipUntilRef.current ? 0 : nextDelay),
|
|
23
23
|
markOpened: () => {
|
|
24
24
|
localSkipUntilRef.current = Date.now() + TOOLTIP_DEFAULT_SKIP_DELAY;
|
|
25
25
|
},
|
|
@@ -203,32 +203,23 @@ export function Tooltip({ children, open: controlledOpen, defaultOpen = false, o
|
|
|
203
203
|
if (!documentRef) {
|
|
204
204
|
return;
|
|
205
205
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
if (triggerElement?.contains(target) ||
|
|
222
|
-
contentElement?.contains(target)) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
closeNow("outside-press");
|
|
226
|
-
};
|
|
227
|
-
documentRef.addEventListener("keydown", handleKeyDown, true);
|
|
228
|
-
documentRef.addEventListener("pointerdown", handlePointerDown, true);
|
|
206
|
+
// The engine owns Escape and outside-press dismissal (NP2, NS7): the
|
|
207
|
+
// tooltip is a non-modal layer, so the shared listeners decide and call
|
|
208
|
+
// back with the reason. An input that preventDefaults Escape keeps it open
|
|
209
|
+
// because the engine skips defaultPrevented keys (E3).
|
|
210
|
+
const lease = acquireSharedLayerStack(documentRef);
|
|
211
|
+
const layer = lease.stack.register({
|
|
212
|
+
element: contentElement,
|
|
213
|
+
reference: triggerElement,
|
|
214
|
+
dismissOnEscape: true,
|
|
215
|
+
dismissOnOutsidePress: true,
|
|
216
|
+
onDismiss: (reason) => {
|
|
217
|
+
closeNow(reason === "escape-key" ? "escape" : "outside-press");
|
|
218
|
+
},
|
|
219
|
+
});
|
|
229
220
|
return () => {
|
|
230
|
-
|
|
231
|
-
|
|
221
|
+
layer.dispose();
|
|
222
|
+
lease.release();
|
|
232
223
|
};
|
|
233
224
|
}, [closeNow, contentElement, effectiveOpen, triggerElement]);
|
|
234
225
|
const context = useMemo(() => ({
|
package/dist/hooks/use-layer.js
CHANGED
|
@@ -52,10 +52,10 @@ export function useLayer(options = {}) {
|
|
|
52
52
|
const layerHandle = activeStack.register({
|
|
53
53
|
element,
|
|
54
54
|
reference,
|
|
55
|
-
boundaries,
|
|
56
|
-
parent,
|
|
57
|
-
dismissOnEscape,
|
|
58
|
-
dismissOnOutsidePress,
|
|
55
|
+
...(boundaries === undefined ? {} : { boundaries }),
|
|
56
|
+
...(parent === undefined ? {} : { parent }),
|
|
57
|
+
...(dismissOnEscape === undefined ? {} : { dismissOnEscape }),
|
|
58
|
+
...(dismissOnOutsidePress === undefined ? {} : { dismissOnOutsidePress }),
|
|
59
59
|
onDismiss: (reason) => onDismissRef.current?.(reason),
|
|
60
60
|
});
|
|
61
61
|
setHandle(layerHandle);
|
|
@@ -42,10 +42,10 @@ export function useOverlay(options = {}) {
|
|
|
42
42
|
useLayer({
|
|
43
43
|
element: positioner.floatingElement,
|
|
44
44
|
reference: positioner.referenceElement,
|
|
45
|
-
boundaries,
|
|
46
|
-
dismissOnEscape,
|
|
47
|
-
dismissOnOutsidePress,
|
|
48
|
-
stack,
|
|
45
|
+
...(boundaries === undefined ? {} : { boundaries }),
|
|
46
|
+
...(dismissOnEscape === undefined ? {} : { dismissOnEscape }),
|
|
47
|
+
...(dismissOnOutsidePress === undefined ? {} : { dismissOnOutsidePress }),
|
|
48
|
+
...(stack === undefined ? {} : { stack }),
|
|
49
49
|
disabled: !isOpen,
|
|
50
50
|
onDismiss: close,
|
|
51
51
|
});
|
|
@@ -91,6 +91,8 @@ export function usePositioner(options = {}) {
|
|
|
91
91
|
skipInitialOptionsEffect.current = false;
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
|
+
// A patch, not a creation object: `undefined` means "reset to the default",
|
|
95
|
+
// so every key is passed explicitly. Omitting one would keep the old value.
|
|
94
96
|
positioner.setOptions({
|
|
95
97
|
placement,
|
|
96
98
|
offset,
|
|
@@ -103,18 +105,7 @@ export function usePositioner(options = {}) {
|
|
|
103
105
|
autoUpdate,
|
|
104
106
|
arrow,
|
|
105
107
|
});
|
|
106
|
-
}, [
|
|
107
|
-
placement,
|
|
108
|
-
offset,
|
|
109
|
-
alignOffset,
|
|
110
|
-
flip,
|
|
111
|
-
shift,
|
|
112
|
-
padding,
|
|
113
|
-
boundary,
|
|
114
|
-
strategy,
|
|
115
|
-
autoUpdate,
|
|
116
|
-
arrow,
|
|
117
|
-
]);
|
|
108
|
+
}, [placement, offset, alignOffset, flip, shift, padding, boundary, strategy, autoUpdate, arrow]);
|
|
118
109
|
const update = useCallback(() => positionerRef.current?.update() ?? Promise.resolve(null), []);
|
|
119
110
|
return {
|
|
120
111
|
result,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export { Portal, type PortalProps } from "./components/portal.js";
|
|
2
|
-
export { PopoverArrow, TooltipArrow, type PopoverArrowProps
|
|
2
|
+
export { PopoverArrow, TooltipArrow, type PopoverArrowProps } from "./components/arrow.js";
|
|
3
3
|
export { Popover, PopoverClose, PopoverContent, PopoverDescription, PopoverHeader, PopoverPopup, PopoverPortal, PopoverPositioner, PopoverTitle, PopoverTrigger, type PopoverAlign, type PopoverArrowConfig, type PopoverChangeReason, type PopoverCollisionAvoidance, type PopoverCloseProps, type PopoverContentProps, type PopoverDescriptionProps, type PopoverDirection, type PopoverHeaderProps, type PopoverPopupProps, type PopoverPortalProps, type PopoverPositionerProps, type PopoverProps, type PopoverSide, type PopoverTitleProps, type PopoverTriggerProps, } from "./components/popover/index.js";
|
|
4
4
|
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type TooltipChangeReason, type TooltipContentProps, type TooltipDirection, type TooltipProps, type TooltipProviderProps, type TooltipTriggerProps, } from "./components/tooltip/index.js";
|
|
5
5
|
export { Dialog, DialogBackdrop, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogPopup, DialogPortal, DialogTitle, DialogTrigger, DialogViewport, type DialogBackdropProps, type DialogChangeReason, type DialogCloseProps, type DialogContentProps, type DialogDescriptionProps, type DialogDirection, type DialogFocusTarget, type DialogFooterProps, type DialogHeaderProps, type DialogPopupProps, type DialogPortalProps, type DialogProps, type DialogTitleProps, type DialogTriggerProps, type DialogViewportProps, } from "./components/dialog/index.js";
|
|
6
6
|
export { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, type ContextMenuAlign, type ContextMenuChangeReason, type ContextMenuCheckboxItemProps, type ContextMenuCollisionAvoidance, type ContextMenuContentProps, type ContextMenuDirection, type ContextMenuGroupProps, type ContextMenuItemProps, type ContextMenuLabelProps, type ContextMenuProps, type ContextMenuRadioGroupProps, type ContextMenuRadioItemProps, type ContextMenuSelectEvent, type ContextMenuSeparatorProps, type ContextMenuShortcutProps, type ContextMenuSide, type ContextMenuSubContentProps, type ContextMenuSubProps, type ContextMenuSubTriggerProps, type ContextMenuTriggerProps, } from "./components/context-menu/index.js";
|
|
7
|
-
export { useEscapeKey, type UseEscapeKeyOptions
|
|
8
|
-
export { useLayer, type UseLayerOptions, type UseLayerReturn
|
|
9
|
-
export { useOverlay, type UseOverlayOptions, type UseOverlayReturn
|
|
7
|
+
export { useEscapeKey, type UseEscapeKeyOptions } from "./hooks/use-escape-key.js";
|
|
8
|
+
export { useLayer, type UseLayerOptions, type UseLayerReturn } from "./hooks/use-layer.js";
|
|
9
|
+
export { useOverlay, type UseOverlayOptions, type UseOverlayReturn } from "./hooks/use-overlay.js";
|
|
10
10
|
export { usePositioner, type UsePositionerOptions, type UsePositionerReturn, } from "./hooks/use-positioner.js";
|
|
11
11
|
export { createFocusContainment, focusElement, focusFirst, getActiveElement, getFocusableElements, isFocusable, lockBodyScroll, restoreFocus, type FocusContainment, type FocusContainmentOptions, type FocusContainmentTarget, } from "./vendor/core/index.js";
|
|
12
12
|
export type { AnimationConfig, AnimationDirection, AnimationDirectionSetting, AnimationEasing, AnimationSetting, CustomAnimationClasses, DismissReason, LayerStack, LayerStackHandle, Placement, PositionerOptions, PositionerResult, ResolvedAnimationConfig, } from "./vendor/core/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
export { Portal } from "./components/portal.js";
|
|
3
|
-
export { PopoverArrow, TooltipArrow
|
|
3
|
+
export { PopoverArrow, TooltipArrow } from "./components/arrow.js";
|
|
4
4
|
export { Popover, PopoverClose, PopoverContent, PopoverDescription, PopoverHeader, PopoverPopup, PopoverPortal, PopoverPositioner, PopoverTitle, PopoverTrigger, } from "./components/popover/index.js";
|
|
5
5
|
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "./components/tooltip/index.js";
|
|
6
6
|
export { Dialog, DialogBackdrop, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogPopup, DialogPortal, DialogTitle, DialogTrigger, DialogViewport, } from "./components/dialog/index.js";
|
|
7
7
|
export { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, } from "./components/context-menu/index.js";
|
|
8
|
-
export { useEscapeKey
|
|
9
|
-
export { useLayer
|
|
10
|
-
export { useOverlay
|
|
8
|
+
export { useEscapeKey } from "./hooks/use-escape-key.js";
|
|
9
|
+
export { useLayer } from "./hooks/use-layer.js";
|
|
10
|
+
export { useOverlay } from "./hooks/use-overlay.js";
|
|
11
11
|
export { usePositioner, } from "./hooks/use-positioner.js";
|
|
12
12
|
export { createFocusContainment, focusElement, focusFirst, getActiveElement, getFocusableElements, isFocusable, lockBodyScroll, restoreFocus, } from "./vendor/core/index.js";
|
|
@@ -27,11 +27,7 @@ const SIDES = ["top", "right", "bottom", "left"];
|
|
|
27
27
|
function splitPlacement(placement) {
|
|
28
28
|
const [rawSide = "", rawAlign] = (placement ?? "").split("-");
|
|
29
29
|
const side = SIDES.includes(rawSide) ? rawSide : null;
|
|
30
|
-
const align = side === null
|
|
31
|
-
? null
|
|
32
|
-
: rawAlign === "start" || rawAlign === "end"
|
|
33
|
-
? rawAlign
|
|
34
|
-
: "center";
|
|
30
|
+
const align = side === null ? null : rawAlign === "start" || rawAlign === "end" ? rawAlign : "center";
|
|
35
31
|
return { side, align };
|
|
36
32
|
}
|
|
37
33
|
/** The side a growth direction implies: it grows away from the anchor edge. */
|
|
@@ -48,18 +44,10 @@ export function getTransformOrigin(side, align, rtl = false) {
|
|
|
48
44
|
}
|
|
49
45
|
const alignment = align ?? "center";
|
|
50
46
|
if (side === "top" || side === "bottom") {
|
|
51
|
-
const horizontal = alignment === "center"
|
|
52
|
-
? "center"
|
|
53
|
-
: (alignment === "start") !== rtl
|
|
54
|
-
? "left"
|
|
55
|
-
: "right";
|
|
47
|
+
const horizontal = alignment === "center" ? "center" : (alignment === "start") !== rtl ? "left" : "right";
|
|
56
48
|
return `${horizontal} ${side === "bottom" ? "top" : "bottom"}`;
|
|
57
49
|
}
|
|
58
|
-
const vertical = alignment === "center"
|
|
59
|
-
? "center"
|
|
60
|
-
: alignment === "start"
|
|
61
|
-
? "top"
|
|
62
|
-
: "bottom";
|
|
50
|
+
const vertical = alignment === "center" ? "center" : alignment === "start" ? "top" : "bottom";
|
|
63
51
|
return `${side === "right" ? "left" : "right"} ${vertical}`;
|
|
64
52
|
}
|
|
65
53
|
/**
|
|
@@ -24,4 +24,4 @@ export declare function prefersReducedMotion(win?: Window | null | undefined): b
|
|
|
24
24
|
* While it runs, `--overlay-transform-origin` points at the anchor so custom
|
|
25
25
|
* CSS can grow from the right edge too.
|
|
26
26
|
*/
|
|
27
|
-
export declare function runOverlayAnimation(element: HTMLElement, { phase, config, placement, reducedMotion
|
|
27
|
+
export declare function runOverlayAnimation(element: HTMLElement, { phase, config, placement, reducedMotion }: RunOverlayAnimationOptions): OverlayAnimationHandle;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { isCustomClasses, resolveAnimationDirection, } from "../types/animation.js";
|
|
2
2
|
import { createExpandKeyframes, createFadeKeyframes, FADE_MOVE_DISTANCE, getTransformOrigin, resolveExpandPlan, splitPlacement, } from "./keyframes.js";
|
|
3
3
|
/** Lazily read the user's reduced-motion preference (SSR-safe). */
|
|
4
|
-
export function prefersReducedMotion(win = typeof window === "undefined"
|
|
5
|
-
? undefined
|
|
6
|
-
: window) {
|
|
4
|
+
export function prefersReducedMotion(win = typeof window === "undefined" ? undefined : window) {
|
|
7
5
|
if (!win || typeof win.matchMedia !== "function") {
|
|
8
6
|
return false;
|
|
9
7
|
}
|
|
@@ -16,8 +14,7 @@ const IMMEDIATE = {
|
|
|
16
14
|
const ORIGIN_VARIABLE = "--overlay-transform-origin";
|
|
17
15
|
function isRtl(element) {
|
|
18
16
|
const view = element.ownerDocument?.defaultView;
|
|
19
|
-
return (element.dir === "rtl" ||
|
|
20
|
-
(view ? view.getComputedStyle(element).direction === "rtl" : false));
|
|
17
|
+
return (element.dir === "rtl" || (view ? view.getComputedStyle(element).direction === "rtl" : false));
|
|
21
18
|
}
|
|
22
19
|
/**
|
|
23
20
|
* Run an enter/exit animation on an element: the built-in `fade` or `expand`
|
|
@@ -28,7 +25,7 @@ function isRtl(element) {
|
|
|
28
25
|
* While it runs, `--overlay-transform-origin` points at the anchor so custom
|
|
29
26
|
* CSS can grow from the right edge too.
|
|
30
27
|
*/
|
|
31
|
-
export function runOverlayAnimation(element, { phase, config, placement, reducedMotion = false
|
|
28
|
+
export function runOverlayAnimation(element, { phase, config, placement, reducedMotion = false }) {
|
|
32
29
|
if (!config.enabled) {
|
|
33
30
|
return IMMEDIATE;
|
|
34
31
|
}
|
|
@@ -97,9 +94,7 @@ export function runOverlayAnimation(element, { phase, config, placement, reduced
|
|
|
97
94
|
if (cancelled) {
|
|
98
95
|
return;
|
|
99
96
|
}
|
|
100
|
-
const animations = typeof element.getAnimations === "function"
|
|
101
|
-
? element.getAnimations()
|
|
102
|
-
: [];
|
|
97
|
+
const animations = typeof element.getAnimations === "function" ? element.getAnimations() : [];
|
|
103
98
|
if (animations.length === 0) {
|
|
104
99
|
// Missing/empty custom CSS must not leave a popup mounted forever.
|
|
105
100
|
settle();
|
|
@@ -144,7 +139,7 @@ export function runOverlayAnimation(element, { phase, config, placement, reduced
|
|
|
144
139
|
}
|
|
145
140
|
else if (config.type === "expand") {
|
|
146
141
|
const plan = resolveExpandPlan({
|
|
147
|
-
placement,
|
|
142
|
+
...(placement === undefined ? {} : { placement }),
|
|
148
143
|
direction: config.direction,
|
|
149
144
|
rtl,
|
|
150
145
|
});
|
|
@@ -43,7 +43,7 @@ export function createOverlayAnimator(host, initialSetting, isDestroyed, onExitF
|
|
|
43
43
|
runOverlayAnimation(content, {
|
|
44
44
|
phase: "enter",
|
|
45
45
|
config,
|
|
46
|
-
placement,
|
|
46
|
+
...(placement === undefined ? {} : { placement }),
|
|
47
47
|
reducedMotion,
|
|
48
48
|
}),
|
|
49
49
|
];
|
|
@@ -82,7 +82,7 @@ export function createOverlayAnimator(host, initialSetting, isDestroyed, onExitF
|
|
|
82
82
|
runOverlayAnimation(content, {
|
|
83
83
|
phase: "exit",
|
|
84
84
|
config,
|
|
85
|
-
placement,
|
|
85
|
+
...(placement === undefined ? {} : { placement }),
|
|
86
86
|
reducedMotion,
|
|
87
87
|
}),
|
|
88
88
|
];
|
|
@@ -1,42 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createTypeahead } from "@zealakit/ui-engine/keyboard";
|
|
2
|
+
import { onContextMenu as onContextMenuRequest } from "@zealakit/ui-engine/pointer";
|
|
3
|
+
import { focusFirstMenuItem, focusLastMenuItem, focusMenuItem, getMenuItems, moveMenuFocus, } from "../menu/navigation.js";
|
|
2
4
|
import { getActiveElement } from "../focus/focus.js";
|
|
3
5
|
/** Pointer/keyboard invocation, item navigation, and selection for menus. */
|
|
4
6
|
export function createContextMenuBehavior(host) {
|
|
5
|
-
|
|
6
|
-
let
|
|
7
|
+
let detachContextMenu = null;
|
|
8
|
+
let disabledGuard = null;
|
|
7
9
|
const isMenu = () => host.getOptions().kind === "context-menu";
|
|
10
|
+
const typeahead = createTypeahead({
|
|
11
|
+
items: () => getMenuItems(host.getOptions().content),
|
|
12
|
+
getActiveIndex: () => {
|
|
13
|
+
const items = getMenuItems(host.getOptions().content);
|
|
14
|
+
const active = getActiveElement(host.doc);
|
|
15
|
+
return active === null ? -1 : items.indexOf(active);
|
|
16
|
+
},
|
|
17
|
+
onMatch: (item) => {
|
|
18
|
+
focusMenuItem(item);
|
|
19
|
+
},
|
|
20
|
+
});
|
|
8
21
|
const behavior = {
|
|
9
22
|
point: null,
|
|
10
23
|
attach() { },
|
|
11
24
|
detach() { },
|
|
12
25
|
reset() {
|
|
13
|
-
typeahead.
|
|
26
|
+
typeahead.reset();
|
|
14
27
|
},
|
|
15
28
|
};
|
|
16
|
-
|
|
29
|
+
// The engine normalizes mouse, keyboard (Shift+F10 / ContextMenu) and touch
|
|
30
|
+
// long press, including Android's duplicate `contextmenu` suppression (E5-style).
|
|
31
|
+
const handleContextMenu = (request) => {
|
|
17
32
|
if (host.isDisabled() || !isMenu()) {
|
|
18
33
|
return;
|
|
19
34
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
keyboardInvokedAt = 0;
|
|
24
|
-
event.preventDefault();
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
event.preventDefault();
|
|
28
|
-
behavior.point = { x: event.clientX, y: event.clientY };
|
|
29
|
-
host.requestOpen("trigger");
|
|
30
|
-
};
|
|
31
|
-
const onTriggerKeyDown = (event) => {
|
|
32
|
-
if (!isMenu() ||
|
|
33
|
-
host.isDisabled() ||
|
|
34
|
-
(event.key !== "ContextMenu" && !(event.shiftKey && event.key === "F10"))) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
event.preventDefault();
|
|
38
|
-
keyboardInvokedAt = Date.now();
|
|
39
|
-
behavior.point = null;
|
|
35
|
+
request.originalEvent.preventDefault();
|
|
36
|
+
behavior.point =
|
|
37
|
+
request.pointerType === "keyboard" ? null : { x: request.clientX, y: request.clientY };
|
|
40
38
|
host.requestOpen("trigger");
|
|
41
39
|
};
|
|
42
40
|
const onMenuKeyDown = (event) => {
|
|
@@ -50,6 +48,9 @@ export function createContextMenuBehavior(host) {
|
|
|
50
48
|
}
|
|
51
49
|
const active = getActiveElement(host.doc);
|
|
52
50
|
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
51
|
+
// Kept local instead of createRovingFocus: a menu must not enter a
|
|
52
|
+
// submenu with a vertical arrow, and this walker also owns the trigger's
|
|
53
|
+
// submenu hand-off (01-1 Step 6 decision, recorded in the commit body).
|
|
53
54
|
event.preventDefault();
|
|
54
55
|
moveMenuFocus(content, event.key === "ArrowDown" ? 1 : -1);
|
|
55
56
|
return;
|
|
@@ -71,12 +72,12 @@ export function createContextMenuBehavior(host) {
|
|
|
71
72
|
}
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
|
-
if (event.key.length === 1 &&
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
76
|
+
// Engine typeahead: 500 ms buffer, accent folding (Vietnamese `đ`),
|
|
77
|
+
// repeated-character cycling, and "start after the active item".
|
|
78
|
+
if (typeahead.handleKeyDown(event)) {
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
}
|
|
80
81
|
}
|
|
81
82
|
};
|
|
82
83
|
const onMenuClick = (event) => {
|
|
@@ -89,8 +90,7 @@ export function createContextMenuBehavior(host) {
|
|
|
89
90
|
if (!item || !options.content.contains(item)) {
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
|
-
if (item.getAttribute("aria-disabled") === "true" ||
|
|
93
|
-
item.hasAttribute("disabled")) {
|
|
93
|
+
if (item.getAttribute("aria-disabled") === "true" || item.hasAttribute("disabled")) {
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
96
|
options.onSelect?.(item, event);
|
|
@@ -103,8 +103,15 @@ export function createContextMenuBehavior(host) {
|
|
|
103
103
|
behavior.attach = () => {
|
|
104
104
|
const { trigger, content } = host.getOptions();
|
|
105
105
|
bound = { trigger, content };
|
|
106
|
-
trigger
|
|
107
|
-
|
|
106
|
+
// A disabled trigger keeps the browser's own context menu: the engine
|
|
107
|
+
// helper always suppresses it, so stop the event before the helper sees it.
|
|
108
|
+
disabledGuard = (event) => {
|
|
109
|
+
if (host.isDisabled()) {
|
|
110
|
+
event.stopImmediatePropagation();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
trigger.addEventListener("contextmenu", disabledGuard);
|
|
114
|
+
detachContextMenu = onContextMenuRequest(trigger, handleContextMenu);
|
|
108
115
|
content.addEventListener("keydown", onMenuKeyDown);
|
|
109
116
|
content.addEventListener("click", onMenuClick);
|
|
110
117
|
};
|
|
@@ -114,8 +121,12 @@ export function createContextMenuBehavior(host) {
|
|
|
114
121
|
}
|
|
115
122
|
const { trigger, content } = bound;
|
|
116
123
|
bound = null;
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
if (disabledGuard !== null) {
|
|
125
|
+
trigger.removeEventListener("contextmenu", disabledGuard);
|
|
126
|
+
disabledGuard = null;
|
|
127
|
+
}
|
|
128
|
+
detachContextMenu?.();
|
|
129
|
+
detachContextMenu = null;
|
|
119
130
|
content.removeEventListener("keydown", onMenuKeyDown);
|
|
120
131
|
content.removeEventListener("click", onMenuClick);
|
|
121
132
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OverlayController, OverlayControllerOptions } from "./types.js";
|
|
2
|
-
export type { OverlayArrowOptions, OverlayChangeReason, OverlayController, OverlayControllerKind, OverlayControllerOptions, OverlayControllerState, OverlayFocusTarget, } from "./types.js";
|
|
2
|
+
export type { OverlayArrowOptions, OverlayChangeReason, OverlayController, OverlayControllerKind, OverlayControllerOptions, OverlayControllerState, OverlayFocusTarget, OverlayOptionsPatch, } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Shared DOM controller used by the non-React adapters.
|
|
5
5
|
*
|