@piying/view-angular-core 1.9.0 → 1.9.2
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, combineLatest } from 'rxjs';
|
|
7
7
|
import { schema } from '@piying/valibot-visit';
|
|
8
8
|
import rfdc from 'rfdc';
|
|
9
9
|
|
|
@@ -262,7 +262,7 @@ class ConstTypeService extends BaseTypeService {
|
|
|
262
262
|
name = 'const';
|
|
263
263
|
parseBase(actionList) {
|
|
264
264
|
const value = this.schema.const;
|
|
265
|
-
const Define = v.pipe(v.
|
|
265
|
+
const Define = v.pipe(v.literal(value), ...this.getAllActionList(actionList));
|
|
266
266
|
return Define;
|
|
267
267
|
}
|
|
268
268
|
}
|
|
@@ -832,24 +832,24 @@ class CommonTypeService extends BaseTypeService {
|
|
|
832
832
|
* 也就是then/else都会合并base,然后按条件展示,
|
|
833
833
|
*/
|
|
834
834
|
const useThen$ = new BehaviorSubject(undefined);
|
|
835
|
-
|
|
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.
|
|
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,7 @@ 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
865
|
},
|
|
866
866
|
}),
|
|
867
867
|
];
|
|
@@ -871,23 +871,25 @@ class CommonTypeService extends BaseTypeService {
|
|
|
871
871
|
const subSchema = this.#mergeSchema(schema$1, schema$1.then);
|
|
872
872
|
thenSchema = v.pipe(this.#jsonSchemaBase(subSchema.schema, () => [
|
|
873
873
|
...subSchema.actionList,
|
|
874
|
-
...hideAction(true),
|
|
875
874
|
]));
|
|
876
875
|
}
|
|
876
|
+
else {
|
|
877
|
+
thenSchema = base1Schema;
|
|
878
|
+
}
|
|
879
|
+
thenSchema = v.pipe(thenSchema, ...hideAction(true));
|
|
877
880
|
let elseSchema;
|
|
878
881
|
if (schema$1.else && !isBoolean(schema$1.else)) {
|
|
879
882
|
const subSchema = this.#mergeSchema(schema$1, schema$1.else);
|
|
880
883
|
elseSchema = v.pipe(this.#jsonSchemaBase(subSchema.schema, () => [
|
|
881
884
|
...subSchema.actionList,
|
|
882
|
-
...hideAction(false),
|
|
883
885
|
]));
|
|
884
886
|
}
|
|
887
|
+
else {
|
|
888
|
+
elseSchema = base1Schema;
|
|
889
|
+
}
|
|
890
|
+
elseSchema = v.pipe(elseSchema, ...hideAction(false));
|
|
885
891
|
// 这种逻辑没问题,因为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 }) => {
|
|
892
|
+
vSchema = v.pipe(v.union([baseSchema, thenSchema, elseSchema]), jsonActions.formConfig({ disableOrUpdateActivate: true }), v.rawCheck(({ dataset, addIssue }) => {
|
|
891
893
|
if (dataset.issues) {
|
|
892
894
|
return;
|
|
893
895
|
}
|
|
@@ -1227,7 +1229,7 @@ class CommonTypeService extends BaseTypeService {
|
|
|
1227
1229
|
properties: {},
|
|
1228
1230
|
additionalProperties: false,
|
|
1229
1231
|
};
|
|
1230
|
-
const childConditionJSchemaList = childList.map(() => ({ properties: {} }));
|
|
1232
|
+
const childConditionJSchemaList = childList.map(() => ({ properties: {}, required: [] }));
|
|
1231
1233
|
const conditionKeyList = [];
|
|
1232
1234
|
for (const key of childKeyList) {
|
|
1233
1235
|
const parentItem = schema.properties?.[key];
|
|
@@ -1245,6 +1247,9 @@ class CommonTypeService extends BaseTypeService {
|
|
|
1245
1247
|
};
|
|
1246
1248
|
childConditionJSchemaList.forEach((item, i) => {
|
|
1247
1249
|
item.properties[key] = childList[i].properties[key];
|
|
1250
|
+
if (childList[i].required && childList[i].required.includes(key)) {
|
|
1251
|
+
item.required.push(key);
|
|
1252
|
+
}
|
|
1248
1253
|
});
|
|
1249
1254
|
}
|
|
1250
1255
|
else {
|
|
@@ -1255,6 +1260,9 @@ class CommonTypeService extends BaseTypeService {
|
|
|
1255
1260
|
};
|
|
1256
1261
|
childConditionJSchemaList.forEach((item, i) => {
|
|
1257
1262
|
item.properties[key] = childList[i].properties[key];
|
|
1263
|
+
if (childList[i].required && childList[i].required.includes(key)) {
|
|
1264
|
+
item.required.push(key);
|
|
1265
|
+
}
|
|
1258
1266
|
});
|
|
1259
1267
|
}
|
|
1260
1268
|
}
|