jb-infinite-scroll 1.1.0

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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +135 -0
  3. package/dist/jb-infinite-scroll.cjs.js +2 -0
  4. package/dist/jb-infinite-scroll.cjs.js.br +0 -0
  5. package/dist/jb-infinite-scroll.cjs.js.gz +0 -0
  6. package/dist/jb-infinite-scroll.cjs.js.map +1 -0
  7. package/dist/jb-infinite-scroll.js +2 -0
  8. package/dist/jb-infinite-scroll.js.br +0 -0
  9. package/dist/jb-infinite-scroll.js.gz +0 -0
  10. package/dist/jb-infinite-scroll.js.map +1 -0
  11. package/dist/jb-infinite-scroll.umd.js +2 -0
  12. package/dist/jb-infinite-scroll.umd.js.br +0 -0
  13. package/dist/jb-infinite-scroll.umd.js.gz +0 -0
  14. package/dist/jb-infinite-scroll.umd.js.map +1 -0
  15. package/dist/web-component/jb-infinite-scroll/lib/Types.d.ts +11 -0
  16. package/dist/web-component/jb-infinite-scroll/lib/jb-infinite-scroll.d.ts +36 -0
  17. package/index.js +1 -0
  18. package/lib/jb-infinite-scroll.html +19 -0
  19. package/lib/jb-infinite-scroll.scss +44 -0
  20. package/lib/jb-infinite-scroll.ts +236 -0
  21. package/lib/types.ts +14 -0
  22. package/package.json +35 -0
  23. package/react/LICENSE +21 -0
  24. package/react/README.md +2 -0
  25. package/react/dist/JBInfiniteScroll.cjs.js +92 -0
  26. package/react/dist/JBInfiniteScroll.cjs.js.map +1 -0
  27. package/react/dist/JBInfiniteScroll.js +86 -0
  28. package/react/dist/JBInfiniteScroll.js.map +1 -0
  29. package/react/dist/JBInfiniteScroll.umd.js +95 -0
  30. package/react/dist/JBInfiniteScroll.umd.js.map +1 -0
  31. package/react/dist/common/hooks/use-event.d.ts +3 -0
  32. package/react/dist/common/hooks/useLazyRef.d.ts +4 -0
  33. package/react/dist/common/hooks/useMobx.d.ts +4 -0
  34. package/react/dist/common/scripts/device-detection.d.ts +1 -0
  35. package/react/dist/common/scripts/persian-helper.d.ts +3 -0
  36. package/react/dist/web-component/jb-infinite-scroll/react/lib/JBInfiniteScroll.d.ts +33 -0
  37. package/react/index.js +1 -0
  38. package/react/lib/JBInfiniteScroll.tsx +107 -0
  39. package/react/package.json +33 -0
  40. package/react/tsconfig.json +18 -0
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import "jb-infinite-scroll";
3
+ import { JBInfiniteScrollWebComponent, StateChangeWaitingBehavior } from "jb-infinite-scroll";
4
+ declare global {
5
+ namespace JSX {
6
+ interface IntrinsicElements {
7
+ 'jb-infinite-scroll': JBInfiniteScrollType;
8
+ }
9
+ interface JBInfiniteScrollType extends React.DetailedHTMLProps<React.HTMLAttributes<JBInfiniteScrollWebComponent>, JBInfiniteScrollWebComponent> {
10
+ "class"?: string;
11
+ "type"?: string;
12
+ }
13
+ }
14
+ }
15
+ declare const JBInfiniteScroll: React.ForwardRefExoticComponent<{
16
+ stateChangeWaitingBehavior?: StateChangeWaitingBehavior;
17
+ disableCaptureScroll?: boolean;
18
+ isListEmpty?: boolean;
19
+ isLoading?: boolean;
20
+ isListEnded?: boolean;
21
+ onScrollEnd?: (e: CustomEvent) => void;
22
+ } & {
23
+ children?: React.ReactNode;
24
+ } & React.RefAttributes<JBInfiniteScrollWebComponent>>;
25
+ export type Props = React.PropsWithChildren<{
26
+ stateChangeWaitingBehavior?: StateChangeWaitingBehavior;
27
+ disableCaptureScroll?: boolean;
28
+ isListEmpty?: boolean;
29
+ isLoading?: boolean;
30
+ isListEnded?: boolean;
31
+ onScrollEnd?: (e: CustomEvent) => void;
32
+ }>;
33
+ export { JBInfiniteScroll, StateChangeWaitingBehavior };
package/react/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/JBInfiniteScroll.js';
@@ -0,0 +1,107 @@
1
+ import React, { useState, useRef, useCallback, useEffect, useImperativeHandle } from 'react';
2
+ import "jb-infinite-scroll";
3
+
4
+ // eslint-disable-next-line no-duplicate-imports
5
+ import {JBInfiniteScrollWebComponent, StateChangeWaitingBehavior} from "jb-infinite-scroll";
6
+ import { useBindEvent } from "../../../../common/hooks/use-event.js";
7
+
8
+ declare global {
9
+ // eslint-disable-next-line @typescript-eslint/no-namespace
10
+ namespace JSX {
11
+ interface IntrinsicElements {
12
+ 'jb-infinite-scroll': JBInfiniteScrollType;
13
+ }
14
+ interface JBInfiniteScrollType extends React.DetailedHTMLProps<React.HTMLAttributes<JBInfiniteScrollWebComponent>, JBInfiniteScrollWebComponent> {
15
+ "class"?: string,
16
+ "type"?: string;
17
+ }
18
+ }
19
+ }
20
+
21
+ const JBInfiniteScroll = React.forwardRef((props: Props, ref:React.ForwardedRef<JBInfiniteScrollWebComponent>) => {
22
+ const element = useRef<JBInfiniteScrollWebComponent>(null);
23
+ const [refChangeCount, refChangeCountSetter] = useState(0);
24
+ useImperativeHandle(
25
+ ref,
26
+ () => (element ? element.current : null),
27
+ [element],
28
+ );
29
+ useEffect(() => {
30
+ refChangeCountSetter(refChangeCount + 1);
31
+ }, [element.current]);
32
+
33
+ useEffect(() => {
34
+ element.current?.checkScrollHeight();
35
+ }, [element.current]);
36
+
37
+ const onScrollEnd = useCallback((e) => {
38
+ if (props.onScrollEnd) {
39
+ props.onScrollEnd(e);
40
+ }
41
+ }, [props.onScrollEnd]);
42
+
43
+ useBindEvent(element, 'scrollEnd', onScrollEnd, true);
44
+
45
+ useEffect(() => {
46
+ if (element.current) {
47
+ if (props.isLoading) {
48
+ element.current.setAttribute('is-loading', 'true');
49
+ } else {
50
+ element.current.setAttribute('is-loading', 'false');
51
+
52
+ }
53
+ }
54
+
55
+ }, [props.isLoading]);
56
+ useEffect(() => {
57
+ if (element.current) {
58
+ if (props.isListEmpty) {
59
+ element.current.setAttribute('is-list-empty', 'true');
60
+ } else {
61
+ element.current.setAttribute('is-list-empty', 'false');
62
+
63
+ }
64
+ }
65
+
66
+ }, [props.isListEmpty]);
67
+ useEffect(() => {
68
+ if (element.current) {
69
+ if (props.isListEnded) {
70
+ element.current?.setAttribute('is-list-ended', 'true');
71
+ } else {
72
+ element.current?.setAttribute('is-list-ended', 'false');
73
+ }
74
+ }
75
+
76
+ }, [props.isListEnded]);
77
+ useEffect(() => {
78
+ if (element.current) {
79
+ if (props.disableCaptureScroll) {
80
+ element.current?.setAttribute('disable-capture-scroll', 'true');
81
+ } else {
82
+ element.current?.setAttribute('disable-capture-scroll', 'false');
83
+ }
84
+ }
85
+
86
+ }, [props.disableCaptureScroll]);
87
+ useEffect(() => {
88
+ if (props.stateChangeWaitingBehavior && element.current) {
89
+ element.current?.setAttribute('state-change-waiting-behavior', props.stateChangeWaitingBehavior);
90
+ }
91
+ }, [props.stateChangeWaitingBehavior]);
92
+ return (
93
+ <jb-infinite-scroll ref={element}>{props.children}</jb-infinite-scroll>
94
+ );
95
+ });
96
+ export type Props = React.PropsWithChildren< {
97
+ stateChangeWaitingBehavior?: StateChangeWaitingBehavior,
98
+ disableCaptureScroll?: boolean,
99
+ isListEmpty?: boolean,
100
+ isLoading?: boolean,
101
+ isListEnded?:boolean,
102
+ onScrollEnd?:(e:CustomEvent)=>void
103
+ }>
104
+
105
+ JBInfiniteScroll.displayName = "JBInfiniteScroll";
106
+
107
+ export {JBInfiniteScroll, StateChangeWaitingBehavior};
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "jb-infinite-scroll-react",
3
+ "description": "infinite scroll react component",
4
+ "type": "module",
5
+ "author": {
6
+ "name": "mohammad javad bathaei",
7
+ "email": "javadbat@gmail.com"
8
+ },
9
+ "keywords": [
10
+ "jb",
11
+ "jb-infinite-scroll",
12
+ "infinite scroll",
13
+ "react component"
14
+ ],
15
+ "version": "1.0.0",
16
+ "bugs": "https://github.com/javadbat/jb-infinite-scroll/issues",
17
+ "license": "MIT",
18
+ "files": [
19
+ "LICENSE",
20
+ "README.md",
21
+ "lib/",
22
+ "dist/"
23
+ ],
24
+ "main": "index.js",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git@github.com:javadbat/jb-infinite-scroll.git"
28
+ },
29
+ "types": "./dist/web-component/jb-infinite-scroll/react/lib/JBInfiniteScroll.d.ts",
30
+ "dependencies": {
31
+ "jb-infinite-scroll": ">=1.0.0"
32
+ }
33
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": "."
4
+ },
5
+ "include": [
6
+ "../../../common/scripts/**/*.ts",
7
+ "../../../common/hooks/**/*.ts",
8
+ "../../../common/hooks/**/*.js",
9
+ "lib/**/*.ts",
10
+ "lib/**/*.tsx"
11
+ ],
12
+ "exclude": [
13
+ "node_modules",
14
+ "**/*.spec.ts",
15
+ "dist",
16
+ ],
17
+ "extends":"../../tsconfig-react.json"
18
+ }