jb-infinite-scroll 1.2.2 → 1.2.4
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 +4 -2
- package/dist/Types.d.ts +15 -0
- package/dist/jb-infinite-scroll.cjs.js +2 -2
- package/dist/jb-infinite-scroll.cjs.js.br +0 -0
- package/dist/jb-infinite-scroll.cjs.js.gz +0 -0
- package/dist/jb-infinite-scroll.cjs.js.map +1 -1
- package/dist/jb-infinite-scroll.d.ts +25 -0
- package/dist/jb-infinite-scroll.d.ts.map +1 -0
- package/dist/jb-infinite-scroll.js +2 -2
- package/dist/jb-infinite-scroll.js.br +0 -0
- package/dist/jb-infinite-scroll.js.gz +0 -0
- package/dist/jb-infinite-scroll.js.map +1 -1
- package/dist/jb-infinite-scroll.umd.js +2 -2
- package/dist/jb-infinite-scroll.umd.js.br +0 -0
- package/dist/jb-infinite-scroll.umd.js.gz +0 -0
- package/dist/jb-infinite-scroll.umd.js.map +1 -1
- package/dist/lib/Types.d.ts +14 -0
- package/dist/lib/jb-infinite-scroll.d.ts +24 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/web-component/jb-infinite-scroll/lib/Types.d.ts +3 -0
- package/lib/global.d.ts +15 -0
- package/lib/jb-infinite-scroll.ts +4 -4
- package/lib/types.ts +5 -1
- package/package.json +2 -2
- package/react/dist/JBInfiniteScroll.cjs.js +2 -85
- package/react/dist/JBInfiniteScroll.cjs.js.map +1 -1
- package/react/dist/JBInfiniteScroll.d.ts +25 -0
- package/react/dist/JBInfiniteScroll.js +2 -79
- package/react/dist/JBInfiniteScroll.js.map +1 -1
- package/react/dist/JBInfiniteScroll.umd.js +2 -88
- package/react/dist/JBInfiniteScroll.umd.js.map +1 -1
- package/react/dist/attributes-hook.d.ts +10 -0
- package/react/dist/events-hook.d.ts +18 -0
- package/react/dist/lib/JBInfiniteScroll.d.ts +34 -0
- package/react/dist/lib/events-hook.d.ts +18 -0
- package/react/dist/web-component/jb-infinite-scroll/react/lib/JBInfiniteScroll.d.ts +3 -4
- package/react/dist/web-component/jb-infinite-scroll/react/lib/events-hook.d.ts +18 -0
- package/react/lib/JBInfiniteScroll.tsx +16 -74
- package/react/lib/attributes-hook.ts +63 -0
- package/react/lib/events-hook.ts +26 -0
- package/react/package.json +1 -1
- package/react/tsconfig.json +4 -5
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import "jb-infinite-scroll";
|
|
3
3
|
import { JBInfiniteScrollWebComponent, StateChangeWaitingBehavior } from "jb-infinite-scroll";
|
|
4
|
+
import { EventProps } from './events-hook.js';
|
|
4
5
|
declare global {
|
|
5
6
|
namespace JSX {
|
|
6
7
|
interface IntrinsicElements {
|
|
@@ -12,24 +13,22 @@ declare global {
|
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
|
-
declare const JBInfiniteScroll: React.ForwardRefExoticComponent<{
|
|
16
|
+
declare const JBInfiniteScroll: React.ForwardRefExoticComponent<EventProps & {
|
|
16
17
|
stateChangeWaitingBehavior?: StateChangeWaitingBehavior;
|
|
17
18
|
disableCaptureScroll?: boolean;
|
|
18
19
|
isListEmpty?: boolean;
|
|
19
20
|
isLoading?: boolean;
|
|
20
21
|
isListEnded?: boolean;
|
|
21
22
|
className?: string;
|
|
22
|
-
onScrollEnd?: (e: CustomEvent) => void;
|
|
23
23
|
} & {
|
|
24
24
|
children?: React.ReactNode;
|
|
25
25
|
} & React.RefAttributes<JBInfiniteScrollWebComponent>>;
|
|
26
|
-
export type Props = React.PropsWithChildren<{
|
|
26
|
+
export type Props = EventProps & React.PropsWithChildren<{
|
|
27
27
|
stateChangeWaitingBehavior?: StateChangeWaitingBehavior;
|
|
28
28
|
disableCaptureScroll?: boolean;
|
|
29
29
|
isListEmpty?: boolean;
|
|
30
30
|
isLoading?: boolean;
|
|
31
31
|
isListEnded?: boolean;
|
|
32
32
|
className?: string;
|
|
33
|
-
onScrollEnd?: (e: CustomEvent) => void;
|
|
34
33
|
}>;
|
|
35
34
|
export { JBInfiniteScroll, StateChangeWaitingBehavior };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import type { JBInfiniteScrollEventType, JBInfiniteScrollWebComponent } from 'jb-infinite-scroll';
|
|
3
|
+
export type EventProps = {
|
|
4
|
+
/**
|
|
5
|
+
* when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
6
|
+
*/
|
|
7
|
+
onLoad?: (e: JBInfiniteScrollEventType<CustomEvent>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
10
|
+
*/
|
|
11
|
+
onInit?: (e: JBInfiniteScrollEventType<CustomEvent>) => void;
|
|
12
|
+
/**
|
|
13
|
+
* on user scroll to the end
|
|
14
|
+
*/
|
|
15
|
+
onScrollEnd?: (e: JBInfiniteScrollEventType<CustomEvent>) => void;
|
|
16
|
+
onScroll?: (e: JBInfiniteScrollEventType<Event>) => void;
|
|
17
|
+
};
|
|
18
|
+
export declare function useEvents(element: RefObject<JBInfiniteScrollWebComponent>, props: EventProps): void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useRef, useCallback, useEffect, useImperativeHandle } from 'react';
|
|
2
2
|
import "jb-infinite-scroll";
|
|
3
|
-
|
|
3
|
+
import { useJBInfiniteScrollAttribute, JBInfiniteScrollAttributes } from './attributes-hook.js';
|
|
4
4
|
// eslint-disable-next-line no-duplicate-imports
|
|
5
|
-
import {JBInfiniteScrollWebComponent, StateChangeWaitingBehavior} from "jb-infinite-scroll";
|
|
6
|
-
import {
|
|
5
|
+
import { JBInfiniteScrollWebComponent, StateChangeWaitingBehavior } from "jb-infinite-scroll";
|
|
6
|
+
import { EventProps, useEvents } from './events-hook.js';
|
|
7
7
|
|
|
8
8
|
declare global {
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
@@ -18,87 +18,29 @@ declare global {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const JBInfiniteScroll = React.forwardRef((props: Props, ref:React.ForwardedRef<JBInfiniteScrollWebComponent>) => {
|
|
21
|
+
const JBInfiniteScroll = React.forwardRef((props: Props, ref: React.ForwardedRef<JBInfiniteScrollWebComponent>) => {
|
|
22
22
|
const element = useRef<JBInfiniteScrollWebComponent>(null);
|
|
23
23
|
useImperativeHandle(
|
|
24
24
|
ref,
|
|
25
|
-
() => (element ? element.current :
|
|
25
|
+
() => (element ? element.current : undefined),
|
|
26
26
|
[element],
|
|
27
27
|
);
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
props.onScrollEnd(e);
|
|
32
|
-
}
|
|
33
|
-
}, [props.onScrollEnd]);
|
|
34
|
-
|
|
35
|
-
useBindEvent(element, 'scrollEnd', onScrollEnd, true);
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
if (element.current && typeof props.isLoading == "boolean") {
|
|
39
|
-
if (props.isLoading) {
|
|
40
|
-
element.current.setAttribute('is-loading', 'true');
|
|
41
|
-
} else {
|
|
42
|
-
element.current.setAttribute('is-loading', 'false');
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}, [element.current, props.isLoading]);
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (element.current, typeof props.isListEmpty == "boolean") {
|
|
50
|
-
if (props.isListEmpty) {
|
|
51
|
-
element.current.setAttribute('is-list-empty', 'true');
|
|
52
|
-
} else {
|
|
53
|
-
element.current.setAttribute('is-list-empty', 'false');
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}, [element.current, props.isListEmpty]);
|
|
29
|
+
useJBInfiniteScrollAttribute(element, props);
|
|
30
|
+
useEvents(element, props);
|
|
59
31
|
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
if (element.current && typeof props.isListEnded == "boolean") {
|
|
62
|
-
if (props.isListEnded) {
|
|
63
|
-
element.current?.setAttribute('is-list-ended', 'true');
|
|
64
|
-
} else {
|
|
65
|
-
element.current?.setAttribute('is-list-ended', 'false');
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}, [element.current, props.isListEnded]);
|
|
70
|
-
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (element.current && typeof props.disableCaptureScroll == "boolean") {
|
|
73
|
-
if (props.disableCaptureScroll) {
|
|
74
|
-
element.current?.setAttribute('disable-capture-scroll', 'true');
|
|
75
|
-
} else {
|
|
76
|
-
element.current?.setAttribute('disable-capture-scroll', 'false');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
}, [element.current, props.disableCaptureScroll]);
|
|
81
|
-
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
if (props.stateChangeWaitingBehavior && element.current) {
|
|
84
|
-
element.current?.setAttribute('state-change-waiting-behavior', props.stateChangeWaitingBehavior);
|
|
85
|
-
}
|
|
86
|
-
}, [element.current, props.stateChangeWaitingBehavior]);
|
|
87
32
|
return (
|
|
88
|
-
<jb-infinite-scroll class={props.className} ref={element}>{props.children}</jb-infinite-scroll>
|
|
33
|
+
<jb-infinite-scroll style={props.style} class={props.className} ref={element}>{props.children}</jb-infinite-scroll>
|
|
89
34
|
);
|
|
90
35
|
});
|
|
91
36
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
className?:string
|
|
99
|
-
onScrollEnd?:(e:CustomEvent)=>void
|
|
100
|
-
}>
|
|
37
|
+
type JBInfiniteScrollProps = {
|
|
38
|
+
|
|
39
|
+
className?: string,
|
|
40
|
+
style?: React.CSSProperties,
|
|
41
|
+
}
|
|
42
|
+
export type Props = JBInfiniteScrollAttributes & EventProps & React.PropsWithChildren<JBInfiniteScrollProps>
|
|
101
43
|
|
|
102
44
|
JBInfiniteScroll.displayName = "JBInfiniteScroll";
|
|
103
45
|
|
|
104
|
-
export {JBInfiniteScroll, StateChangeWaitingBehavior};
|
|
46
|
+
export { JBInfiniteScroll, StateChangeWaitingBehavior };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { JBInfiniteScrollWebComponent, type StateChangeWaitingBehavior} from "jb-infinite-scroll";
|
|
2
|
+
import { type ValidationItem } from "jb-validation";
|
|
3
|
+
import { RefObject, useEffect } from "react";
|
|
4
|
+
|
|
5
|
+
export type JBInfiniteScrollAttributes = {
|
|
6
|
+
stateChangeWaitingBehavior?: StateChangeWaitingBehavior,
|
|
7
|
+
disableCaptureScroll?: boolean,
|
|
8
|
+
isListEmpty?: boolean,
|
|
9
|
+
isLoading?: boolean,
|
|
10
|
+
isListEnded?:boolean,
|
|
11
|
+
}
|
|
12
|
+
export function useJBInfiniteScrollAttribute(element: RefObject<JBInfiniteScrollWebComponent>, props: JBInfiniteScrollAttributes) {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (element.current && typeof props.isLoading == "boolean") {
|
|
15
|
+
if (props.isLoading) {
|
|
16
|
+
element.current.setAttribute('is-loading', 'true');
|
|
17
|
+
} else {
|
|
18
|
+
element.current.setAttribute('is-loading', 'false');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}, [element.current, props.isLoading]);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (element.current, typeof props.isListEmpty == "boolean") {
|
|
26
|
+
if (props.isListEmpty) {
|
|
27
|
+
element.current.setAttribute('is-list-empty', 'true');
|
|
28
|
+
} else {
|
|
29
|
+
element.current.setAttribute('is-list-empty', 'false');
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}, [element.current, props.isListEmpty]);
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (element.current && typeof props.isListEnded == "boolean") {
|
|
38
|
+
if (props.isListEnded) {
|
|
39
|
+
element.current?.setAttribute('is-list-ended', 'true');
|
|
40
|
+
} else {
|
|
41
|
+
element.current?.setAttribute('is-list-ended', 'false');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}, [element.current, props.isListEnded]);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (element.current && typeof props.disableCaptureScroll == "boolean") {
|
|
49
|
+
if (props.disableCaptureScroll) {
|
|
50
|
+
element.current?.setAttribute('disable-capture-scroll', 'true');
|
|
51
|
+
} else {
|
|
52
|
+
element.current?.setAttribute('disable-capture-scroll', 'false');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}, [element.current, props.disableCaptureScroll]);
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (props.stateChangeWaitingBehavior && element.current) {
|
|
60
|
+
element.current?.setAttribute('state-change-waiting-behavior', props.stateChangeWaitingBehavior);
|
|
61
|
+
}
|
|
62
|
+
}, [element.current, props.stateChangeWaitingBehavior]);
|
|
63
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useEvent } from "jb-core/react";
|
|
2
|
+
import { RefObject } from "react";
|
|
3
|
+
import type { JBInfiniteScrollEventType, JBInfiniteScrollWebComponent } from 'jb-infinite-scroll';
|
|
4
|
+
|
|
5
|
+
export type EventProps = {
|
|
6
|
+
/**
|
|
7
|
+
* when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
8
|
+
*/
|
|
9
|
+
onLoad?: (e: JBInfiniteScrollEventType<CustomEvent>) => void,
|
|
10
|
+
/**
|
|
11
|
+
* when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
12
|
+
*/
|
|
13
|
+
onInit?: (e: JBInfiniteScrollEventType<CustomEvent>) => void,
|
|
14
|
+
/**
|
|
15
|
+
* on user scroll to the end
|
|
16
|
+
*/
|
|
17
|
+
onScrollEnd?:(e:JBInfiniteScrollEventType<CustomEvent>)=>void
|
|
18
|
+
onScroll?:(e:JBInfiniteScrollEventType<Event>)=>void
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
export function useEvents(element: RefObject<JBInfiniteScrollWebComponent>, props: EventProps) {
|
|
22
|
+
useEvent(element, 'load', props.onLoad, true);
|
|
23
|
+
useEvent(element, 'init', props.onInit, true);
|
|
24
|
+
useEvent(element, "scroll", props.onScroll);
|
|
25
|
+
useEvent(element, "scrollEnd", props.onScrollEnd, true);
|
|
26
|
+
}
|
package/react/package.json
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "git@github.com:javadbat/jb-infinite-scroll.git"
|
|
28
28
|
},
|
|
29
|
-
"types": "./dist/
|
|
29
|
+
"types": "./dist/JBInfiniteScroll.d.ts",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"jb-infinite-scroll": ">=1.0.0"
|
|
32
32
|
}
|
package/react/tsconfig.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"baseUrl": "."
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"rootDir": "./lib",
|
|
5
|
+
"declarationDir": "./dist"
|
|
4
6
|
},
|
|
5
7
|
"include": [
|
|
6
|
-
"../../../common/scripts/**/*.ts",
|
|
7
|
-
"../../../common/hooks/**/*.ts",
|
|
8
|
-
"../../../common/hooks/**/*.js",
|
|
9
8
|
"lib/**/*.ts",
|
|
10
9
|
"lib/**/*.tsx"
|
|
11
10
|
],
|
|
@@ -14,5 +13,5 @@
|
|
|
14
13
|
"**/*.spec.ts",
|
|
15
14
|
"dist",
|
|
16
15
|
],
|
|
17
|
-
"extends":"
|
|
16
|
+
"extends":"jb-core/configs/tsconfig-react.json"
|
|
18
17
|
}
|