cmat 0.0.105 → 0.0.107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/fesm2022/cmat.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i3$1 from '@angular/material/core';
|
|
2
2
|
import { DateAdapter, MAT_DATE_LOCALE, MatRippleModule, MatOption, _countGroupLabelsBeforeOption } from '@angular/material/core';
|
|
3
3
|
import * as i0 from '@angular/core';
|
|
4
|
-
import { InjectionToken, inject, Injectable, Directive, signal, DestroyRef, contentChild, TemplateRef, input, computed, effect, ChangeDetectionStrategy, ViewEncapsulation, Component, model, output, ElementRef, numberAttribute, booleanAttribute, viewChild, contentChildren, DOCUMENT, Renderer2, untracked, Input, ViewContainerRef, forwardRef, SecurityContext, HostListener, EventEmitter, Injector, afterNextRender, HostBinding, Pipe, viewChildren, ApplicationRef, createComponent, HostAttributeToken } from '@angular/core';
|
|
4
|
+
import { InjectionToken, inject, Injectable, Directive, signal, DestroyRef, contentChild, TemplateRef, input, computed, effect, ChangeDetectionStrategy, ViewEncapsulation, Component, model, output, ElementRef, numberAttribute, booleanAttribute, viewChild, contentChildren, DOCUMENT, Renderer2, untracked, Input, ViewContainerRef, forwardRef, SecurityContext, HostListener, EventEmitter, Injector, afterNextRender, HostBinding, Pipe, viewChildren, ChangeDetectorRef, ApplicationRef, createComponent, HostAttributeToken } from '@angular/core';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
6
|
import localeData from 'dayjs/plugin/localeData';
|
|
7
7
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
@@ -15154,6 +15154,14 @@ class CmatSelectTableComponent {
|
|
|
15154
15154
|
...(ngDevMode ? [{ debugName: "_requiredSignal" }] : /* istanbul ignore next */ []));
|
|
15155
15155
|
this.ngControl = inject(NgControl, { optional: true, self: true });
|
|
15156
15156
|
this._destroyRef = inject(DestroyRef);
|
|
15157
|
+
this._cdr = inject(ChangeDetectorRef);
|
|
15158
|
+
// _init 重入守卫:selectControl.setValue 触发 MatSelect._onChange → writeValue → _init 递归
|
|
15159
|
+
this._initRunning = false;
|
|
15160
|
+
// 保存 writeValue 传入的原始值(可能是部分行对象),
|
|
15161
|
+
// dataSource 变更时始终用原始值重新解析,避免 _init 解析后覆盖 _value 导致原始值丢失
|
|
15162
|
+
this._rawValue = null;
|
|
15163
|
+
// dataSource effect 解析期间为 true,阻止 writeValue 覆盖 _rawValue
|
|
15164
|
+
this._resolvingFromDataSource = false;
|
|
15157
15165
|
this._nullRow = { id: null };
|
|
15158
15166
|
this._value = null;
|
|
15159
15167
|
this._triggerLabel = computed(() => this.customTriggerLabelFn()?.(this.completeRowList()) ??
|
|
@@ -15182,8 +15190,7 @@ class CmatSelectTableComponent {
|
|
|
15182
15190
|
this._setPanelClass();
|
|
15183
15191
|
}
|
|
15184
15192
|
});
|
|
15185
|
-
// 监听 dataSource signal
|
|
15186
|
-
// signal input 不触发 ngOnChanges,此处为 dataSource 的唯一处理入口
|
|
15193
|
+
// 监听 dataSource signal 变化,重建数据结构并解析表单值
|
|
15187
15194
|
effect(() => {
|
|
15188
15195
|
const ds = this.dataSource();
|
|
15189
15196
|
if (!ds || !isArray(ds.data) || ds.data.length === 0)
|
|
@@ -15206,22 +15213,19 @@ class CmatSelectTableComponent {
|
|
|
15206
15213
|
this._rowById.set(rowKey, row);
|
|
15207
15214
|
}
|
|
15208
15215
|
});
|
|
15209
|
-
//
|
|
15210
|
-
if (this.
|
|
15211
|
-
|
|
15212
|
-
|
|
15213
|
-
|
|
15214
|
-
currentValue.forEach((v) => this._updateCompleteRowList(v, true, list));
|
|
15216
|
+
// matSelect 就绪后,用原始值重新解析(不用 this.value,它可能已被上次 _init 覆盖为解析后的完整行)
|
|
15217
|
+
if (this._matSelect) {
|
|
15218
|
+
this._resolvingFromDataSource = true;
|
|
15219
|
+
try {
|
|
15220
|
+
this._init(this._rawValue);
|
|
15215
15221
|
}
|
|
15216
|
-
|
|
15217
|
-
this.
|
|
15218
|
-
}
|
|
15219
|
-
this.completeRowList.set(list);
|
|
15220
|
-
this._value =
|
|
15221
|
-
list.length > 0 ? [...list] : currentValue;
|
|
15222
|
-
if (this._matSelect) {
|
|
15223
|
-
this._matSelect.writeValue(this._value);
|
|
15222
|
+
finally {
|
|
15223
|
+
this._resolvingFromDataSource = false;
|
|
15224
15224
|
}
|
|
15225
|
+
this.stateChanges.next();
|
|
15226
|
+
// effect 在 CD 之后执行,当前 CD 已处理过投影内容,
|
|
15227
|
+
// 推迟到微任务强制第二轮 CD 刷新 <mat-select-trigger>
|
|
15228
|
+
Promise.resolve().then(() => this._cdr.detectChanges());
|
|
15225
15229
|
}
|
|
15226
15230
|
});
|
|
15227
15231
|
});
|
|
@@ -15356,6 +15360,10 @@ class CmatSelectTableComponent {
|
|
|
15356
15360
|
}
|
|
15357
15361
|
}
|
|
15358
15362
|
writeValue(value) {
|
|
15363
|
+
// dataSource effect 解析期间,_onModelChange 级联触发的 writeValue 不覆盖原始值
|
|
15364
|
+
if (!this._resolvingFromDataSource) {
|
|
15365
|
+
this._rawValue = value;
|
|
15366
|
+
}
|
|
15359
15367
|
this._init(value);
|
|
15360
15368
|
}
|
|
15361
15369
|
ngOnChanges(changes) {
|
|
@@ -15460,25 +15468,50 @@ class CmatSelectTableComponent {
|
|
|
15460
15468
|
return this.addNullRow();
|
|
15461
15469
|
}
|
|
15462
15470
|
_init(value) {
|
|
15463
|
-
|
|
15464
|
-
if (
|
|
15465
|
-
|
|
15466
|
-
|
|
15467
|
-
|
|
15471
|
+
// selectControl.setValue 触发 MatSelect._onChange → writeValue → _init 递归,直接跳过
|
|
15472
|
+
if (this._initRunning)
|
|
15473
|
+
return;
|
|
15474
|
+
this._initRunning = true;
|
|
15475
|
+
try {
|
|
15476
|
+
const list = [];
|
|
15477
|
+
if (value) {
|
|
15478
|
+
const multiple = this.multiple();
|
|
15479
|
+
if (multiple && Array.isArray(value)) {
|
|
15480
|
+
value.forEach((v) => this._updateCompleteRowList(v, true, list));
|
|
15481
|
+
}
|
|
15482
|
+
else if (!multiple) {
|
|
15483
|
+
this._updateCompleteRowList(value, true, list);
|
|
15484
|
+
}
|
|
15468
15485
|
}
|
|
15469
|
-
|
|
15470
|
-
|
|
15486
|
+
this.completeRowList.set(list);
|
|
15487
|
+
this._value =
|
|
15488
|
+
this.completeRowList().length > 0 ? [...this.completeRowList()] : value;
|
|
15489
|
+
if (this._matSelect) {
|
|
15490
|
+
this._matSelect.writeValue(this._value);
|
|
15491
|
+
}
|
|
15492
|
+
// 同步 selectControl,临时替换 MatSelect._onChange 为 no-op
|
|
15493
|
+
// 阻断 selectControl.setValue → MatSelect._onChange → _onModelChange → 父 FormControl 级联
|
|
15494
|
+
if (this.selectControl) {
|
|
15495
|
+
const origOnChange = this._matSelect?._onChange;
|
|
15496
|
+
if (this._matSelect) {
|
|
15497
|
+
this._matSelect._onChange = () => { };
|
|
15498
|
+
}
|
|
15499
|
+
try {
|
|
15500
|
+
this.selectControl.setValue(this.value, { emitEvent: false });
|
|
15501
|
+
}
|
|
15502
|
+
finally {
|
|
15503
|
+
if (this._matSelect && origOnChange) {
|
|
15504
|
+
this._matSelect._onChange = origOnChange;
|
|
15505
|
+
}
|
|
15506
|
+
}
|
|
15507
|
+
}
|
|
15508
|
+
// 将解析后的完整行传播回父表单(_resolvingFromDataSource 阻止 writeValue 覆盖 _rawValue)
|
|
15509
|
+
if (this.completeRowList().length > 0) {
|
|
15510
|
+
this._onModelChange(this._value);
|
|
15471
15511
|
}
|
|
15472
15512
|
}
|
|
15473
|
-
|
|
15474
|
-
|
|
15475
|
-
this.completeRowList().length > 0 ? [...this.completeRowList()] : value;
|
|
15476
|
-
if (this._matSelect) {
|
|
15477
|
-
this._matSelect.writeValue(this._value);
|
|
15478
|
-
}
|
|
15479
|
-
// 确保 selectControl 与当前值同步
|
|
15480
|
-
if (this.selectControl) {
|
|
15481
|
-
this.selectControl.setValue(this.value, { emitEvent: false });
|
|
15513
|
+
finally {
|
|
15514
|
+
this._initRunning = false;
|
|
15482
15515
|
}
|
|
15483
15516
|
}
|
|
15484
15517
|
_updateCompleteRowList(value, selected, list = this.completeRowList()) {
|