linear-react-components-ui 2.2.0-beta.1 → 2.2.0-beta.11
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/lib/inputs2/selectfield/base.js +33 -15
- package/lib/inputs2/selectfield/base.js.map +1 -1
- package/lib/inputs2/selectfield/context.d.ts +1 -0
- package/lib/inputs2/selectfield/context.js.map +1 -1
- package/lib/inputs2/selectfield/item.js +52 -50
- package/lib/inputs2/selectfield/item.js.map +1 -1
- package/lib/inputs2/selectfield/listbox.d.ts +1 -2
- package/lib/inputs2/selectfield/listbox.js +0 -8
- package/lib/inputs2/selectfield/listbox.js.map +1 -1
- package/lib/inputs2/selectfield/types.d.ts +3 -5
- package/lib/inputs2/selectfield/types.js.map +1 -1
- package/lib/node_modules/lodash/lodash.js +2 -2
- package/lib/node_modules/lodash/lodash.js.map +1 -1
- package/lib/panel/Content.js +77 -20
- package/lib/panel/Content.js.map +1 -1
- package/lib/panel/helpers.js +16 -1
- package/lib/panel/helpers.js.map +1 -1
- package/lib/panel/types.d.ts +6 -3
- package/package.json +1 -1
- package/lib/hooks/useScrollEndReached/index.d.ts +0 -8
- package/lib/hooks/useScrollEndReached/index.js +0 -103
- package/lib/hooks/useScrollEndReached/index.js.map +0 -1
- package/lib/hooks/useScrollEndReached/types.d.ts +0 -6
package/lib/panel/Content.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { c as compilerRuntimeExports } from "../_virtual/compiler-runtime.js";
|
|
3
|
-
import { useContext, useRef } from "react";
|
|
4
|
-
import PanelContext from "./helpers.js";
|
|
3
|
+
import { useContext, useRef, useEffect } from "react";
|
|
4
|
+
import PanelContext, { getCurrentThreshold } from "./helpers.js";
|
|
5
5
|
import NoPermission from "../noPermission/index.js";
|
|
6
|
-
import { useScrollEndReached } from "../hooks/useScrollEndReached/index.js";
|
|
7
6
|
const PanelContent = (t0) => {
|
|
8
|
-
const $ = compilerRuntimeExports.c(
|
|
7
|
+
const $ = compilerRuntimeExports.c(18);
|
|
9
8
|
let children;
|
|
10
9
|
let customClass;
|
|
11
10
|
let rest;
|
|
@@ -32,12 +31,28 @@ const PanelContent = (t0) => {
|
|
|
32
31
|
} = useContext(PanelContext);
|
|
33
32
|
const onEndReachedThreshold = t1 === void 0 ? 0.1 : t1;
|
|
34
33
|
const rootElementRef = useRef(null);
|
|
34
|
+
const lastScrollHeight = useRef(0);
|
|
35
|
+
const enableOnEndReached = useRef(true);
|
|
35
36
|
let t2;
|
|
36
37
|
if ($[4] !== onEndReached || $[5] !== onEndReachedThreshold) {
|
|
37
|
-
t2 = {
|
|
38
|
-
|
|
39
|
-
onEndReached
|
|
40
|
-
|
|
38
|
+
t2 = async () => {
|
|
39
|
+
const element = rootElementRef.current;
|
|
40
|
+
if (element && onEndReached) {
|
|
41
|
+
const {
|
|
42
|
+
scrollTop,
|
|
43
|
+
scrollHeight,
|
|
44
|
+
clientHeight
|
|
45
|
+
} = element;
|
|
46
|
+
const scrollOffset = scrollHeight - clientHeight - scrollTop - 1;
|
|
47
|
+
const threshold = getCurrentThreshold(element, onEndReachedThreshold);
|
|
48
|
+
if (scrollOffset <= threshold && enableOnEndReached.current) {
|
|
49
|
+
enableOnEndReached.current = false;
|
|
50
|
+
await new Promise((resolve) => {
|
|
51
|
+
resolve(onEndReached());
|
|
52
|
+
});
|
|
53
|
+
lastScrollHeight.current = scrollHeight;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
41
56
|
};
|
|
42
57
|
$[4] = onEndReached;
|
|
43
58
|
$[5] = onEndReachedThreshold;
|
|
@@ -45,23 +60,65 @@ const PanelContent = (t0) => {
|
|
|
45
60
|
} else {
|
|
46
61
|
t2 = $[6];
|
|
47
62
|
}
|
|
48
|
-
|
|
63
|
+
const onScrollEndReached = t2;
|
|
64
|
+
let t3;
|
|
65
|
+
if ($[7] !== onEndReached || $[8] !== onScrollEndReached) {
|
|
66
|
+
t3 = () => {
|
|
67
|
+
let observer;
|
|
68
|
+
if (rootElementRef?.current && onEndReached) {
|
|
69
|
+
observer = new ResizeObserver(() => {
|
|
70
|
+
const currentElement = rootElementRef.current;
|
|
71
|
+
if (currentElement) {
|
|
72
|
+
const {
|
|
73
|
+
scrollHeight: scrollHeight_0
|
|
74
|
+
} = currentElement;
|
|
75
|
+
if (scrollHeight_0 && scrollHeight_0 !== lastScrollHeight.current) {
|
|
76
|
+
enableOnEndReached.current = true;
|
|
77
|
+
observer?.disconnect();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
observer.observe(rootElementRef.current);
|
|
82
|
+
rootElementRef.current.addEventListener("scroll", onScrollEndReached);
|
|
83
|
+
rootElementRef.current.addEventListener("resize", onScrollEndReached);
|
|
84
|
+
}
|
|
85
|
+
return () => {
|
|
86
|
+
rootElementRef.current?.removeEventListener("scroll", onScrollEndReached);
|
|
87
|
+
rootElementRef.current?.removeEventListener("resize", onScrollEndReached);
|
|
88
|
+
observer?.disconnect();
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
$[7] = onEndReached;
|
|
92
|
+
$[8] = onScrollEndReached;
|
|
93
|
+
$[9] = t3;
|
|
94
|
+
} else {
|
|
95
|
+
t3 = $[9];
|
|
96
|
+
}
|
|
97
|
+
let t4;
|
|
98
|
+
if ($[10] !== onScrollEndReached) {
|
|
99
|
+
t4 = [onScrollEndReached];
|
|
100
|
+
$[10] = onScrollEndReached;
|
|
101
|
+
$[11] = t4;
|
|
102
|
+
} else {
|
|
103
|
+
t4 = $[11];
|
|
104
|
+
}
|
|
105
|
+
useEffect(t3, t4);
|
|
49
106
|
if (!opened) {
|
|
50
107
|
return null;
|
|
51
108
|
}
|
|
52
|
-
let
|
|
53
|
-
if ($[
|
|
54
|
-
|
|
55
|
-
$[
|
|
56
|
-
$[
|
|
57
|
-
$[
|
|
58
|
-
$[
|
|
59
|
-
$[
|
|
60
|
-
$[
|
|
109
|
+
let t5;
|
|
110
|
+
if ($[12] !== children || $[13] !== customClass || $[14] !== hideContent || $[15] !== opened || $[16] !== rest) {
|
|
111
|
+
t5 = hideContent ? /* @__PURE__ */ jsx(NoPermission, {}) : /* @__PURE__ */ jsx("div", { ref: rootElementRef, className: `panel-content ${customClass ?? ""}`, ...rest, children: opened && children });
|
|
112
|
+
$[12] = children;
|
|
113
|
+
$[13] = customClass;
|
|
114
|
+
$[14] = hideContent;
|
|
115
|
+
$[15] = opened;
|
|
116
|
+
$[16] = rest;
|
|
117
|
+
$[17] = t5;
|
|
61
118
|
} else {
|
|
62
|
-
|
|
119
|
+
t5 = $[17];
|
|
63
120
|
}
|
|
64
|
-
return
|
|
121
|
+
return t5;
|
|
65
122
|
};
|
|
66
123
|
export {
|
|
67
124
|
PanelContent as default
|
package/lib/panel/Content.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Content.js","sources":["../../src/lib/panel/Content.tsx"],"sourcesContent":["import { useContext, useRef } from 'react';\nimport PanelContext from './helpers';\nimport NoPermission from '../noPermission';\nimport { IPanelContentProps } from './types';\
|
|
1
|
+
{"version":3,"file":"Content.js","sources":["../../src/lib/panel/Content.tsx"],"sourcesContent":["import { useCallback, useContext, useEffect, useRef } from 'react';\nimport PanelContext, { getCurrentThreshold } from './helpers';\nimport NoPermission from '../noPermission';\nimport { IPanelContentProps } from './types';\n\nconst PanelContent = ({ customClass, children, ...rest }: IPanelContentProps) => {\n const {\n opened, onEndReached, onEndReachedThreshold = 0.1, hideContent,\n } = useContext(PanelContext);\n const rootElementRef = useRef<HTMLDivElement>(null);\n const lastScrollHeight = useRef(0);\n const enableOnEndReached = useRef(true);\n\n const onScrollEndReached = useCallback(async () => {\n const element = rootElementRef.current;\n\n if (element && onEndReached) {\n const { scrollTop, scrollHeight, clientHeight } = element;\n const scrollOffset = scrollHeight - clientHeight - scrollTop - 1;\n const threshold = getCurrentThreshold(element, onEndReachedThreshold);\n\n if (scrollOffset <= threshold && enableOnEndReached.current) {\n enableOnEndReached.current = false;\n await new Promise((resolve) => {\n resolve(onEndReached());\n });\n lastScrollHeight.current = scrollHeight;\n }\n }\n }, [\n onEndReached, onEndReachedThreshold,\n rootElementRef.current, lastScrollHeight.current,\n ]);\n\n useEffect(() => {\n let observer: ResizeObserver | null;\n if (rootElementRef?.current && onEndReached) {\n observer = new ResizeObserver(() => {\n const currentElement = rootElementRef.current;\n if (currentElement) {\n const { scrollHeight } = currentElement as HTMLDivElement;\n if (scrollHeight && scrollHeight !== lastScrollHeight.current) {\n enableOnEndReached.current = true;\n observer?.disconnect();\n }\n }\n });\n\n observer.observe(rootElementRef.current);\n rootElementRef.current.addEventListener('scroll', onScrollEndReached);\n rootElementRef.current.addEventListener('resize', onScrollEndReached);\n }\n\n return () => {\n rootElementRef.current?.removeEventListener('scroll', onScrollEndReached);\n rootElementRef.current?.removeEventListener('resize', onScrollEndReached);\n observer?.disconnect();\n };\n }, [onScrollEndReached]);\n\n if (!opened) return null;\n return (\n hideContent\n ? (\n <NoPermission />\n )\n : (\n <div\n ref={rootElementRef}\n className={`panel-content ${customClass ?? ''}`}\n {...rest}>\n {opened && children}\n </div>\n )\n );\n};\n\nexport default PanelContent;\n"],"names":["PanelContent","t0","$","_c","children","customClass","rest","opened","onEndReached","onEndReachedThreshold","t1","hideContent","useContext","PanelContext","undefined","rootElementRef","useRef","lastScrollHeight","enableOnEndReached","t2","element","current","scrollTop","scrollHeight","clientHeight","scrollOffset","threshold","getCurrentThreshold","Promise","resolve","onScrollEndReached","t3","observer","ResizeObserver","currentElement","scrollHeight_0","disconnect","observe","addEventListener","removeEventListener","t4","useEffect","t5"],"mappings":";;;;;AAKA,MAAMA,eAAeC,CAAAA,OAAA;AAAA,QAAAC,IAAAC,uBAAAA,EAAA,EAAA;AAAA,MAAAC;AAAA,MAAAC;AAAA,MAAAC;AAAA,MAAAJ,SAAAD,IAAA;AAAC,KAAA;AAAA,MAAAI;AAAAA,MAAAD;AAAAA,MAAA,GAA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,OACzCC,MACHC,oBAAAH,UACH;AACCF,YAAAE;AAAAF,YAAAG;AAAAH,YAAAS;AAAAT,YAAAK;AAAAL,YAAAI;AAAAJ,YAAAwC;AAAAA,EAAA,OAAA;AAAAA,SAAAxC,EAAA,EAAA;AAAA,EAAA;AAAA,SAXLwC;AAWK;"}
|
package/lib/panel/helpers.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { createContext } from "react";
|
|
2
|
+
function getCurrentThreshold(scrollableElement, scrollThreshold) {
|
|
3
|
+
const MIN_THRESHOLD = 0;
|
|
4
|
+
const MAX_THRESHOLD = 1;
|
|
5
|
+
if (scrollThreshold < MIN_THRESHOLD) return MIN_THRESHOLD;
|
|
6
|
+
if (scrollThreshold > MAX_THRESHOLD) return MAX_THRESHOLD;
|
|
7
|
+
const {
|
|
8
|
+
scrollHeight,
|
|
9
|
+
clientHeight
|
|
10
|
+
} = scrollableElement;
|
|
11
|
+
const offsetHeight = scrollHeight - clientHeight;
|
|
12
|
+
const calculatedScrollThreshold = Math.round(scrollHeight * scrollThreshold);
|
|
13
|
+
const maxScrollThreshold = Math.round(offsetHeight - offsetHeight * 0.3);
|
|
14
|
+
return Math.min(calculatedScrollThreshold, maxScrollThreshold);
|
|
15
|
+
}
|
|
2
16
|
const PanelContext = createContext({});
|
|
3
17
|
export {
|
|
4
|
-
PanelContext as default
|
|
18
|
+
PanelContext as default,
|
|
19
|
+
getCurrentThreshold
|
|
5
20
|
};
|
|
6
21
|
//# sourceMappingURL=helpers.js.map
|
package/lib/panel/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sources":["../../src/lib/panel/helpers.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { ContextProps } from './types';\n\nexport function getCurrentThreshold(\n scrollableElement: HTMLDivElement,\n scrollThreshold: number,\n): number {\n const MIN_THRESHOLD = 0;\n const MAX_THRESHOLD = 1;\n if (scrollThreshold < MIN_THRESHOLD) return MIN_THRESHOLD;\n if (scrollThreshold > MAX_THRESHOLD) return MAX_THRESHOLD;\n const { scrollHeight, clientHeight } = scrollableElement;\n const offsetHeight = scrollHeight - clientHeight;\n\n const calculatedScrollThreshold = Math.round(scrollHeight * scrollThreshold);\n const maxScrollThreshold = Math.round(offsetHeight - (offsetHeight * 0.3));\n\n return Math.min(calculatedScrollThreshold, maxScrollThreshold);\n}\n\nconst PanelContext = createContext<ContextProps>({} as ContextProps);\n\nexport default PanelContext;\n"],"names":["PanelContext","createContext"],"mappings":";
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../../src/lib/panel/helpers.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { ContextProps } from './types';\n\nexport function getCurrentThreshold(\n scrollableElement: HTMLDivElement,\n scrollThreshold: number,\n): number {\n const MIN_THRESHOLD = 0;\n const MAX_THRESHOLD = 1;\n if (scrollThreshold < MIN_THRESHOLD) return MIN_THRESHOLD;\n if (scrollThreshold > MAX_THRESHOLD) return MAX_THRESHOLD;\n const { scrollHeight, clientHeight } = scrollableElement;\n const offsetHeight = scrollHeight - clientHeight;\n\n const calculatedScrollThreshold = Math.round(scrollHeight * scrollThreshold);\n const maxScrollThreshold = Math.round(offsetHeight - (offsetHeight * 0.3));\n\n return Math.min(calculatedScrollThreshold, maxScrollThreshold);\n}\n\nconst PanelContext = createContext<ContextProps>({} as ContextProps);\n\nexport default PanelContext;\n"],"names":["getCurrentThreshold","scrollableElement","scrollThreshold","MIN_THRESHOLD","MAX_THRESHOLD","scrollHeight","clientHeight","offsetHeight","calculatedScrollThreshold","Math","round","maxScrollThreshold","min","PanelContext","createContext"],"mappings":";AAGO,SAASA,oBACdC,mBACAC,iBACQ;AACR,QAAMC,gBAAgB;AACtB,QAAMC,gBAAgB;AACtB,MAAIF,kBAAkBC,cAAe,QAAOA;AAC5C,MAAID,kBAAkBE,cAAe,QAAOA;AAC5C,QAAM;AAAA,IAAEC;AAAAA,IAAcC;AAAAA,EAAAA,IAAiBL;AACvC,QAAMM,eAAeF,eAAeC;AAEpC,QAAME,4BAA4BC,KAAKC,MAAML,eAAeH,eAAe;AAC3E,QAAMS,qBAAqBF,KAAKC,MAAMH,eAAgBA,eAAe,GAAI;AAEzE,SAAOE,KAAKG,IAAIJ,2BAA2BG,kBAAkB;AAC/D;AAEA,MAAME,eAAeC,cAA4B,CAAA,CAAkB;"}
|
package/lib/panel/types.d.ts
CHANGED
|
@@ -2,10 +2,9 @@ import { ComponentPropsWithoutRef, ReactElement, ReactNode } from 'react';
|
|
|
2
2
|
import { PermissionAttr } from '../@types/PermissionAttr';
|
|
3
3
|
import { default as ColorStyles } from '../internals/colorStyles';
|
|
4
4
|
import { IconNames } from '../@types/Icon';
|
|
5
|
-
import { UseScrollEndReachedParams } from '../hooks/useScrollEndReached/types';
|
|
6
5
|
export type Func = () => void;
|
|
7
6
|
export type AsyncFunc = () => Promise<void>;
|
|
8
|
-
export interface IPanelProps extends Omit<ComponentPropsWithoutRef<'div'>, 'className'
|
|
7
|
+
export interface IPanelProps extends Omit<ComponentPropsWithoutRef<'div'>, 'className'> {
|
|
9
8
|
customClass?: string;
|
|
10
9
|
startOpened?: boolean;
|
|
11
10
|
toggleable?: boolean;
|
|
@@ -13,6 +12,8 @@ export interface IPanelProps extends Omit<ComponentPropsWithoutRef<'div'>, 'clas
|
|
|
13
12
|
colorStyle?: typeof ColorStyles | string;
|
|
14
13
|
gridCols?: string;
|
|
15
14
|
title?: string;
|
|
15
|
+
onEndReached?: Func | AsyncFunc;
|
|
16
|
+
onEndReachedThreshold?: number;
|
|
16
17
|
permissionAttr?: PermissionAttr | PermissionAttr[];
|
|
17
18
|
}
|
|
18
19
|
export interface IPanelContentProps extends Omit<ComponentPropsWithoutRef<'div'>, 'className'> {
|
|
@@ -27,11 +28,13 @@ export interface IPanelHeaderProps extends Omit<ComponentPropsWithoutRef<'div'>,
|
|
|
27
28
|
customClassForTitle?: string;
|
|
28
29
|
headerColored?: boolean;
|
|
29
30
|
}
|
|
30
|
-
export type ContextProps =
|
|
31
|
+
export type ContextProps = {
|
|
31
32
|
toggleable: boolean;
|
|
32
33
|
handlerToggleable: () => void;
|
|
33
34
|
opened: boolean;
|
|
34
35
|
hideContent: boolean;
|
|
36
|
+
onEndReached?: Func | AsyncFunc;
|
|
37
|
+
onEndReachedThreshold: number;
|
|
35
38
|
};
|
|
36
39
|
export interface IParameterFunction {
|
|
37
40
|
props: any;
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { AsyncFunc, Func, UseScrollEndReachedParams } from './types';
|
|
2
|
-
export interface ScrollEndReachedParams extends UseScrollEndReachedParams {
|
|
3
|
-
elementRef: React.RefObject<HTMLElement | null>;
|
|
4
|
-
onEndReached?: Func | AsyncFunc;
|
|
5
|
-
onEndReachedThreshold?: number;
|
|
6
|
-
}
|
|
7
|
-
export declare function getCurrentThreshold(scrollableElement: HTMLElement, scrollThreshold: number): number;
|
|
8
|
-
export declare function useScrollEndReached({ elementRef, onEndReached, onEndReachedThreshold, }: ScrollEndReachedParams): void;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { c as compilerRuntimeExports } from "../../_virtual/compiler-runtime.js";
|
|
2
|
-
import { useRef, useEffect } from "react";
|
|
3
|
-
function getCurrentThreshold(scrollableElement, scrollThreshold) {
|
|
4
|
-
const MIN_THRESHOLD = 0;
|
|
5
|
-
const MAX_THRESHOLD = 1;
|
|
6
|
-
if (scrollThreshold < MIN_THRESHOLD) return MIN_THRESHOLD;
|
|
7
|
-
if (scrollThreshold > MAX_THRESHOLD) return MAX_THRESHOLD;
|
|
8
|
-
const {
|
|
9
|
-
scrollHeight,
|
|
10
|
-
clientHeight
|
|
11
|
-
} = scrollableElement;
|
|
12
|
-
const offsetHeight = scrollHeight - clientHeight;
|
|
13
|
-
const calculatedScrollThreshold = Math.round(scrollHeight * scrollThreshold);
|
|
14
|
-
const maxScrollThreshold = Math.round(offsetHeight - offsetHeight * 0.3);
|
|
15
|
-
return Math.min(calculatedScrollThreshold, maxScrollThreshold);
|
|
16
|
-
}
|
|
17
|
-
function useScrollEndReached(t0) {
|
|
18
|
-
const $ = compilerRuntimeExports.c(9);
|
|
19
|
-
const {
|
|
20
|
-
elementRef,
|
|
21
|
-
onEndReached,
|
|
22
|
-
onEndReachedThreshold: t1
|
|
23
|
-
} = t0;
|
|
24
|
-
const onEndReachedThreshold = t1 === void 0 ? 0.1 : t1;
|
|
25
|
-
const lastScrollHeight = useRef(0);
|
|
26
|
-
const enableOnEndReached = useRef(true);
|
|
27
|
-
let t2;
|
|
28
|
-
if ($[0] !== elementRef || $[1] !== onEndReached || $[2] !== onEndReachedThreshold) {
|
|
29
|
-
t2 = async () => {
|
|
30
|
-
const element = elementRef.current;
|
|
31
|
-
if (element && onEndReached) {
|
|
32
|
-
const {
|
|
33
|
-
scrollTop,
|
|
34
|
-
scrollHeight,
|
|
35
|
-
clientHeight
|
|
36
|
-
} = element;
|
|
37
|
-
const scrollOffset = scrollHeight - clientHeight - scrollTop - 1;
|
|
38
|
-
const threshold = getCurrentThreshold(element, onEndReachedThreshold);
|
|
39
|
-
if (scrollOffset <= threshold && enableOnEndReached.current && scrollHeight !== lastScrollHeight.current) {
|
|
40
|
-
enableOnEndReached.current = false;
|
|
41
|
-
await new Promise((resolve) => {
|
|
42
|
-
resolve(onEndReached());
|
|
43
|
-
});
|
|
44
|
-
enableOnEndReached.current = true;
|
|
45
|
-
lastScrollHeight.current = scrollHeight;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
$[0] = elementRef;
|
|
50
|
-
$[1] = onEndReached;
|
|
51
|
-
$[2] = onEndReachedThreshold;
|
|
52
|
-
$[3] = t2;
|
|
53
|
-
} else {
|
|
54
|
-
t2 = $[3];
|
|
55
|
-
}
|
|
56
|
-
const onScrollEndReached = t2;
|
|
57
|
-
let t3;
|
|
58
|
-
if ($[4] !== elementRef || $[5] !== onEndReached || $[6] !== onScrollEndReached) {
|
|
59
|
-
t3 = () => {
|
|
60
|
-
let observer;
|
|
61
|
-
const element_0 = elementRef.current;
|
|
62
|
-
if (element_0 && onEndReached) {
|
|
63
|
-
observer = new ResizeObserver(() => {
|
|
64
|
-
const currentElement = elementRef.current;
|
|
65
|
-
if (currentElement) {
|
|
66
|
-
const {
|
|
67
|
-
scrollHeight: scrollHeight_0
|
|
68
|
-
} = currentElement;
|
|
69
|
-
if (scrollHeight_0 && scrollHeight_0 !== lastScrollHeight.current) {
|
|
70
|
-
enableOnEndReached.current = true;
|
|
71
|
-
observer?.disconnect();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
observer.observe(element_0);
|
|
76
|
-
element_0.addEventListener("scroll", onScrollEndReached);
|
|
77
|
-
}
|
|
78
|
-
return () => {
|
|
79
|
-
element_0?.removeEventListener("scroll", onScrollEndReached);
|
|
80
|
-
observer?.disconnect();
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
$[4] = elementRef;
|
|
84
|
-
$[5] = onEndReached;
|
|
85
|
-
$[6] = onScrollEndReached;
|
|
86
|
-
$[7] = t3;
|
|
87
|
-
} else {
|
|
88
|
-
t3 = $[7];
|
|
89
|
-
}
|
|
90
|
-
let t4;
|
|
91
|
-
if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
|
|
92
|
-
t4 = [];
|
|
93
|
-
$[8] = t4;
|
|
94
|
-
} else {
|
|
95
|
-
t4 = $[8];
|
|
96
|
-
}
|
|
97
|
-
useEffect(t3, t4);
|
|
98
|
-
}
|
|
99
|
-
export {
|
|
100
|
-
getCurrentThreshold,
|
|
101
|
-
useScrollEndReached
|
|
102
|
-
};
|
|
103
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/lib/hooks/useScrollEndReached/index.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { AsyncFunc, Func, UseScrollEndReachedParams } from \"./types\";\n\nexport interface ScrollEndReachedParams extends UseScrollEndReachedParams {\n elementRef: React.RefObject<HTMLElement | null>;\n onEndReached?: Func | AsyncFunc;\n onEndReachedThreshold?: number;\n}\n\nexport function getCurrentThreshold(\n scrollableElement: HTMLElement,\n scrollThreshold: number,\n): number {\n const MIN_THRESHOLD = 0;\n const MAX_THRESHOLD = 1;\n if (scrollThreshold < MIN_THRESHOLD) return MIN_THRESHOLD;\n if (scrollThreshold > MAX_THRESHOLD) return MAX_THRESHOLD;\n const { scrollHeight, clientHeight } = scrollableElement;\n const offsetHeight = scrollHeight - clientHeight;\n\n const calculatedScrollThreshold = Math.round(scrollHeight * scrollThreshold);\n const maxScrollThreshold = Math.round(offsetHeight - (offsetHeight * 0.3));\n\n return Math.min(calculatedScrollThreshold, maxScrollThreshold);\n}\n\nexport function useScrollEndReached({\n elementRef,\n onEndReached,\n onEndReachedThreshold = 0.1,\n}: ScrollEndReachedParams) {\n const lastScrollHeight = useRef(0);\n const enableOnEndReached = useRef(true);\n\n const onScrollEndReached = async () => {\n const element = elementRef.current;\n \n if (element && onEndReached) {\n const { scrollTop, scrollHeight, clientHeight } = element;\n const scrollOffset = scrollHeight - clientHeight - scrollTop - 1;\n const threshold = getCurrentThreshold(element, onEndReachedThreshold);\n\n if (\n scrollOffset <= threshold && enableOnEndReached.current \n && scrollHeight !== lastScrollHeight.current\n ) {\n enableOnEndReached.current = false;\n await new Promise((resolve) => {\n resolve(onEndReached());\n });\n enableOnEndReached.current = true;\n lastScrollHeight.current = scrollHeight;\n }\n }\n };\n\n useEffect(() => {\n let observer: ResizeObserver | null;\n const element = elementRef.current;\n if (element && onEndReached) {\n observer = new ResizeObserver(() => {\n const currentElement = elementRef.current;\n if (currentElement) {\n const { scrollHeight } = currentElement as HTMLDivElement;\n if (scrollHeight && scrollHeight !== lastScrollHeight.current) {\n enableOnEndReached.current = true;\n observer?.disconnect();\n }\n }\n });\n \n observer.observe(element);\n element.addEventListener('scroll', onScrollEndReached);\n }\n \n return () => {\n element?.removeEventListener('scroll', onScrollEndReached);\n observer?.disconnect();\n };\n }, []);\n}\n"],"names":["getCurrentThreshold","scrollableElement","scrollThreshold","MIN_THRESHOLD","MAX_THRESHOLD","scrollHeight","clientHeight","offsetHeight","calculatedScrollThreshold","Math","round","maxScrollThreshold","min","useScrollEndReached","t0","$","_c","elementRef","onEndReached","onEndReachedThreshold","t1","undefined","lastScrollHeight","useRef","enableOnEndReached","t2","element","current","scrollTop","scrollOffset","threshold","Promise","resolve","onScrollEndReached","t3","observer","element_0","ResizeObserver","currentElement","scrollHeight_0","disconnect","observe","addEventListener","removeEventListener","t4","Symbol","for","useEffect"],"mappings":";;AASO,SAASA,oBACdC,mBACAC,iBACQ;AACR,QAAMC,gBAAgB;AACtB,QAAMC,gBAAgB;AACtB,MAAIF,kBAAkBC,cAAe,QAAOA;AAC5C,MAAID,kBAAkBE,cAAe,QAAOA;AAC5C,QAAM;AAAA,IAAEC;AAAAA,IAAcC;AAAAA,EAAAA,IAAiBL;AACvC,QAAMM,eAAeF,eAAeC;AAEpC,QAAME,4BAA4BC,KAAKC,MAAML,eAAeH,eAAe;AAC3E,QAAMS,qBAAqBF,KAAKC,MAAMH,eAAgBA,eAAe,GAAI;AAEzE,SAAOE,KAAKG,IAAIJ,2BAA2BG,kBAAkB;AAC/D;AAEO,SAAAE,oBAAAC,IAAA;AAAA,QAAAC,IAAAC,uBAAAA,EAAA,CAAA;AAA6B,QAAA;AAAA,IAAAC;AAAAA,IAAAC;AAAAA,IAAAC,uBAAAC;AAAAA,EAAAA,IAAAN;AAGlC,QAAAK,wBAAAC,OAAAC,SAAA,MAAAD;AAEA,QAAAE,mBAAyBC,OAAO,CAAC;AACjC,QAAAC,qBAA2BD,OAAO,IAAI;AAAE,MAAAE;AAAA,MAAAV,EAAA,CAAA,MAAAE,cAAAF,SAAAG,gBAAAH,EAAA,CAAA,MAAAI,uBAAA;AAEbM,qBAAA;AACzB,YAAAC,UAAgBT,WAAUU;AAE1B,UAAID,WAAAR,cA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