angular-infinity-scrolling 1.5.4 → 2.0.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.
- package/README.md +46 -48
- package/ng-package.json +6 -6
- package/package.json +33 -31
- package/src/lib/angular-infinity-scroller.directive.spec.ts +8 -8
- package/src/lib/angular-infinity-scroller.directive.ts +43 -39
- package/src/public-api.ts +5 -5
- package/tsconfig.lib.json +15 -15
- package/tsconfig.lib.prod.json +11 -11
- package/tsconfig.spec.json +15 -15
package/README.md
CHANGED
|
@@ -1,48 +1,46 @@
|
|
|
1
|
-
## Thank you for using angular -infinity-scroller for infinite scrolling.
|
|
2
|
-
|
|
3
|
-
> [!TIP]
|
|
4
|
-
> Note: Current version of package is compatible with angular version above 17
|
|
5
|
-
|
|
6
|
-
go to the directory, open terminal and and install package using `npm i angular-infinity-scroller`
|
|
7
|
-
Go to the ts file of component e.g. example.component.ts and add AngularInfinityScrollerDirective inside imports.
|
|
8
|
-
|
|
9
|
-
```ruby
|
|
10
|
-
import {AngularInfinityScrollerDirective} from "angular-infinity-scroller";
|
|
11
|
-
|
|
12
|
-
@Component({
|
|
13
|
-
selector: 'app-example',
|
|
14
|
-
imports: [
|
|
15
|
-
AngularInfinityScrollerDirective,
|
|
16
|
-
],
|
|
17
|
-
templateUrl: './exaple.component.html',
|
|
18
|
-
styleUrl: './exaple.component.scss',
|
|
19
|
-
})
|
|
20
|
-
export class ExampleComponent{}
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
followed by consuming the directive in example.component.
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Currently Directive has 2 properties
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
scrollDistance - input which accpet a number between 1 and 10.
|
|
31
|
-
Describing to emit the data if scrollable height is less than or equal to (number*10) percent.
|
|
32
|
-
[scrollDistance]='2' value will be emitted if scrollable height is less than or 20%.
|
|
33
|
-
|
|
34
|
-
onScrolled - output that accept a voidFunction to be invoked on emit
|
|
35
|
-
(onScrolled)="handleScroll()"
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
```ruby
|
|
39
|
-
<div class='scrollable-parent' angularInfinityScroller [scrollDistance]="4" (onScrolled)="handleScroll()">
|
|
40
|
-
</div>
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
Any suggestions or contributions are most welcome.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Happy coding!!
|
|
48
|
-
```
|
|
1
|
+
## Thank you for using angular -infinity-scroller for infinite scrolling.
|
|
2
|
+
|
|
3
|
+
> [!TIP]
|
|
4
|
+
> Note: Current version of package is compatible with angular version above 17
|
|
5
|
+
|
|
6
|
+
go to the directory, open terminal and and install package using `npm i angular-infinity-scroller`
|
|
7
|
+
Go to the ts file of component e.g. example.component.ts and add AngularInfinityScrollerDirective inside imports.
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
import {AngularInfinityScrollerDirective} from "angular-infinity-scroller";
|
|
11
|
+
|
|
12
|
+
@Component({
|
|
13
|
+
selector: 'app-example',
|
|
14
|
+
imports: [
|
|
15
|
+
AngularInfinityScrollerDirective,
|
|
16
|
+
],
|
|
17
|
+
templateUrl: './exaple.component.html',
|
|
18
|
+
styleUrl: './exaple.component.scss',
|
|
19
|
+
})
|
|
20
|
+
export class ExampleComponent{}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
followed by consuming the directive in example.component.
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Currently Directive has 2 properties
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
scrollDistance - input which accpet a number between 1 and 10.
|
|
31
|
+
Describing to emit the data if scrollable height is less than or equal to (number*10) percent.
|
|
32
|
+
[scrollDistance]='2' value will be emitted if scrollable height is less than or 20%.
|
|
33
|
+
|
|
34
|
+
onScrolled - output that accept a voidFunction to be invoked on emit
|
|
35
|
+
(onScrolled)="handleScroll()"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
<div class='scrollable-parent' angularInfinityScroller [scrollDistance]="4" (onScrolled)="handleScroll()">
|
|
40
|
+
</div>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
Any suggestions or contributions are most welcome. If you are facing any issue with the packge please raise the issue in the github, I'll happt to resolve the bugs.
|
|
45
|
+
Happy coding!!
|
|
46
|
+
```
|
package/ng-package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
|
|
3
|
-
"dest": "../../dist/angular-infinity-scroller",
|
|
4
|
-
"lib": {
|
|
5
|
-
"entryFile": "src/public-api.ts"
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
|
|
3
|
+
"dest": "../../dist/angular-infinity-scroller",
|
|
4
|
+
"lib": {
|
|
5
|
+
"entryFile": "src/public-api.ts"
|
|
6
|
+
}
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "angular-infinity-scrolling",
|
|
3
|
-
"version": "
|
|
4
|
-
"repository": {
|
|
5
|
-
"type": "git",
|
|
6
|
-
"url": "https://github.com/Jayant061/angular-infinity-scroller"
|
|
7
|
-
},
|
|
8
|
-
"bugs": {
|
|
9
|
-
"url": "https://github.com/Jayant061/angular-infinity-scroller/issues"
|
|
10
|
-
},
|
|
11
|
-
"keywords": [
|
|
12
|
-
"Angular-infinity-scrolling",
|
|
13
|
-
"Angular-infinity-scroller",
|
|
14
|
-
"infinity-scroller",
|
|
15
|
-
"Angular-infinite-scroller",
|
|
16
|
-
"Angular-infinite-scroll",
|
|
17
|
-
"infinte-scroll",
|
|
18
|
-
"infinite",
|
|
19
|
-
"Angular"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "angular-infinity-scrolling",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/Jayant061/angular-infinity-scroller"
|
|
7
|
+
},
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/Jayant061/angular-infinity-scroller/issues"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"Angular-infinity-scrolling",
|
|
13
|
+
"Angular-infinity-scroller",
|
|
14
|
+
"infinity-scroller",
|
|
15
|
+
"Angular-infinite-scroller",
|
|
16
|
+
"Angular-infinite-scroll",
|
|
17
|
+
"infinte-scroll",
|
|
18
|
+
"infinite",
|
|
19
|
+
"Angular",
|
|
20
|
+
"ngx-infinite-scroller",
|
|
21
|
+
"ng-infinite-scroll"
|
|
22
|
+
],
|
|
23
|
+
"author": "Jayant Thakur",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@angular/common": "^19.0.0",
|
|
27
|
+
"@angular/core": "^19.0.0"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"tslib": "^2.3.0"
|
|
31
|
+
},
|
|
32
|
+
"sideEffects": false
|
|
33
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AngularInfinityScrollerDirective } from './angular-infinity-scroller.directive';
|
|
2
|
-
|
|
3
|
-
describe('AngularInfinityScrollerDirective', () => {
|
|
4
|
-
it('should create an instance', () => {
|
|
5
|
-
const directive = new AngularInfinityScrollerDirective();
|
|
6
|
-
expect(directive).toBeTruthy();
|
|
7
|
-
});
|
|
8
|
-
});
|
|
1
|
+
import { AngularInfinityScrollerDirective } from './angular-infinity-scroller.directive';
|
|
2
|
+
|
|
3
|
+
describe('AngularInfinityScrollerDirective', () => {
|
|
4
|
+
it('should create an instance', () => {
|
|
5
|
+
const directive = new AngularInfinityScrollerDirective();
|
|
6
|
+
expect(directive).toBeTruthy();
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
import { Directive, ElementRef, inject, input, output } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
@Directive({
|
|
4
|
-
selector: '[angularInfinityScroller]',
|
|
5
|
-
standalone: true
|
|
6
|
-
})
|
|
7
|
-
export class AngularInfinityScrollerDirective {
|
|
8
|
-
|
|
9
|
-
constructor() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
import { computed, Directive, ElementRef, inject, input, output, signal } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
@Directive({
|
|
4
|
+
selector: '[angularInfinityScroller]',
|
|
5
|
+
standalone: true
|
|
6
|
+
})
|
|
7
|
+
export class AngularInfinityScrollerDirective {
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
this.onScroll = this.onScroll.bind(this);
|
|
11
|
+
}
|
|
12
|
+
public scrollDistance = input<number>(2);
|
|
13
|
+
private readonly scrollDistanceCoefficient = computed(() => {
|
|
14
|
+
const val = this.scrollDistance();
|
|
15
|
+
if (val > 9) {
|
|
16
|
+
return 2
|
|
17
|
+
}
|
|
18
|
+
return val;
|
|
19
|
+
})
|
|
20
|
+
public onScrolled = output();
|
|
21
|
+
private el: ElementRef<HTMLDivElement> = inject(ElementRef);
|
|
22
|
+
private prevScrollHeight = signal<number>(0);
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
ngAfterViewInit(): void {
|
|
26
|
+
this.el.nativeElement.addEventListener('scroll', this.onScroll);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private onScroll(): void {
|
|
30
|
+
const height = Math.floor(this.el?.nativeElement.scrollHeight - this.el.nativeElement.clientHeight);
|
|
31
|
+
const scrollValue = Math.floor(this.el?.nativeElement.scrollTop);
|
|
32
|
+
const unexploredContentHeight = height - this.prevScrollHeight();
|
|
33
|
+
const emitTriggerHeight = this.prevScrollHeight() + Math.ceil((1 - ((this.scrollDistanceCoefficient()) / 10)) * unexploredContentHeight);
|
|
34
|
+
if (scrollValue >= (emitTriggerHeight) && this.prevScrollHeight() !== height) {
|
|
35
|
+
this.onScrolled.emit();
|
|
36
|
+
this.prevScrollHeight.set(height);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
ngOnDestroy(): void {
|
|
40
|
+
this.el.nativeElement.removeEventListener('scroll', this.onScroll);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
package/src/public-api.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Public API Surface of angular-infinity-scroller
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export * from './lib/angular-infinity-scroller.directive'
|
|
1
|
+
/*
|
|
2
|
+
* Public API Surface of angular-infinity-scroller
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from './lib/angular-infinity-scroller.directive'
|
package/tsconfig.lib.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
-
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
-
{
|
|
4
|
-
"extends": "../../tsconfig.json",
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"outDir": "../../out-tsc/lib",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"inlineSources": true,
|
|
10
|
-
"types": []
|
|
11
|
-
},
|
|
12
|
-
"exclude": [
|
|
13
|
-
"**/*.spec.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
1
|
+
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
+
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
+
{
|
|
4
|
+
"extends": "../../tsconfig.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"outDir": "../../out-tsc/lib",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"inlineSources": true,
|
|
10
|
+
"types": []
|
|
11
|
+
},
|
|
12
|
+
"exclude": [
|
|
13
|
+
"**/*.spec.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
package/tsconfig.lib.prod.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
-
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
-
{
|
|
4
|
-
"extends": "./tsconfig.lib.json",
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"declarationMap": false
|
|
7
|
-
},
|
|
8
|
-
"angularCompilerOptions": {
|
|
9
|
-
"compilationMode": "partial"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
+
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
+
{
|
|
4
|
+
"extends": "./tsconfig.lib.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"declarationMap": false
|
|
7
|
+
},
|
|
8
|
+
"angularCompilerOptions": {
|
|
9
|
+
"compilationMode": "partial"
|
|
10
|
+
}
|
|
11
|
+
}
|
package/tsconfig.spec.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
-
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
-
{
|
|
4
|
-
"extends": "../../tsconfig.json",
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"outDir": "../../out-tsc/spec",
|
|
7
|
-
"types": [
|
|
8
|
-
"jasmine"
|
|
9
|
-
]
|
|
10
|
-
},
|
|
11
|
-
"include": [
|
|
12
|
-
"**/*.spec.ts",
|
|
13
|
-
"**/*.d.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
1
|
+
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
+
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
+
{
|
|
4
|
+
"extends": "../../tsconfig.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"outDir": "../../out-tsc/spec",
|
|
7
|
+
"types": [
|
|
8
|
+
"jasmine"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"include": [
|
|
12
|
+
"**/*.spec.ts",
|
|
13
|
+
"**/*.d.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|