angular-infinity-scrolling 1.5.4 → 2.0.1

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 CHANGED
@@ -1,48 +1,47 @@
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
- If you are facing any issue with the packge please raise the issue in the github.
46
- I'll happy to resolve the bugs.
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 9.
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
+ NOTE: if invalid scrollDistance is given, then default value of 2 will be used for calculation;
34
+
35
+ onScrolled - output that accept a voidFunction to be invoked on emit
36
+ (onScrolled)="handleScroll()"
37
+ ```
38
+
39
+ ```ruby
40
+ <div class='scrollable-parent' angularInfinityScroller [scrollDistance]="2" (onScrolled)="handleScroll()">
41
+ </div>
42
+ ```
43
+
44
+ ```
45
+ 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.
46
+ Happy coding!!
47
+ ```
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": "1.5.4",
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
- "author": "Jayant Thakur",
22
- "license": "ISC",
23
- "peerDependencies": {
24
- "@angular/common": "^19.0.0",
25
- "@angular/core": "^19.0.0"
26
- },
27
- "dependencies": {
28
- "tslib": "^2.3.0"
29
- },
30
- "sideEffects": false
31
- }
1
+ {
2
+ "name": "angular-infinity-scrolling",
3
+ "version": "2.0.1",
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
- public scrollDistance = input<number>();
11
- public onScrolled = output();
12
- private el:ElementRef<HTMLDivElement> = inject(ElementRef);
13
- private prevScrollHeight:number = 0;
14
- ngAfterViewInit(): void {
15
- this.el.nativeElement.addEventListener('scroll',this.onScroll.bind(this));
16
- }
17
-
18
- ngOnDestroy(): void {
19
- this.el.nativeElement.removeEventListener('scroll',this.onScroll.bind(this));
20
- }
21
- private isEmit:boolean = true;
22
- private onScroll():void{
23
- const height = Math.floor(this.el?.nativeElement.scrollHeight - this.el.nativeElement.clientHeight);
24
- const scrollValue = Math.floor(this.el?.nativeElement.scrollTop);
25
- const emitTriggerHeight = Math.ceil((1-((this.scrollDistance()??2)/10))*height);
26
- if(scrollValue>= (emitTriggerHeight) && !this.isEmit){
27
- return;
28
- }
29
- else if(scrollValue < (emitTriggerHeight)){
30
- this.isEmit = true;
31
- }
32
- if(scrollValue>= (emitTriggerHeight) && this.prevScrollHeight !== height){
33
- this.onScrolled.emit();
34
- this.prevScrollHeight = height;
35
- this.isEmit = false;
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
+ }
@@ -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
+ }
@@ -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
+ }