@piying/view-angular-core 1.9.3 → 1.9.4

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, distinctUntilChanged, skip, combineLatest } from 'rxjs';
6
+ import { merge, map, BehaviorSubject, switchMap, distinctUntilChanged, combineLatest } from 'rxjs';
7
7
  import { schema } from '@piying/valibot-visit';
8
8
  import rfdc from 'rfdc';
9
9
 
@@ -627,6 +627,7 @@ function toFixedList(data, labelFn = (a) => a) {
627
627
  return data.map((item) => ({ label: labelFn(item), value: item }));
628
628
  }
629
629
 
630
+ const EMPTY_DEFINE = v.pipe(v.any(), jsonActions.setComponent(''));
630
631
  function arrayIntersection(a, b) {
631
632
  if (!isNil(a) && !isNil(b)) {
632
633
  a = Array.isArray(a) ? a : [a];
@@ -827,34 +828,32 @@ class CommonTypeService extends BaseTypeService {
827
828
  });
828
829
  }
829
830
  else if ('if' in schema$1) {
830
- /**
831
- * 当前设计中if/then/else是采用的分离显示
832
- * 也就是then/else都会合并base,然后按条件展示,
833
- */
834
- const useThen$ = new BehaviorSubject(undefined);
835
- let base1Schema = v.pipe(this.#jsonSchemaBase(schema$1, () => [
836
- ...this.getValidationActionList(schema$1),
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
831
  /** 仅为验证项,非显示用 */
850
832
  let ifVSchema;
851
833
  if (isBoolean(schema$1.if)) {
852
834
  ifVSchema = v.pipe(v.any(), v.check(() => !!schema$1.if));
853
835
  }
854
836
  else {
855
- const ifSchema = this.#mergeSchema(schema$1, schema$1.if);
856
- ifVSchema = v.pipe(this.#jsonSchemaBase(ifSchema.schema, () => ifSchema.actionList));
837
+ const ifSchema = this.resolveSchema2(schema$1.if);
838
+ ifVSchema = v.pipe(this.#jsonSchemaBase(ifSchema, () => this.getValidationActionList(ifSchema)));
857
839
  }
840
+ /**
841
+ * 当前设计中if/then/else是采用的分离显示
842
+ * 也就是then/else都会合并base,然后按条件展示,
843
+ */
844
+ const useThen$ = new BehaviorSubject(undefined);
845
+ const baseSchema = this.#jsonSchemaBase(schema$1, () => [
846
+ ...this.getValidationActionList(schema$1),
847
+ jsonActions.valueChange((fn) => {
848
+ fn().subscribe(({ list: [value], field }) => {
849
+ const isThen = isBoolean(schema$1.if)
850
+ ? schema$1.if
851
+ : v.safeParse(ifVSchema, value).success;
852
+ field.form.parent.activateIndex$.set(isThen ? 1 : 2);
853
+ useThen$.next(isThen);
854
+ });
855
+ }),
856
+ ]);
858
857
  function hideAction(isThen) {
859
858
  return [
860
859
  jsonActions.renderConfig({ hidden: true }),
@@ -864,57 +863,58 @@ class CommonTypeService extends BaseTypeService {
864
863
  return fn({ list: [['..', 0]] }).pipe(switchMap(({ list: [] }) => useThen$), map((a) => (a === undefined ? true : isThen ? !a : a)), distinctUntilChanged());
865
864
  },
866
865
  }),
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
- });
875
- },
876
- }),
877
866
  ];
878
867
  }
879
868
  let thenSchema;
880
869
  if (schema$1.then && !isBoolean(schema$1.then)) {
881
- const subSchema = this.#mergeSchema(schema$1, schema$1.then);
882
- thenSchema = v.pipe(this.#jsonSchemaBase(subSchema.schema, () => [
883
- ...subSchema.actionList,
870
+ const subSchema = this.resolveSchema2(schema$1.then);
871
+ thenSchema = v.pipe(this.#jsonSchemaBase(subSchema, () => [
872
+ ...this.getValidationActionList(subSchema),
873
+ ...hideAction(true),
884
874
  ]));
875
+ if (!subSchema.__resolved.type.types.includes('object')) {
876
+ thenSchema = v.pipe(thenSchema, jsonActions.setComponent(''), jsonActions.renderConfig({ hidden: true }));
877
+ }
885
878
  }
886
879
  else {
887
- thenSchema = base1Schema;
880
+ thenSchema = EMPTY_DEFINE;
888
881
  }
889
- thenSchema = v.pipe(thenSchema, ...hideAction(true));
890
882
  let elseSchema;
891
883
  if (schema$1.else && !isBoolean(schema$1.else)) {
892
- const subSchema = this.#mergeSchema(schema$1, schema$1.else);
893
- elseSchema = v.pipe(this.#jsonSchemaBase(subSchema.schema, () => [
894
- ...subSchema.actionList,
884
+ const subSchema = this.resolveSchema2(schema$1.else);
885
+ elseSchema = v.pipe(this.#jsonSchemaBase(subSchema, () => [
886
+ ...this.getValidationActionList(subSchema),
887
+ ...hideAction(false),
895
888
  ]));
889
+ if (!subSchema.__resolved.type.types.includes('object')) {
890
+ elseSchema = v.pipe(elseSchema, jsonActions.setComponent(''), jsonActions.renderConfig({ hidden: true }));
891
+ }
896
892
  }
897
893
  else {
898
- elseSchema = base1Schema;
894
+ elseSchema = EMPTY_DEFINE;
899
895
  }
900
- elseSchema = v.pipe(elseSchema, ...hideAction(false));
901
896
  // 这种逻辑没问题,因为jsonschema验证中,也会出现base和子级架构一起验证
902
897
  vSchema = v.pipe(v.union([baseSchema, thenSchema, elseSchema]), jsonActions.formConfig({ disableOrUpdateActivate: true }), v.rawCheck(({ dataset, addIssue }) => {
903
898
  if (dataset.issues) {
904
899
  return;
905
900
  }
901
+ const result = v.safeParse(baseSchema, dataset.value);
902
+ if (!result.success) {
903
+ addIssue({ label: `if:default` });
904
+ return;
905
+ }
906
906
  const status = useThen$.value;
907
907
  if (status && thenSchema) {
908
908
  const result = v.safeParse(thenSchema, dataset.value);
909
909
  if (!result.success) {
910
- addIssue();
910
+ addIssue({ label: `if:then` });
911
911
  return;
912
912
  }
913
913
  }
914
914
  if (!status && elseSchema) {
915
915
  const result = v.safeParse(elseSchema, dataset.value);
916
916
  if (!result.success) {
917
- addIssue();
917
+ addIssue({ label: `if:else` });
918
918
  return;
919
919
  }
920
920
  }