matcha-components 19.10.0 → 19.13.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.
@@ -1,7 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { EventEmitter, Component, Input, Output, ContentChildren, ElementRef, Renderer2, Inject, HostListener, Directive, NgModule } from '@angular/core';
3
3
  import { animation, style, animate, trigger, transition, useAnimation, state, query, stagger, animateChild, sequence, group } from '@angular/animations';
4
- import { Subscription } from 'rxjs';
4
+ import { Subscription, Subject } from 'rxjs';
5
+ import { debounceTime } from 'rxjs/operators';
5
6
  import * as i1 from '@angular/common';
6
7
  import { CommonModule } from '@angular/common';
7
8
 
@@ -500,12 +501,18 @@ class MatchaInfiniteScrollDataComponent {
500
501
  this.aggregatedData = new EventEmitter();
501
502
  this.aggregatedList = [];
502
503
  this.currentPage = 0;
503
- this.subscription = new Subscription();
504
+ // Subscription para as chamadas do loadData
505
+ this.dataSubscription = new Subscription();
506
+ // Subscription exclusiva para o debounce do searchTerm
507
+ this.searchSubscription = new Subscription();
508
+ // Subject para aplicar debounce no searchTerm
509
+ this.searchTermSubject = new Subject();
504
510
  }
505
511
  ngOnInit() {
506
512
  this.initialize();
513
+ // Configura o Intersection Observer para carregamento via scroll
507
514
  const options = {
508
- root: null, // utiliza a viewport como área de visualização
515
+ root: null,
509
516
  rootMargin: '0px',
510
517
  threshold: this.threshold
511
518
  };
@@ -517,18 +524,24 @@ class MatchaInfiniteScrollDataComponent {
517
524
  });
518
525
  }, options);
519
526
  this.observer.observe(this.element.nativeElement);
527
+ // Inscreve para receber alterações do searchTerm com debounce
528
+ this.searchSubscription = this.searchTermSubject.pipe(debounceTime(300) // ajuste o tempo conforme necessário
529
+ ).subscribe(() => {
530
+ // Reseta e carrega a primeira página após o debounce
531
+ this.resetData();
532
+ this.loadNextPage();
533
+ });
520
534
  }
521
535
  /**
522
- * Detecta mudanças no resetKey e, se for o caso, reseta a lista e a página atual.
536
+ * Detecta mudanças nos inputs e, se for o caso, reseta a lista e a página atual.
523
537
  */
524
538
  ngOnChanges(changes) {
525
539
  if (changes['resetKey'] && !changes['resetKey'].firstChange) {
526
- this.reset();
540
+ this.resetData();
527
541
  }
528
542
  if (changes['searchTerm'] && !changes['searchTerm'].firstChange) {
529
- // Reset e dispara imediatamente a carga para o autocomplete
530
- this.reset();
531
- this.loadNextPage();
543
+ // Emite o novo valor para o Subject e aguarda o debounce
544
+ this.searchTermSubject.next(changes['searchTerm'].currentValue);
532
545
  }
533
546
  }
534
547
  /**
@@ -540,12 +553,12 @@ class MatchaInfiniteScrollDataComponent {
540
553
  this.aggregatedData.emit(this.aggregatedList);
541
554
  }
542
555
  /**
543
- * Reseta o estado interno da diretiva.
556
+ * Reseta apenas as assinaturas e o estado dos dados (não a inscrição do searchTerm).
544
557
  */
545
- reset() {
546
- // Cancela quaisquer assinaturas pendentes
547
- this.subscription.unsubscribe();
548
- this.subscription = new Subscription();
558
+ resetData() {
559
+ // Cancela as assinaturas das chamadas de loadData
560
+ this.dataSubscription.unsubscribe();
561
+ this.dataSubscription = new Subscription();
549
562
  // Re-inicializa a lista e o contador
550
563
  this.initialize();
551
564
  }
@@ -564,11 +577,12 @@ class MatchaInfiniteScrollDataComponent {
564
577
  this.aggregatedData.emit(this.aggregatedList);
565
578
  }
566
579
  });
567
- this.subscription.add(sub);
580
+ this.dataSubscription.add(sub);
568
581
  }
569
582
  ngOnDestroy() {
570
583
  this.observer.disconnect();
571
- this.subscription.unsubscribe();
584
+ this.dataSubscription.unsubscribe();
585
+ this.searchSubscription.unsubscribe();
572
586
  }
573
587
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.4", ngImport: i0, type: MatchaInfiniteScrollDataComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); }
574
588
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.1.4", type: MatchaInfiniteScrollDataComponent, isStandalone: false, selector: "matcha-infinite-scroll-data", inputs: { loadData: "loadData", initialList: "initialList", threshold: "threshold", resetKey: "resetKey", searchTerm: "searchTerm" }, outputs: { aggregatedData: "aggregatedData" }, usesOnChanges: true, ngImport: i0, template: "", styles: ["", ":host{height:1px;opacity:0}\n"] }); }