@cngx/ui 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/README.md +15 -7
- package/fesm2022/cngx-ui-mat-paginator.mjs +215 -0
- package/fesm2022/cngx-ui-mat-paginator.mjs.map +1 -0
- package/fesm2022/cngx-ui-paginator.mjs +1868 -0
- package/fesm2022/cngx-ui-paginator.mjs.map +1 -0
- package/fesm2022/cngx-ui-tabs.mjs +6 -4
- package/fesm2022/cngx-ui-tabs.mjs.map +1 -1
- package/fesm2022/cngx-ui.mjs +2 -2
- package/fesm2022/cngx-ui.mjs.map +1 -1
- package/mat-paginator/README.md +135 -0
- package/package.json +9 -5
- package/paginator/README.md +131 -0
- package/types/cngx-ui-mat-paginator.d.ts +108 -0
- package/types/cngx-ui-paginator.d.ts +1035 -0
- package/types/cngx-ui-tabs.d.ts +2 -0
- package/fesm2022/cngx-ui-material.mjs +0 -90
- package/fesm2022/cngx-ui-material.mjs.map +0 -1
- package/material/README.md +0 -90
- package/types/cngx-ui-material.d.ts +0 -47
package/README.md
CHANGED
|
@@ -8,17 +8,25 @@ ready to drop into an application without additional template work.
|
|
|
8
8
|
|
|
9
9
|
### CngxMatPaginator
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
`@cngx/common`)
|
|
11
|
+
`[cngxMatPaginator]` bridge that adopts an existing `<mat-paginator>` in place -
|
|
12
|
+
the signal-native `CngxPaginate` brain (headless, `@cngx/common`) takes over its
|
|
13
|
+
state with no DOM rewrite.
|
|
13
14
|
|
|
14
15
|
```html
|
|
15
|
-
<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
<mat-paginator
|
|
17
|
+
cngxMatPaginator
|
|
18
|
+
#pg="cngxMatPaginator"
|
|
19
|
+
[total]="items().length"
|
|
20
|
+
[pageSizeOptions]="[5, 10, 25]"
|
|
21
|
+
></mat-paginator>
|
|
22
|
+
<ul>
|
|
23
|
+
@for (item of items().slice(pg.paginate.range()[0], pg.paginate.range()[1]); track item.id) {
|
|
24
|
+
<li>{{ item.label }}</li>
|
|
25
|
+
}
|
|
26
|
+
</ul>
|
|
19
27
|
```
|
|
20
28
|
|
|
21
|
-
**Inputs:** `
|
|
29
|
+
**Inputs:** `total`, `cngxPageIndex`, `cngxPageSize`, `state` (forwarded to the composed brain), `pageSizeOptions` (number[])
|
|
22
30
|
|
|
23
31
|
### CngxSpeakButton
|
|
24
32
|
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { inject, input, ElementRef, Renderer2, DestroyRef, computed, effect, untracked, Directive } from '@angular/core';
|
|
3
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
4
|
+
import { MatPaginator } from '@angular/material/paginator';
|
|
5
|
+
import * as i1 from '@cngx/common/data';
|
|
6
|
+
import { CngxPaginate, connectPaginateResetOn } from '@cngx/common/data';
|
|
7
|
+
export { CngxPaginateResetOn, CngxPaginateRouting } from '@cngx/common/data';
|
|
8
|
+
|
|
9
|
+
/** English default announcement. Localise via `[announceLabel]`. */
|
|
10
|
+
const defaultAnnounceLabel = (c) => `Page ${c.page} of ${c.totalPages}, showing items ${c.start} to ${c.end} of ${c.total}`;
|
|
11
|
+
/**
|
|
12
|
+
* The in-place adoption half of the Material paginator instrumentation: add
|
|
13
|
+
* `cngxMatPaginator` to an existing `<mat-paginator>` and the signal-native
|
|
14
|
+
* {@link CngxPaginate} brain takes over its state with no DOM rewrite, mirroring
|
|
15
|
+
* `[cngxMatStepper]` / `[cngxMatTabs]`.
|
|
16
|
+
*
|
|
17
|
+
* The bridge composes the untouched brain via `hostDirectives`, injects the
|
|
18
|
+
* consumer's own `MatPaginator` with `{ self: true }`, and syncs the four
|
|
19
|
+
* Material properties (`length` / `pageIndex` / `pageSize` / `disabled`) plus
|
|
20
|
+
* `pageSizeOptions` against the brain's `computed()` graph, forwarding `(page)`
|
|
21
|
+
* back into the brain.
|
|
22
|
+
*
|
|
23
|
+
* Beyond plain `<mat-paginator>`, the bridge adds:
|
|
24
|
+
* - `[resetOn]` - jump to the first page whenever a bound key (a sort / filter /
|
|
25
|
+
* search value) changes, so a filtered result set never strands the user on a
|
|
26
|
+
* now-empty page. Pass a primitive (or a `computed` string key); an inline
|
|
27
|
+
* array literal recomputes every change-detection pass and would reset on each.
|
|
28
|
+
* - `[announce]` - mount a visually-hidden `aria-live` region that speaks the new
|
|
29
|
+
* page + visible range after every change; `<mat-paginator>` only relabels its
|
|
30
|
+
* own range text, which AT does not announce. Localise via `[announceLabel]`.
|
|
31
|
+
* - `[cngxPaginateRouting]` (generic companion directive from `@cngx/common/data`)
|
|
32
|
+
* - persist the page / size in the URL query string for deep-linkable,
|
|
33
|
+
* back-button-safe pagination.
|
|
34
|
+
*
|
|
35
|
+
* ```html
|
|
36
|
+
* <mat-paginator
|
|
37
|
+
* cngxMatPaginator
|
|
38
|
+
* #pg="cngxMatPaginator"
|
|
39
|
+
* [total]="items.length"
|
|
40
|
+
* [pageSizeOptions]="[5, 10, 25]"
|
|
41
|
+
* />
|
|
42
|
+
* <ul>
|
|
43
|
+
* @for (item of items.slice(pg.paginate.range()[0], pg.paginate.range()[1]); track item.id) {
|
|
44
|
+
* <li>{{ item.label }}</li>
|
|
45
|
+
* }
|
|
46
|
+
* </ul>
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @category ui/mat-paginator
|
|
50
|
+
* @docsKind primary
|
|
51
|
+
* @wcag AA
|
|
52
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/ui/mat-paginator/mat-paginator-bridge.directive.ts
|
|
53
|
+
* @since 0.1.0
|
|
54
|
+
* @relatedTo CngxPaginate, CngxMatStepper, CngxPaginator
|
|
55
|
+
* <example-url>http://localhost:4200/#/common/data/data-source/datasource-cngxpaginate-manual-pipeline</example-url>
|
|
56
|
+
* <example-url>http://localhost:4200/#/common/data/paginate-list/bridge-announce-page-changes</example-url>
|
|
57
|
+
* <example-url>http://localhost:4200/#/common/data/paginate-list/instrumentation-bridge-cngxmatpaginator</example-url>
|
|
58
|
+
* <example-url>http://localhost:4200/#/common/data/paginate-list/paginated-list-cngxpaginate-cngxmatpaginator</example-url>
|
|
59
|
+
* <example-url>http://localhost:4200/#/common/data/paginate-list/uncontrolled-mode-zero-class-boilerplate</example-url>
|
|
60
|
+
*/
|
|
61
|
+
class CngxMatPaginator {
|
|
62
|
+
matPaginator = inject(MatPaginator, { self: true });
|
|
63
|
+
/**
|
|
64
|
+
* The composed {@link CngxPaginate} brain. Public so a sibling list or table
|
|
65
|
+
* outside the `<mat-paginator>` reads `range()` via `#ref="cngxMatPaginator"`.
|
|
66
|
+
*/
|
|
67
|
+
paginate = inject(CngxPaginate);
|
|
68
|
+
/** Options for the page-size selector. A Material-render concern, owned here. */
|
|
69
|
+
pageSizeOptions = input([5, 10, 25], ...(ngDevMode ? [{ debugName: "pageSizeOptions" }] : /* istanbul ignore next */ []));
|
|
70
|
+
/**
|
|
71
|
+
* Reset key. When its value changes (after the initial render) the brain jumps
|
|
72
|
+
* to the first page. Bind the sort / filter / search value a result set
|
|
73
|
+
* depends on. Pass a primitive or a `computed` - an inline array / object
|
|
74
|
+
* literal recomputes every change-detection pass and would reset every time.
|
|
75
|
+
*/
|
|
76
|
+
resetOn = input(undefined, { ...(ngDevMode ? { debugName: "resetOn" } : /* istanbul ignore next */ {}), alias: 'resetOn' });
|
|
77
|
+
/** Speak page changes through a visually-hidden `aria-live` region when `true`. */
|
|
78
|
+
announce = input(false, { ...(ngDevMode ? { debugName: "announce" } : /* istanbul ignore next */ {}), alias: 'announce' });
|
|
79
|
+
/** Builds the announcement string. Defaults to an English template. */
|
|
80
|
+
announceLabel = input(defaultAnnounceLabel, { ...(ngDevMode ? { debugName: "announceLabel" } : /* istanbul ignore next */ {}), alias: 'announceLabel' });
|
|
81
|
+
elementRef = inject(ElementRef);
|
|
82
|
+
renderer = inject(Renderer2);
|
|
83
|
+
destroyRef = inject(DestroyRef);
|
|
84
|
+
/** The live-region message - derived, so it never drifts from brain state. */
|
|
85
|
+
announceMessage = computed(() => {
|
|
86
|
+
const total = this.paginate.total();
|
|
87
|
+
const start = total === 0 ? 0 : this.paginate.range()[0] + 1;
|
|
88
|
+
const end = Math.min(this.paginate.range()[1], total);
|
|
89
|
+
return this.announceLabel()({
|
|
90
|
+
page: this.paginate.pageIndex() + 1,
|
|
91
|
+
totalPages: this.paginate.totalPages(),
|
|
92
|
+
start,
|
|
93
|
+
end,
|
|
94
|
+
total,
|
|
95
|
+
});
|
|
96
|
+
}, ...(ngDevMode ? [{ debugName: "announceMessage" }] : /* istanbul ignore next */ []));
|
|
97
|
+
liveRegion = null;
|
|
98
|
+
constructor() {
|
|
99
|
+
effect(() => {
|
|
100
|
+
const length = this.paginate.total();
|
|
101
|
+
const pageIndex = this.paginate.pageIndex();
|
|
102
|
+
const pageSize = this.paginate.pageSize();
|
|
103
|
+
const busy = this.paginate.isBusy();
|
|
104
|
+
const options = this.pageSizeOptions();
|
|
105
|
+
untracked(() => {
|
|
106
|
+
// `length` and `pageIndex` setters self-call markForCheck on
|
|
107
|
+
// MatPaginator's OnPush view; writing them every run dirties the view
|
|
108
|
+
// so the non-self-dirtying writes below flush in the same re-render -
|
|
109
|
+
// including the disabled-only case where busy flips while page and
|
|
110
|
+
// total hold. `pageSize` is written before `pageSizeOptions` so the
|
|
111
|
+
// displayed-options merge keeps the active size selectable.
|
|
112
|
+
this.matPaginator.length = length;
|
|
113
|
+
this.matPaginator.pageSize = pageSize;
|
|
114
|
+
this.matPaginator.pageSizeOptions = options;
|
|
115
|
+
this.matPaginator.pageIndex = pageIndex;
|
|
116
|
+
this.matPaginator.disabled = busy;
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
this.matPaginator.page.pipe(takeUntilDestroyed()).subscribe((event) => {
|
|
120
|
+
// setPageSize(..., false) suppresses the implicit page reset so the
|
|
121
|
+
// explicit setPage below lands the index mat-paginator already computed.
|
|
122
|
+
// No property setter emits `page`, so these brain writes never re-enter
|
|
123
|
+
// through this subscription; the path is loop-free without an echo guard.
|
|
124
|
+
this.paginate.setPageSize(event.pageSize, false);
|
|
125
|
+
this.paginate.setPage(event.pageIndex);
|
|
126
|
+
});
|
|
127
|
+
// Reset-on-change, shared verbatim with the shell input and the generic
|
|
128
|
+
// [cngxPaginateResetOn] directive.
|
|
129
|
+
connectPaginateResetOn(this.paginate, this.resetOn);
|
|
130
|
+
// AT announcement. The region is created lazily on first opt-in, then its
|
|
131
|
+
// text tracks the derived message. textContent is written through the
|
|
132
|
+
// renderer so it stays SSR-safe.
|
|
133
|
+
effect(() => {
|
|
134
|
+
if (!this.announce()) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const message = this.announceMessage();
|
|
138
|
+
untracked(() => {
|
|
139
|
+
this.liveRegion ??= this.createLiveRegion();
|
|
140
|
+
this.renderer.setProperty(this.liveRegion, 'textContent', message);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
this.destroyRef.onDestroy(() => this.liveRegion?.remove());
|
|
144
|
+
}
|
|
145
|
+
/** A visually-hidden polite live region appended to the host paginator. */
|
|
146
|
+
createLiveRegion() {
|
|
147
|
+
const span = this.renderer.createElement('span');
|
|
148
|
+
this.renderer.addClass(span, 'cngx-mat-paginator-live');
|
|
149
|
+
this.renderer.setAttribute(span, 'aria-live', 'polite');
|
|
150
|
+
this.renderer.setAttribute(span, 'aria-atomic', 'true');
|
|
151
|
+
this.renderer.setAttribute(span, 'role', 'status');
|
|
152
|
+
// Inline sr-only - the bridge ships no stylesheet, so it cannot rely on a
|
|
153
|
+
// visually-hidden class being present in the consumer's CSS.
|
|
154
|
+
for (const [prop, value] of [
|
|
155
|
+
['position', 'absolute'],
|
|
156
|
+
['width', '1px'],
|
|
157
|
+
['height', '1px'],
|
|
158
|
+
['margin', '-1px'],
|
|
159
|
+
['padding', '0'],
|
|
160
|
+
['overflow', 'hidden'],
|
|
161
|
+
['clip', 'rect(0 0 0 0)'],
|
|
162
|
+
['clip-path', 'inset(50%)'],
|
|
163
|
+
['white-space', 'nowrap'],
|
|
164
|
+
['border', '0'],
|
|
165
|
+
]) {
|
|
166
|
+
this.renderer.setStyle(span, prop, value);
|
|
167
|
+
}
|
|
168
|
+
this.renderer.appendChild(this.elementRef.nativeElement, span);
|
|
169
|
+
return span;
|
|
170
|
+
}
|
|
171
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMatPaginator, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
172
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxMatPaginator, isStandalone: true, selector: "[cngxMatPaginator]", inputs: { pageSizeOptions: { classPropertyName: "pageSizeOptions", publicName: "pageSizeOptions", isSignal: true, isRequired: false, transformFunction: null }, resetOn: { classPropertyName: "resetOn", publicName: "resetOn", isSignal: true, isRequired: false, transformFunction: null }, announce: { classPropertyName: "announce", publicName: "announce", isSignal: true, isRequired: false, transformFunction: null }, announceLabel: { classPropertyName: "announceLabel", publicName: "announceLabel", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.aria-busy": "paginate.isBusy()" } }, exportAs: ["cngxMatPaginator"], hostDirectives: [{ directive: i1.CngxPaginate, inputs: ["cngxPageIndex", "cngxPageIndex", "cngxPageSize", "cngxPageSize", "total", "total", "state", "state"], outputs: ["pageChange", "pageChange", "pageSizeChange", "pageSizeChange"] }], ngImport: i0 });
|
|
173
|
+
}
|
|
174
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMatPaginator, decorators: [{
|
|
175
|
+
type: Directive,
|
|
176
|
+
args: [{
|
|
177
|
+
selector: '[cngxMatPaginator]',
|
|
178
|
+
exportAs: 'cngxMatPaginator',
|
|
179
|
+
standalone: true,
|
|
180
|
+
host: {
|
|
181
|
+
// MatPaginator disables its nav buttons on busy but says nothing about why;
|
|
182
|
+
// aria-busy on the host communicates the updating state to AT, reactively.
|
|
183
|
+
'[attr.aria-busy]': 'paginate.isBusy()',
|
|
184
|
+
},
|
|
185
|
+
hostDirectives: [
|
|
186
|
+
{
|
|
187
|
+
directive: CngxPaginate,
|
|
188
|
+
inputs: ['cngxPageIndex', 'cngxPageSize', 'total', 'state'],
|
|
189
|
+
outputs: ['pageChange', 'pageSizeChange'],
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
}]
|
|
193
|
+
}], ctorParameters: () => [], propDecorators: { pageSizeOptions: [{ type: i0.Input, args: [{ isSignal: true, alias: "pageSizeOptions", required: false }] }], resetOn: [{ type: i0.Input, args: [{ isSignal: true, alias: "resetOn", required: false }] }], announce: [{ type: i0.Input, args: [{ isSignal: true, alias: "announce", required: false }] }], announceLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "announceLabel", required: false }] }] } });
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @module @cngx/ui/mat-paginator
|
|
197
|
+
*
|
|
198
|
+
* Material instrumentation for `<mat-paginator>`: the `[cngxMatPaginator]` bridge
|
|
199
|
+
* `CngxMatPaginator` adopts an existing `<mat-paginator>` in place, letting the
|
|
200
|
+
* signal-native `CngxPaginate` brain drive its state with no DOM rewrite. It adds
|
|
201
|
+
* `[resetOn]` (reset to first on upstream change) and `[announce]` (live-region
|
|
202
|
+
* page announcements).
|
|
203
|
+
*
|
|
204
|
+
* The brain-level `CngxPaginateResetOn` / `CngxPaginateRouting` companion
|
|
205
|
+
* directives (deep-link / reset for any `cngxPaginate` host) live in
|
|
206
|
+
* `@cngx/common/data`; they are re-exported here for discoverability alongside
|
|
207
|
+
* the bridge.
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Generated bundle index. Do not edit.
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
export { CngxMatPaginator };
|
|
215
|
+
//# sourceMappingURL=cngx-ui-mat-paginator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cngx-ui-mat-paginator.mjs","sources":["../../../projects/ui/mat-paginator/mat-paginator-bridge.directive.ts","../../../projects/ui/mat-paginator/public-api.ts","../../../projects/ui/mat-paginator/cngx-ui-mat-paginator.ts"],"sourcesContent":["import {\n computed,\n DestroyRef,\n Directive,\n effect,\n ElementRef,\n inject,\n input,\n Renderer2,\n untracked,\n} from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { MatPaginator, type PageEvent } from '@angular/material/paginator';\nimport { CngxPaginate, connectPaginateResetOn } from '@cngx/common/data';\n\n/**\n * Context handed to {@link CngxMatPaginator.announceLabel} to build the\n * screen-reader announcement after each page / page-size change.\n *\n * @category ui/mat-paginator\n */\nexport interface CngxMatPaginatorAnnounceContext {\n /** 1-based current page. */\n readonly page: number;\n /** Total page count (minimum 1). */\n readonly totalPages: number;\n /** 1-based index of the first item on the page. */\n readonly start: number;\n /** 1-based index of the last item on the page, capped at `total`. */\n readonly end: number;\n /** Total item count before pagination. */\n readonly total: number;\n}\n\n/** English default announcement. Localise via `[announceLabel]`. */\nconst defaultAnnounceLabel = (c: CngxMatPaginatorAnnounceContext): string =>\n `Page ${c.page} of ${c.totalPages}, showing items ${c.start} to ${c.end} of ${c.total}`;\n\n/**\n * The in-place adoption half of the Material paginator instrumentation: add\n * `cngxMatPaginator` to an existing `<mat-paginator>` and the signal-native\n * {@link CngxPaginate} brain takes over its state with no DOM rewrite, mirroring\n * `[cngxMatStepper]` / `[cngxMatTabs]`.\n *\n * The bridge composes the untouched brain via `hostDirectives`, injects the\n * consumer's own `MatPaginator` with `{ self: true }`, and syncs the four\n * Material properties (`length` / `pageIndex` / `pageSize` / `disabled`) plus\n * `pageSizeOptions` against the brain's `computed()` graph, forwarding `(page)`\n * back into the brain.\n *\n * Beyond plain `<mat-paginator>`, the bridge adds:\n * - `[resetOn]` - jump to the first page whenever a bound key (a sort / filter /\n * search value) changes, so a filtered result set never strands the user on a\n * now-empty page. Pass a primitive (or a `computed` string key); an inline\n * array literal recomputes every change-detection pass and would reset on each.\n * - `[announce]` - mount a visually-hidden `aria-live` region that speaks the new\n * page + visible range after every change; `<mat-paginator>` only relabels its\n * own range text, which AT does not announce. Localise via `[announceLabel]`.\n * - `[cngxPaginateRouting]` (generic companion directive from `@cngx/common/data`)\n * - persist the page / size in the URL query string for deep-linkable,\n * back-button-safe pagination.\n *\n * ```html\n * <mat-paginator\n * cngxMatPaginator\n * #pg=\"cngxMatPaginator\"\n * [total]=\"items.length\"\n * [pageSizeOptions]=\"[5, 10, 25]\"\n * />\n * <ul>\n * @for (item of items.slice(pg.paginate.range()[0], pg.paginate.range()[1]); track item.id) {\n * <li>{{ item.label }}</li>\n * }\n * </ul>\n * ```\n *\n * @category ui/mat-paginator\n * @docsKind primary\n * @wcag AA\n * @github https://github.com/cngxjs/cngx/blob/main/projects/ui/mat-paginator/mat-paginator-bridge.directive.ts\n * @since 0.1.0\n * @relatedTo CngxPaginate, CngxMatStepper, CngxPaginator\n * <example-url>http://localhost:4200/#/common/data/data-source/datasource-cngxpaginate-manual-pipeline</example-url>\n * <example-url>http://localhost:4200/#/common/data/paginate-list/bridge-announce-page-changes</example-url>\n * <example-url>http://localhost:4200/#/common/data/paginate-list/instrumentation-bridge-cngxmatpaginator</example-url>\n * <example-url>http://localhost:4200/#/common/data/paginate-list/paginated-list-cngxpaginate-cngxmatpaginator</example-url>\n * <example-url>http://localhost:4200/#/common/data/paginate-list/uncontrolled-mode-zero-class-boilerplate</example-url>\n */\n@Directive({\n selector: '[cngxMatPaginator]',\n exportAs: 'cngxMatPaginator',\n standalone: true,\n host: {\n // MatPaginator disables its nav buttons on busy but says nothing about why;\n // aria-busy on the host communicates the updating state to AT, reactively.\n '[attr.aria-busy]': 'paginate.isBusy()',\n },\n hostDirectives: [\n {\n directive: CngxPaginate,\n inputs: ['cngxPageIndex', 'cngxPageSize', 'total', 'state'],\n outputs: ['pageChange', 'pageSizeChange'],\n },\n ],\n})\nexport class CngxMatPaginator {\n private readonly matPaginator = inject(MatPaginator, { self: true });\n /**\n * The composed {@link CngxPaginate} brain. Public so a sibling list or table\n * outside the `<mat-paginator>` reads `range()` via `#ref=\"cngxMatPaginator\"`.\n */\n readonly paginate = inject(CngxPaginate);\n\n /** Options for the page-size selector. A Material-render concern, owned here. */\n readonly pageSizeOptions = input<number[]>([5, 10, 25]);\n\n /**\n * Reset key. When its value changes (after the initial render) the brain jumps\n * to the first page. Bind the sort / filter / search value a result set\n * depends on. Pass a primitive or a `computed` - an inline array / object\n * literal recomputes every change-detection pass and would reset every time.\n */\n readonly resetOn = input<unknown>(undefined, { alias: 'resetOn' });\n\n /** Speak page changes through a visually-hidden `aria-live` region when `true`. */\n readonly announce = input(false, { alias: 'announce' });\n\n /** Builds the announcement string. Defaults to an English template. */\n readonly announceLabel = input<(context: CngxMatPaginatorAnnounceContext) => string>(\n defaultAnnounceLabel,\n { alias: 'announceLabel' },\n );\n\n private readonly elementRef = inject<ElementRef<HTMLElement>>(ElementRef);\n private readonly renderer = inject(Renderer2);\n private readonly destroyRef = inject(DestroyRef);\n\n /** The live-region message - derived, so it never drifts from brain state. */\n private readonly announceMessage = computed(() => {\n const total = this.paginate.total();\n const start = total === 0 ? 0 : this.paginate.range()[0] + 1;\n const end = Math.min(this.paginate.range()[1], total);\n return this.announceLabel()({\n page: this.paginate.pageIndex() + 1,\n totalPages: this.paginate.totalPages(),\n start,\n end,\n total,\n });\n });\n\n private liveRegion: HTMLElement | null = null;\n\n constructor() {\n effect(() => {\n const length = this.paginate.total();\n const pageIndex = this.paginate.pageIndex();\n const pageSize = this.paginate.pageSize();\n const busy = this.paginate.isBusy();\n const options = this.pageSizeOptions();\n untracked(() => {\n // `length` and `pageIndex` setters self-call markForCheck on\n // MatPaginator's OnPush view; writing them every run dirties the view\n // so the non-self-dirtying writes below flush in the same re-render -\n // including the disabled-only case where busy flips while page and\n // total hold. `pageSize` is written before `pageSizeOptions` so the\n // displayed-options merge keeps the active size selectable.\n this.matPaginator.length = length;\n this.matPaginator.pageSize = pageSize;\n this.matPaginator.pageSizeOptions = options;\n this.matPaginator.pageIndex = pageIndex;\n this.matPaginator.disabled = busy;\n });\n });\n\n this.matPaginator.page.pipe(takeUntilDestroyed()).subscribe((event: PageEvent) => {\n // setPageSize(..., false) suppresses the implicit page reset so the\n // explicit setPage below lands the index mat-paginator already computed.\n // No property setter emits `page`, so these brain writes never re-enter\n // through this subscription; the path is loop-free without an echo guard.\n this.paginate.setPageSize(event.pageSize, false);\n this.paginate.setPage(event.pageIndex);\n });\n\n // Reset-on-change, shared verbatim with the shell input and the generic\n // [cngxPaginateResetOn] directive.\n connectPaginateResetOn(this.paginate, this.resetOn);\n\n // AT announcement. The region is created lazily on first opt-in, then its\n // text tracks the derived message. textContent is written through the\n // renderer so it stays SSR-safe.\n effect(() => {\n if (!this.announce()) {\n return;\n }\n const message = this.announceMessage();\n untracked(() => {\n this.liveRegion ??= this.createLiveRegion();\n this.renderer.setProperty(this.liveRegion, 'textContent', message);\n });\n });\n\n this.destroyRef.onDestroy(() => this.liveRegion?.remove());\n }\n\n /** A visually-hidden polite live region appended to the host paginator. */\n private createLiveRegion(): HTMLElement {\n const span = this.renderer.createElement('span') as HTMLElement;\n this.renderer.addClass(span, 'cngx-mat-paginator-live');\n this.renderer.setAttribute(span, 'aria-live', 'polite');\n this.renderer.setAttribute(span, 'aria-atomic', 'true');\n this.renderer.setAttribute(span, 'role', 'status');\n // Inline sr-only - the bridge ships no stylesheet, so it cannot rely on a\n // visually-hidden class being present in the consumer's CSS.\n for (const [prop, value] of [\n ['position', 'absolute'],\n ['width', '1px'],\n ['height', '1px'],\n ['margin', '-1px'],\n ['padding', '0'],\n ['overflow', 'hidden'],\n ['clip', 'rect(0 0 0 0)'],\n ['clip-path', 'inset(50%)'],\n ['white-space', 'nowrap'],\n ['border', '0'],\n ]) {\n this.renderer.setStyle(span, prop, value);\n }\n this.renderer.appendChild(this.elementRef.nativeElement, span);\n return span;\n }\n}\n","/**\n * @module @cngx/ui/mat-paginator\n *\n * Material instrumentation for `<mat-paginator>`: the `[cngxMatPaginator]` bridge\n * `CngxMatPaginator` adopts an existing `<mat-paginator>` in place, letting the\n * signal-native `CngxPaginate` brain drive its state with no DOM rewrite. It adds\n * `[resetOn]` (reset to first on upstream change) and `[announce]` (live-region\n * page announcements).\n *\n * The brain-level `CngxPaginateResetOn` / `CngxPaginateRouting` companion\n * directives (deep-link / reset for any `cngxPaginate` host) live in\n * `@cngx/common/data`; they are re-exported here for discoverability alongside\n * the bridge.\n */\nexport {\n CngxMatPaginator,\n type CngxMatPaginatorAnnounceContext,\n} from './mat-paginator-bridge.directive';\nexport { CngxPaginateResetOn, CngxPaginateRouting } from '@cngx/common/data';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;AAkCA;AACA,MAAM,oBAAoB,GAAG,CAAC,CAAkC,KAC9D,CAAA,KAAA,EAAQ,CAAC,CAAC,IAAI,CAAA,IAAA,EAAO,CAAC,CAAC,UAAU,CAAA,gBAAA,EAAmB,CAAC,CAAC,KAAK,CAAA,IAAA,EAAO,CAAC,CAAC,GAAG,CAAA,IAAA,EAAO,CAAC,CAAC,KAAK,CAAA,CAAE;AAEzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDG;MAkBU,gBAAgB,CAAA;IACV,YAAY,GAAG,MAAM,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACpE;;;AAGG;AACM,IAAA,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC;;IAG/B,eAAe,GAAG,KAAK,CAAW,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAA,IAAA,SAAA,GAAA,CAAA,EAAA,SAAA,EAAA,iBAAA,EAAA,CAAA,8BAAA,EAAA,C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