@a-type/ui 6.1.26 → 6.1.28
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/components/infiniteLoadTrigger/InfiniteLoadTrigger.js +2 -15
- package/dist/components/infiniteLoadTrigger/InfiniteLoadTrigger.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useOnVisible.d.ts +1 -0
- package/dist/hooks/useOnVisible.js +24 -0
- package/dist/hooks/useOnVisible.js.map +1 -0
- package/package.json +1 -1
- package/src/components/infiniteLoadTrigger/InfiniteLoadTrigger.tsx +29 -42
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useOnVisible.ts +29 -0
|
@@ -11,24 +11,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import classNames from 'clsx';
|
|
14
|
-
import { useEffect, useRef } from 'react';
|
|
15
|
-
import { useStableCallback } from '../../hooks.js';
|
|
16
14
|
import useMergedRef from '../../hooks/useMergedRef.js';
|
|
15
|
+
import { useOnVisible } from '../../hooks/useOnVisible.js';
|
|
17
16
|
export const InfiniteLoadTrigger = function InfiniteLoadTrigger(_a) {
|
|
18
17
|
var { ref, className, onVisible } = _a, rest = __rest(_a, ["ref", "className", "onVisible"]);
|
|
19
|
-
const innerRef =
|
|
20
|
-
const stableOnVisible = useStableCallback(onVisible);
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
const observer = new IntersectionObserver((entries) => {
|
|
23
|
-
if (entries[0].isIntersecting) {
|
|
24
|
-
stableOnVisible();
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
observer.observe(innerRef.current);
|
|
28
|
-
return () => {
|
|
29
|
-
observer.disconnect();
|
|
30
|
-
};
|
|
31
|
-
}, [stableOnVisible]);
|
|
18
|
+
const innerRef = useOnVisible(onVisible);
|
|
32
19
|
return (_jsx("div", Object.assign({ ref: useMergedRef(ref, innerRef), className: classNames('flex flex-col items-center', className) }, rest)));
|
|
33
20
|
};
|
|
34
21
|
//# sourceMappingURL=InfiniteLoadTrigger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InfiniteLoadTrigger.js","sourceRoot":"","sources":["../../../src/components/infiniteLoadTrigger/InfiniteLoadTrigger.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,UAAU,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"InfiniteLoadTrigger.js","sourceRoot":"","sources":["../../../src/components/infiniteLoadTrigger/InfiniteLoadTrigger.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,UAAU,MAAM,MAAM,CAAC;AAE9B,OAAO,YAAY,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAQ3D,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,mBAAmB,CAAC,EAO/D;QAP+D,EAC/D,GAAG,EACH,SAAS,EACT,SAAS,OAIT,EAHG,IAAI,cAJwD,iCAK/D,CADO;IAIP,MAAM,QAAQ,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IAEzC,OAAO,CACN,4BACC,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,EAChC,SAAS,EAAE,UAAU,CAAC,4BAA4B,EAAE,SAAS,CAAC,IAC1D,IAAI,EACP,CACF,CAAC;AACH,CAAC,CAAC"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './useAnimationFrame.js';
|
|
|
2
2
|
export * from './useLongPress.js';
|
|
3
3
|
export * from './useMergedRef.js';
|
|
4
4
|
export * from './useOnUnmount.js';
|
|
5
|
+
export * from './useOnVisible.js';
|
|
5
6
|
export * from './useOverrideTheme.js';
|
|
6
7
|
export * from './useSize.js';
|
|
7
8
|
export * from './useStableCallback.js';
|
package/dist/hooks/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from './useAnimationFrame.js';
|
|
|
2
2
|
export * from './useLongPress.js';
|
|
3
3
|
export * from './useMergedRef.js';
|
|
4
4
|
export * from './useOnUnmount.js';
|
|
5
|
+
export * from './useOnVisible.js';
|
|
5
6
|
export * from './useOverrideTheme.js';
|
|
6
7
|
export * from './useSize.js';
|
|
7
8
|
export * from './useStableCallback.js';
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useOnVisible(onVisible?: () => void): import("react").RefObject<any>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useStableCallback } from './useStableCallback.js';
|
|
3
|
+
export function useOnVisible(onVisible) {
|
|
4
|
+
const innerRef = useRef(null);
|
|
5
|
+
const stableOnVisible = useStableCallback(onVisible);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const current = innerRef.current;
|
|
8
|
+
if (!current ||
|
|
9
|
+
!(current instanceof HTMLElement || current instanceof SVGElement)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const observer = new IntersectionObserver((entries) => {
|
|
13
|
+
if (entries[0].isIntersecting) {
|
|
14
|
+
stableOnVisible();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
observer.observe(innerRef.current);
|
|
18
|
+
return () => {
|
|
19
|
+
observer.disconnect();
|
|
20
|
+
};
|
|
21
|
+
}, [stableOnVisible]);
|
|
22
|
+
return innerRef;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=useOnVisible.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnVisible.js","sourceRoot":"","sources":["../../src/hooks/useOnVisible.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,UAAU,YAAY,CAAC,SAAsB;IAClD,MAAM,QAAQ,GAAG,MAAM,CAAM,IAAI,CAAC,CAAC;IAEnC,MAAM,eAAe,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACrD,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QACjC,IACC,CAAC,OAAO;YACR,CAAC,CAAC,OAAO,YAAY,WAAW,IAAI,OAAO,YAAY,UAAU,CAAC,EACjE,CAAC;YACF,OAAO;QACR,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,CAAC,OAAO,EAAE,EAAE;YACrD,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC;gBAC/B,eAAe,EAAE,CAAC;YACnB,CAAC;QACF,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAQ,CAAC,CAAC;QACpC,OAAO,GAAG,EAAE;YACX,QAAQ,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAEtB,OAAO,QAAQ,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,42 +1,29 @@
|
|
|
1
|
-
import classNames from 'clsx';
|
|
2
|
-
import { ReactNode
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
export interface InfiniteLoadTriggerProps {
|
|
7
|
-
className?: string;
|
|
8
|
-
children?: ReactNode;
|
|
9
|
-
onVisible?: () => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const InfiniteLoadTrigger = function InfiniteLoadTrigger({
|
|
13
|
-
ref,
|
|
14
|
-
className,
|
|
15
|
-
onVisible,
|
|
16
|
-
...rest
|
|
17
|
-
}: InfiniteLoadTriggerProps & {
|
|
18
|
-
ref?: React.Ref<HTMLDivElement>;
|
|
19
|
-
}) {
|
|
20
|
-
const innerRef =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return () => {
|
|
31
|
-
observer.disconnect();
|
|
32
|
-
};
|
|
33
|
-
}, [stableOnVisible]);
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<div
|
|
37
|
-
ref={useMergedRef(ref, innerRef)}
|
|
38
|
-
className={classNames('flex flex-col items-center', className)}
|
|
39
|
-
{...rest}
|
|
40
|
-
/>
|
|
41
|
-
);
|
|
42
|
-
};
|
|
1
|
+
import classNames from 'clsx';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import useMergedRef from '../../hooks/useMergedRef.js';
|
|
4
|
+
import { useOnVisible } from '../../hooks/useOnVisible.js';
|
|
5
|
+
|
|
6
|
+
export interface InfiniteLoadTriggerProps {
|
|
7
|
+
className?: string;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
onVisible?: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const InfiniteLoadTrigger = function InfiniteLoadTrigger({
|
|
13
|
+
ref,
|
|
14
|
+
className,
|
|
15
|
+
onVisible,
|
|
16
|
+
...rest
|
|
17
|
+
}: InfiniteLoadTriggerProps & {
|
|
18
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
19
|
+
}) {
|
|
20
|
+
const innerRef = useOnVisible(onVisible);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<div
|
|
24
|
+
ref={useMergedRef(ref, innerRef)}
|
|
25
|
+
className={classNames('flex flex-col items-center', className)}
|
|
26
|
+
{...rest}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
};
|
package/src/hooks/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './useAnimationFrame.js';
|
|
|
2
2
|
export * from './useLongPress.js';
|
|
3
3
|
export * from './useMergedRef.js';
|
|
4
4
|
export * from './useOnUnmount.js';
|
|
5
|
+
export * from './useOnVisible.js';
|
|
5
6
|
export * from './useOverrideTheme.js';
|
|
6
7
|
export * from './useSize.js';
|
|
7
8
|
export * from './useStableCallback.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useStableCallback } from './useStableCallback.js';
|
|
3
|
+
|
|
4
|
+
export function useOnVisible(onVisible?: () => void) {
|
|
5
|
+
const innerRef = useRef<any>(null);
|
|
6
|
+
|
|
7
|
+
const stableOnVisible = useStableCallback(onVisible);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const current = innerRef.current;
|
|
10
|
+
if (
|
|
11
|
+
!current ||
|
|
12
|
+
!(current instanceof HTMLElement || current instanceof SVGElement)
|
|
13
|
+
) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const observer = new IntersectionObserver((entries) => {
|
|
18
|
+
if (entries[0].isIntersecting) {
|
|
19
|
+
stableOnVisible();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
observer.observe(innerRef.current!);
|
|
23
|
+
return () => {
|
|
24
|
+
observer.disconnect();
|
|
25
|
+
};
|
|
26
|
+
}, [stableOnVisible]);
|
|
27
|
+
|
|
28
|
+
return innerRef;
|
|
29
|
+
}
|