@piying/view-angular-core 1.9.1 → 1.9.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.
@@ -3,7 +3,7 @@ import * as v from 'valibot';
3
3
  import * as jsonActions from '@piying/view-angular-core';
4
4
  import { hideWhen, patchInputs, asControl, setComponent } from '@piying/view-angular-core';
5
5
  import { computed } from '@angular/core';
6
- import { merge, map, BehaviorSubject, switchMap, combineLatest } from 'rxjs';
6
+ import { merge, map, BehaviorSubject, switchMap, distinctUntilChanged, skip, combineLatest } from 'rxjs';
7
7
  import { schema } from '@piying/valibot-visit';
8
8
  import rfdc from 'rfdc';
9
9
 
@@ -355,7 +355,7 @@ class ObjectTypeService extends BaseTypeService {
355
355
  });
356
356
  const depList = schema$1.dependentRequired?.[key];
357
357
  if (depList) {
358
- propVSchema = v.pipe(propVSchema, jsonActions.patchHooks({
358
+ propVSchema = v.pipe(propVSchema, jsonActions.mergeHooks({
359
359
  allFieldsResolved: (field) => {
360
360
  field.form.control.statusChanges.subscribe(() => {
361
361
  const valid = field.form.control.valid;
@@ -832,24 +832,24 @@ class CommonTypeService extends BaseTypeService {
832
832
  * 也就是then/else都会合并base,然后按条件展示,
833
833
  */
834
834
  const useThen$ = new BehaviorSubject(undefined);
835
- const baseSchema = v.pipe(this.#jsonSchemaBase(schema$1, () => [
835
+ let base1Schema = v.pipe(this.#jsonSchemaBase(schema$1, () => [
836
836
  ...this.getValidationActionList(schema$1),
837
- jsonActions.hideWhen({
838
- disabled: false,
839
- listen: (fn) => fn({}).pipe(map(({ list: [value], field }) => {
840
- const isThen = isBoolean(schema$1.if)
841
- ? schema$1.if
842
- : v.safeParse(ifVSchema, value).success;
843
- field.form.parent.activateIndex$.set(isThen ? 1 : 2);
844
- useThen$.next(isThen);
845
- return !((isThen && !thenSchema) || (!isThen && !elseSchema));
846
- })),
847
- }),
848
837
  ]));
838
+ const baseSchema = v.pipe(base1Schema, jsonActions.hideWhen({
839
+ disabled: false,
840
+ listen: (fn) => fn({}).pipe(map(({ list: [value], field }) => {
841
+ const isThen = isBoolean(schema$1.if)
842
+ ? schema$1.if
843
+ : v.safeParse(ifVSchema, value).success;
844
+ field.form.parent.activateIndex$.set(isThen ? 1 : 2);
845
+ useThen$.next(isThen);
846
+ return true;
847
+ })),
848
+ }));
849
849
  /** 仅为验证项,非显示用 */
850
850
  let ifVSchema;
851
851
  if (isBoolean(schema$1.if)) {
852
- ifVSchema = v.literal(schema$1.if);
852
+ ifVSchema = v.pipe(v.any(), v.check(() => !!schema$1.if));
853
853
  }
854
854
  else {
855
855
  const ifSchema = this.#mergeSchema(schema$1, schema$1.if);
@@ -861,7 +861,17 @@ class CommonTypeService extends BaseTypeService {
861
861
  jsonActions.hideWhen({
862
862
  disabled: true,
863
863
  listen(fn) {
864
- return fn({ list: [['..', 0]] }).pipe(switchMap(({ list: [] }) => useThen$), map((a) => (a === undefined ? true : isThen ? !a : a)));
864
+ return fn({ list: [['..', 0]] }).pipe(switchMap(({ list: [] }) => useThen$), map((a) => (a === undefined ? true : isThen ? !a : a)), distinctUntilChanged());
865
+ },
866
+ }),
867
+ jsonActions.mergeHooks({
868
+ allFieldsResolved: (field) => {
869
+ let baseField = field.get(['..', 0]);
870
+ field.form.control?.valueChanges
871
+ .pipe(skip(1))
872
+ .subscribe((value) => {
873
+ baseField?.form.control?.updateValue(value);
874
+ });
865
875
  },
866
876
  }),
867
877
  ];
@@ -871,23 +881,25 @@ class CommonTypeService extends BaseTypeService {
871
881
  const subSchema = this.#mergeSchema(schema$1, schema$1.then);
872
882
  thenSchema = v.pipe(this.#jsonSchemaBase(subSchema.schema, () => [
873
883
  ...subSchema.actionList,
874
- ...hideAction(true),
875
884
  ]));
876
885
  }
886
+ else {
887
+ thenSchema = base1Schema;
888
+ }
889
+ thenSchema = v.pipe(thenSchema, ...hideAction(true));
877
890
  let elseSchema;
878
891
  if (schema$1.else && !isBoolean(schema$1.else)) {
879
892
  const subSchema = this.#mergeSchema(schema$1, schema$1.else);
880
893
  elseSchema = v.pipe(this.#jsonSchemaBase(subSchema.schema, () => [
881
894
  ...subSchema.actionList,
882
- ...hideAction(false),
883
895
  ]));
884
896
  }
897
+ else {
898
+ elseSchema = base1Schema;
899
+ }
900
+ elseSchema = v.pipe(elseSchema, ...hideAction(false));
885
901
  // 这种逻辑没问题,因为jsonschema验证中,也会出现base和子级架构一起验证
886
- vSchema = v.pipe(v.union([
887
- baseSchema,
888
- thenSchema ?? baseSchema,
889
- elseSchema ?? baseSchema,
890
- ].filter(Boolean)), jsonActions.formConfig({ disableOrUpdateActivate: true }), v.rawCheck(({ dataset, addIssue }) => {
902
+ vSchema = v.pipe(v.union([baseSchema, thenSchema, elseSchema]), jsonActions.formConfig({ disableOrUpdateActivate: true }), v.rawCheck(({ dataset, addIssue }) => {
891
903
  if (dataset.issues) {
892
904
  return;
893
905
  }
@@ -1036,7 +1048,7 @@ class CommonTypeService extends BaseTypeService {
1036
1048
  }
1037
1049
  conditionResult.conditionKeyList = excludeFixedConditionList;
1038
1050
  }
1039
- const checkAction = jsonActions.patchHooks({
1051
+ const checkAction = jsonActions.mergeHooks({
1040
1052
  allFieldsResolved: (field) => {
1041
1053
  const displayName = ['..', 2];
1042
1054
  const list = [];