@nanahoshi/mona-ui 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,173 @@
1
+ import { G as GridNavigationService, a as GridService, g as gridListBaseThemeVariants, e as gridFooterThemeVariants, f as gridFooterTableThemeVariants, c as gridListTableThemeVariants, h as GRID_DEFAULT_VIRTUAL_ROW_HEIGHT, d as GridColgroupComponent } from './nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-bduDEm-x.mjs';
2
+ import { CdkVirtualScrollViewport, CdkFixedSizeVirtualScroll, CdkVirtualForOf } from '@angular/cdk/scrolling';
3
+ import * as i0 from '@angular/core';
4
+ import { inject, DestroyRef, ElementRef, Injector, viewChild, computed, input, effect, untracked, afterNextRender, ChangeDetectionStrategy, Component } from '@angular/core';
5
+ import { toObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';
6
+ import { ImmutableList } from '@mirei/ts-collections';
7
+ import { rxTimeout } from '@nanahoshi/mona-ui/internal';
8
+ import { fromEvent } from 'rxjs';
9
+ import { G as GridAddRowComponent, a as GridDetailRowComponent, b as GridGroupRowComponent, c as GridRowComponent } from './nanahoshi-mona-ui-grid-grid-row.component-Dwy8hCm7.mjs';
10
+ import { GridFooterRowComponent } from './nanahoshi-mona-ui-grid-grid-footer-row.component--nF_Q7Bd.mjs';
11
+
12
+ class GridVirtualListComponent {
13
+ #destroyRef;
14
+ #gridNavigationService;
15
+ #groupColumns$;
16
+ #hostElementRef;
17
+ #injector;
18
+ constructor() {
19
+ this.#destroyRef = inject(DestroyRef);
20
+ this.#gridNavigationService = inject(GridNavigationService);
21
+ this.#groupColumns$ = toObservable(inject(GridService).groupColumns);
22
+ this.#hostElementRef = inject((ElementRef));
23
+ this.#injector = inject(Injector);
24
+ this.addRowScrollElementRef = viewChild("addRowScrollElement", /* @ts-ignore */
25
+ ...(ngDevMode ? [{ debugName: "addRowScrollElementRef" }] : /* istanbul ignore next */ []));
26
+ this.bodyTableElementRef = viewChild.required("bodyTable", /* @ts-ignore */
27
+ ...(ngDevMode ? [{ debugName: "bodyTableElementRef" }] : /* istanbul ignore next */ []));
28
+ this.footerScrollElementRef = viewChild("footerScrollElement", /* @ts-ignore */
29
+ ...(ngDevMode ? [{ debugName: "footerScrollElementRef" }] : /* istanbul ignore next */ []));
30
+ this.baseClass = computed(() => {
31
+ return (gridListBaseThemeVariants({ virtual: true }) +
32
+ " [&_mona-grid-toggle>span]:min-h-0 [&_mona-grid-toggle>span]:h-full" +
33
+ " [&_mona-grid-command-cell]:min-h-0 [&_mona-grid-command-cell>div]:min-h-0");
34
+ }, /* @ts-ignore */
35
+ ...(ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []));
36
+ this.bodyRows = computed(() => this.gridService.createBodyRows(this.data()), /* @ts-ignore */
37
+ ...(ngDevMode ? [{ debugName: "bodyRows" }] : /* istanbul ignore next */ []));
38
+ this.footerClass = computed(() => {
39
+ return gridFooterThemeVariants();
40
+ }, /* @ts-ignore */
41
+ ...(ngDevMode ? [{ debugName: "footerClass" }] : /* istanbul ignore next */ []));
42
+ this.footerTableClass = computed(() => {
43
+ return gridFooterTableThemeVariants();
44
+ }, /* @ts-ignore */
45
+ ...(ngDevMode ? [{ debugName: "footerTableClass" }] : /* istanbul ignore next */ []));
46
+ this.gridService = inject(GridService);
47
+ this.tableClass = computed(() => {
48
+ return gridListTableThemeVariants();
49
+ }, /* @ts-ignore */
50
+ ...(ngDevMode ? [{ debugName: "tableClass" }] : /* istanbul ignore next */ []));
51
+ this.viewport = viewChild.required(CdkVirtualScrollViewport, /* @ts-ignore */
52
+ ...(ngDevMode ? [{ debugName: "viewport" }] : /* istanbul ignore next */ []));
53
+ this.data = input(ImmutableList.create(), /* @ts-ignore */
54
+ ...(ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []));
55
+ effect(() => {
56
+ const footerScrollElement = this.footerScrollElementRef()?.nativeElement ?? null;
57
+ untracked(() => this.gridService.footerScrollElement.set(footerScrollElement));
58
+ });
59
+ effect(() => {
60
+ const addRowScrollElement = this.addRowScrollElementRef()?.nativeElement ?? null;
61
+ const scrollLeft = this.gridService.horizontalScrollLeft();
62
+ untracked(() => this.setElementScrollLeft(addRowScrollElement, scrollLeft));
63
+ });
64
+ afterNextRender({
65
+ read: () => {
66
+ const bodyTableElement = this.bodyTableElementRef().nativeElement;
67
+ const bodyScrollElement = this.#hostElementRef.nativeElement.querySelector(".cdk-virtual-scroll-viewport");
68
+ this.gridService.bodyTableElement.set(bodyTableElement);
69
+ this.gridService.bodyScrollElement.set(bodyScrollElement);
70
+ this.setFocusSubscription();
71
+ this.setScrollEndSubscription();
72
+ this.#destroyRef.onDestroy(() => {
73
+ if (this.gridService.bodyTableElement() === bodyTableElement) {
74
+ this.gridService.bodyTableElement.set(null);
75
+ }
76
+ if (bodyScrollElement != null && this.gridService.bodyScrollElement() === bodyScrollElement) {
77
+ this.gridService.bodyScrollElement.set(null);
78
+ }
79
+ if (this.gridService.footerScrollElement() === this.footerScrollElementRef()?.nativeElement) {
80
+ this.gridService.footerScrollElement.set(null);
81
+ }
82
+ });
83
+ }
84
+ });
85
+ this.setGroupSubscriptions();
86
+ this.setSelectedKeysLoadSubscription();
87
+ }
88
+ onViewportFocus() {
89
+ this.#gridNavigationService.focusActiveCellOrFirstHeader();
90
+ }
91
+ trackBodyRow(_, bodyRow) {
92
+ return bodyRow.key;
93
+ }
94
+ setElementScrollLeft(element, scrollLeft) {
95
+ if (element != null && element.scrollLeft !== scrollLeft) {
96
+ element.scrollLeft = scrollLeft;
97
+ }
98
+ }
99
+ setFocusSubscription() {
100
+ fromEvent(this.#hostElementRef.nativeElement, "focus")
101
+ .pipe(takeUntilDestroyed(this.#destroyRef))
102
+ .subscribe(() => {
103
+ this.#gridNavigationService.focusActiveCellOrFirstHeader();
104
+ });
105
+ }
106
+ setGroupSubscriptions() {
107
+ // Workaround for @angular/components issue #21793 — virtual scroll does not update
108
+ // the rendered range when data changes until the user scrolls.
109
+ this.#groupColumns$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => {
110
+ afterNextRender(() => {
111
+ const renderedRange = this.viewport().getRenderedRange();
112
+ this.viewport().setRenderedRange({
113
+ start: renderedRange.start,
114
+ end: renderedRange.end + 1
115
+ });
116
+ }, { injector: this.#injector });
117
+ });
118
+ }
119
+ setScrollEndSubscription() {
120
+ const viewport = this.viewport();
121
+ viewport.scrolledIndexChange.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => {
122
+ const bottomOffset = viewport.measureScrollOffset("bottom");
123
+ const itemHeight = this.gridService.virtualScrollOptions().height ?? GRID_DEFAULT_VIRTUAL_ROW_HEIGHT;
124
+ const threshold = this.gridService.scrollEndThreshold();
125
+ if (bottomOffset <= threshold * itemHeight) {
126
+ this.gridService.scrollEnd$.next();
127
+ }
128
+ });
129
+ }
130
+ setSelectedKeysLoadSubscription() {
131
+ this.gridService.selectedKeysLoad$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(selectedKeys => {
132
+ const firstKey = selectedKeys.firstOrDefault();
133
+ const selectBy = this.gridService.selectBy();
134
+ if (firstKey == null || selectBy == null) {
135
+ return;
136
+ }
137
+ const index = this.bodyRows().findIndex(bodyRow => {
138
+ if (bodyRow.type !== "data") {
139
+ return false;
140
+ }
141
+ const key = typeof selectBy === "string" ? bodyRow.row.data[selectBy] : selectBy(bodyRow.row.data);
142
+ return key === firstKey;
143
+ });
144
+ if (index !== -1) {
145
+ rxTimeout(this.#destroyRef, () => {
146
+ this.viewport().scrollToIndex(index);
147
+ });
148
+ }
149
+ });
150
+ }
151
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: GridVirtualListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
152
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: GridVirtualListComponent, isStandalone: true, selector: "mona-grid-virtual-list", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class": "baseClass()", "style.--mona-grid-row-height": "gridService.virtualScrollOptions().height + 'px'" } }, viewQueries: [{ propertyName: "addRowScrollElementRef", first: true, predicate: ["addRowScrollElement"], descendants: true, isSignal: true }, { propertyName: "bodyTableElementRef", first: true, predicate: ["bodyTable"], descendants: true, isSignal: true }, { propertyName: "footerScrollElementRef", first: true, predicate: ["footerScrollElement"], descendants: true, isSignal: true }, { propertyName: "viewport", first: true, predicate: CdkVirtualScrollViewport, descendants: true, isSignal: true }], ngImport: i0, template: "@if (gridService.addRowVisible()) {\n <div\n class=\"shrink-0 overflow-hidden border-b border-b-border\"\n [style.margin-inline-end.px]=\"gridService.scrollbarGutterWidth()\"\n #addRowScrollElement>\n <table role=\"presentation\" [class]=\"tableClass()\" [style.width.px]=\"gridService.tableWidth()\">\n <colgroup monaGridColgroup></colgroup>\n <tbody role=\"rowgroup\">\n <tr monaGridAddRow></tr>\n </tbody>\n </table>\n </div>\n}\n\n<cdk-virtual-scroll-viewport\n class=\"flex-1 min-h-0\"\n [itemSize]=\"gridService.virtualScrollOptions().height\"\n [minBufferPx]=\"gridService.virtualGridMinBuffer()\"\n [maxBufferPx]=\"gridService.virtualGridMaxBuffer()\">\n <table role=\"presentation\" #bodyTable [class]=\"tableClass()\" [style.width.px]=\"gridService.tableWidth()\">\n <colgroup monaGridColgroup></colgroup>\n <tbody role=\"rowgroup\" tabindex=\"0\" (focus)=\"onViewportFocus()\">\n <ng-container *cdkVirtualFor=\"let bodyRow of bodyRows(); let rowIndex = index; trackBy: trackBodyRow\">\n @if (bodyRow.type === \"group\") {\n <tr monaGridGroupRow [group]=\"bodyRow\" [rowIndex]=\"rowIndex\"></tr>\n } @else if (bodyRow.type === \"groupFooter\") {\n <tr monaGridFooterRow [groupKey]=\"bodyRow.groupAggregate.groupKey\"></tr>\n } @else {\n <tr monaGridRow [row]=\"bodyRow.row\" [index]=\"rowIndex\"></tr>\n @if (gridService.isRowExpanded(bodyRow.row) && !gridService.rowDragInProgress()) {\n <tr monaGridDetailRow [row]=\"bodyRow.row\"></tr>\n }\n }\n </ng-container>\n </tbody>\n </table>\n</cdk-virtual-scroll-viewport>\n\n@if (gridService.hasFooter()) {\n <div [class]=\"footerClass()\" [style.margin-inline-end.px]=\"gridService.scrollbarGutterWidth()\" #footerScrollElement>\n <div>\n <table role=\"presentation\" [class]=\"footerTableClass()\" [style.width.px]=\"gridService.tableWidth()\">\n <colgroup monaGridColgroup></colgroup>\n <tfoot role=\"rowgroup\">\n <tr monaGridFooterRow></tr>\n </tfoot>\n </table>\n </div>\n </div>\n}\n", dependencies: [{ kind: "component", type: CdkVirtualScrollViewport, selector: "cdk-virtual-scroll-viewport", inputs: ["orientation", "appendOnly"], outputs: ["scrolledIndexChange"] }, { kind: "directive", type: CdkFixedSizeVirtualScroll, selector: "cdk-virtual-scroll-viewport[itemSize]", inputs: ["itemSize", "minBufferPx", "maxBufferPx"] }, { kind: "directive", type: CdkVirtualForOf, selector: "[cdkVirtualFor][cdkVirtualForOf]", inputs: ["cdkVirtualForOf", "cdkVirtualForTrackBy", "cdkVirtualForTemplate", "cdkVirtualForTemplateCacheSize"] }, { kind: "component", type: GridAddRowComponent, selector: "tr[monaGridAddRow]" }, { kind: "component", type: GridColgroupComponent, selector: "colgroup[monaGridColgroup]" }, { kind: "component", type: GridDetailRowComponent, selector: "tr[monaGridDetailRow]", inputs: ["row"] }, { kind: "component", type: GridFooterRowComponent, selector: "tr[monaGridFooterRow]", inputs: ["groupKey"] }, { kind: "component", type: GridGroupRowComponent, selector: "tr[monaGridGroupRow]", inputs: ["group", "rowIndex"] }, { kind: "component", type: GridRowComponent, selector: "tr[monaGridRow]", inputs: ["index", "row"], exportAs: ["monaGridRow"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
153
+ }
154
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: GridVirtualListComponent, decorators: [{
155
+ type: Component,
156
+ args: [{ selector: "mona-grid-virtual-list", imports: [
157
+ CdkVirtualScrollViewport,
158
+ CdkFixedSizeVirtualScroll,
159
+ CdkVirtualForOf,
160
+ GridAddRowComponent,
161
+ GridColgroupComponent,
162
+ GridDetailRowComponent,
163
+ GridFooterRowComponent,
164
+ GridGroupRowComponent,
165
+ GridRowComponent
166
+ ], changeDetection: ChangeDetectionStrategy.OnPush, host: {
167
+ "[class]": "baseClass()",
168
+ "[style.--mona-grid-row-height]": "gridService.virtualScrollOptions().height + 'px'"
169
+ }, template: "@if (gridService.addRowVisible()) {\n <div\n class=\"shrink-0 overflow-hidden border-b border-b-border\"\n [style.margin-inline-end.px]=\"gridService.scrollbarGutterWidth()\"\n #addRowScrollElement>\n <table role=\"presentation\" [class]=\"tableClass()\" [style.width.px]=\"gridService.tableWidth()\">\n <colgroup monaGridColgroup></colgroup>\n <tbody role=\"rowgroup\">\n <tr monaGridAddRow></tr>\n </tbody>\n </table>\n </div>\n}\n\n<cdk-virtual-scroll-viewport\n class=\"flex-1 min-h-0\"\n [itemSize]=\"gridService.virtualScrollOptions().height\"\n [minBufferPx]=\"gridService.virtualGridMinBuffer()\"\n [maxBufferPx]=\"gridService.virtualGridMaxBuffer()\">\n <table role=\"presentation\" #bodyTable [class]=\"tableClass()\" [style.width.px]=\"gridService.tableWidth()\">\n <colgroup monaGridColgroup></colgroup>\n <tbody role=\"rowgroup\" tabindex=\"0\" (focus)=\"onViewportFocus()\">\n <ng-container *cdkVirtualFor=\"let bodyRow of bodyRows(); let rowIndex = index; trackBy: trackBodyRow\">\n @if (bodyRow.type === \"group\") {\n <tr monaGridGroupRow [group]=\"bodyRow\" [rowIndex]=\"rowIndex\"></tr>\n } @else if (bodyRow.type === \"groupFooter\") {\n <tr monaGridFooterRow [groupKey]=\"bodyRow.groupAggregate.groupKey\"></tr>\n } @else {\n <tr monaGridRow [row]=\"bodyRow.row\" [index]=\"rowIndex\"></tr>\n @if (gridService.isRowExpanded(bodyRow.row) && !gridService.rowDragInProgress()) {\n <tr monaGridDetailRow [row]=\"bodyRow.row\"></tr>\n }\n }\n </ng-container>\n </tbody>\n </table>\n</cdk-virtual-scroll-viewport>\n\n@if (gridService.hasFooter()) {\n <div [class]=\"footerClass()\" [style.margin-inline-end.px]=\"gridService.scrollbarGutterWidth()\" #footerScrollElement>\n <div>\n <table role=\"presentation\" [class]=\"footerTableClass()\" [style.width.px]=\"gridService.tableWidth()\">\n <colgroup monaGridColgroup></colgroup>\n <tfoot role=\"rowgroup\">\n <tr monaGridFooterRow></tr>\n </tfoot>\n </table>\n </div>\n </div>\n}\n" }]
170
+ }], ctorParameters: () => [], propDecorators: { addRowScrollElementRef: [{ type: i0.ViewChild, args: ["addRowScrollElement", { isSignal: true }] }], bodyTableElementRef: [{ type: i0.ViewChild, args: ["bodyTable", { isSignal: true }] }], footerScrollElementRef: [{ type: i0.ViewChild, args: ["footerScrollElement", { isSignal: true }] }], viewport: [{ type: i0.ViewChild, args: [i0.forwardRef(() => CdkVirtualScrollViewport), { isSignal: true }] }], data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: false }] }] } });
171
+
172
+ export { GridVirtualListComponent };
173
+ //# sourceMappingURL=nanahoshi-mona-ui-grid-grid-virtual-list.component-DArxdAah.mjs.map