@hexdspace/react 0.1.30 → 0.1.31
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/dist/index.js +48 -57
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2740,7 +2740,27 @@ function Popover({
|
|
|
2740
2740
|
import { cva as cva7 } from "class-variance-authority";
|
|
2741
2741
|
import { AnimatePresence as AnimatePresence4, motion as motion4 } from "motion/react";
|
|
2742
2742
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
|
2743
|
+
import * as React13 from "react";
|
|
2744
|
+
|
|
2745
|
+
// src/ui/utils/refs.ts
|
|
2743
2746
|
import * as React12 from "react";
|
|
2747
|
+
function useComposedRefs(...refs) {
|
|
2748
|
+
return React12.useCallback(
|
|
2749
|
+
(node) => {
|
|
2750
|
+
for (const ref of refs) {
|
|
2751
|
+
if (!ref) continue;
|
|
2752
|
+
if (typeof ref === "function") {
|
|
2753
|
+
ref(node);
|
|
2754
|
+
} else if (ref) {
|
|
2755
|
+
ref.current = node;
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
},
|
|
2759
|
+
[refs]
|
|
2760
|
+
);
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
// src/ui/components/DropdownMenu.tsx
|
|
2744
2764
|
import { jsx as jsx19, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
2745
2765
|
var dropdownMenuContentVariants = cva7(
|
|
2746
2766
|
cn(
|
|
@@ -2809,14 +2829,14 @@ var dropdownMenuItemVariants = cva7(
|
|
|
2809
2829
|
}
|
|
2810
2830
|
);
|
|
2811
2831
|
function useWindowTimeout() {
|
|
2812
|
-
const timeoutRef =
|
|
2813
|
-
const clear =
|
|
2832
|
+
const timeoutRef = React13.useRef(null);
|
|
2833
|
+
const clear = React13.useCallback(() => {
|
|
2814
2834
|
if (timeoutRef.current !== null) {
|
|
2815
2835
|
window.clearTimeout(timeoutRef.current);
|
|
2816
2836
|
timeoutRef.current = null;
|
|
2817
2837
|
}
|
|
2818
2838
|
}, []);
|
|
2819
|
-
const set =
|
|
2839
|
+
const set = React13.useCallback(
|
|
2820
2840
|
(fn, ms) => {
|
|
2821
2841
|
clear();
|
|
2822
2842
|
timeoutRef.current = window.setTimeout(() => {
|
|
@@ -2826,7 +2846,7 @@ function useWindowTimeout() {
|
|
|
2826
2846
|
},
|
|
2827
2847
|
[clear]
|
|
2828
2848
|
);
|
|
2829
|
-
|
|
2849
|
+
React13.useEffect(() => clear, [clear]);
|
|
2830
2850
|
return { set, clear };
|
|
2831
2851
|
}
|
|
2832
2852
|
function DropdownMenu({
|
|
@@ -2851,65 +2871,43 @@ function DropdownMenu({
|
|
|
2851
2871
|
style,
|
|
2852
2872
|
contentProps
|
|
2853
2873
|
}) {
|
|
2854
|
-
const [uncontrolledOpen, setUncontrolledOpen] =
|
|
2874
|
+
const [uncontrolledOpen, setUncontrolledOpen] = React13.useState(defaultOpen ?? false);
|
|
2855
2875
|
const isControlled = open2 !== void 0;
|
|
2856
2876
|
const resolvedOpen = isControlled ? open2 : uncontrolledOpen;
|
|
2857
2877
|
const motionDuration = useMotionDuration("--motion-fast", 0.14);
|
|
2858
|
-
const suppressDurationMs = Math.max(hoverCloseDelayMs, Math.round(motionDuration * 1e3) + 40);
|
|
2859
2878
|
const closeTimer = useWindowTimeout();
|
|
2860
|
-
const triggerRef =
|
|
2861
|
-
const contentRef =
|
|
2862
|
-
const openedByHoverRef =
|
|
2863
|
-
const
|
|
2864
|
-
const
|
|
2865
|
-
const isSuppressed = React12.useCallback(() => {
|
|
2866
|
-
if (!hoverOpen) return false;
|
|
2867
|
-
return Date.now() < suppressUntilRef.current;
|
|
2868
|
-
}, [hoverOpen]);
|
|
2869
|
-
const suppressReopen = React12.useCallback(() => {
|
|
2870
|
-
if (!hoverOpen) return;
|
|
2871
|
-
suppressUntilRef.current = Date.now() + suppressDurationMs;
|
|
2872
|
-
}, [hoverOpen, suppressDurationMs]);
|
|
2873
|
-
const handleOpenChange = React12.useCallback(
|
|
2879
|
+
const triggerRef = React13.useRef(null);
|
|
2880
|
+
const contentRef = React13.useRef(null);
|
|
2881
|
+
const openedByHoverRef = React13.useRef(false);
|
|
2882
|
+
const lastInputRef = React13.useRef("unknown");
|
|
2883
|
+
const handleOpenChange = React13.useCallback(
|
|
2874
2884
|
(nextOpen) => {
|
|
2875
2885
|
closeTimer.clear();
|
|
2876
2886
|
if (!nextOpen && hoverOpen && openedByHoverRef.current) {
|
|
2877
|
-
suppressReopen();
|
|
2878
2887
|
openedByHoverRef.current = false;
|
|
2879
2888
|
}
|
|
2880
2889
|
if (!isControlled) setUncontrolledOpen(nextOpen);
|
|
2881
2890
|
onOpenChange?.(nextOpen);
|
|
2882
2891
|
},
|
|
2883
|
-
[closeTimer, hoverOpen, isControlled, onOpenChange
|
|
2892
|
+
[closeTimer, hoverOpen, isControlled, onOpenChange]
|
|
2884
2893
|
);
|
|
2885
|
-
const isTargetInside =
|
|
2894
|
+
const isTargetInside = React13.useCallback((target) => {
|
|
2886
2895
|
if (!(target instanceof Node)) return false;
|
|
2887
2896
|
return Boolean(triggerRef.current?.contains(target) || contentRef.current?.contains(target));
|
|
2888
2897
|
}, []);
|
|
2889
|
-
const scheduleClose =
|
|
2898
|
+
const scheduleClose = React13.useCallback(() => {
|
|
2890
2899
|
if (!hoverOpen) return;
|
|
2891
2900
|
closeTimer.set(() => handleOpenChange(false), hoverCloseDelayMs);
|
|
2892
2901
|
}, [closeTimer, handleOpenChange, hoverCloseDelayMs, hoverOpen]);
|
|
2893
|
-
const setRef = (ref, node) => {
|
|
2894
|
-
if (typeof ref === "function") {
|
|
2895
|
-
ref(node);
|
|
2896
|
-
} else if (ref && typeof ref === "object") {
|
|
2897
|
-
ref.current = node;
|
|
2898
|
-
}
|
|
2899
|
-
};
|
|
2900
2902
|
const triggerElement = trigger;
|
|
2901
2903
|
const triggerProps = triggerElement.props;
|
|
2902
|
-
const
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
setRef(triggerProps.ref, node);
|
|
2906
|
-
},
|
|
2904
|
+
const composedTriggerRef = useComposedRefs(triggerRef, triggerProps.ref);
|
|
2905
|
+
const resolvedTrigger = hoverOpen ? React13.cloneElement(triggerElement, {
|
|
2906
|
+
ref: composedTriggerRef,
|
|
2907
2907
|
onPointerEnter: (event) => {
|
|
2908
2908
|
triggerProps.onPointerEnter?.(event);
|
|
2909
|
-
if (isSuppressed()) return;
|
|
2910
2909
|
openedByHoverRef.current = true;
|
|
2911
2910
|
lastInputRef.current = "pointer";
|
|
2912
|
-
suppressUntilRef.current = 0;
|
|
2913
2911
|
closeTimer.clear();
|
|
2914
2912
|
handleOpenChange(true);
|
|
2915
2913
|
},
|
|
@@ -2922,28 +2920,24 @@ function DropdownMenu({
|
|
|
2922
2920
|
if (isTargetInside(event.relatedTarget)) return;
|
|
2923
2921
|
scheduleClose();
|
|
2924
2922
|
},
|
|
2925
|
-
onFocus: (event) => {
|
|
2926
|
-
triggerProps.onFocus?.(event);
|
|
2927
|
-
if (lastInputRef.current === "pointer") return;
|
|
2928
|
-
if (isSuppressed()) return;
|
|
2929
|
-
openedByHoverRef.current = false;
|
|
2930
|
-
closeTimer.clear();
|
|
2931
|
-
handleOpenChange(true);
|
|
2932
|
-
},
|
|
2933
2923
|
onKeyDown: (event) => {
|
|
2934
2924
|
triggerProps.onKeyDown?.(event);
|
|
2935
2925
|
lastInputRef.current = "keyboard";
|
|
2936
2926
|
}
|
|
2937
2927
|
}) : trigger;
|
|
2938
2928
|
const contentPropsWithRef = contentProps;
|
|
2939
|
-
const {
|
|
2929
|
+
const {
|
|
2930
|
+
className: contentClassName,
|
|
2931
|
+
style: contentStyle,
|
|
2932
|
+
ref: contentPropRef,
|
|
2933
|
+
...restContentProps
|
|
2934
|
+
} = contentPropsWithRef ?? {};
|
|
2935
|
+
const composedContentRef = useComposedRefs(contentRef, contentPropRef);
|
|
2940
2936
|
const onPointerDownOutside = (event) => {
|
|
2941
2937
|
restContentProps.onPointerDownOutside?.(event);
|
|
2942
|
-
if (openedByHoverRef.current) suppressReopen();
|
|
2943
2938
|
};
|
|
2944
2939
|
const onInteractOutside = (event) => {
|
|
2945
2940
|
restContentProps.onInteractOutside?.(event);
|
|
2946
|
-
if (openedByHoverRef.current) suppressReopen();
|
|
2947
2941
|
};
|
|
2948
2942
|
const resolvedContentProps = hoverOpen ? {
|
|
2949
2943
|
...restContentProps,
|
|
@@ -2982,10 +2976,7 @@ function DropdownMenu({
|
|
|
2982
2976
|
motion4.div,
|
|
2983
2977
|
{
|
|
2984
2978
|
className: cn(dropdownMenuContentVariants({ chrome }), className, contentClassName),
|
|
2985
|
-
ref:
|
|
2986
|
-
contentRef.current = node;
|
|
2987
|
-
setRef(contentPropRef, node);
|
|
2988
|
-
},
|
|
2979
|
+
ref: composedContentRef,
|
|
2989
2980
|
initial: {
|
|
2990
2981
|
opacity: 0,
|
|
2991
2982
|
scale: 0.98,
|
|
@@ -3009,7 +3000,7 @@ function DropdownMenu({
|
|
|
3009
3000
|
) : null }) })
|
|
3010
3001
|
] });
|
|
3011
3002
|
}
|
|
3012
|
-
var DropdownMenuItem =
|
|
3003
|
+
var DropdownMenuItem = React13.forwardRef(
|
|
3013
3004
|
({ className, inset, destructive, ...props }, ref) => /* @__PURE__ */ jsx19(
|
|
3014
3005
|
DropdownMenuPrimitive.Item,
|
|
3015
3006
|
{
|
|
@@ -3020,13 +3011,13 @@ var DropdownMenuItem = React12.forwardRef(
|
|
|
3020
3011
|
)
|
|
3021
3012
|
);
|
|
3022
3013
|
DropdownMenuItem.displayName = "DropdownMenuItem";
|
|
3023
|
-
var DropdownMenuSeparator =
|
|
3014
|
+
var DropdownMenuSeparator = React13.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx19(DropdownMenuPrimitive.Separator, { ref, className: cn("my-1 h-px bg-(--divider)", className), ...props }));
|
|
3024
3015
|
DropdownMenuSeparator.displayName = "DropdownMenuSeparator";
|
|
3025
3016
|
|
|
3026
3017
|
// src/ui/components/Kbd.tsx
|
|
3027
|
-
import * as
|
|
3018
|
+
import * as React14 from "react";
|
|
3028
3019
|
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
3029
|
-
var Kbd =
|
|
3020
|
+
var Kbd = React14.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx20(
|
|
3030
3021
|
"span",
|
|
3031
3022
|
{
|
|
3032
3023
|
ref,
|