@cngx/common 0.1.0-rc.2 → 0.1.0-rc.3
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/data/README.md
CHANGED
|
@@ -778,7 +778,10 @@ readonly dataSource = injectSmartDataSource(this.residents);
|
|
|
778
778
|
</table>
|
|
779
779
|
}
|
|
780
780
|
|
|
781
|
-
<
|
|
781
|
+
<mat-paginator
|
|
782
|
+
[length]="pg.total()" [pageIndex]="pg.pageIndex()" [pageSize]="pg.pageSize()"
|
|
783
|
+
(page)="pg.setPageSize($event.pageSize, false); pg.setPage($event.pageIndex)"
|
|
784
|
+
></mat-paginator>
|
|
782
785
|
</div>
|
|
783
786
|
```
|
|
784
787
|
|
|
@@ -814,12 +817,16 @@ The paginator accepts `[state]` and blocks navigation while busy:
|
|
|
814
817
|
<div cngxPaginate #pg="cngxPaginate"
|
|
815
818
|
[total]="dataSource.filteredCount()" [state]="residents">
|
|
816
819
|
<!-- table -->
|
|
817
|
-
<
|
|
820
|
+
<mat-paginator
|
|
821
|
+
[length]="pg.total()" [pageIndex]="pg.pageIndex()" [pageSize]="pg.pageSize()"
|
|
822
|
+
[disabled]="pg.isBusy()"
|
|
823
|
+
(page)="pg.setPageSize($event.pageSize, false); pg.setPage($event.pageIndex)"
|
|
824
|
+
></mat-paginator>
|
|
818
825
|
</div>
|
|
819
826
|
```
|
|
820
827
|
|
|
821
828
|
- `setPage()`, `next()`, `previous()`, `setPageSize()` are no-ops while `isBusy`
|
|
822
|
-
-
|
|
829
|
+
- bind `[disabled]="pg.isBusy()"` so the rendered controls reflect busy state
|
|
823
830
|
- No manual disabled management needed
|
|
824
831
|
|
|
825
832
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { input, signal, computed, output, Directive, inject, TemplateRef, model, contentChild, afterNextRender, DestroyRef, ChangeDetectionStrategy, Component,
|
|
2
|
+
import { input, signal, computed, output, Directive, inject, TemplateRef, model, contentChild, afterNextRender, DestroyRef, ChangeDetectionStrategy, Component, effect, untracked, InjectionToken, Injector, ViewContainerRef, LOCALE_ID, ViewEncapsulation, isDevMode, ElementRef, runInInjectionContext } from '@angular/core';
|
|
3
3
|
import { NgTemplateOutlet, DOCUMENT } from '@angular/common';
|
|
4
4
|
import { CngxChip } from '@cngx/common/display';
|
|
5
5
|
import { CngxMultiChipGroup, CngxChipInGroup, CngxSearch } from '@cngx/common/interactive';
|
|
6
|
+
import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
|
|
7
|
+
import { Router, ActivatedRoute } from '@angular/router';
|
|
6
8
|
import { DataSource } from '@angular/cdk/collections';
|
|
7
|
-
import { toObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
8
9
|
import { arrayEqual } from '@cngx/utils';
|
|
9
10
|
import { buildAsyncStateView, createTransitionTracker } from '@cngx/core/utils';
|
|
10
11
|
import { isObservable, firstValueFrom, defer, tap, filter, map } from 'rxjs';
|
|
@@ -615,8 +616,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
615
616
|
* @for (item of items.slice(pg.range()[0], pg.range()[1]); track item.id) { ... }
|
|
616
617
|
* </div>
|
|
617
618
|
*
|
|
618
|
-
* //
|
|
619
|
-
* <
|
|
619
|
+
* // Drive any UI off the brain - e.g. a Material paginator wired by hand:
|
|
620
|
+
* <mat-paginator
|
|
621
|
+
* [length]="pg.total()" [pageIndex]="pg.pageIndex()" [pageSize]="pg.pageSize()"
|
|
622
|
+
* (page)="pg.setPageSize($event.pageSize, false); pg.setPage($event.pageIndex)" />
|
|
620
623
|
*
|
|
621
624
|
* @category common/data/paginate
|
|
622
625
|
* @docsKind primary
|
|
@@ -626,11 +629,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
626
629
|
* @relatedTo CngxSort, CngxFilter, CngxSmartDataSource
|
|
627
630
|
*
|
|
628
631
|
* <example-url>http://localhost:4200/#/common/data/data-source/datasource-cngxpaginate-manual-pipeline</example-url>
|
|
629
|
-
* <example-url>http://localhost:4200/#/common/data/
|
|
632
|
+
* <example-url>http://localhost:4200/#/common/data/paginate-list/bridge-announce-page-changes</example-url>
|
|
633
|
+
* <example-url>http://localhost:4200/#/common/data/paginate-list/instrumentation-bridge-cngxmatpaginator</example-url>
|
|
630
634
|
* <example-url>http://localhost:4200/#/common/data/paginate-list/paginated-list-cngxpaginate-cngxmatpaginator</example-url>
|
|
631
635
|
* <example-url>http://localhost:4200/#/common/data/paginate-list/uncontrolled-mode-zero-class-boilerplate</example-url>
|
|
632
|
-
* <example-url>http://localhost:4200/#/common/data/smart-data-source/auto-wired</example-url>
|
|
633
|
-
* <example-url>http://localhost:4200/#/common/data/smart-data-source/how-it-works-hostdirectives-inject</example-url>
|
|
634
636
|
* <example-url>http://localhost:4200/#/common/data/smart-data-source/smartdatasource-cngxpaginate-hostdirective</example-url>
|
|
635
637
|
*/
|
|
636
638
|
class CngxPaginate {
|
|
@@ -674,7 +676,16 @@ class CngxPaginate {
|
|
|
674
676
|
range = computed(() => {
|
|
675
677
|
const start = this.pageIndex() * this.pageSize();
|
|
676
678
|
return [start, start + this.pageSize()];
|
|
677
|
-
}, ...(ngDevMode ?
|
|
679
|
+
}, { ...(ngDevMode ? { debugName: "range" } : /* istanbul ignore next */ {}), equal: (a, b) => a[0] === b[0] && a[1] === b[1] });
|
|
680
|
+
/**
|
|
681
|
+
* `[0, end]` cumulative slice indices for append-don't-replace (load-more)
|
|
682
|
+
* consumers: every page already stepped through, sliced from the top. `end`
|
|
683
|
+
* is `(pageIndex + 1) * pageSize` - the count revealed so far, uncapped (a
|
|
684
|
+
* partial final page is clamped by the consumer against `total`).
|
|
685
|
+
* Pure derivation of `pageIndex` / `pageSize`; the explicit tuple `equal`
|
|
686
|
+
* stops a fresh-array identity from cascading downstream.
|
|
687
|
+
*/
|
|
688
|
+
cumulativeRange = computed(() => [0, (this.pageIndex() + 1) * this.pageSize()], { ...(ngDevMode ? { debugName: "cumulativeRange" } : /* istanbul ignore next */ {}), equal: (a, b) => a[0] === b[0] && a[1] === b[1] });
|
|
678
689
|
/** Emitted when the page index changes. */
|
|
679
690
|
pageChange = output();
|
|
680
691
|
/** Emitted when the page size changes. */
|
|
@@ -734,6 +745,301 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
734
745
|
}]
|
|
735
746
|
}], propDecorators: { pageIndexInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPageIndex", required: false }] }], pageSizeInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPageSize", required: false }] }], total: [{ type: i0.Input, args: [{ isSignal: true, alias: "total", required: false }] }], state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: false }] }], pageChange: [{ type: i0.Output, args: ["pageChange"] }], pageSizeChange: [{ type: i0.Output, args: ["pageSizeChange"] }] } });
|
|
736
747
|
|
|
748
|
+
/**
|
|
749
|
+
* Wires the reset-on-change behaviour onto a {@link CngxPaginate} brain: when
|
|
750
|
+
* `key()` changes (after the initial run) the paginator jumps to the first
|
|
751
|
+
* page. The first run captures the mounting value without resetting, and an
|
|
752
|
+
* already-first paginator emits nothing.
|
|
753
|
+
*
|
|
754
|
+
* Shared by `[cngxPaginateResetOn]`, the `CngxPaginator` shell's `resetOn`
|
|
755
|
+
* input, and the `CngxMatPaginator` bridge's `resetOn` input, so the behaviour
|
|
756
|
+
* is byte-identical across all three. Call inside an injection context
|
|
757
|
+
* (constructor or field initialiser).
|
|
758
|
+
*
|
|
759
|
+
* @category common/data/paginate
|
|
760
|
+
* @since 0.1.0
|
|
761
|
+
*/
|
|
762
|
+
function connectPaginateResetOn(paginate, key) {
|
|
763
|
+
let seen = false;
|
|
764
|
+
effect(() => {
|
|
765
|
+
key();
|
|
766
|
+
if (!seen) {
|
|
767
|
+
seen = true;
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
untracked(() => {
|
|
771
|
+
if (paginate.pageIndex() !== 0) {
|
|
772
|
+
paginate.setPage(0);
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Resets a `cngxPaginate` host to the first page whenever the bound key
|
|
779
|
+
* changes - the composable form of {@link connectPaginateResetOn}. Drop it on
|
|
780
|
+
* the same element as `cngxPaginate` (or a `CngxPaginator` / `CngxMatPaginator`,
|
|
781
|
+
* which provide the brain), and bind the sort / filter / search value a result
|
|
782
|
+
* set depends on, so a narrowed result never strands the user on a now-empty
|
|
783
|
+
* page.
|
|
784
|
+
*
|
|
785
|
+
* Bind a primitive or a `computed` - an inline array / object literal recomputes
|
|
786
|
+
* every change-detection pass and would reset on each.
|
|
787
|
+
*
|
|
788
|
+
* ```html
|
|
789
|
+
* <table cngxPaginate [cngxPaginateResetOn]="filter()"><!-- ... --></table>
|
|
790
|
+
* ```
|
|
791
|
+
*
|
|
792
|
+
* @category common/data/paginate
|
|
793
|
+
* @docsKind primary
|
|
794
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/paginate/paginate-reset.directive.ts
|
|
795
|
+
* @since 0.1.0
|
|
796
|
+
* @relatedTo CngxPaginate, CngxPaginator, CngxMatPaginator
|
|
797
|
+
*/
|
|
798
|
+
class CngxPaginateResetOn {
|
|
799
|
+
paginate = inject(CngxPaginate);
|
|
800
|
+
/** The reset key. A change (after mount) jumps the paginator to page 0. */
|
|
801
|
+
key = input(undefined, { ...(ngDevMode ? { debugName: "key" } : /* istanbul ignore next */ {}), alias: 'cngxPaginateResetOn' });
|
|
802
|
+
constructor() {
|
|
803
|
+
connectPaginateResetOn(this.paginate, this.key);
|
|
804
|
+
}
|
|
805
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPaginateResetOn, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
806
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxPaginateResetOn, isStandalone: true, selector: "[cngxPaginateResetOn]", inputs: { key: { classPropertyName: "key", publicName: "cngxPaginateResetOn", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxPaginateResetOn"], ngImport: i0 });
|
|
807
|
+
}
|
|
808
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPaginateResetOn, decorators: [{
|
|
809
|
+
type: Directive,
|
|
810
|
+
args: [{
|
|
811
|
+
selector: '[cngxPaginateResetOn]',
|
|
812
|
+
exportAs: 'cngxPaginateResetOn',
|
|
813
|
+
standalone: true,
|
|
814
|
+
}]
|
|
815
|
+
}], ctorParameters: () => [], propDecorators: { key: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPaginateResetOn", required: false }] }] } });
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Persists a `cngxPaginate` host's page / size in the URL query string, so a
|
|
819
|
+
* paginated view is deep-linkable and survives reload / back / forward.
|
|
820
|
+
*
|
|
821
|
+
* Drop it on the same element as `cngxPaginate` (or a `CngxPaginator` /
|
|
822
|
+
* `CngxMatPaginator`, which provide the brain). The page is written 1-based
|
|
823
|
+
* (`?page=2`) for human-readable URLs; the brain stays 0-based.
|
|
824
|
+
*
|
|
825
|
+
* ```html
|
|
826
|
+
* <cngx-paginator cngxPaginateRouting [total]="items().length"></cngx-paginator>
|
|
827
|
+
* ```
|
|
828
|
+
*
|
|
829
|
+
* Two paginators on one route must take distinct param names via
|
|
830
|
+
* `[cngxPaginatePageParam]` / `[cngxPaginateSizeParam]` to avoid a collision.
|
|
831
|
+
* Requires `@angular/router` (`provideRouter`); without it the directive is an
|
|
832
|
+
* inert no-op (a dev-mode warning is logged). Framework-agnostic of any UI - it
|
|
833
|
+
* needs only the brain and the router.
|
|
834
|
+
*
|
|
835
|
+
* @category common/data/paginate
|
|
836
|
+
* @docsKind primary
|
|
837
|
+
* @wcag AA
|
|
838
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/paginate/paginate-routing.directive.ts
|
|
839
|
+
* @since 0.1.0
|
|
840
|
+
* @relatedTo CngxPaginate, CngxPaginator, CngxMatPaginator
|
|
841
|
+
* <example-url>http://localhost:4200/#/ui/paginator/paginator-behaviors/url-synced-paging</example-url>
|
|
842
|
+
*/
|
|
843
|
+
class CngxPaginateRouting {
|
|
844
|
+
paginate = inject(CngxPaginate);
|
|
845
|
+
router = inject(Router, { optional: true });
|
|
846
|
+
route = inject(ActivatedRoute, { optional: true });
|
|
847
|
+
destroyRef = inject(DestroyRef);
|
|
848
|
+
/** Query-param name for the 1-based page. */
|
|
849
|
+
pageParam = input('page', { ...(ngDevMode ? { debugName: "pageParam" } : /* istanbul ignore next */ {}), alias: 'cngxPaginatePageParam' });
|
|
850
|
+
/** Query-param name for the page size. */
|
|
851
|
+
sizeParam = input('pageSize', { ...(ngDevMode ? { debugName: "sizeParam" } : /* istanbul ignore next */ {}), alias: 'cngxPaginateSizeParam' });
|
|
852
|
+
// Set while applying a URL change to the brain, so the brain -> URL effect
|
|
853
|
+
// does not bounce the same value straight back as a redundant navigation.
|
|
854
|
+
applyingFromUrl = false;
|
|
855
|
+
constructor() {
|
|
856
|
+
const router = this.router;
|
|
857
|
+
const route = this.route;
|
|
858
|
+
if (!router || !route) {
|
|
859
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
860
|
+
console.warn('[cngxPaginateRouting]: no Router available - directive is a no-op. ' +
|
|
861
|
+
'Provide @angular/router via provideRouter(...) to enable URL-synced pagination.');
|
|
862
|
+
}
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
// brain -> URL. Tracks the effective page / size; merges into the existing
|
|
866
|
+
// query string and replaces history so paging does not stack back entries.
|
|
867
|
+
// The param-name inputs are read lazily inside untracked, so a late-bound
|
|
868
|
+
// alias is already set by the time the first navigation fires.
|
|
869
|
+
effect(() => {
|
|
870
|
+
const page = this.paginate.pageIndex() + 1;
|
|
871
|
+
const size = this.paginate.pageSize();
|
|
872
|
+
if (this.applyingFromUrl) {
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
untracked(() => {
|
|
876
|
+
void router.navigate([], {
|
|
877
|
+
relativeTo: route,
|
|
878
|
+
queryParams: { [this.pageParam()]: page, [this.sizeParam()]: size },
|
|
879
|
+
queryParamsHandling: 'merge',
|
|
880
|
+
replaceUrl: true,
|
|
881
|
+
});
|
|
882
|
+
});
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
ngOnInit() {
|
|
886
|
+
const route = this.route;
|
|
887
|
+
if (!route) {
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
// URL -> brain, wired in ngOnInit so the param-name inputs are resolved
|
|
891
|
+
// before queryParamMap replays the current params on subscribe (a
|
|
892
|
+
// deep-linked page / size therefore lands before first paint). The
|
|
893
|
+
// subscription stays live for back / forward navigation.
|
|
894
|
+
route.queryParamMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((params) => {
|
|
895
|
+
const size = Number(params.get(this.sizeParam()));
|
|
896
|
+
const page = Number(params.get(this.pageParam()));
|
|
897
|
+
this.applyingFromUrl = true;
|
|
898
|
+
try {
|
|
899
|
+
if (Number.isFinite(size) && size > 0 && size !== this.paginate.pageSize()) {
|
|
900
|
+
this.paginate.setPageSize(size, false);
|
|
901
|
+
}
|
|
902
|
+
const index = (Number.isFinite(page) && page > 0 ? page : 1) - 1;
|
|
903
|
+
if (index !== this.paginate.pageIndex()) {
|
|
904
|
+
this.paginate.setPage(index);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
finally {
|
|
908
|
+
this.applyingFromUrl = false;
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPaginateRouting, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
913
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxPaginateRouting, isStandalone: true, selector: "[cngxPaginateRouting]", inputs: { pageParam: { classPropertyName: "pageParam", publicName: "cngxPaginatePageParam", isSignal: true, isRequired: false, transformFunction: null }, sizeParam: { classPropertyName: "sizeParam", publicName: "cngxPaginateSizeParam", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxPaginateRouting"], ngImport: i0 });
|
|
914
|
+
}
|
|
915
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPaginateRouting, decorators: [{
|
|
916
|
+
type: Directive,
|
|
917
|
+
args: [{
|
|
918
|
+
selector: '[cngxPaginateRouting]',
|
|
919
|
+
exportAs: 'cngxPaginateRouting',
|
|
920
|
+
standalone: true,
|
|
921
|
+
}]
|
|
922
|
+
}], ctorParameters: () => [], propDecorators: { pageParam: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPaginatePageParam", required: false }] }], sizeParam: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPaginateSizeParam", required: false }] }] } });
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* DI token the `CngxBucketPaginate` range model provides via `useExisting`.
|
|
926
|
+
* The category chips segment (`cngx-pgn-alpha`) injects this rather than the
|
|
927
|
+
* concrete directive class, keeping the strip decompose-ready and the model
|
|
928
|
+
* swappable.
|
|
929
|
+
*
|
|
930
|
+
* @category common/data/paginate
|
|
931
|
+
* @wcag AA
|
|
932
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/paginate/bucket-paginate-host.token.ts
|
|
933
|
+
* @since 0.1.0
|
|
934
|
+
*/
|
|
935
|
+
const CNGX_BUCKET_PAGINATE_HOST = new InjectionToken('CngxBucketPaginateHost');
|
|
936
|
+
|
|
937
|
+
/** Two `ReadonlySet`s are equal when they hold the same members. */
|
|
938
|
+
function setEquals(a, b) {
|
|
939
|
+
if (a.size !== b.size) {
|
|
940
|
+
return false;
|
|
941
|
+
}
|
|
942
|
+
for (const value of a) {
|
|
943
|
+
if (!b.has(value)) {
|
|
944
|
+
return false;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
return true;
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Range/category pagination model - a sibling to {@link CngxPaginate}, NOT a
|
|
951
|
+
* mode flag on it. Where `CngxPaginate` steps a page index over a slice window,
|
|
952
|
+
* this directive partitions a collection into labelled buckets (letter ranges,
|
|
953
|
+
* date bands, price tiers) and tracks which one is active. The page-index brain
|
|
954
|
+
* stays single-responsibility; a consumer composes whichever model the data
|
|
955
|
+
* calls for (Komposition statt Konfiguration).
|
|
956
|
+
*
|
|
957
|
+
* The empty/disabled state of every bucket is **derived**, never managed: a
|
|
958
|
+
* bucket is empty when no bound item matches its predicate, computed from the
|
|
959
|
+
* `items` / `buckets` inputs. There is no synced flag and no effect.
|
|
960
|
+
*
|
|
961
|
+
* `active` is the two-way primary value (a `model<string | null>()`):
|
|
962
|
+
* `null` shows the unfiltered collection; a label filters to that bucket.
|
|
963
|
+
* `select(label)` toggles - re-selecting the active bucket clears it.
|
|
964
|
+
*
|
|
965
|
+
* ```html
|
|
966
|
+
* <div
|
|
967
|
+
* cngxBucketPaginate
|
|
968
|
+
* #bp="cngxBucketPaginate"
|
|
969
|
+
* [buckets]="letterBuckets"
|
|
970
|
+
* [items]="people"
|
|
971
|
+
* [(active)]="activeBucket"
|
|
972
|
+
* >
|
|
973
|
+
* @for (p of bp.active() ? people.filter(byActiveBucket) : people; track p.id) { ... }
|
|
974
|
+
* </div>
|
|
975
|
+
* ```
|
|
976
|
+
*
|
|
977
|
+
* @category common/data/paginate
|
|
978
|
+
* @docsKind primary
|
|
979
|
+
* @wcag AA
|
|
980
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/paginate/bucket-paginate.directive.ts
|
|
981
|
+
* @since 0.1.0
|
|
982
|
+
* @relatedTo CngxPaginate, CngxFilter
|
|
983
|
+
* <example-url>http://localhost:4200/#/ui/paginator/paginator-modes/alphabetical</example-url>
|
|
984
|
+
*/
|
|
985
|
+
class CngxBucketPaginate {
|
|
986
|
+
/** The buckets to partition into, in render order. One chip per entry. */
|
|
987
|
+
buckets = input([], ...(ngDevMode ? [{ debugName: "buckets" }] : /* istanbul ignore next */ []));
|
|
988
|
+
/** The collection the buckets test against. Drives the derived empty state. */
|
|
989
|
+
items = input([], ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
|
|
990
|
+
/**
|
|
991
|
+
* Active bucket label, or `null` for the unfiltered collection. The two-way
|
|
992
|
+
* primary value (`[(active)]`); a `model()` because it is the directive's
|
|
993
|
+
* bindable state, not a derived read.
|
|
994
|
+
*/
|
|
995
|
+
active = model(null, ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
996
|
+
/**
|
|
997
|
+
* Labels of every bucket whose predicate matches no bound item. A pure
|
|
998
|
+
* `computed()` over `items` / `buckets` - the disabled chips read this, so
|
|
999
|
+
* the empty state is derived, never synced. The explicit set `equal` stops a
|
|
1000
|
+
* fresh-`Set` identity from cascading downstream on every unrelated recompute.
|
|
1001
|
+
*/
|
|
1002
|
+
emptyLabels = computed(() => {
|
|
1003
|
+
const items = this.items();
|
|
1004
|
+
const empties = new Set();
|
|
1005
|
+
for (const bucket of this.buckets()) {
|
|
1006
|
+
if (!items.some((item) => bucket.match(item))) {
|
|
1007
|
+
empties.add(bucket.label);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
return empties;
|
|
1011
|
+
}, { ...(ngDevMode ? { debugName: "emptyLabels" } : /* istanbul ignore next */ {}), equal: setEquals });
|
|
1012
|
+
/** `true` when no bound item falls into the bucket. */
|
|
1013
|
+
isEmpty(label) {
|
|
1014
|
+
return this.emptyLabels().has(label);
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Select the bucket, or clear the selection when it is already active
|
|
1018
|
+
* (toggle). An empty bucket is a no-op - it never becomes the active filter.
|
|
1019
|
+
*/
|
|
1020
|
+
select(label) {
|
|
1021
|
+
if (this.isEmpty(label)) {
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
this.active.update((current) => (current === label ? null : label));
|
|
1025
|
+
}
|
|
1026
|
+
/** Clear the active bucket - show the unfiltered collection. */
|
|
1027
|
+
clear() {
|
|
1028
|
+
this.active.set(null);
|
|
1029
|
+
}
|
|
1030
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBucketPaginate, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1031
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxBucketPaginate, isStandalone: true, selector: "[cngxBucketPaginate]", inputs: { buckets: { classPropertyName: "buckets", publicName: "buckets", isSignal: true, isRequired: false, transformFunction: null }, items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, active: { classPropertyName: "active", publicName: "active", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { active: "activeChange" }, providers: [{ provide: CNGX_BUCKET_PAGINATE_HOST, useExisting: CngxBucketPaginate }], exportAs: ["cngxBucketPaginate"], ngImport: i0 });
|
|
1032
|
+
}
|
|
1033
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBucketPaginate, decorators: [{
|
|
1034
|
+
type: Directive,
|
|
1035
|
+
args: [{
|
|
1036
|
+
selector: '[cngxBucketPaginate]',
|
|
1037
|
+
exportAs: 'cngxBucketPaginate',
|
|
1038
|
+
standalone: true,
|
|
1039
|
+
providers: [{ provide: CNGX_BUCKET_PAGINATE_HOST, useExisting: CngxBucketPaginate }],
|
|
1040
|
+
}]
|
|
1041
|
+
}], propDecorators: { buckets: [{ type: i0.Input, args: [{ isSignal: true, alias: "buckets", required: false }] }], items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], active: [{ type: i0.Input, args: [{ isSignal: true, alias: "active", required: false }] }, { type: i0.Output, args: ["activeChange"] }] } });
|
|
1042
|
+
|
|
737
1043
|
/**
|
|
738
1044
|
* Minimal CDK `DataSource` that bridges a Signal to the CDK table's
|
|
739
1045
|
* Observable-based data contract.
|
|
@@ -3058,5 +3364,5 @@ function createMaterialBidirectionalSync(opts) {
|
|
|
3058
3364
|
* Generated bundle index. Do not edit.
|
|
3059
3365
|
*/
|
|
3060
3366
|
|
|
3061
|
-
export { CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_RECYCLER_I18N, CngxAsync, CngxDataSource, CngxFilter, CngxFilterChip, CngxFilterChips, CngxMeasure, CngxMetric, CngxPaginate, CngxRecyclerAnnouncer, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxTrend, CngxVirtualItem, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createManualState, createMaterialBidirectionalSync, injectAsyncState, injectDataSource, injectRecycler, injectSmartDataSource, provideRecyclerI18n, resolveAsyncView };
|
|
3367
|
+
export { CNGX_BUCKET_PAGINATE_HOST, CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_RECYCLER_I18N, CngxAsync, CngxBucketPaginate, CngxDataSource, CngxFilter, CngxFilterChip, CngxFilterChips, CngxMeasure, CngxMetric, CngxPaginate, CngxPaginateResetOn, CngxPaginateRouting, CngxRecyclerAnnouncer, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxTrend, CngxVirtualItem, connectPaginateResetOn, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createManualState, createMaterialBidirectionalSync, fromHttpResource, fromResource, injectAsyncState, injectDataSource, injectRecycler, injectSmartDataSource, provideRecyclerI18n, resolveAsyncView, tapAsyncProgress, tapAsyncState, tapHttpAsyncState };
|
|
3062
3368
|
//# sourceMappingURL=cngx-common-data.mjs.map
|