@yakad/ui 1.3.157 → 1.3.159
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/ActiveOnVisible/ActiveOnVisible.d.ts +1 -0
- package/dist/ActiveOnVisible/ActiveOnVisible.js +15 -13
- package/dist/Dropdown/Dropdown.js +5 -2
- package/dist/Popup/Popup.js +8 -4
- package/dist/RenderByScroll/RenderByScroll.js +11 -7
- package/dist/Text/Text.d.ts +10 -22
- package/dist/WithOverlay/WithOverlay.d.ts +2 -2
- package/dist/WithOverlay/WithOverlay.js +14 -13
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/interactionHooks/useOnDoubleTap.d.ts +1 -1
- package/dist/interactionHooks/useOnDoubleTap.js +6 -5
- package/dist/interactionHooks/useOnHoverChange.d.ts +1 -1
- package/dist/interactionHooks/useOnHoverChange.js +8 -7
- package/dist/interactionHooks/useOnOutsideClick.d.ts +1 -1
- package/dist/interactionHooks/useOnOutsideClick.js +6 -5
- package/dist/interactionHooks/useOnPinch.d.ts +1 -1
- package/dist/interactionHooks/useOnPinch.js +6 -5
- package/dist/interactionHooks/useOnResizeChange.d.ts +2 -0
- package/dist/interactionHooks/{useOnResizeObserver.js → useOnResizeChange.js} +6 -5
- package/dist/interactionHooks/useOnRightClick.d.ts +1 -1
- package/dist/interactionHooks/useOnRightClick.js +6 -5
- package/dist/interactionHooks/useOnRotate.d.ts +1 -1
- package/dist/interactionHooks/useOnRotate.js +6 -5
- package/dist/interactionHooks/useOnScroll.d.ts +1 -1
- package/dist/interactionHooks/useOnScroll.js +8 -8
- package/dist/interactionHooks/useOnSwipe.d.ts +1 -1
- package/dist/interactionHooks/useOnSwipe.js +6 -5
- package/dist/interactionHooks/useOnVisibilityChange.d.ts +2 -0
- package/dist/interactionHooks/useOnVisibilityChange.js +21 -0
- package/package.json +3 -3
- package/dist/WithInteractions/WithInteractions.d.ts +0 -25
- package/dist/WithInteractions/WithInteractions.js +0 -226
- package/dist/interactionHooks/useOnResizeObserver.d.ts +0 -2
- package/dist/interactionHooks/useOnVisibilityObserver.d.ts +0 -2
- package/dist/interactionHooks/useOnVisibilityObserver.js +0 -20
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { StackProps } from "..";
|
|
3
3
|
export interface ActiveOnVisibleProps extends StackProps {
|
|
4
|
+
onVisibilityChange?: (visible: boolean) => void;
|
|
4
5
|
}
|
|
5
6
|
export declare const ActiveOnVisible: import("react").ForwardRefExoticComponent<ActiveOnVisibleProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -11,23 +11,25 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
|
15
|
+
import { Stack, useOnVisibilityChange } from "..";
|
|
16
16
|
export const ActiveOnVisible = forwardRef(function ActiveOnVisible(_a, forwardedRef) {
|
|
17
|
-
var { style, children } = _a, restProps = __rest(_a, ["style", "children"]);
|
|
17
|
+
var { onVisibilityChange, style, children } = _a, restProps = __rest(_a, ["onVisibilityChange", "style", "children"]);
|
|
18
18
|
const localRef = useRef(null);
|
|
19
|
+
const [boxHeight, setBoxHeight] = useState(0);
|
|
20
|
+
// const isVisible = boxHeight === 0;
|
|
19
21
|
// Let the parent access our DOM node
|
|
20
22
|
useImperativeHandle(forwardedRef, () => localRef.current);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const boxRect = localRef.current.getBoundingClientRect();
|
|
23
|
+
useOnVisibilityChange((visible) => {
|
|
24
|
+
var _a;
|
|
25
|
+
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(visible);
|
|
26
|
+
if (visible) {
|
|
27
|
+
setBoxHeight(0);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const boxRect = (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
29
31
|
setBoxHeight(boxRect.height);
|
|
30
32
|
}
|
|
31
|
-
};
|
|
32
|
-
return (_jsx(
|
|
33
|
+
}, localRef);
|
|
34
|
+
return (_jsx(Stack, Object.assign({ ref: localRef }, restProps, { style: Object.assign({ height: boxHeight || "auto" }, style), children: children })));
|
|
33
35
|
});
|
|
@@ -13,7 +13,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { useRef, useState, useEffect, forwardRef, useImperativeHandle, } from "react";
|
|
15
15
|
import classNames from "classnames";
|
|
16
|
-
import { Card,
|
|
16
|
+
import { Card, useOnOutsideClick } from "..";
|
|
17
17
|
import styles from "./Dropdown.module.css";
|
|
18
18
|
export const Dropdown = forwardRef(function Dropdown(_a, forwardedRef) {
|
|
19
19
|
var { fullWidthOnParentDemand = false, // Def in Card is True
|
|
@@ -72,7 +72,10 @@ export const Dropdown = forwardRef(function Dropdown(_a, forwardedRef) {
|
|
|
72
72
|
setIsPlaced(true);
|
|
73
73
|
}
|
|
74
74
|
}, [children, placementTargetRef]);
|
|
75
|
-
|
|
75
|
+
useOnOutsideClick(() => {
|
|
76
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
77
|
+
}, dropdownRef);
|
|
78
|
+
return (_jsxs(_Fragment, { children: [!triggerref && _jsx("div", { ref: fallbackTriggerRef }), _jsx(Card, Object.assign({ ref: dropdownRef, fullWidthOnParentDemand: fullWidthOnParentDemand, blur: blur, level: level }, restProps, { className: classNames(styles.dropdownCard, { [styles.isPlacedAbove]: isPlacedAbove }, className), style: Object.assign({ top: dropdownPosition.top, left: dropdownPosition.left, visibility: isPlaced ? "visible" : "hidden" }, style), children: children })), _jsx("span", { className: classNames(styles.arrow, {
|
|
76
79
|
[styles.isPlacedAbove]: isPlacedAbove,
|
|
77
80
|
}, { [styles.blur]: blur }), style: {
|
|
78
81
|
top: arrowPosition.top,
|
package/dist/Popup/Popup.js
CHANGED
|
@@ -11,12 +11,16 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { forwardRef } from "react";
|
|
14
|
+
import { forwardRef, useImperativeHandle } from "react";
|
|
15
15
|
import classNames from "classnames";
|
|
16
16
|
import { Symbol } from "@yakad/symbols";
|
|
17
|
-
import { Button, Card, Row, Screen, Spacer, Stack, Text,
|
|
17
|
+
import { Button, Card, Row, Screen, Spacer, Stack, Text, useOnOutsideClick, } from "..";
|
|
18
18
|
import styles from "./Popup.module.css";
|
|
19
|
-
export const Popup = forwardRef(function Popup(_a,
|
|
19
|
+
export const Popup = forwardRef(function Popup(_a, forwardedRef) {
|
|
20
20
|
var { align, onClose, heading, className, children } = _a, restProps = __rest(_a, ["align", "onClose", "heading", "className", "children"]);
|
|
21
|
-
|
|
21
|
+
const localRef = useOnOutsideClick(() => {
|
|
22
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
23
|
+
});
|
|
24
|
+
useImperativeHandle(forwardedRef, () => localRef.current);
|
|
25
|
+
return (_jsx(Screen, { align: "center", className: styles.popupscreen, children: _jsxs(Card, Object.assign({ ref: localRef }, restProps, { className: classNames(styles.popup, className), children: [_jsxs(Row, { style: { marginBottom: "2rem" }, children: [_jsx(Text, { variant: "heading4", children: heading }), _jsx(Spacer, {}), _jsx(Button, { title: "Close", icon: _jsx(Symbol, { icon: "close" }), onClick: onClose })] }), _jsx(Stack, { align: align, style: { width: "100%", overflowY: "auto" }, children: children })] })) }));
|
|
22
26
|
});
|
|
@@ -12,8 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import React, { forwardRef, useEffect, useRef, useState } from "react";
|
|
15
|
-
import { Stack,
|
|
16
|
-
const data = Array.from({ length: 78 });
|
|
15
|
+
import { ActiveOnVisible, Stack, useOnVisibilityChange } from "..";
|
|
17
16
|
export const RenderByScroll = forwardRef(function RenderByScroll(_a, ref) {
|
|
18
17
|
var { scrollMarginTop = 8, // Sticky Header Height
|
|
19
18
|
extraRender = 5, jumpToIndex = 0, stopNewRenders, newChildRendered, style, children } = _a, restProps = __rest(_a, ["scrollMarginTop", "extraRender", "jumpToIndex", "stopNewRenders", "newChildRendered", "style", "children"]);
|
|
@@ -44,7 +43,7 @@ export const RenderByScroll = forwardRef(function RenderByScroll(_a, ref) {
|
|
|
44
43
|
useEffect(() => {
|
|
45
44
|
const isPriorityBYHighSide = overRenderedOnHighSide < 1 ||
|
|
46
45
|
overRenderedOnHighSide - 1 <= overRenderedOnLowSide;
|
|
47
|
-
const isHighSideNewRenderRemains = rendered.highest <
|
|
46
|
+
const isHighSideNewRenderRemains = rendered.highest < childrenArray.length - 1;
|
|
48
47
|
const isLowSideNewRenderRemains = rendered.lowest > 0;
|
|
49
48
|
if (!stopNewRenders) {
|
|
50
49
|
if (isPriorityBYHighSide &&
|
|
@@ -81,12 +80,17 @@ export const RenderByScroll = forwardRef(function RenderByScroll(_a, ref) {
|
|
|
81
80
|
return () => clearTimeout(timeout);
|
|
82
81
|
// eslint-disable-next-line
|
|
83
82
|
}, [jumpToIndex]);
|
|
84
|
-
|
|
83
|
+
const onvisibRef = useOnVisibilityChange((visible) => {
|
|
84
|
+
setIsVisibleLowSideLimitSensor(visible);
|
|
85
|
+
});
|
|
86
|
+
return (_jsxs(Stack, Object.assign({ ref: ref }, restProps, { style: Object.assign({ minHeight: "100vh" }, style), children: [rendered.lowest > 0 && (_jsx("div", { ref: onvisibRef, style: {
|
|
85
87
|
marginBottom: `${scrollMarginTop}rem`,
|
|
86
|
-
}
|
|
87
|
-
i <= rendered.highest && (_jsx(
|
|
88
|
+
} })), childrenArray.map((child, i) => i >= rendered.lowest &&
|
|
89
|
+
i <= rendered.highest && (_jsx(ActiveOnVisible, { ref: (el) => {
|
|
88
90
|
childRefs.current[i] = el;
|
|
89
91
|
}, style: {
|
|
90
92
|
scrollMarginTop: `${scrollMarginTop}rem`,
|
|
91
|
-
},
|
|
93
|
+
}, onVisibilityChange: (visible) => {
|
|
94
|
+
visible && handleOnVisible(i);
|
|
95
|
+
}, children: child }, i)))] })));
|
|
92
96
|
});
|
package/dist/Text/Text.d.ts
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
type TextVariant = "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "body1" | "body2" | "body3" | "body4" | "body5" | "body6" | "caption" | "span";
|
|
3
|
-
export interface
|
|
3
|
+
export interface TextProps<T> extends React.HTMLAttributes<T> {
|
|
4
4
|
variant?: TextVariant;
|
|
5
5
|
color?: "onSurfaceColor" | "onSurfaceVariantColor";
|
|
6
6
|
children?: React.ReactNode;
|
|
7
7
|
}
|
|
8
|
-
export declare const H1: import("react").ForwardRefExoticComponent<
|
|
9
|
-
export declare const H2: import("react").ForwardRefExoticComponent<
|
|
10
|
-
export declare const H3: import("react").ForwardRefExoticComponent<
|
|
11
|
-
export declare const H4: import("react").ForwardRefExoticComponent<
|
|
12
|
-
export declare const H5: import("react").ForwardRefExoticComponent<
|
|
13
|
-
export declare const H6: import("react").ForwardRefExoticComponent<
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
export declare const P: import("react").ForwardRefExoticComponent<ParagraphProps & import("react").RefAttributes<HTMLParagraphElement>>;
|
|
19
|
-
export interface SpanProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
20
|
-
variant?: TextVariant;
|
|
21
|
-
children?: React.ReactNode;
|
|
22
|
-
}
|
|
23
|
-
export declare const Span: import("react").ForwardRefExoticComponent<SpanProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
24
|
-
export interface TextProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
25
|
-
variant?: TextVariant;
|
|
26
|
-
children?: React.ReactNode;
|
|
27
|
-
}
|
|
28
|
-
export declare const Text: import("react").ForwardRefExoticComponent<TextProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
8
|
+
export declare const H1: import("react").ForwardRefExoticComponent<TextProps<HTMLHeadingElement> & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
9
|
+
export declare const H2: import("react").ForwardRefExoticComponent<TextProps<HTMLHeadingElement> & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
10
|
+
export declare const H3: import("react").ForwardRefExoticComponent<TextProps<HTMLHeadingElement> & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
11
|
+
export declare const H4: import("react").ForwardRefExoticComponent<TextProps<HTMLHeadingElement> & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
12
|
+
export declare const H5: import("react").ForwardRefExoticComponent<TextProps<HTMLHeadingElement> & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
13
|
+
export declare const H6: import("react").ForwardRefExoticComponent<TextProps<HTMLHeadingElement> & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
14
|
+
export declare const P: import("react").ForwardRefExoticComponent<TextProps<HTMLParagraphElement> & import("react").RefAttributes<HTMLParagraphElement>>;
|
|
15
|
+
export declare const Span: import("react").ForwardRefExoticComponent<TextProps<HTMLSpanElement> & import("react").RefAttributes<HTMLSpanElement>>;
|
|
16
|
+
export declare const Text: import("react").ForwardRefExoticComponent<TextProps<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
|
|
29
17
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
|
-
import { Dropdown, DropdownProps, Popup, PopupProps,
|
|
2
|
+
import { Dropdown, DropdownProps, Popup, PopupProps, StackProps } from "..";
|
|
3
3
|
export interface OverlayProps {
|
|
4
4
|
triggerref?: RefObject<HTMLElement | null>;
|
|
5
5
|
onClose?: () => void;
|
|
6
6
|
}
|
|
7
7
|
type AllowedOverlays = React.ReactElement<PopupProps, typeof Popup> | React.ReactElement<DropdownProps, typeof Dropdown>;
|
|
8
|
-
export interface WithOverlayProps extends
|
|
8
|
+
export interface WithOverlayProps extends StackProps {
|
|
9
9
|
trigger?: "onClick" | "onRightClick";
|
|
10
10
|
overlay?: AllowedOverlays;
|
|
11
11
|
children?: React.ReactElement;
|
|
@@ -13,14 +13,21 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { useState, cloneElement, useEffect, useRef, forwardRef, useImperativeHandle, } from "react";
|
|
15
15
|
import { createPortal } from "react-dom";
|
|
16
|
-
import {
|
|
16
|
+
import { Stack, useOnRightClick, } from "..";
|
|
17
17
|
export const WithOverlay = forwardRef(function WithOverlay(_a, forwardedRef) {
|
|
18
|
-
var { trigger = "onClick", overlay, children,
|
|
18
|
+
var { trigger = "onClick", overlay, children, onClick } = _a, restProps = __rest(_a, ["trigger", "overlay", "children", "onClick"]);
|
|
19
19
|
// Get Triggers ref and send to Overlay
|
|
20
|
-
const
|
|
21
|
-
// Let the parent access our DOM node
|
|
22
|
-
useImperativeHandle(forwardedRef, () => triggerRef.current);
|
|
20
|
+
const localRef = useRef(null);
|
|
23
21
|
const [showOverlay, setShowOverlay] = useState(false);
|
|
22
|
+
useOnRightClick(() => {
|
|
23
|
+
setShowOverlay(true);
|
|
24
|
+
}, localRef);
|
|
25
|
+
const onClickHandler = (e) => {
|
|
26
|
+
trigger === "onClick" && setShowOverlay((prev) => !prev);
|
|
27
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
28
|
+
};
|
|
29
|
+
// Let the parent access our DOM node
|
|
30
|
+
useImperativeHandle(forwardedRef, () => localRef.current);
|
|
24
31
|
// Disable Body Scroll on showOverlay
|
|
25
32
|
useEffect(() => {
|
|
26
33
|
document.body.style.overflow = showOverlay ? "hidden" : "initial";
|
|
@@ -33,18 +40,12 @@ export const WithOverlay = forwardRef(function WithOverlay(_a, forwardedRef) {
|
|
|
33
40
|
const teleport = overlay &&
|
|
34
41
|
portalRoot &&
|
|
35
42
|
createPortal(cloneElement(overlay, {
|
|
36
|
-
triggerref:
|
|
43
|
+
triggerref: localRef,
|
|
37
44
|
onClose: () => {
|
|
38
45
|
var _a, _b;
|
|
39
46
|
(_b = (_a = overlay.props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
40
47
|
setShowOverlay(false);
|
|
41
48
|
},
|
|
42
49
|
}), portalRoot);
|
|
43
|
-
return (_jsxs(_Fragment, { children: [_jsx(
|
|
44
|
-
trigger === "onRightClick" && setShowOverlay(true);
|
|
45
|
-
onRightClick === null || onRightClick === void 0 ? void 0 : onRightClick(e);
|
|
46
|
-
}, onClick: (e) => {
|
|
47
|
-
trigger === "onClick" && setShowOverlay(true);
|
|
48
|
-
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
49
|
-
}, children: children })), showOverlay && teleport] }));
|
|
50
|
+
return (_jsxs(_Fragment, { children: [_jsx(Stack, Object.assign({ ref: localRef }, restProps, { onClick: onClickHandler, children: children })), showOverlay && teleport] }));
|
|
50
51
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,6 @@ export * from "./RadioButton/RadioButton";
|
|
|
29
29
|
export * from "./CodeBox/CodeBox";
|
|
30
30
|
export * from "./Display/Display";
|
|
31
31
|
export * from "./WithOverlay/WithOverlay";
|
|
32
|
-
export * from "./WithInteractions/WithInteractions";
|
|
33
32
|
export * from "./RenderByScroll/RenderByScroll";
|
|
34
33
|
export * from "./ActiveOnVisible/ActiveOnVisible";
|
|
35
34
|
export * from "./Dropdown/Dropdown";
|
|
@@ -41,7 +40,7 @@ export * from "./interactionHooks/useOnDoubleTap";
|
|
|
41
40
|
export * from "./interactionHooks/useOnSwipe";
|
|
42
41
|
export * from "./interactionHooks/useOnPinch";
|
|
43
42
|
export * from "./interactionHooks/useOnRotate";
|
|
44
|
-
export * from "./interactionHooks/
|
|
45
|
-
export * from "./interactionHooks/
|
|
43
|
+
export * from "./interactionHooks/useOnResizeChange";
|
|
44
|
+
export * from "./interactionHooks/useOnVisibilityChange";
|
|
46
45
|
export * from "./interactionHooks/useOnHoverChange";
|
|
47
46
|
export * from "./interactionHooks/useOnScroll";
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,6 @@ export * from "./CodeBox/CodeBox";
|
|
|
34
34
|
// Utilities
|
|
35
35
|
export * from "./Display/Display"; // Stack Based
|
|
36
36
|
export * from "./WithOverlay/WithOverlay";
|
|
37
|
-
export * from "./WithInteractions/WithInteractions"; // Stack Based
|
|
38
37
|
export * from "./RenderByScroll/RenderByScroll"; // Stack Based
|
|
39
38
|
export * from "./ActiveOnVisible/ActiveOnVisible"; // Stack Based
|
|
40
39
|
// Overlays
|
|
@@ -47,7 +46,7 @@ export * from "./interactionHooks/useOnDoubleTap";
|
|
|
47
46
|
export * from "./interactionHooks/useOnSwipe";
|
|
48
47
|
export * from "./interactionHooks/useOnPinch";
|
|
49
48
|
export * from "./interactionHooks/useOnRotate";
|
|
50
|
-
export * from "./interactionHooks/
|
|
51
|
-
export * from "./interactionHooks/
|
|
49
|
+
export * from "./interactionHooks/useOnResizeChange";
|
|
50
|
+
export * from "./interactionHooks/useOnVisibilityChange";
|
|
52
51
|
export * from "./interactionHooks/useOnHoverChange";
|
|
53
52
|
export * from "./interactionHooks/useOnScroll";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
|
-
export declare function useOnDoubleTap<T extends HTMLElement = HTMLElement>(callback: (e: TouchEvent) => void): RefObject<T | null>;
|
|
2
|
+
export declare function useOnDoubleTap<T extends HTMLElement = HTMLElement>(callback: (e: TouchEvent) => void, ref?: RefObject<T | null> | undefined): RefObject<T | null>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
-
export function useOnDoubleTap(callback) {
|
|
3
|
-
const
|
|
2
|
+
export function useOnDoubleTap(callback, ref) {
|
|
3
|
+
const defaultRef = useRef(null);
|
|
4
|
+
const targetRef = ref !== null && ref !== void 0 ? ref : defaultRef;
|
|
4
5
|
const [lastTap, setLastTap] = useState(0);
|
|
5
6
|
const handleDoubleTap = useCallback((e) => {
|
|
6
7
|
const now = Date.now();
|
|
@@ -10,13 +11,13 @@ export function useOnDoubleTap(callback) {
|
|
|
10
11
|
setLastTap(now);
|
|
11
12
|
}, [callback, lastTap]);
|
|
12
13
|
useEffect(() => {
|
|
13
|
-
const element =
|
|
14
|
+
const element = targetRef.current;
|
|
14
15
|
if (!element)
|
|
15
16
|
return;
|
|
16
17
|
element.addEventListener("touchend", handleDoubleTap);
|
|
17
18
|
return () => {
|
|
18
19
|
element.removeEventListener("touchend", handleDoubleTap);
|
|
19
20
|
};
|
|
20
|
-
}, [handleDoubleTap]);
|
|
21
|
-
return
|
|
21
|
+
}, [handleDoubleTap, targetRef]);
|
|
22
|
+
return targetRef;
|
|
22
23
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
|
-
export declare function useOnHoverChange<T extends HTMLElement = HTMLElement>(callback: (e: MouseEvent,
|
|
2
|
+
export declare function useOnHoverChange<T extends HTMLElement = HTMLElement>(callback: (e: MouseEvent, hover: boolean) => void, ref?: RefObject<T | null> | undefined): RefObject<T | null>;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
-
export function useOnHoverChange(callback) {
|
|
3
|
-
const
|
|
2
|
+
export function useOnHoverChange(callback, ref) {
|
|
3
|
+
const defaultRef = useRef(null);
|
|
4
|
+
const targetRef = ref !== null && ref !== void 0 ? ref : defaultRef;
|
|
4
5
|
const handleMouseEnter = useCallback((e) => {
|
|
5
|
-
window.matchMedia("(pointer: fine)").matches && callback(e,
|
|
6
|
+
window.matchMedia("(pointer: fine)").matches && callback(e, true);
|
|
6
7
|
}, [callback]);
|
|
7
8
|
const handleMouseLeave = useCallback((e) => {
|
|
8
|
-
window.matchMedia("(pointer: fine)").matches && callback(e,
|
|
9
|
+
window.matchMedia("(pointer: fine)").matches && callback(e, false);
|
|
9
10
|
}, [callback]);
|
|
10
11
|
useEffect(() => {
|
|
11
|
-
const element =
|
|
12
|
+
const element = targetRef.current;
|
|
12
13
|
if (!element)
|
|
13
14
|
return;
|
|
14
15
|
element.addEventListener("mouseenter", handleMouseEnter);
|
|
@@ -17,6 +18,6 @@ export function useOnHoverChange(callback) {
|
|
|
17
18
|
element.removeEventListener("mouseenter", handleMouseEnter);
|
|
18
19
|
element.removeEventListener("mouseleave", handleMouseLeave);
|
|
19
20
|
};
|
|
20
|
-
}, [handleMouseEnter, handleMouseLeave]);
|
|
21
|
-
return
|
|
21
|
+
}, [handleMouseEnter, handleMouseLeave, targetRef]);
|
|
22
|
+
return targetRef;
|
|
22
23
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
|
-
export declare function useOnOutsideClick<T extends HTMLElement = HTMLElement>(callback: (e: MouseEvent) => void): RefObject<T | null>;
|
|
2
|
+
export declare function useOnOutsideClick<T extends HTMLElement = HTMLElement>(callback: (e: MouseEvent) => void, ref?: RefObject<T | null> | undefined): RefObject<T | null>;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
-
export function useOnOutsideClick(callback) {
|
|
3
|
-
const
|
|
2
|
+
export function useOnOutsideClick(callback, ref) {
|
|
3
|
+
const defaultRef = useRef(null);
|
|
4
|
+
const targetRef = ref !== null && ref !== void 0 ? ref : defaultRef;
|
|
4
5
|
const handleClick = useCallback((e) => {
|
|
5
6
|
e.preventDefault();
|
|
6
|
-
const element =
|
|
7
|
+
const element = targetRef.current;
|
|
7
8
|
if (!element)
|
|
8
9
|
return;
|
|
9
10
|
if (!element.contains(e.target)) {
|
|
10
11
|
callback(e);
|
|
11
12
|
}
|
|
12
|
-
}, [callback]);
|
|
13
|
+
}, [callback, targetRef]);
|
|
13
14
|
useEffect(() => {
|
|
14
15
|
document.addEventListener("click", handleClick);
|
|
15
16
|
return () => {
|
|
16
17
|
document.removeEventListener("click", handleClick);
|
|
17
18
|
};
|
|
18
19
|
}, [handleClick]);
|
|
19
|
-
return
|
|
20
|
+
return targetRef;
|
|
20
21
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
|
-
export declare function useOnPinch<T extends HTMLElement = HTMLElement>(callback: (e: TouchEvent, action: "in" | "out") => void): RefObject<T | null>;
|
|
2
|
+
export declare function useOnPinch<T extends HTMLElement = HTMLElement>(callback: (e: TouchEvent, action: "in" | "out") => void, ref?: RefObject<T | null> | undefined): RefObject<T | null>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
-
export function useOnPinch(callback) {
|
|
3
|
-
const
|
|
2
|
+
export function useOnPinch(callback, ref) {
|
|
3
|
+
const defaultRef = useRef(null);
|
|
4
|
+
const targetRef = ref !== null && ref !== void 0 ? ref : defaultRef;
|
|
4
5
|
const [startDistance, setStartDistance] = useState(0);
|
|
5
6
|
const getDistance = (t1, t2) => Math.hypot(t2.clientX - t1.clientX, t2.clientY - t1.clientY);
|
|
6
7
|
const handleStart = useCallback((e) => {
|
|
@@ -20,7 +21,7 @@ export function useOnPinch(callback) {
|
|
|
20
21
|
}
|
|
21
22
|
}, [callback, startDistance]);
|
|
22
23
|
useEffect(() => {
|
|
23
|
-
const element =
|
|
24
|
+
const element = targetRef.current;
|
|
24
25
|
if (!element)
|
|
25
26
|
return;
|
|
26
27
|
element.addEventListener("touchstart", handleStart);
|
|
@@ -29,6 +30,6 @@ export function useOnPinch(callback) {
|
|
|
29
30
|
element.removeEventListener("touchstart", handleStart);
|
|
30
31
|
element.removeEventListener("touchmove", handleMove);
|
|
31
32
|
};
|
|
32
|
-
}, [handleMove, handleStart]);
|
|
33
|
-
return
|
|
33
|
+
}, [handleMove, handleStart, targetRef]);
|
|
34
|
+
return targetRef;
|
|
34
35
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
-
export function
|
|
3
|
-
const
|
|
2
|
+
export function useOnResizeChange(callback, ref) {
|
|
3
|
+
const defaultRef = useRef(null);
|
|
4
|
+
const targetRef = ref !== null && ref !== void 0 ? ref : defaultRef;
|
|
4
5
|
const handleResize = useCallback((e) => {
|
|
5
6
|
callback(e);
|
|
6
7
|
}, [callback]);
|
|
7
8
|
useEffect(() => {
|
|
8
|
-
const element =
|
|
9
|
+
const element = targetRef.current;
|
|
9
10
|
if (!element)
|
|
10
11
|
return;
|
|
11
12
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
@@ -17,6 +18,6 @@ export function useOnResizeObserver(callback) {
|
|
|
17
18
|
return () => {
|
|
18
19
|
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
|
|
19
20
|
};
|
|
20
|
-
}, [handleResize]);
|
|
21
|
-
return
|
|
21
|
+
}, [handleResize, targetRef]);
|
|
22
|
+
return targetRef;
|
|
22
23
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
|
-
export declare function useOnRightClick<T extends HTMLElement = HTMLElement>(callback: (e: MouseEvent) => void): RefObject<T | null>;
|
|
2
|
+
export declare function useOnRightClick<T extends HTMLElement = HTMLElement>(callback: (e: MouseEvent) => void, ref?: RefObject<T | null> | undefined): RefObject<T | null>;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
-
export function useOnRightClick(callback) {
|
|
3
|
-
const
|
|
2
|
+
export function useOnRightClick(callback, ref) {
|
|
3
|
+
const defaultRef = useRef(null);
|
|
4
|
+
const targetRef = ref !== null && ref !== void 0 ? ref : defaultRef;
|
|
4
5
|
const handleContextMenu = useCallback((e) => {
|
|
5
6
|
e.preventDefault();
|
|
6
7
|
callback(e);
|
|
7
8
|
}, [callback]);
|
|
8
9
|
useEffect(() => {
|
|
9
|
-
const element =
|
|
10
|
+
const element = targetRef.current;
|
|
10
11
|
if (!element)
|
|
11
12
|
return;
|
|
12
13
|
element.addEventListener("contextmenu", handleContextMenu);
|
|
13
14
|
return () => {
|
|
14
15
|
element.removeEventListener("contextmenu", handleContextMenu);
|
|
15
16
|
};
|
|
16
|
-
}, [handleContextMenu]);
|
|
17
|
-
return
|
|
17
|
+
}, [handleContextMenu, targetRef]);
|
|
18
|
+
return targetRef;
|
|
18
19
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
|
-
export declare function useOnRotate<T extends HTMLElement = HTMLElement>(callback: (e: TouchEvent, deltaAngle: number) => void): RefObject<T | null>;
|
|
2
|
+
export declare function useOnRotate<T extends HTMLElement = HTMLElement>(callback: (e: TouchEvent, deltaAngle: number) => void, ref?: RefObject<T | null> | undefined): RefObject<T | null>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
-
export function useOnRotate(callback) {
|
|
3
|
-
const
|
|
2
|
+
export function useOnRotate(callback, ref) {
|
|
3
|
+
const defaultRef = useRef(null);
|
|
4
|
+
const targetRef = ref !== null && ref !== void 0 ? ref : defaultRef;
|
|
4
5
|
const [startAngle, setStartAngle] = useState(0);
|
|
5
6
|
const getAngle = (t1, t2) => Math.atan2(t2.clientY - t1.clientY, t2.clientX - t1.clientX) *
|
|
6
7
|
(180 / Math.PI);
|
|
@@ -21,7 +22,7 @@ export function useOnRotate(callback) {
|
|
|
21
22
|
}
|
|
22
23
|
}, [callback, startAngle]);
|
|
23
24
|
useEffect(() => {
|
|
24
|
-
const element =
|
|
25
|
+
const element = targetRef.current;
|
|
25
26
|
if (!element)
|
|
26
27
|
return;
|
|
27
28
|
element.addEventListener("touchstart", handleStart);
|
|
@@ -30,6 +31,6 @@ export function useOnRotate(callback) {
|
|
|
30
31
|
element.removeEventListener("touchstart", handleStart);
|
|
31
32
|
element.removeEventListener("touchmove", handleMove);
|
|
32
33
|
};
|
|
33
|
-
}, [handleMove, handleStart]);
|
|
34
|
-
return
|
|
34
|
+
}, [handleMove, handleStart, targetRef]);
|
|
35
|
+
return targetRef;
|
|
35
36
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
|
-
export declare function useOnScroll<T extends HTMLElement = HTMLElement>(callback: (
|
|
2
|
+
export declare function useOnScroll<T extends HTMLElement = HTMLElement>(callback: (scrolling: boolean) => void, ref?: RefObject<T | null> | undefined): RefObject<T | null>;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
-
export function useOnScroll(callback) {
|
|
3
|
-
const
|
|
2
|
+
export function useOnScroll(callback, ref) {
|
|
3
|
+
const defaultRef = useRef(null);
|
|
4
|
+
const targetRef = ref !== null && ref !== void 0 ? ref : defaultRef;
|
|
4
5
|
const scrollTimeoutRef = useRef(undefined);
|
|
5
6
|
const scrollingRef = useRef(false);
|
|
6
7
|
const handleScroll = useCallback(() => {
|
|
7
|
-
console.log("bb123");
|
|
8
8
|
if (!scrollingRef.current) {
|
|
9
9
|
scrollingRef.current = true;
|
|
10
|
-
callback(
|
|
10
|
+
callback(true);
|
|
11
11
|
}
|
|
12
12
|
clearTimeout(scrollTimeoutRef.current);
|
|
13
13
|
scrollTimeoutRef.current = setTimeout(() => {
|
|
14
14
|
scrollingRef.current = false;
|
|
15
|
-
callback(
|
|
15
|
+
callback(false);
|
|
16
16
|
}, 150);
|
|
17
17
|
}, [callback]);
|
|
18
18
|
useEffect(() => {
|
|
19
|
-
const element =
|
|
19
|
+
const element = targetRef.current;
|
|
20
20
|
if (!element)
|
|
21
21
|
return;
|
|
22
22
|
element.addEventListener("scroll", handleScroll);
|
|
@@ -24,6 +24,6 @@ export function useOnScroll(callback) {
|
|
|
24
24
|
element.removeEventListener("scroll", handleScroll);
|
|
25
25
|
clearTimeout(scrollTimeoutRef.current);
|
|
26
26
|
};
|
|
27
|
-
}, [handleScroll]);
|
|
28
|
-
return
|
|
27
|
+
}, [handleScroll, targetRef]);
|
|
28
|
+
return targetRef;
|
|
29
29
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
|
-
export declare function useOnSwipe<T extends HTMLElement = HTMLElement>(callback: (e: TouchEvent, direction: "left" | "right" | "up" | "down") => void): RefObject<T | null>;
|
|
2
|
+
export declare function useOnSwipe<T extends HTMLElement = HTMLElement>(callback: (e: TouchEvent, direction: "left" | "right" | "up" | "down") => void, ref?: RefObject<T | null> | undefined): RefObject<T | null>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
-
export function useOnSwipe(callback) {
|
|
3
|
-
const
|
|
2
|
+
export function useOnSwipe(callback, ref) {
|
|
3
|
+
const defaultRef = useRef(null);
|
|
4
|
+
const targetRef = ref !== null && ref !== void 0 ? ref : defaultRef;
|
|
4
5
|
const [swipeCoordinates, setSwipeCoordinates] = useState({
|
|
5
6
|
startX: 0,
|
|
6
7
|
startY: 0,
|
|
@@ -36,7 +37,7 @@ export function useOnSwipe(callback) {
|
|
|
36
37
|
}
|
|
37
38
|
}, [callback, swipeCoordinates.endX, swipeCoordinates.startX, swipeCoordinates.endY, swipeCoordinates.startY]);
|
|
38
39
|
useEffect(() => {
|
|
39
|
-
const element =
|
|
40
|
+
const element = targetRef.current;
|
|
40
41
|
if (!element)
|
|
41
42
|
return;
|
|
42
43
|
element.addEventListener("touchstart", touchStart, { passive: true });
|
|
@@ -47,6 +48,6 @@ export function useOnSwipe(callback) {
|
|
|
47
48
|
element.removeEventListener("touchmove", touchMove);
|
|
48
49
|
element.removeEventListener("touchend", touchEnd);
|
|
49
50
|
};
|
|
50
|
-
}, [touchStart, touchMove, touchEnd]);
|
|
51
|
-
return
|
|
51
|
+
}, [touchStart, touchMove, touchEnd, targetRef]);
|
|
52
|
+
return targetRef;
|
|
52
53
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
export function useOnVisibilityChange(callback, ref) {
|
|
3
|
+
const defaultRef = useRef(null);
|
|
4
|
+
const targetRef = ref !== null && ref !== void 0 ? ref : defaultRef;
|
|
5
|
+
const handleVisibility = useCallback((visible) => {
|
|
6
|
+
callback(visible);
|
|
7
|
+
}, [callback]);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const element = targetRef.current;
|
|
10
|
+
if (!element)
|
|
11
|
+
return;
|
|
12
|
+
const intersectionObserver = new IntersectionObserver((entries) => {
|
|
13
|
+
entries[0].isIntersecting ? handleVisibility(true) : handleVisibility(false);
|
|
14
|
+
});
|
|
15
|
+
intersectionObserver.observe(element);
|
|
16
|
+
return () => {
|
|
17
|
+
intersectionObserver === null || intersectionObserver === void 0 ? void 0 : intersectionObserver.disconnect();
|
|
18
|
+
};
|
|
19
|
+
}, [handleVisibility, targetRef]);
|
|
20
|
+
return targetRef;
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yakad/ui",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.159",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Natiq",
|
|
6
6
|
"description": "UI components for NextJS/React",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@yakad/lib": "1.0.22",
|
|
36
|
-
"@yakad/symbols": "
|
|
36
|
+
"@yakad/symbols": "1.0.28",
|
|
37
37
|
"classnames": "2.5.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
@@ -47,4 +47,4 @@
|
|
|
47
47
|
"react": "^19.0.0",
|
|
48
48
|
"react-dom": "^19.0.0"
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { StackProps } from "../Stack/Stack";
|
|
3
|
-
export interface WithInteractionsProps extends StackProps {
|
|
4
|
-
onRightClick?: (e: MouseEvent) => void;
|
|
5
|
-
onTap?: (e: TouchEvent) => void;
|
|
6
|
-
onDoubleTap?: (e: TouchEvent) => void;
|
|
7
|
-
onOutsideClick?: () => void;
|
|
8
|
-
onSwipeLeft?: () => void;
|
|
9
|
-
onSwipeRight?: () => void;
|
|
10
|
-
onSwipeUp?: () => void;
|
|
11
|
-
onSwipeDown?: () => void;
|
|
12
|
-
onPinchIn?: () => void;
|
|
13
|
-
onPinchOut?: () => void;
|
|
14
|
-
onRotate?: (angle: number) => void;
|
|
15
|
-
onScrollStart?: () => void;
|
|
16
|
-
onScrollStop?: () => void;
|
|
17
|
-
onResize?: (entry: ResizeObserverEntry) => void;
|
|
18
|
-
onVisibilityChange?: (visible: boolean) => void;
|
|
19
|
-
onVisible?: () => void;
|
|
20
|
-
onHidden?: () => void;
|
|
21
|
-
onMouseHoverChange?: (isHover: boolean, e: MouseEvent) => void;
|
|
22
|
-
onMouseHoverStart?: (e: MouseEvent) => void;
|
|
23
|
-
onMouseHoverLeave?: (e: MouseEvent) => void;
|
|
24
|
-
}
|
|
25
|
-
export declare const WithInteractions: import("react").ForwardRefExoticComponent<WithInteractionsProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
15
|
-
import { Stack } from "../Stack/Stack";
|
|
16
|
-
export const WithInteractions = forwardRef(function WithInteractions(_a, forwardedRef) {
|
|
17
|
-
var { children, onRightClick, onTap, onDoubleTap, onOutsideClick, onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, onPinchIn, onPinchOut, onRotate, onScrollStart, onScrollStop, onResize, onVisibilityChange, onVisible, onHidden, onMouseHoverChange, onMouseHoverStart, onMouseHoverLeave } = _a, restProps = __rest(_a, ["children", "onRightClick", "onTap", "onDoubleTap", "onOutsideClick", "onSwipeLeft", "onSwipeRight", "onSwipeUp", "onSwipeDown", "onPinchIn", "onPinchOut", "onRotate", "onScrollStart", "onScrollStop", "onResize", "onVisibilityChange", "onVisible", "onHidden", "onMouseHoverChange", "onMouseHoverStart", "onMouseHoverLeave"]);
|
|
18
|
-
const localRef = useRef(null);
|
|
19
|
-
// Let the parent access our DOM node
|
|
20
|
-
useImperativeHandle(forwardedRef, () => localRef.current);
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
const el = localRef.current;
|
|
23
|
-
if (!el)
|
|
24
|
-
return;
|
|
25
|
-
// Event cleanup store
|
|
26
|
-
const cleanupFns = [];
|
|
27
|
-
// === RIGHT CLICK ===
|
|
28
|
-
if (onRightClick) {
|
|
29
|
-
const handler = (e) => {
|
|
30
|
-
e.preventDefault();
|
|
31
|
-
onRightClick(e);
|
|
32
|
-
};
|
|
33
|
-
el.addEventListener("contextmenu", handler);
|
|
34
|
-
cleanupFns.push(() => el.removeEventListener("contextmenu", handler));
|
|
35
|
-
}
|
|
36
|
-
// === OUTSIDE CLICK ===
|
|
37
|
-
if (onOutsideClick) {
|
|
38
|
-
const handler = (e) => {
|
|
39
|
-
if (!el.contains(e.target)) {
|
|
40
|
-
onOutsideClick();
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
document.addEventListener("click", handler);
|
|
44
|
-
cleanupFns.push(() => document.removeEventListener("click", handler));
|
|
45
|
-
}
|
|
46
|
-
// === TAP & DOUBLE TAP ===
|
|
47
|
-
if (onTap || onDoubleTap) {
|
|
48
|
-
let lastTap = 0;
|
|
49
|
-
const tapHandler = (e) => {
|
|
50
|
-
const now = Date.now();
|
|
51
|
-
if (now - lastTap < 300) {
|
|
52
|
-
onDoubleTap === null || onDoubleTap === void 0 ? void 0 : onDoubleTap(e);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
onTap === null || onTap === void 0 ? void 0 : onTap(e);
|
|
56
|
-
}
|
|
57
|
-
lastTap = now;
|
|
58
|
-
};
|
|
59
|
-
el.addEventListener("touchend", tapHandler);
|
|
60
|
-
cleanupFns.push(() => el.removeEventListener("touchend", tapHandler));
|
|
61
|
-
}
|
|
62
|
-
// === SWIPE ===
|
|
63
|
-
if (onSwipeLeft || onSwipeRight || onSwipeUp || onSwipeDown) {
|
|
64
|
-
let startX = 0, startY = 0, endX = 0, endY = 0;
|
|
65
|
-
const touchStart = (e) => {
|
|
66
|
-
const t = e.touches[0];
|
|
67
|
-
startX = t.clientX;
|
|
68
|
-
startY = t.clientY;
|
|
69
|
-
endX = startX;
|
|
70
|
-
endY = startY;
|
|
71
|
-
};
|
|
72
|
-
const touchMove = (e) => {
|
|
73
|
-
const t = e.touches[0];
|
|
74
|
-
endX = t.clientX;
|
|
75
|
-
endY = t.clientY;
|
|
76
|
-
};
|
|
77
|
-
const touchEnd = () => {
|
|
78
|
-
const dx = endX - startX;
|
|
79
|
-
const dy = endY - startY;
|
|
80
|
-
const absDx = Math.abs(dx);
|
|
81
|
-
const absDy = Math.abs(dy);
|
|
82
|
-
const threshold = 30;
|
|
83
|
-
if (absDx > absDy) {
|
|
84
|
-
if (dx > threshold)
|
|
85
|
-
onSwipeRight === null || onSwipeRight === void 0 ? void 0 : onSwipeRight();
|
|
86
|
-
if (dx < -threshold)
|
|
87
|
-
onSwipeLeft === null || onSwipeLeft === void 0 ? void 0 : onSwipeLeft();
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
if (dy > threshold)
|
|
91
|
-
onSwipeDown === null || onSwipeDown === void 0 ? void 0 : onSwipeDown();
|
|
92
|
-
if (dy < -threshold)
|
|
93
|
-
onSwipeUp === null || onSwipeUp === void 0 ? void 0 : onSwipeUp();
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
el.addEventListener("touchstart", touchStart);
|
|
97
|
-
el.addEventListener("touchmove", touchMove);
|
|
98
|
-
el.addEventListener("touchend", touchEnd);
|
|
99
|
-
cleanupFns.push(() => {
|
|
100
|
-
el.removeEventListener("touchstart", touchStart);
|
|
101
|
-
el.removeEventListener("touchmove", touchMove);
|
|
102
|
-
el.removeEventListener("touchend", touchEnd);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
// === PINCH & ROTATE ===
|
|
106
|
-
if (onPinchIn || onPinchOut || onRotate) {
|
|
107
|
-
let startDistance = 0;
|
|
108
|
-
let startAngle = 0;
|
|
109
|
-
const getDistance = (t1, t2) => Math.hypot(t2.clientX - t1.clientX, t2.clientY - t1.clientY);
|
|
110
|
-
const getAngle = (t1, t2) => Math.atan2(t2.clientY - t1.clientY, t2.clientX - t1.clientX) *
|
|
111
|
-
(180 / Math.PI);
|
|
112
|
-
const handleStart = (e) => {
|
|
113
|
-
if (e.touches.length === 2) {
|
|
114
|
-
const [t1, t2] = e.touches;
|
|
115
|
-
startDistance = getDistance(t1, t2);
|
|
116
|
-
startAngle = getAngle(t1, t2);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
const handleMove = (e) => {
|
|
120
|
-
if (e.touches.length === 2) {
|
|
121
|
-
const [t1, t2] = e.touches;
|
|
122
|
-
const dist = getDistance(t1, t2);
|
|
123
|
-
const angle = getAngle(t1, t2);
|
|
124
|
-
if (dist < startDistance - 20)
|
|
125
|
-
onPinchIn === null || onPinchIn === void 0 ? void 0 : onPinchIn();
|
|
126
|
-
if (dist > startDistance + 20)
|
|
127
|
-
onPinchOut === null || onPinchOut === void 0 ? void 0 : onPinchOut();
|
|
128
|
-
const deltaAngle = angle - startAngle;
|
|
129
|
-
if (Math.abs(deltaAngle) > 15) {
|
|
130
|
-
onRotate === null || onRotate === void 0 ? void 0 : onRotate(deltaAngle);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
el.addEventListener("touchstart", handleStart);
|
|
135
|
-
el.addEventListener("touchmove", handleMove);
|
|
136
|
-
cleanupFns.push(() => {
|
|
137
|
-
el.removeEventListener("touchstart", handleStart);
|
|
138
|
-
el.removeEventListener("touchmove", handleMove);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
// === RESIZE OBSERVER ===
|
|
142
|
-
let resizeObserver = null;
|
|
143
|
-
if (onResize) {
|
|
144
|
-
resizeObserver = new ResizeObserver((entries) => {
|
|
145
|
-
for (const entry of entries) {
|
|
146
|
-
onResize(entry);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
resizeObserver.observe(el);
|
|
150
|
-
cleanupFns.push(() => resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect());
|
|
151
|
-
}
|
|
152
|
-
// === VISIBILITY OBSERVER ===
|
|
153
|
-
let intersectionObserver = null;
|
|
154
|
-
if (onVisibilityChange || onVisible || onHidden) {
|
|
155
|
-
intersectionObserver = new IntersectionObserver((entries) => {
|
|
156
|
-
entries[0].isIntersecting ? onVisible === null || onVisible === void 0 ? void 0 : onVisible() : onHidden === null || onHidden === void 0 ? void 0 : onHidden();
|
|
157
|
-
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(entries[0].isIntersecting);
|
|
158
|
-
});
|
|
159
|
-
intersectionObserver.observe(el);
|
|
160
|
-
cleanupFns.push(() => intersectionObserver === null || intersectionObserver === void 0 ? void 0 : intersectionObserver.disconnect());
|
|
161
|
-
}
|
|
162
|
-
// === On Hover Change ===
|
|
163
|
-
const hasFinePointer = window.matchMedia("(pointer: fine)").matches;
|
|
164
|
-
if (hasFinePointer &&
|
|
165
|
-
(onMouseHoverChange || onMouseHoverStart || onMouseHoverLeave)) {
|
|
166
|
-
const mouseEnter = (e) => {
|
|
167
|
-
onMouseHoverChange === null || onMouseHoverChange === void 0 ? void 0 : onMouseHoverChange(true, e);
|
|
168
|
-
onMouseHoverStart === null || onMouseHoverStart === void 0 ? void 0 : onMouseHoverStart(e);
|
|
169
|
-
};
|
|
170
|
-
const mouseLeave = (e) => {
|
|
171
|
-
onMouseHoverChange === null || onMouseHoverChange === void 0 ? void 0 : onMouseHoverChange(true, e);
|
|
172
|
-
onMouseHoverLeave === null || onMouseHoverLeave === void 0 ? void 0 : onMouseHoverLeave(e);
|
|
173
|
-
};
|
|
174
|
-
el.addEventListener("mouseenter", mouseEnter);
|
|
175
|
-
el.addEventListener("mouseleave", mouseLeave);
|
|
176
|
-
cleanupFns.push(() => {
|
|
177
|
-
el.removeEventListener("mouseenter", mouseEnter);
|
|
178
|
-
el.removeEventListener("mouseleave", mouseLeave);
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
// === SCROLL START/END ===
|
|
182
|
-
if (onScrollStart) {
|
|
183
|
-
let scrolling = false;
|
|
184
|
-
let scrollTimeout;
|
|
185
|
-
const scrollHandler = () => {
|
|
186
|
-
if (!scrolling) {
|
|
187
|
-
scrolling = true;
|
|
188
|
-
onScrollStart === null || onScrollStart === void 0 ? void 0 : onScrollStart();
|
|
189
|
-
}
|
|
190
|
-
clearTimeout(scrollTimeout);
|
|
191
|
-
scrollTimeout = setTimeout(() => {
|
|
192
|
-
scrolling = false;
|
|
193
|
-
onScrollStop === null || onScrollStop === void 0 ? void 0 : onScrollStop();
|
|
194
|
-
}, 150);
|
|
195
|
-
};
|
|
196
|
-
el.addEventListener("scroll", scrollHandler);
|
|
197
|
-
cleanupFns.push(() => el.removeEventListener("scroll", scrollHandler));
|
|
198
|
-
}
|
|
199
|
-
// Cleanup on unmount
|
|
200
|
-
return () => {
|
|
201
|
-
cleanupFns.forEach((fn) => fn());
|
|
202
|
-
};
|
|
203
|
-
}, [
|
|
204
|
-
onRightClick,
|
|
205
|
-
onTap,
|
|
206
|
-
onDoubleTap,
|
|
207
|
-
onOutsideClick,
|
|
208
|
-
onSwipeLeft,
|
|
209
|
-
onSwipeRight,
|
|
210
|
-
onSwipeUp,
|
|
211
|
-
onSwipeDown,
|
|
212
|
-
onPinchIn,
|
|
213
|
-
onPinchOut,
|
|
214
|
-
onRotate,
|
|
215
|
-
onScrollStart,
|
|
216
|
-
onScrollStop,
|
|
217
|
-
onResize,
|
|
218
|
-
onVisibilityChange,
|
|
219
|
-
onVisible,
|
|
220
|
-
onHidden,
|
|
221
|
-
onMouseHoverChange,
|
|
222
|
-
onMouseHoverStart,
|
|
223
|
-
onMouseHoverLeave,
|
|
224
|
-
]);
|
|
225
|
-
return (_jsx(Stack, Object.assign({ ref: localRef }, restProps, { children: children })));
|
|
226
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
-
export function useOnVisibilityObserver(callback) {
|
|
3
|
-
const ref = useRef(null);
|
|
4
|
-
const handleVisibility = useCallback((action) => {
|
|
5
|
-
callback(action);
|
|
6
|
-
}, [callback]);
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const element = ref.current;
|
|
9
|
-
if (!element)
|
|
10
|
-
return;
|
|
11
|
-
const intersectionObserver = new IntersectionObserver((entries) => {
|
|
12
|
-
entries[0].isIntersecting ? handleVisibility("visible") : handleVisibility("hidden");
|
|
13
|
-
});
|
|
14
|
-
intersectionObserver.observe(element);
|
|
15
|
-
return () => {
|
|
16
|
-
intersectionObserver === null || intersectionObserver === void 0 ? void 0 : intersectionObserver.disconnect();
|
|
17
|
-
};
|
|
18
|
-
}, [handleVisibility]);
|
|
19
|
-
return ref;
|
|
20
|
-
}
|