@dev-tcloud/tcloud-ui 6.6.0 → 6.6.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/fesm2022/dev-tcloud-tcloud-ui.mjs +113 -12
- package/fesm2022/dev-tcloud-tcloud-ui.mjs.map +1 -1
- package/lib/_modules/tcloud-ui-pagination/pipes/tcloud-ui-pagination.pipe.d.ts +2 -1
- package/lib/_modules/tcloud-ui-pagination/tcloud-ui-pagination.component.d.ts +15 -4
- package/lib/_services/tcloud-ui-pagination.service.d.ts +15 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, Component, EventEmitter, Input, Output, forwardRef, ViewChild, InjectionToken, Optional, Inject, input, effect, Directive, Pipe, ViewEncapsulation, signal, inject, HostListener, ChangeDetectionStrategy, NgModule, makeEnvironmentProviders, output, ContentChildren, computed, ApplicationRef, model, viewChild } from '@angular/core';
|
|
2
|
+
import { Injectable, Component, EventEmitter, Input, Output, forwardRef, ViewChild, InjectionToken, Optional, Inject, input, effect, Directive, Pipe, ViewEncapsulation, signal, inject, HostListener, ChangeDetectorRef, ChangeDetectionStrategy, NgModule, makeEnvironmentProviders, output, ContentChildren, computed, ApplicationRef, model, viewChild } from '@angular/core';
|
|
3
3
|
import * as i1 from '@angular/common';
|
|
4
4
|
import { CommonModule, DatePipe, DOCUMENT } from '@angular/common';
|
|
5
5
|
import { Subject, Subscription, debounceTime, distinctUntilChanged, map, BehaviorSubject } from 'rxjs';
|
|
@@ -6312,15 +6312,49 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImpo
|
|
|
6312
6312
|
args: ['paste', ['$event']]
|
|
6313
6313
|
}] } });
|
|
6314
6314
|
|
|
6315
|
+
[];
|
|
6315
6316
|
class TCloudUiPaginationService {
|
|
6316
6317
|
constructor() {
|
|
6318
|
+
this._pagination = [];
|
|
6319
|
+
this._stateTotal = new Subject();
|
|
6320
|
+
this.stateTotal$ = this._stateTotal.asObservable();
|
|
6321
|
+
this._collectionChanged = new Subject();
|
|
6322
|
+
this.collectionChanged$ = this._collectionChanged.asObservable();
|
|
6317
6323
|
this.total = 0;
|
|
6318
6324
|
}
|
|
6319
|
-
set_total(total) {
|
|
6320
|
-
this.
|
|
6325
|
+
set_total(args, total) {
|
|
6326
|
+
if (args.id && this.getPaginations(args.id)) {
|
|
6327
|
+
for (let i = 0; i < (this._pagination).length; i++) {
|
|
6328
|
+
if (this._pagination[i].id === args.id) {
|
|
6329
|
+
this._pagination[i].total = total;
|
|
6330
|
+
this._pagination[i].itemsPerPage = args.itemsPerPage;
|
|
6331
|
+
this._pagination[i].currentPage = args.currentPage;
|
|
6332
|
+
}
|
|
6333
|
+
}
|
|
6334
|
+
this._stateTotal.next(this._pagination);
|
|
6335
|
+
return;
|
|
6336
|
+
}
|
|
6337
|
+
(this._pagination).push({
|
|
6338
|
+
id: args.id,
|
|
6339
|
+
total: total,
|
|
6340
|
+
itemsPerPage: args.itemsPerPage,
|
|
6341
|
+
currentPage: args.currentPage
|
|
6342
|
+
});
|
|
6343
|
+
this._stateTotal.next(this._pagination);
|
|
6321
6344
|
}
|
|
6322
6345
|
get_total() {
|
|
6323
|
-
return this.
|
|
6346
|
+
return this._pagination;
|
|
6347
|
+
}
|
|
6348
|
+
getPaginations(id) {
|
|
6349
|
+
for (let i = 0; i < (this._pagination).length; i++) {
|
|
6350
|
+
if (this._pagination[i].id === id) {
|
|
6351
|
+
return this._pagination[i];
|
|
6352
|
+
}
|
|
6353
|
+
}
|
|
6354
|
+
return undefined;
|
|
6355
|
+
}
|
|
6356
|
+
notifyCollectionChange(id) {
|
|
6357
|
+
this._collectionChanged.next(id);
|
|
6324
6358
|
}
|
|
6325
6359
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: TCloudUiPaginationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
6326
6360
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: TCloudUiPaginationService, providedIn: 'root' }); }
|
|
@@ -6335,11 +6369,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImpo
|
|
|
6335
6369
|
class TCloudUiPaginationPipe {
|
|
6336
6370
|
constructor() {
|
|
6337
6371
|
this._tcloudUiPaginationService = inject(TCloudUiPaginationService);
|
|
6338
|
-
this.
|
|
6372
|
+
this._previousLengths = new Map();
|
|
6339
6373
|
}
|
|
6340
6374
|
transform(collection, args) {
|
|
6375
|
+
args.id = (args.id) ?? 'tcloud-ui-pagination-component-alone';
|
|
6376
|
+
const currentLength = collection?.length || 0;
|
|
6377
|
+
const previousLength = this._previousLengths.get(args.id) || 0;
|
|
6378
|
+
// Se o tamanho da coleção mudou, reseta a página para 1
|
|
6379
|
+
if (previousLength !== currentLength && previousLength > 0) {
|
|
6380
|
+
args.currentPage = 1;
|
|
6381
|
+
// Notifica ao serviço para atualizar o estado
|
|
6382
|
+
this._tcloudUiPaginationService.notifyCollectionChange(args.id);
|
|
6383
|
+
}
|
|
6384
|
+
this._previousLengths.set(args.id, currentLength);
|
|
6341
6385
|
const total = Math.ceil((collection?.length || 0) / args.itemsPerPage);
|
|
6342
|
-
this._tcloudUiPaginationService.set_total(total);
|
|
6386
|
+
this._tcloudUiPaginationService.set_total(args, total);
|
|
6343
6387
|
if (!Array.isArray(collection) ||
|
|
6344
6388
|
isNaN(args.currentPage) ||
|
|
6345
6389
|
isNaN(args.itemsPerPage)) {
|
|
@@ -6368,20 +6412,75 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImpo
|
|
|
6368
6412
|
|
|
6369
6413
|
class TCloudUiPaginationComponent {
|
|
6370
6414
|
constructor() {
|
|
6371
|
-
this.
|
|
6372
|
-
|
|
6415
|
+
this._id = 'tcloud-ui-pagination-component-alone';
|
|
6416
|
+
this._currentPage = 1;
|
|
6373
6417
|
this._tcloudUiPaginationService = inject(TCloudUiPaginationService);
|
|
6418
|
+
this._changeDetectorRef = inject(ChangeDetectorRef);
|
|
6419
|
+
this._lastTotalPages = 1;
|
|
6374
6420
|
this.pageChange = new EventEmitter();
|
|
6375
6421
|
this.pageInputError = false;
|
|
6376
6422
|
}
|
|
6423
|
+
generateID() {
|
|
6424
|
+
return `tcloud-ui-pagination-${Math.floor(Math.random() * Math.floor(Math.random() * Date.now()))}`;
|
|
6425
|
+
}
|
|
6426
|
+
set id(value) {
|
|
6427
|
+
// Use o ID fornecido, ou gere um novo
|
|
6428
|
+
this._id = value || this.generateID();
|
|
6429
|
+
}
|
|
6430
|
+
get id() {
|
|
6431
|
+
return this._id || this.generateID();
|
|
6432
|
+
}
|
|
6433
|
+
set currentPage(value) {
|
|
6434
|
+
this._currentPage = value;
|
|
6435
|
+
}
|
|
6436
|
+
get currentPage() {
|
|
6437
|
+
return this._currentPage;
|
|
6438
|
+
}
|
|
6439
|
+
ngOnInit() {
|
|
6440
|
+
this._tcloudUiPaginationService.stateTotal$.subscribe((items) => {
|
|
6441
|
+
let pagination = {};
|
|
6442
|
+
for (let i = 0; i < (items).length; i++) {
|
|
6443
|
+
if (items[i].id === this.id) {
|
|
6444
|
+
pagination = items[i];
|
|
6445
|
+
}
|
|
6446
|
+
}
|
|
6447
|
+
const newTotalPages = pagination.total || 1;
|
|
6448
|
+
// Se o total de páginas mudou e a página atual é inválida, reseta para 1
|
|
6449
|
+
if (this._lastTotalPages !== newTotalPages && this._currentPage > newTotalPages) {
|
|
6450
|
+
this._currentPage = 1;
|
|
6451
|
+
// Agenda a emissão para depois da detecção de mudanças
|
|
6452
|
+
Promise.resolve().then(() => {
|
|
6453
|
+
this.pageChange.emit(1);
|
|
6454
|
+
});
|
|
6455
|
+
}
|
|
6456
|
+
this._lastTotalPages = newTotalPages;
|
|
6457
|
+
this._changeDetectorRef.markForCheck();
|
|
6458
|
+
});
|
|
6459
|
+
// Escuta mudanças na coleção (filtros)
|
|
6460
|
+
this._tcloudUiPaginationService.collectionChanged$.subscribe((changedId) => {
|
|
6461
|
+
if (changedId === this.id) {
|
|
6462
|
+
this._changeDetectorRef.markForCheck();
|
|
6463
|
+
}
|
|
6464
|
+
});
|
|
6465
|
+
}
|
|
6377
6466
|
previous() {
|
|
6378
6467
|
if (this.currentPage > 1) {
|
|
6379
6468
|
this.currentPage--;
|
|
6380
6469
|
this.pageChange.emit(this.currentPage);
|
|
6381
6470
|
}
|
|
6382
6471
|
}
|
|
6472
|
+
getTotal() {
|
|
6473
|
+
const items = this._tcloudUiPaginationService.get_total();
|
|
6474
|
+
let pagination = {};
|
|
6475
|
+
for (let i = 0; i < (items).length; i++) {
|
|
6476
|
+
if (items[i].id === this.id) {
|
|
6477
|
+
pagination = items[i];
|
|
6478
|
+
}
|
|
6479
|
+
}
|
|
6480
|
+
return pagination;
|
|
6481
|
+
}
|
|
6383
6482
|
get totalPages() {
|
|
6384
|
-
return this.
|
|
6483
|
+
return this.getTotal().total;
|
|
6385
6484
|
}
|
|
6386
6485
|
next() {
|
|
6387
6486
|
if (this.currentPage < this.totalPages) {
|
|
@@ -6415,15 +6514,17 @@ class TCloudUiPaginationComponent {
|
|
|
6415
6514
|
return page < 10 ? `0${page}` : `${page}`;
|
|
6416
6515
|
}
|
|
6417
6516
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: TCloudUiPaginationComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
6418
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.18", type: TCloudUiPaginationComponent, isStandalone: true, selector: "tcloud-ui-pagination", inputs: { currentPage: "currentPage" }, outputs: { pageChange: "pageChange" }, ngImport: i0, template: "<div class=\"pagination-container\">\n\t<button class=\"arrow\" [disabled]=\"currentPage === 1\" (click)=\"previous()\"><i class=\"fas fa-angle-left\"></i></button>\n\n\t<span class=\"label f-family f-weight-600 f-size-14 c-neutral-700\">P\u00E1gina</span>\n\n\t<div class=\"page-input-container\">\n\t\t<input\n\t\t\ttype=\"text\"\n\t\t\tclass=\"page-input\"\n\t\t\t[ngClass]=\"{'error': pageInputError}\"\n\t\t\t[value]=\"formatPage(currentPage)\"\n\t\t\t(keyup.enter)=\"goToPage($event)\"\n\t\t\t(blur)=\"goToPage($event)\"\n\t\t/>\n\t</div>\n\n\t<span class=\"label f-family f-weight-600 f-size-14 c-neutral-700\">de
|
|
6517
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.18", type: TCloudUiPaginationComponent, isStandalone: true, selector: "tcloud-ui-pagination", inputs: { id: "id", currentPage: "currentPage" }, outputs: { pageChange: "pageChange" }, ngImport: i0, template: "<div class=\"pagination-container\">\n\t<button class=\"arrow\" [disabled]=\"currentPage === 1\" (click)=\"previous()\"><i class=\"fas fa-angle-left\"></i></button>\n\n\t<span class=\"label f-family f-weight-600 f-size-14 c-neutral-700\">P\u00E1gina</span>\n\n\t<div class=\"page-input-container\">\n\t\t<input\n\t\t\ttype=\"text\"\n\t\t\tclass=\"page-input\"\n\t\t\t[ngClass]=\"{'error': pageInputError}\"\n\t\t\t[value]=\"formatPage(currentPage)\"\n\t\t\t(keyup.enter)=\"goToPage($event)\"\n\t\t\t(blur)=\"goToPage($event)\"\n\t\t/>\n\t</div>\n\n\t<span class=\"label f-family f-weight-600 f-size-14 c-neutral-700\">de\n\t\t{{ totalPages }}\n\t</span>\n\n\t<button class=\"arrow\" [disabled]=\"currentPage === totalPages\" (click)=\"next()\"><i class=\"fas fa-angle-right\"></i></button>\n</div>\n", styles: [":host{display:block}.pagination-container{display:flex;align-items:center;gap:8px;font-family:var(--f-family);justify-content:center}.pagination-container .label{color:var(--c-neutral-700)}.pagination-container .page-input-container{position:relative;width:48px;height:32px}.pagination-container .page-input{width:100%;height:100%;padding:var(--size-4) var(--size-8);border:1px solid var(--c-neutral-300);border-radius:var(--bor-radius-8);font-size:var(--f-size-14);font-family:var(--f-family);font-weight:var(--f-weight-600);color:var(--c-neutral-700);text-align:center;background-color:var(--c-neutral-50);outline:none;transition:border-color .2s ease}.pagination-container .page-input:focus:not(.error){border-color:var(--c-primary-500)}.pagination-container .page-input.error{border-color:var(--c-danger-500)}.pagination-container .page-input.error:focus{border-color:var(--c-danger-500)}.pagination-container .arrow{background-color:var(--c-neutral-100);border:1px solid var(--c-neutral-300);border-radius:var(--bor-radius-8);width:32px;height:32px;font-size:var(--f-size-16);color:var(--c-neutral-300);cursor:pointer;transition:all .2s ease;display:flex;align-items:center;justify-content:center}.pagination-container .arrow:disabled{cursor:not-allowed;opacity:.5}.pagination-container .arrow:hover:not(:disabled){background-color:var(--c-primary-100);border-color:var(--c-primary-300);color:var(--c-primary-500)}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
6419
6518
|
}
|
|
6420
6519
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: TCloudUiPaginationComponent, decorators: [{
|
|
6421
6520
|
type: Component,
|
|
6422
6521
|
args: [{ selector: 'tcloud-ui-pagination', imports: [
|
|
6423
6522
|
CommonModule,
|
|
6424
6523
|
TCloudUiPaginationPipe
|
|
6425
|
-
], changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, template: "<div class=\"pagination-container\">\n\t<button class=\"arrow\" [disabled]=\"currentPage === 1\" (click)=\"previous()\"><i class=\"fas fa-angle-left\"></i></button>\n\n\t<span class=\"label f-family f-weight-600 f-size-14 c-neutral-700\">P\u00E1gina</span>\n\n\t<div class=\"page-input-container\">\n\t\t<input\n\t\t\ttype=\"text\"\n\t\t\tclass=\"page-input\"\n\t\t\t[ngClass]=\"{'error': pageInputError}\"\n\t\t\t[value]=\"formatPage(currentPage)\"\n\t\t\t(keyup.enter)=\"goToPage($event)\"\n\t\t\t(blur)=\"goToPage($event)\"\n\t\t/>\n\t</div>\n\n\t<span class=\"label f-family f-weight-600 f-size-14 c-neutral-700\">de
|
|
6426
|
-
}], propDecorators: {
|
|
6524
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, template: "<div class=\"pagination-container\">\n\t<button class=\"arrow\" [disabled]=\"currentPage === 1\" (click)=\"previous()\"><i class=\"fas fa-angle-left\"></i></button>\n\n\t<span class=\"label f-family f-weight-600 f-size-14 c-neutral-700\">P\u00E1gina</span>\n\n\t<div class=\"page-input-container\">\n\t\t<input\n\t\t\ttype=\"text\"\n\t\t\tclass=\"page-input\"\n\t\t\t[ngClass]=\"{'error': pageInputError}\"\n\t\t\t[value]=\"formatPage(currentPage)\"\n\t\t\t(keyup.enter)=\"goToPage($event)\"\n\t\t\t(blur)=\"goToPage($event)\"\n\t\t/>\n\t</div>\n\n\t<span class=\"label f-family f-weight-600 f-size-14 c-neutral-700\">de\n\t\t{{ totalPages }}\n\t</span>\n\n\t<button class=\"arrow\" [disabled]=\"currentPage === totalPages\" (click)=\"next()\"><i class=\"fas fa-angle-right\"></i></button>\n</div>\n", styles: [":host{display:block}.pagination-container{display:flex;align-items:center;gap:8px;font-family:var(--f-family);justify-content:center}.pagination-container .label{color:var(--c-neutral-700)}.pagination-container .page-input-container{position:relative;width:48px;height:32px}.pagination-container .page-input{width:100%;height:100%;padding:var(--size-4) var(--size-8);border:1px solid var(--c-neutral-300);border-radius:var(--bor-radius-8);font-size:var(--f-size-14);font-family:var(--f-family);font-weight:var(--f-weight-600);color:var(--c-neutral-700);text-align:center;background-color:var(--c-neutral-50);outline:none;transition:border-color .2s ease}.pagination-container .page-input:focus:not(.error){border-color:var(--c-primary-500)}.pagination-container .page-input.error{border-color:var(--c-danger-500)}.pagination-container .page-input.error:focus{border-color:var(--c-danger-500)}.pagination-container .arrow{background-color:var(--c-neutral-100);border:1px solid var(--c-neutral-300);border-radius:var(--bor-radius-8);width:32px;height:32px;font-size:var(--f-size-16);color:var(--c-neutral-300);cursor:pointer;transition:all .2s ease;display:flex;align-items:center;justify-content:center}.pagination-container .arrow:disabled{cursor:not-allowed;opacity:.5}.pagination-container .arrow:hover:not(:disabled){background-color:var(--c-primary-100);border-color:var(--c-primary-300);color:var(--c-primary-500)}\n"] }]
|
|
6525
|
+
}], propDecorators: { id: [{
|
|
6526
|
+
type: Input
|
|
6527
|
+
}], currentPage: [{
|
|
6427
6528
|
type: Input
|
|
6428
6529
|
}], pageChange: [{
|
|
6429
6530
|
type: Output
|