@piying/view-angular-core 1.5.9 → 1.5.11
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.
|
@@ -290,6 +290,9 @@ class AbstractControl {
|
|
|
290
290
|
injector;
|
|
291
291
|
/** model的value */
|
|
292
292
|
value$$;
|
|
293
|
+
/** 已激活的子级,用于校验获得返回值之类 */
|
|
294
|
+
activatedChildren$$;
|
|
295
|
+
/** 通用的子级,用于查询之类 */
|
|
293
296
|
children$$;
|
|
294
297
|
/** disabled */
|
|
295
298
|
selfDisabled$$ = computed(() => this.config$?.().disabled ?? false);
|
|
@@ -457,8 +460,8 @@ class AbstractControl {
|
|
|
457
460
|
get pending() {
|
|
458
461
|
return this.status$$() === PENDING;
|
|
459
462
|
}
|
|
460
|
-
selfUpdateOn$$ = computed(() => this.config$?.().updateOn);
|
|
461
|
-
updateOn$$ = computed(() => (this
|
|
463
|
+
#selfUpdateOn$$ = computed(() => this.config$?.().updateOn);
|
|
464
|
+
updateOn$$ = computed(() => (this.#selfUpdateOn$$() || this.parent?.updateOn$$()) ?? 'change');
|
|
462
465
|
markAsTouched() {
|
|
463
466
|
this.selfTouched$.set(true);
|
|
464
467
|
}
|
|
@@ -525,8 +528,9 @@ class AbstractControl {
|
|
|
525
528
|
return null;
|
|
526
529
|
}
|
|
527
530
|
setControl(name, control) { }
|
|
531
|
+
/** 校验和获得值用 */
|
|
528
532
|
reduceChildren(initialValue, fn, shortCircuit) {
|
|
529
|
-
const childrenMap = this.children
|
|
533
|
+
const childrenMap = (this.activatedChildren$$ ?? this.children$$)?.();
|
|
530
534
|
if (!childrenMap) {
|
|
531
535
|
return initialValue;
|
|
532
536
|
}
|
|
@@ -623,7 +627,9 @@ class FieldGroupbase extends AbstractControl {
|
|
|
623
627
|
const restValue = this.getResetValue(viewValue);
|
|
624
628
|
this.beforeUpdateList.forEach((fn) => fn(restValue, type !== UpdateType.init));
|
|
625
629
|
}
|
|
626
|
-
else if (this.config$().groupMode === 'loose'
|
|
630
|
+
else if (this.config$().groupMode === 'loose' ||
|
|
631
|
+
this.config$().groupMode === 'strict') {
|
|
632
|
+
// loose下为了输出值,strict下为了验证
|
|
627
633
|
const resetValue = this.getResetValue(viewValue);
|
|
628
634
|
this.resetValue$.set(resetValue);
|
|
629
635
|
}
|
|
@@ -671,84 +677,75 @@ class FieldGroupbase extends AbstractControl {
|
|
|
671
677
|
}
|
|
672
678
|
}
|
|
673
679
|
|
|
674
|
-
class
|
|
675
|
-
#deletionMode$$ = computed(() => this.config$().deletionMode ?? 'shrink');
|
|
680
|
+
class FieldGroup extends FieldGroupbase {
|
|
676
681
|
value$$ = computed(() => {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
list.push(control.value$$());
|
|
681
|
-
}
|
|
682
|
-
else {
|
|
683
|
-
if (this.#deletionMode$$() === 'shrink') {
|
|
684
|
-
return list;
|
|
685
|
-
}
|
|
686
|
-
else if (this.#deletionMode$$() === 'mark') {
|
|
687
|
-
list.push(undefined);
|
|
688
|
-
}
|
|
682
|
+
const result = this._reduceChildren({ ...this.resetValue$() }, (acc, control, name) => {
|
|
683
|
+
if (control.shouldInclude$$()) {
|
|
684
|
+
acc[name] = control.value;
|
|
689
685
|
}
|
|
690
|
-
return
|
|
686
|
+
return acc;
|
|
691
687
|
});
|
|
692
|
-
|
|
693
|
-
|
|
688
|
+
const returnResult = Object.keys(result).length
|
|
689
|
+
? result
|
|
690
|
+
: this.emptyValue$$();
|
|
694
691
|
return (this.config$().transfomer?.toModel?.(returnResult, this) ?? returnResult);
|
|
695
692
|
});
|
|
696
|
-
|
|
693
|
+
#controls$$ = computed(() => ({
|
|
697
694
|
...this.fixedControls$(),
|
|
698
695
|
...this.resetControls$(),
|
|
699
|
-
|
|
700
|
-
fixedControls$ = signal(
|
|
701
|
-
resetControls$ = signal(
|
|
696
|
+
}));
|
|
697
|
+
fixedControls$ = signal({});
|
|
698
|
+
resetControls$ = signal({});
|
|
702
699
|
get controls() {
|
|
703
|
-
return this
|
|
700
|
+
return this.#controls$$();
|
|
704
701
|
}
|
|
702
|
+
children$$ = computed(() => Object.values(this.#controls$$()));
|
|
705
703
|
removeRestControl(key) {
|
|
706
704
|
if (!this.resetControls$()[key]) {
|
|
707
705
|
return;
|
|
708
706
|
}
|
|
709
707
|
this.resetControls$.update((controls) => {
|
|
710
|
-
controls = controls
|
|
711
|
-
controls
|
|
708
|
+
controls = { ...controls };
|
|
709
|
+
delete controls[key];
|
|
712
710
|
return controls;
|
|
713
711
|
});
|
|
714
712
|
}
|
|
715
713
|
setControl(key, control) {
|
|
716
714
|
const controls$ = this.inited ? this.resetControls$ : this.fixedControls$;
|
|
717
|
-
|
|
718
|
-
controls$.update((list) => {
|
|
719
|
-
list = list.slice();
|
|
720
|
-
list[key] = control;
|
|
721
|
-
return list;
|
|
722
|
-
});
|
|
715
|
+
controls$.update((controls) => ({ ...controls, [key]: control }));
|
|
723
716
|
control.setParent(this);
|
|
724
717
|
}
|
|
725
|
-
get length() {
|
|
726
|
-
return this.controls.length;
|
|
727
|
-
}
|
|
728
718
|
getRawValue() {
|
|
729
|
-
return this._reduceChildren(
|
|
719
|
+
return this._reduceChildren({}, (acc, control, key) => {
|
|
730
720
|
acc[key] = control.getRawValue();
|
|
731
721
|
return acc;
|
|
732
722
|
});
|
|
733
723
|
}
|
|
734
724
|
clear() {
|
|
735
|
-
if (this.resetControls$().length < 1)
|
|
725
|
+
if (Object.keys(this.resetControls$()).length < 1)
|
|
736
726
|
return;
|
|
737
|
-
this.beforeUpdateList.forEach((fn) => fn(
|
|
727
|
+
this.beforeUpdateList.forEach((fn) => fn({}, false));
|
|
738
728
|
}
|
|
739
729
|
/** @internal */
|
|
740
730
|
_forEachChild(cb) {
|
|
741
|
-
this
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
}
|
|
731
|
+
const controls = this.#controls$$();
|
|
732
|
+
Object.keys(controls).forEach((key) => {
|
|
733
|
+
cb(controls[key], key);
|
|
745
734
|
});
|
|
746
735
|
}
|
|
747
736
|
find(key) {
|
|
748
|
-
return this
|
|
737
|
+
return this.#controls$$()[key];
|
|
749
738
|
}
|
|
750
|
-
getResetValue(
|
|
751
|
-
|
|
739
|
+
getResetValue(inputValue) {
|
|
740
|
+
const controls = this.fixedControls$();
|
|
741
|
+
return inputValue
|
|
742
|
+
? Object.keys(inputValue).reduce((obj, key) => {
|
|
743
|
+
if (!(key in controls)) {
|
|
744
|
+
obj[key] = inputValue[key];
|
|
745
|
+
}
|
|
746
|
+
return obj;
|
|
747
|
+
}, {})
|
|
748
|
+
: {};
|
|
752
749
|
}
|
|
753
750
|
}
|
|
754
751
|
|
|
@@ -861,6 +858,87 @@ class FieldControl extends AbstractControl {
|
|
|
861
858
|
}
|
|
862
859
|
}
|
|
863
860
|
|
|
861
|
+
class FieldArray extends FieldGroupbase {
|
|
862
|
+
#deletionMode$$ = computed(() => this.config$().deletionMode ?? 'shrink');
|
|
863
|
+
value$$ = computed(() => {
|
|
864
|
+
let list = [];
|
|
865
|
+
this._reduceChildren(list, (acc, control, name) => {
|
|
866
|
+
if (control && control.shouldInclude$$()) {
|
|
867
|
+
list.push(control.value$$());
|
|
868
|
+
}
|
|
869
|
+
else {
|
|
870
|
+
if (this.#deletionMode$$() === 'shrink') {
|
|
871
|
+
return list;
|
|
872
|
+
}
|
|
873
|
+
else if (this.#deletionMode$$() === 'mark') {
|
|
874
|
+
list.push(undefined);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
return list;
|
|
878
|
+
});
|
|
879
|
+
list = [...list, ...(this.resetValue$() ?? [])];
|
|
880
|
+
const returnResult = list.length === 0 ? this.emptyValue$$() : list;
|
|
881
|
+
return (this.config$().transfomer?.toModel?.(returnResult, this) ?? returnResult);
|
|
882
|
+
});
|
|
883
|
+
children$$ = computed(() => [
|
|
884
|
+
...this.fixedControls$(),
|
|
885
|
+
...this.resetControls$(),
|
|
886
|
+
]);
|
|
887
|
+
fixedControls$ = signal([]);
|
|
888
|
+
resetControls$ = signal([]);
|
|
889
|
+
get controls() {
|
|
890
|
+
return this.children$$();
|
|
891
|
+
}
|
|
892
|
+
removeRestControl(key) {
|
|
893
|
+
if (!this.resetControls$()[key]) {
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
this.resetControls$.update((controls) => {
|
|
897
|
+
controls = controls.slice();
|
|
898
|
+
controls.splice(key, 1);
|
|
899
|
+
return controls;
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
setControl(key, control) {
|
|
903
|
+
const controls$ = this.inited ? this.resetControls$ : this.fixedControls$;
|
|
904
|
+
key = this.inited ? key - this.fixedControls$().length : key;
|
|
905
|
+
controls$.update((list) => {
|
|
906
|
+
list = list.slice();
|
|
907
|
+
list[key] = control;
|
|
908
|
+
return list;
|
|
909
|
+
});
|
|
910
|
+
control.setParent(this);
|
|
911
|
+
}
|
|
912
|
+
get length() {
|
|
913
|
+
return this.controls.length;
|
|
914
|
+
}
|
|
915
|
+
getRawValue() {
|
|
916
|
+
return this._reduceChildren([], (acc, control, key) => {
|
|
917
|
+
acc[key] = control.getRawValue();
|
|
918
|
+
return acc;
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
clear() {
|
|
922
|
+
if (this.resetControls$().length < 1)
|
|
923
|
+
return;
|
|
924
|
+
this.beforeUpdateList.forEach((fn) => fn([], false));
|
|
925
|
+
}
|
|
926
|
+
/** @internal */
|
|
927
|
+
_forEachChild(cb) {
|
|
928
|
+
this.children$$().forEach((control, index) => {
|
|
929
|
+
if (control) {
|
|
930
|
+
cb(control, index);
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
find(key) {
|
|
935
|
+
return this.children$$()[key];
|
|
936
|
+
}
|
|
937
|
+
getResetValue(value = []) {
|
|
938
|
+
return value.slice(this.fixedControls$().length);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
|
|
864
942
|
// 切换索引后,理论上应该触发下值变更,否则不知道值是什么
|
|
865
943
|
class FieldLogicGroup extends FieldArray {
|
|
866
944
|
activateIndex$ = signal(0);
|
|
@@ -886,10 +964,13 @@ class FieldLogicGroup extends FieldArray {
|
|
|
886
964
|
}
|
|
887
965
|
return list;
|
|
888
966
|
}
|
|
967
|
+
activatedChildren$$ = computed(() => {
|
|
968
|
+
return this.#getActivateControls();
|
|
969
|
+
});
|
|
889
970
|
getValue(rawData) {
|
|
890
971
|
const controls = rawData
|
|
891
|
-
? this
|
|
892
|
-
: this
|
|
972
|
+
? this.activatedChildren$$()
|
|
973
|
+
: this.activatedChildren$$().filter((control) => control.shouldInclude$$());
|
|
893
974
|
const control = controls[0];
|
|
894
975
|
if (controls.length === 0) {
|
|
895
976
|
return this.emptyValue$$();
|
|
@@ -958,85 +1039,6 @@ function isFieldLogicGroup(input) {
|
|
|
958
1039
|
return input instanceof FieldLogicGroup;
|
|
959
1040
|
}
|
|
960
1041
|
|
|
961
|
-
class FieldGroup extends FieldGroupbase {
|
|
962
|
-
value$$ = computed(() => {
|
|
963
|
-
const result = this._reduceChildren({ ...this.#looseValue$$() }, (acc, control, name) => {
|
|
964
|
-
if (control.shouldInclude$$()) {
|
|
965
|
-
acc[name] = control.value;
|
|
966
|
-
}
|
|
967
|
-
return acc;
|
|
968
|
-
});
|
|
969
|
-
const returnResult = Object.keys(result).length
|
|
970
|
-
? result
|
|
971
|
-
: this.emptyValue$$();
|
|
972
|
-
return (this.config$().transfomer?.toModel?.(returnResult, this) ?? returnResult);
|
|
973
|
-
});
|
|
974
|
-
#controls$$ = computed(() => ({
|
|
975
|
-
...this.fixedControls$(),
|
|
976
|
-
...this.resetControls$(),
|
|
977
|
-
}));
|
|
978
|
-
fixedControls$ = signal({});
|
|
979
|
-
resetControls$ = signal({});
|
|
980
|
-
get controls() {
|
|
981
|
-
return this.#controls$$();
|
|
982
|
-
}
|
|
983
|
-
children$$ = computed(() => Object.values(this.#controls$$()));
|
|
984
|
-
removeRestControl(key) {
|
|
985
|
-
if (!this.resetControls$()[key]) {
|
|
986
|
-
return;
|
|
987
|
-
}
|
|
988
|
-
this.resetControls$.update((controls) => {
|
|
989
|
-
controls = { ...controls };
|
|
990
|
-
delete controls[key];
|
|
991
|
-
return controls;
|
|
992
|
-
});
|
|
993
|
-
}
|
|
994
|
-
setControl(key, control) {
|
|
995
|
-
const controls$ = this.inited ? this.resetControls$ : this.fixedControls$;
|
|
996
|
-
controls$.update((controls) => ({ ...controls, [key]: control }));
|
|
997
|
-
control.setParent(this);
|
|
998
|
-
}
|
|
999
|
-
getRawValue() {
|
|
1000
|
-
return this._reduceChildren({}, (acc, control, key) => {
|
|
1001
|
-
acc[key] = control.getRawValue();
|
|
1002
|
-
return acc;
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
clear() {
|
|
1006
|
-
if (Object.keys(this.resetControls$()).length < 1)
|
|
1007
|
-
return;
|
|
1008
|
-
this.beforeUpdateList.forEach((fn) => fn({}, false));
|
|
1009
|
-
}
|
|
1010
|
-
/** @internal */
|
|
1011
|
-
_forEachChild(cb) {
|
|
1012
|
-
const controls = this.#controls$$();
|
|
1013
|
-
Object.keys(controls).forEach((key) => {
|
|
1014
|
-
cb(controls[key], key);
|
|
1015
|
-
});
|
|
1016
|
-
}
|
|
1017
|
-
find(key) {
|
|
1018
|
-
return this.#controls$$()[key];
|
|
1019
|
-
}
|
|
1020
|
-
getResetValue(inputValue) {
|
|
1021
|
-
const controls = this.fixedControls$();
|
|
1022
|
-
return inputValue
|
|
1023
|
-
? Object.keys(inputValue).reduce((obj, item) => {
|
|
1024
|
-
if (!(item in controls)) {
|
|
1025
|
-
obj[item] = inputValue[item];
|
|
1026
|
-
}
|
|
1027
|
-
return obj;
|
|
1028
|
-
}, {})
|
|
1029
|
-
: {};
|
|
1030
|
-
}
|
|
1031
|
-
#looseValue$$ = computed(() => {
|
|
1032
|
-
const resetValue = this.resetValue$();
|
|
1033
|
-
if (!resetValue || isFieldLogicGroup(this.parent)) {
|
|
1034
|
-
return undefined;
|
|
1035
|
-
}
|
|
1036
|
-
return resetValue;
|
|
1037
|
-
});
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
1042
|
function isGroup(schema) {
|
|
1041
1043
|
return schema.isGroup;
|
|
1042
1044
|
}
|