@cngx/common 0.1.0-rc.1 → 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 +10 -3
- package/fesm2022/cngx-common-data.mjs +379 -57
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-stepper.mjs +318 -5
- package/fesm2022/cngx-common-stepper.mjs.map +1 -1
- package/fesm2022/cngx-common-tabs.mjs +532 -151
- package/fesm2022/cngx-common-tabs.mjs.map +1 -1
- package/fesm2022/cngx-common.mjs +1 -1
- package/package.json +2 -2
- package/stepper/README.md +0 -13
- package/types/cngx-common-data.d.ts +446 -41
- package/types/cngx-common-stepper.d.ts +350 -6
- package/types/cngx-common-tabs.d.ts +586 -191
- package/tabs/README.md +0 -32
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.
|
|
@@ -2963,40 +3269,53 @@ const CNGX_COMMIT_CONTROLLER_FACTORY = new InjectionToken('CngxCommitControllerF
|
|
|
2963
3269
|
*
|
|
2964
3270
|
* Both sides clean up via `destroyRef`.
|
|
2965
3271
|
*
|
|
2966
|
-
* **Pessimistic-commit gate (deliberately absent).** An earlier draft
|
|
2967
|
-
* carried a third option `commitState: CngxAsyncState<unknown>` that
|
|
2968
|
-
* gated the Material write while `commitState.isPending()`. The plan
|
|
2969
|
-
* (`global-material-bridge-and-architecture-hardening-plan` §54)
|
|
2970
|
-
* specified this gate "for the pessimistic flow." Implementation
|
|
2971
|
-
* showed the gate is redundant: cngx commit handlers already keep
|
|
2972
|
-
* `presenter.activeIndex` at the origin during pessimistic-pending,
|
|
2973
|
-
* so the equality guard alone suppresses the Material write.
|
|
2974
|
-
* Conversely, in optimistic mode the presenter advances IMMEDIATELY
|
|
2975
|
-
* (before the commit settles); a `pending`-keyed gate would suppress
|
|
2976
|
-
* that legitimate advance and break the optimistic UX. Dropping the
|
|
2977
|
-
* gate makes both modes work via the simple presenter→Material
|
|
2978
|
-
* mirror — same outcome as the gate version for pessimistic, and the
|
|
2979
|
-
* correct outcome for optimistic.
|
|
2980
|
-
*
|
|
2981
3272
|
* **Material-eager-advance reconciliation.** Material's MDC click
|
|
2982
|
-
* handler advances `selectedIndex`
|
|
2983
|
-
*
|
|
2984
|
-
* `
|
|
2985
|
-
*
|
|
2986
|
-
*
|
|
2987
|
-
*
|
|
2988
|
-
*
|
|
2989
|
-
*
|
|
2990
|
-
*
|
|
2991
|
-
*
|
|
2992
|
-
*
|
|
2993
|
-
*
|
|
2994
|
-
*
|
|
3273
|
+
* handler advances `selectedIndex` *before* the Material→presenter
|
|
3274
|
+
* subscription forwards the click. When the presenter HOLDS its index
|
|
3275
|
+
* (pessimistic mode + bound `commitAction`), the subscriber does NOT
|
|
3276
|
+
* write Material back: on a SUCCESSFUL commit the presenter later
|
|
3277
|
+
* advances to the clicked target and Material is already there, so the
|
|
3278
|
+
* mirror effect is a no-op (no flash); on a REJECTED commit the presenter
|
|
3279
|
+
* never moves, leaving Material eager-advanced on the refused tab. The
|
|
3280
|
+
* host detects the rejection through its own commit lifecycle and calls
|
|
3281
|
+
* {@link CngxMaterialBidirectionalSyncHandle.reconcile} to snap Material
|
|
3282
|
+
* back. Writing from inside the subscriber instead is unsafe: Material's
|
|
3283
|
+
* `selectedIndex` read-back lags a programmatic write, so the mirror
|
|
3284
|
+
* effect's equality guard reads a stale value and skips the corrective
|
|
3285
|
+
* write, sticking the visual on the wrong tab.
|
|
3286
|
+
*
|
|
3287
|
+
* **Self-echo suppression (loop-safety).** Every programmatic
|
|
3288
|
+
* `selectedIndex` write makes Material re-emit `selectionChange`. The
|
|
3289
|
+
* factory records each value it writes and drops the matching echo
|
|
3290
|
+
* (`indexOf` + splice, which also prunes earlier writes whose echo
|
|
3291
|
+
* Material coalesced away) before any other processing. This is
|
|
3292
|
+
* load-bearing for an ASYNC commit-action: Material emits the echo a
|
|
3293
|
+
* microtask later, by which point the commit may have advanced
|
|
3294
|
+
* `presenterIndex`, so an equality-only guard (`presenterIndex() ===
|
|
3295
|
+
* idx`) would FAIL to drop the echo — it would re-enter the subscriber
|
|
3296
|
+
* and ping-pong against the in-flight navigation (the demo freezes).
|
|
3297
|
+
* Matching the echo by the value we wrote drops it regardless of where
|
|
3298
|
+
* the presenter has moved.
|
|
2995
3299
|
*
|
|
2996
3300
|
* @category common/data/material-bridge
|
|
2997
3301
|
*/
|
|
2998
3302
|
function createMaterialBidirectionalSync(opts) {
|
|
2999
3303
|
const { presenterIndex, readSelectedIndex, writeSelectedIndex, selectionChange$, onMaterialSelection, injector, destroyRef, } = opts;
|
|
3304
|
+
// Indices WE wrote into Material, awaiting their echo. Material
|
|
3305
|
+
// re-emits `selectionChange` for every programmatic `selectedIndex`
|
|
3306
|
+
// write, so each of our writes produces an echo that must NOT be
|
|
3307
|
+
// treated as a user selection. Equality against `presenterIndex()`
|
|
3308
|
+
// alone is insufficient: with an async commit-action the presenter may
|
|
3309
|
+
// have advanced by the time the echo arrives, so the echo no longer
|
|
3310
|
+
// equality-drops and would re-enter the subscriber. `indexOf` + splice
|
|
3311
|
+
// drops the echo by the value we wrote (and prunes any earlier write
|
|
3312
|
+
// whose echo Material coalesced away), regardless of where the
|
|
3313
|
+
// presenter has since moved - the loop can never form.
|
|
3314
|
+
const selfEchoes = [];
|
|
3315
|
+
const writeMaterial = (idx) => {
|
|
3316
|
+
selfEchoes.push(idx);
|
|
3317
|
+
writeSelectedIndex(idx);
|
|
3318
|
+
};
|
|
3000
3319
|
runInInjectionContext(injector, () => {
|
|
3001
3320
|
effect(() => {
|
|
3002
3321
|
const desired = presenterIndex();
|
|
@@ -3004,34 +3323,37 @@ function createMaterialBidirectionalSync(opts) {
|
|
|
3004
3323
|
if (readSelectedIndex() === desired) {
|
|
3005
3324
|
return;
|
|
3006
3325
|
}
|
|
3007
|
-
|
|
3326
|
+
writeMaterial(desired);
|
|
3008
3327
|
});
|
|
3009
3328
|
});
|
|
3010
3329
|
});
|
|
3011
|
-
selectionChange
|
|
3012
|
-
|
|
3013
|
-
.
|
|
3330
|
+
selectionChange$.pipe(takeUntilDestroyed(destroyRef)).subscribe((idx) => {
|
|
3331
|
+
// Drop our own write-echo (and any coalesced-away earlier write).
|
|
3332
|
+
const echoAt = selfEchoes.indexOf(idx);
|
|
3333
|
+
if (echoAt !== -1) {
|
|
3334
|
+
selfEchoes.splice(0, echoAt + 1);
|
|
3335
|
+
return;
|
|
3336
|
+
}
|
|
3014
3337
|
if (presenterIndex() === idx) {
|
|
3015
3338
|
return;
|
|
3016
3339
|
}
|
|
3017
3340
|
onMaterialSelection(idx);
|
|
3018
|
-
// Material
|
|
3019
|
-
//
|
|
3020
|
-
//
|
|
3021
|
-
//
|
|
3022
|
-
//
|
|
3023
|
-
//
|
|
3024
|
-
//
|
|
3025
|
-
//
|
|
3026
|
-
//
|
|
3027
|
-
//
|
|
3028
|
-
// but the early-return guard at the top of this subscriber
|
|
3029
|
-
// (`presenterIndex() === idx`) drops the re-entrant emission.
|
|
3030
|
-
const reconciled = presenterIndex();
|
|
3031
|
-
if (readSelectedIndex() !== reconciled) {
|
|
3032
|
-
writeSelectedIndex(reconciled);
|
|
3033
|
-
}
|
|
3341
|
+
// No write-back here. Material eager-advanced to the clicked tab; in
|
|
3342
|
+
// pessimistic mode the presenter HOLDS at origin, so on SUCCESS the
|
|
3343
|
+
// presenter later advances to this target and Material is already
|
|
3344
|
+
// there (no flash, no fight with Material's async `selectedIndex`).
|
|
3345
|
+
// On REJECTION the presenter never moves, leaving Material diverged -
|
|
3346
|
+
// the host detects that and calls `reconcile()` from its commit
|
|
3347
|
+
// lifecycle. Writing here while the commit is in flight is unsafe:
|
|
3348
|
+
// Material's `selectedIndex` read-back lags a programmatic write, so
|
|
3349
|
+
// the mirror effect's equality guard reads a stale value and skips
|
|
3350
|
+
// the corrective write (the visual sticks on the wrong tab).
|
|
3034
3351
|
});
|
|
3352
|
+
return {
|
|
3353
|
+
reconcile: () => {
|
|
3354
|
+
writeMaterial(presenterIndex());
|
|
3355
|
+
},
|
|
3356
|
+
};
|
|
3035
3357
|
}
|
|
3036
3358
|
|
|
3037
3359
|
/**
|
|
@@ -3042,5 +3364,5 @@ function createMaterialBidirectionalSync(opts) {
|
|
|
3042
3364
|
* Generated bundle index. Do not edit.
|
|
3043
3365
|
*/
|
|
3044
3366
|
|
|
3045
|
-
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 };
|
|
3046
3368
|
//# sourceMappingURL=cngx-common-data.mjs.map
|