@piying/view-angular-core 1.10.4 → 2.0.1
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { signal, computed, InjectionToken, effect, inject, Injector, untracked, DestroyRef, linkedSignal, isSignal, EnvironmentInjector } from '@angular/core';
|
|
2
2
|
import * as v from 'valibot';
|
|
3
|
-
import { isObservable, BehaviorSubject, Subject, combineLatest, startWith, skip, map } from 'rxjs';
|
|
3
|
+
import { isObservable, BehaviorSubject, Subject, tap, pipe, shareReplay, combineLatest, startWith, skip, map } from 'rxjs';
|
|
4
4
|
import rfdc from 'rfdc';
|
|
5
5
|
import { deepEqual } from 'fast-equals';
|
|
6
6
|
import { createRawConfig, metadataList, defineName, BaseSchemaHandle, convertSchema, convertCore } from '@piying/valibot-visit';
|
|
@@ -919,20 +919,6 @@ key, formConfig$$, isRoot, injector) {
|
|
|
919
919
|
return control;
|
|
920
920
|
}
|
|
921
921
|
|
|
922
|
-
function unWrapSignal$1(value) {
|
|
923
|
-
return isSignal(value) ? value() : value;
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
const DCONFIG_EFAULT_MERGE_STRAGEGY = {
|
|
927
|
-
props: 'merge',
|
|
928
|
-
formConfig: 'merge',
|
|
929
|
-
renderConfig: 'merge',
|
|
930
|
-
inputs: 'merge',
|
|
931
|
-
outputs: 'merge',
|
|
932
|
-
wrappers: 'replace',
|
|
933
|
-
attributes: 'merge',
|
|
934
|
-
};
|
|
935
|
-
|
|
936
922
|
class ParentMap extends Map {
|
|
937
923
|
parent;
|
|
938
924
|
constructor(parent) {
|
|
@@ -952,10 +938,6 @@ function arrayStartsWith(list, parts) {
|
|
|
952
938
|
return (Array.isArray(parts) ? parts : [parts]).every((item, index) => item === list[index]);
|
|
953
939
|
}
|
|
954
940
|
|
|
955
|
-
function unWrapSignal(value) {
|
|
956
|
-
return isSignal(value) ? value() : value;
|
|
957
|
-
}
|
|
958
|
-
|
|
959
941
|
function toArray(input) {
|
|
960
942
|
return input === undefined
|
|
961
943
|
? input
|
|
@@ -1048,11 +1030,10 @@ function createViewControlLink(fieldControl, cva, injector) {
|
|
|
1048
1030
|
}
|
|
1049
1031
|
return (destroy) => {
|
|
1050
1032
|
disposeList.forEach((fn) => fn());
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
}
|
|
1033
|
+
// todo 需要优化
|
|
1034
|
+
untracked(() => {
|
|
1035
|
+
fieldControl().updateValue(fieldControl().value$$(), true);
|
|
1036
|
+
});
|
|
1056
1037
|
};
|
|
1057
1038
|
}
|
|
1058
1039
|
|
|
@@ -1134,6 +1115,173 @@ function getDeepError(control) {
|
|
|
1134
1115
|
return list;
|
|
1135
1116
|
}
|
|
1136
1117
|
|
|
1118
|
+
const DefaultOptions$1 = { autoDestroy: true };
|
|
1119
|
+
/** set输入,()输出的是管道后的值, */
|
|
1120
|
+
function observableSignal(initialValue, options) {
|
|
1121
|
+
options = { ...DefaultOptions$1, ...options };
|
|
1122
|
+
const inputS$ = signal(initialValue, options);
|
|
1123
|
+
const outputS$ = signal(undefined);
|
|
1124
|
+
const loading$ = signal(false);
|
|
1125
|
+
const inputR$ = new BehaviorSubject(undefined);
|
|
1126
|
+
inputR$.next(inputS$());
|
|
1127
|
+
const data = inputR$.pipe(tap(() => {
|
|
1128
|
+
loading$.set(true);
|
|
1129
|
+
}), options?.pipe ? options.pipe : pipe(), shareReplay());
|
|
1130
|
+
const oldOutputSet = outputS$.set;
|
|
1131
|
+
data.subscribe((value) => {
|
|
1132
|
+
oldOutputSet(value);
|
|
1133
|
+
loading$.set(false);
|
|
1134
|
+
});
|
|
1135
|
+
const oldSet = inputS$.set;
|
|
1136
|
+
const changed$ = outputS$;
|
|
1137
|
+
changed$.set = (value) => {
|
|
1138
|
+
inputR$.next(value);
|
|
1139
|
+
return oldSet(value);
|
|
1140
|
+
};
|
|
1141
|
+
changed$.update = (fn) => {
|
|
1142
|
+
const newValue = fn(inputS$());
|
|
1143
|
+
return changed$.set(newValue);
|
|
1144
|
+
};
|
|
1145
|
+
changed$.output = outputS$;
|
|
1146
|
+
changed$.input = inputS$;
|
|
1147
|
+
changed$.input$$ = inputR$.asObservable();
|
|
1148
|
+
changed$.output$$ = data;
|
|
1149
|
+
changed$.subject = inputR$;
|
|
1150
|
+
if (options?.injector || options.autoDestroy) {
|
|
1151
|
+
const injector = options?.injector ?? inject(Injector, { optional: true });
|
|
1152
|
+
if (injector) {
|
|
1153
|
+
injector.get(DestroyRef).onDestroy(() => {
|
|
1154
|
+
inputR$.complete();
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
return changed$;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
function asyncObjectSignal(initialValue, options) {
|
|
1162
|
+
const data$ = signal(initialValue);
|
|
1163
|
+
let mapFn$ = signal(undefined);
|
|
1164
|
+
const signalList$ = signal([]);
|
|
1165
|
+
const value$$ = computed(() => {
|
|
1166
|
+
const signalList = signalList$();
|
|
1167
|
+
const data = data$();
|
|
1168
|
+
let mapFn = mapFn$();
|
|
1169
|
+
if (!signalList.length) {
|
|
1170
|
+
return mapFn ? mapFn(data) : data;
|
|
1171
|
+
}
|
|
1172
|
+
const data2 = { ...data };
|
|
1173
|
+
signalList.forEach(([key, value]) => {
|
|
1174
|
+
data2[key] = value();
|
|
1175
|
+
});
|
|
1176
|
+
return mapFn ? mapFn(data2) : data2;
|
|
1177
|
+
}, options);
|
|
1178
|
+
const disposeMap = new Map();
|
|
1179
|
+
const changed$ = value$$;
|
|
1180
|
+
changed$.connect = (key, value) => {
|
|
1181
|
+
changed$.disconnect(key);
|
|
1182
|
+
let dispose;
|
|
1183
|
+
if (isPromise(value)) {
|
|
1184
|
+
// promise
|
|
1185
|
+
let isDestroy = false;
|
|
1186
|
+
value.then((value) => {
|
|
1187
|
+
if (isDestroy) {
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
data$.update((lastData) => ({ ...lastData, [key]: value }));
|
|
1191
|
+
});
|
|
1192
|
+
dispose = () => {
|
|
1193
|
+
isDestroy = true;
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
else if (isSubscribable(value)) {
|
|
1197
|
+
// rxjs
|
|
1198
|
+
const ref = value.subscribe({
|
|
1199
|
+
next: (value) => {
|
|
1200
|
+
data$.update((lastData) => ({ ...lastData, [key]: value }));
|
|
1201
|
+
},
|
|
1202
|
+
});
|
|
1203
|
+
dispose = () => {
|
|
1204
|
+
ref.unsubscribe();
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
else if (isSignal(value)) {
|
|
1208
|
+
signalList$.update((list) => {
|
|
1209
|
+
list = list.slice();
|
|
1210
|
+
list.push([key, value]);
|
|
1211
|
+
return list;
|
|
1212
|
+
});
|
|
1213
|
+
dispose = () => {
|
|
1214
|
+
signalList$.update((list) => {
|
|
1215
|
+
const index = list.findIndex((item) => value === item[1]);
|
|
1216
|
+
if (index !== -1) {
|
|
1217
|
+
list = list.slice();
|
|
1218
|
+
list.splice(index, 1);
|
|
1219
|
+
}
|
|
1220
|
+
return list;
|
|
1221
|
+
});
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
else {
|
|
1225
|
+
// 普通类型
|
|
1226
|
+
data$.update((lastData) => ({ ...lastData, [key]: value }));
|
|
1227
|
+
}
|
|
1228
|
+
if (dispose) {
|
|
1229
|
+
disposeMap.set(key, dispose);
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
changed$.disconnect = (key) => {
|
|
1233
|
+
untracked(() => {
|
|
1234
|
+
disposeMap.get(key)?.();
|
|
1235
|
+
disposeMap.delete(key);
|
|
1236
|
+
});
|
|
1237
|
+
};
|
|
1238
|
+
changed$.set = (key) => {
|
|
1239
|
+
data$.set(key);
|
|
1240
|
+
};
|
|
1241
|
+
changed$.update = (fn) => {
|
|
1242
|
+
const result = fn(changed$());
|
|
1243
|
+
data$.set(result);
|
|
1244
|
+
};
|
|
1245
|
+
changed$.map = (input) => {
|
|
1246
|
+
mapFn$.set(input);
|
|
1247
|
+
};
|
|
1248
|
+
return changed$;
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
function combineSignal(initialValue = [], options) {
|
|
1252
|
+
const list$ = signal(initialValue);
|
|
1253
|
+
const input$$ = computed(() => list$().map((item) => item()), options);
|
|
1254
|
+
const changed$ = input$$;
|
|
1255
|
+
changed$.add = (item, index) => {
|
|
1256
|
+
list$.update((list) => {
|
|
1257
|
+
if (typeof index === 'number') {
|
|
1258
|
+
list = list.slice();
|
|
1259
|
+
list.splice(index, 0, item);
|
|
1260
|
+
return list;
|
|
1261
|
+
}
|
|
1262
|
+
return [...list, item];
|
|
1263
|
+
});
|
|
1264
|
+
};
|
|
1265
|
+
changed$.remove = (item) => {
|
|
1266
|
+
list$.update((list) => {
|
|
1267
|
+
const index = list.indexOf(item);
|
|
1268
|
+
if (index === -1) {
|
|
1269
|
+
return list;
|
|
1270
|
+
}
|
|
1271
|
+
list = list.slice();
|
|
1272
|
+
list.splice(index, 1);
|
|
1273
|
+
return list;
|
|
1274
|
+
});
|
|
1275
|
+
};
|
|
1276
|
+
changed$.items = () => list$();
|
|
1277
|
+
changed$.clean = () => list$.set([]);
|
|
1278
|
+
changed$.update = (fn) => {
|
|
1279
|
+
const list = fn(list$());
|
|
1280
|
+
list$.set(list);
|
|
1281
|
+
};
|
|
1282
|
+
return changed$;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1137
1285
|
function* groupGenerator(list) {
|
|
1138
1286
|
for (const item of list) {
|
|
1139
1287
|
if (!item.keyPath?.length && item.fixedChildren?.().length) {
|
|
@@ -1187,86 +1335,40 @@ const FindConfigToken = new InjectionToken('FindConfig');
|
|
|
1187
1335
|
function FindConfigFactory() {
|
|
1188
1336
|
const globalConfig = inject(PI_VIEW_CONFIG_TOKEN);
|
|
1189
1337
|
return {
|
|
1190
|
-
|
|
1338
|
+
findWrapperComponent: (wrapper) => {
|
|
1191
1339
|
let config;
|
|
1192
1340
|
let type;
|
|
1193
1341
|
if (typeof wrapper === 'string') {
|
|
1194
1342
|
config = globalConfig?.wrappers?.[wrapper];
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
else if (typeof wrapper.type === 'string') {
|
|
1198
|
-
const defaultConfig = globalConfig?.wrappers?.[wrapper.type];
|
|
1199
|
-
if (defaultConfig) {
|
|
1200
|
-
config = {
|
|
1201
|
-
type: defaultConfig.type,
|
|
1202
|
-
inputs: { ...defaultConfig.inputs, ...wrapper.inputs },
|
|
1203
|
-
attributes: { ...defaultConfig.attributes, ...wrapper.attributes },
|
|
1204
|
-
outputs: { ...defaultConfig.outputs, ...wrapper.outputs },
|
|
1205
|
-
};
|
|
1343
|
+
if (!config) {
|
|
1344
|
+
throw new Error(`🈳wrapper:[${type}]❗`);
|
|
1206
1345
|
}
|
|
1207
|
-
|
|
1208
|
-
}
|
|
1209
|
-
else {
|
|
1210
|
-
config = wrapper;
|
|
1211
|
-
}
|
|
1212
|
-
if (!config) {
|
|
1213
|
-
throw new Error(`🈳wrapper:[${type}]❗`);
|
|
1346
|
+
return config?.type;
|
|
1214
1347
|
}
|
|
1215
|
-
return
|
|
1348
|
+
return wrapper;
|
|
1216
1349
|
},
|
|
1217
1350
|
findComponentConfig: (type) => {
|
|
1218
|
-
let define;
|
|
1219
|
-
let defaultConfig;
|
|
1220
1351
|
if (typeof type === 'string') {
|
|
1221
1352
|
const config = globalConfig?.types?.[type];
|
|
1222
1353
|
if (!config) {
|
|
1223
1354
|
throw new Error(`🈳define:[${type}]❗`);
|
|
1224
1355
|
}
|
|
1225
|
-
|
|
1226
|
-
if (Object.keys(config).length) {
|
|
1227
|
-
define = {
|
|
1228
|
-
...config,
|
|
1229
|
-
};
|
|
1230
|
-
return {
|
|
1231
|
-
define: { ...config },
|
|
1232
|
-
defaultConfig,
|
|
1233
|
-
};
|
|
1234
|
-
}
|
|
1356
|
+
return config.type;
|
|
1235
1357
|
}
|
|
1236
1358
|
else {
|
|
1237
|
-
return
|
|
1359
|
+
return type;
|
|
1238
1360
|
}
|
|
1239
|
-
return {
|
|
1240
|
-
define,
|
|
1241
|
-
defaultConfig,
|
|
1242
|
-
};
|
|
1243
1361
|
},
|
|
1244
1362
|
};
|
|
1245
1363
|
}
|
|
1246
1364
|
|
|
1247
1365
|
var _a;
|
|
1248
|
-
// todo 临时同步
|
|
1249
|
-
function defineSync(field) {
|
|
1250
|
-
const define = field.define?.();
|
|
1251
|
-
if (define &&
|
|
1252
|
-
(field.inputs !== define.inputs ||
|
|
1253
|
-
field.outputs !== define.outputs ||
|
|
1254
|
-
field.attributes !== define.attributes)) {
|
|
1255
|
-
field.define = signal({
|
|
1256
|
-
...define,
|
|
1257
|
-
inputs: field.inputs,
|
|
1258
|
-
outputs: field.outputs,
|
|
1259
|
-
attributes: field.attributes,
|
|
1260
|
-
});
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
1366
|
class FormBuilder {
|
|
1264
1367
|
#scopeMap = inject(PI_FORM_BUILDER_ALIAS_MAP, { optional: true }) ??
|
|
1265
1368
|
new ParentMap();
|
|
1266
1369
|
#options = inject(PI_FORM_BUILDER_OPTIONS_TOKEN);
|
|
1267
1370
|
#injector = inject(Injector);
|
|
1268
1371
|
#envInjector = inject(EnvironmentInjector);
|
|
1269
|
-
#globalConfig = inject(PI_VIEW_CONFIG_TOKEN);
|
|
1270
1372
|
#allFieldInitHookList = [];
|
|
1271
1373
|
buildRoot(item) {
|
|
1272
1374
|
const field = this.#buildControl({
|
|
@@ -1307,51 +1409,17 @@ class FormBuilder {
|
|
|
1307
1409
|
// 单独一项
|
|
1308
1410
|
field, index) {
|
|
1309
1411
|
// 利用类型查引用,
|
|
1310
|
-
let viewDefaultConfig;
|
|
1311
1412
|
const type = field.type;
|
|
1312
1413
|
let define;
|
|
1313
1414
|
if (type) {
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
const
|
|
1319
|
-
const
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
field.inputs,
|
|
1323
|
-
], false, mergeStrategy?.inputs ?? DCONFIG_EFAULT_MERGE_STRAGEGY.inputs);
|
|
1324
|
-
const outputs = this.configMerge([
|
|
1325
|
-
this.#globalConfig?.defaultConfig?.outputs,
|
|
1326
|
-
viewDefaultConfig?.outputs,
|
|
1327
|
-
field.outputs,
|
|
1328
|
-
], false, mergeStrategy?.outputs ?? DCONFIG_EFAULT_MERGE_STRAGEGY.outputs);
|
|
1329
|
-
const attributes = this.configMerge([
|
|
1330
|
-
this.#globalConfig?.defaultConfig?.attributes,
|
|
1331
|
-
viewDefaultConfig?.attributes,
|
|
1332
|
-
field.attributes,
|
|
1333
|
-
], false, mergeStrategy?.attributes ?? DCONFIG_EFAULT_MERGE_STRAGEGY.attributes);
|
|
1334
|
-
const wrappers1 = this.configMergeRaw([
|
|
1335
|
-
this.#globalConfig?.defaultConfig?.wrappers,
|
|
1336
|
-
viewDefaultConfig?.wrappers,
|
|
1337
|
-
field.wrappers,
|
|
1338
|
-
], true, mergeStrategy?.wrappers ?? DCONFIG_EFAULT_MERGE_STRAGEGY.wrappers);
|
|
1339
|
-
const wrappers = this.#resolveWrappers(wrappers1);
|
|
1340
|
-
const props = this.configMerge([
|
|
1341
|
-
this.#globalConfig?.defaultConfig?.props,
|
|
1342
|
-
viewDefaultConfig?.props,
|
|
1343
|
-
field.props,
|
|
1344
|
-
], false, mergeStrategy?.props ?? DCONFIG_EFAULT_MERGE_STRAGEGY.props);
|
|
1345
|
-
const formConfig$ = this.configMerge([
|
|
1346
|
-
this.#globalConfig?.defaultConfig?.formConfig,
|
|
1347
|
-
viewDefaultConfig?.formConfig,
|
|
1348
|
-
field.formConfig,
|
|
1349
|
-
], false, mergeStrategy?.formConfig ?? DCONFIG_EFAULT_MERGE_STRAGEGY.formConfig);
|
|
1350
|
-
const renderConfig = this.configMerge([
|
|
1351
|
-
this.#globalConfig?.defaultConfig?.renderConfig,
|
|
1352
|
-
viewDefaultConfig?.renderConfig,
|
|
1353
|
-
field.renderConfig,
|
|
1354
|
-
], false, mergeStrategy?.renderConfig ?? DCONFIG_EFAULT_MERGE_STRAGEGY.renderConfig);
|
|
1415
|
+
define = this.#findConfig.findComponentConfig(type);
|
|
1416
|
+
}
|
|
1417
|
+
const inputs = field.inputs;
|
|
1418
|
+
const outputs = field.outputs;
|
|
1419
|
+
const attributes = field.attributes;
|
|
1420
|
+
const events = field.events;
|
|
1421
|
+
const formConfig$ = signal(field.formConfig ?? {});
|
|
1422
|
+
const renderConfig = signal(field.renderConfig ?? {});
|
|
1355
1423
|
let control;
|
|
1356
1424
|
let keyPath = field.key;
|
|
1357
1425
|
if (isFieldLogicGroup(parent.form)) {
|
|
@@ -1388,23 +1456,31 @@ class FormBuilder {
|
|
|
1388
1456
|
origin: field,
|
|
1389
1457
|
renderConfig: renderConfig,
|
|
1390
1458
|
formConfig: formConfig$,
|
|
1391
|
-
props,
|
|
1459
|
+
props: field.props,
|
|
1392
1460
|
context: this.#options.context,
|
|
1393
1461
|
priority: field.priority,
|
|
1394
1462
|
hooks: field.hooks,
|
|
1395
1463
|
alias: field.alias,
|
|
1396
|
-
inputs
|
|
1397
|
-
|
|
1398
|
-
|
|
1464
|
+
get inputs() {
|
|
1465
|
+
return resolvedConfig.define().inputs;
|
|
1466
|
+
},
|
|
1467
|
+
get outputs() {
|
|
1468
|
+
return resolvedConfig.define().outputs;
|
|
1469
|
+
},
|
|
1470
|
+
get events() {
|
|
1471
|
+
return resolvedConfig.define().events;
|
|
1472
|
+
},
|
|
1473
|
+
get attributes() {
|
|
1474
|
+
return resolvedConfig.define().attributes;
|
|
1475
|
+
},
|
|
1399
1476
|
define: define
|
|
1400
|
-
? signal({
|
|
1477
|
+
? signal({ type: define, inputs, outputs, attributes, events })
|
|
1401
1478
|
: undefined,
|
|
1402
|
-
wrappers,
|
|
1479
|
+
wrappers: field.wrappers,
|
|
1403
1480
|
injector: this.#envInjector,
|
|
1404
1481
|
};
|
|
1405
1482
|
resolvedConfig =
|
|
1406
1483
|
this.afterResolveConfig(field, resolvedConfig) ?? resolvedConfig;
|
|
1407
|
-
defineSync(resolvedConfig);
|
|
1408
1484
|
if (field.movePath) {
|
|
1409
1485
|
this.#moveViewField(field.movePath, resolvedConfig);
|
|
1410
1486
|
}
|
|
@@ -1618,38 +1694,6 @@ class FormBuilder {
|
|
|
1618
1694
|
result.injector = injector.get(EnvironmentInjector);
|
|
1619
1695
|
return result;
|
|
1620
1696
|
}
|
|
1621
|
-
configMergeRaw(list, isArray, strategy) {
|
|
1622
|
-
let value;
|
|
1623
|
-
if (isArray) {
|
|
1624
|
-
if (strategy === 'merge') {
|
|
1625
|
-
value = list
|
|
1626
|
-
.filter(Boolean)
|
|
1627
|
-
.flat()
|
|
1628
|
-
.map((item) => unWrapSignal$1(item));
|
|
1629
|
-
}
|
|
1630
|
-
else {
|
|
1631
|
-
value = list.reduce((data, item) => unWrapSignal$1(item) ?? data, []);
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
else {
|
|
1635
|
-
if (strategy === 'merge') {
|
|
1636
|
-
value = list.reduce((obj, item) => ({
|
|
1637
|
-
...obj,
|
|
1638
|
-
...unWrapSignal$1(item),
|
|
1639
|
-
}), {});
|
|
1640
|
-
}
|
|
1641
|
-
else {
|
|
1642
|
-
value = list.reduce((data, item) => unWrapSignal$1(item) ?? data, {});
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
return value;
|
|
1646
|
-
}
|
|
1647
|
-
/**
|
|
1648
|
-
* 后面覆盖前面
|
|
1649
|
-
* */
|
|
1650
|
-
configMerge(list, isArray, strategy) {
|
|
1651
|
-
return signal(this.configMergeRaw(list, isArray, strategy));
|
|
1652
|
-
}
|
|
1653
1697
|
#moveViewField(key, inputField) {
|
|
1654
1698
|
const parent = fieldQuery(key, inputField, this.#scopeMap, this.#options.resolvedField$());
|
|
1655
1699
|
if (!parent) {
|
|
@@ -1661,18 +1705,6 @@ class FormBuilder {
|
|
|
1661
1705
|
parent.fixedChildren().push(inputField);
|
|
1662
1706
|
}
|
|
1663
1707
|
#findConfig = inject(FindConfigToken);
|
|
1664
|
-
#resolveWrappers(wrappers) {
|
|
1665
|
-
const result = (wrappers ?? []).map((wrapper) => {
|
|
1666
|
-
const config = this.#findConfig.findWrapper(wrapper);
|
|
1667
|
-
return {
|
|
1668
|
-
inputs: signal(config.inputs),
|
|
1669
|
-
outputs: config.outputs,
|
|
1670
|
-
attributes: signal(config.attributes),
|
|
1671
|
-
type: config.type,
|
|
1672
|
-
};
|
|
1673
|
-
});
|
|
1674
|
-
return signal(result);
|
|
1675
|
-
}
|
|
1676
1708
|
}
|
|
1677
1709
|
_a = FormBuilder;
|
|
1678
1710
|
|
|
@@ -1703,8 +1735,7 @@ function setComponent(type) {
|
|
|
1703
1735
|
});
|
|
1704
1736
|
}
|
|
1705
1737
|
function findComponent(field, type) {
|
|
1706
|
-
return field.injector.get(FindConfigToken).findComponentConfig(type)
|
|
1707
|
-
.type;
|
|
1738
|
+
return field.injector.get(FindConfigToken).findComponentConfig(type);
|
|
1708
1739
|
}
|
|
1709
1740
|
|
|
1710
1741
|
const setHooks = (hooks) => rawConfig((field) => {
|
|
@@ -1743,223 +1774,6 @@ function removeHooks(list) {
|
|
|
1743
1774
|
});
|
|
1744
1775
|
}
|
|
1745
1776
|
|
|
1746
|
-
function setInputs(inputs) {
|
|
1747
|
-
return rawConfig((field) => {
|
|
1748
|
-
field.inputs = inputs;
|
|
1749
|
-
});
|
|
1750
|
-
}
|
|
1751
|
-
function patchInputs(inputs) {
|
|
1752
|
-
return rawConfig((field) => {
|
|
1753
|
-
field.inputs = {
|
|
1754
|
-
...field.inputs,
|
|
1755
|
-
...inputs,
|
|
1756
|
-
};
|
|
1757
|
-
});
|
|
1758
|
-
}
|
|
1759
|
-
function removeInputs(list) {
|
|
1760
|
-
return rawConfig((field) => {
|
|
1761
|
-
const oldValue = unWrapSignal(field.inputs);
|
|
1762
|
-
if (!oldValue) {
|
|
1763
|
-
return;
|
|
1764
|
-
}
|
|
1765
|
-
list.forEach((item) => {
|
|
1766
|
-
delete oldValue[item];
|
|
1767
|
-
});
|
|
1768
|
-
field.inputs = oldValue;
|
|
1769
|
-
});
|
|
1770
|
-
}
|
|
1771
|
-
function asyncInputMerge(dataObj, data$) {
|
|
1772
|
-
const signalObj = {};
|
|
1773
|
-
const inputList = Object.keys(dataObj);
|
|
1774
|
-
inputList.forEach((key) => {
|
|
1775
|
-
const result = dataObj[key];
|
|
1776
|
-
if (isPromise(result)) {
|
|
1777
|
-
// promise
|
|
1778
|
-
result.then((value) => {
|
|
1779
|
-
data$.update((lastData) => {
|
|
1780
|
-
lastData = { ...lastData };
|
|
1781
|
-
lastData[key] = value;
|
|
1782
|
-
return lastData;
|
|
1783
|
-
});
|
|
1784
|
-
});
|
|
1785
|
-
}
|
|
1786
|
-
else if (isSubscribable(result)) {
|
|
1787
|
-
// rxjs
|
|
1788
|
-
result.subscribe({
|
|
1789
|
-
next: (value) => {
|
|
1790
|
-
data$.update((lastData) => {
|
|
1791
|
-
lastData = { ...lastData };
|
|
1792
|
-
lastData[key] = value;
|
|
1793
|
-
return lastData;
|
|
1794
|
-
});
|
|
1795
|
-
},
|
|
1796
|
-
});
|
|
1797
|
-
}
|
|
1798
|
-
else if (isSignal(result)) {
|
|
1799
|
-
signalObj[key] = result;
|
|
1800
|
-
}
|
|
1801
|
-
else {
|
|
1802
|
-
// 普通类型
|
|
1803
|
-
data$.update((lastData) => {
|
|
1804
|
-
lastData = { ...lastData };
|
|
1805
|
-
lastData[key] = result;
|
|
1806
|
-
return lastData;
|
|
1807
|
-
});
|
|
1808
|
-
}
|
|
1809
|
-
});
|
|
1810
|
-
const signalKeyList = Object.keys(signalObj);
|
|
1811
|
-
if (signalKeyList.length) {
|
|
1812
|
-
const newData = linkedSignal(computed(() => ({
|
|
1813
|
-
...data$(),
|
|
1814
|
-
...signalKeyList.reduce((obj, key) => ({ ...obj, [key]: signalObj[key]() }), {}),
|
|
1815
|
-
})));
|
|
1816
|
-
newData.set = (value) => {
|
|
1817
|
-
data$.set(value);
|
|
1818
|
-
};
|
|
1819
|
-
newData.update = (fn) => {
|
|
1820
|
-
const result = fn(newData());
|
|
1821
|
-
data$.set(result);
|
|
1822
|
-
};
|
|
1823
|
-
return newData;
|
|
1824
|
-
}
|
|
1825
|
-
return data$;
|
|
1826
|
-
}
|
|
1827
|
-
function patchAsyncFn(patchKey) {
|
|
1828
|
-
return (dataObj, options) => rawConfig((rawField) => {
|
|
1829
|
-
const inputList = Object.keys(dataObj);
|
|
1830
|
-
const hookName = options?.hookName ?? 'allFieldsResolved';
|
|
1831
|
-
// 设置初始值
|
|
1832
|
-
rawField[patchKey] = {
|
|
1833
|
-
...rawField[patchKey],
|
|
1834
|
-
...inputList.reduce((obj, item) => {
|
|
1835
|
-
obj[item] = rawField[patchKey]?.[item] ?? undefined;
|
|
1836
|
-
return obj;
|
|
1837
|
-
}, {}),
|
|
1838
|
-
};
|
|
1839
|
-
return mergeHooksFn({
|
|
1840
|
-
[hookName]: (field) => {
|
|
1841
|
-
const result = asyncInputMerge(Object.entries(dataObj).reduce((obj, [key, value]) => {
|
|
1842
|
-
obj[key] = value(field);
|
|
1843
|
-
return obj;
|
|
1844
|
-
}, {}), field[patchKey]);
|
|
1845
|
-
if (patchKey !== 'props') {
|
|
1846
|
-
field.define.update((data) => ({
|
|
1847
|
-
...data,
|
|
1848
|
-
[patchKey]: result,
|
|
1849
|
-
}));
|
|
1850
|
-
}
|
|
1851
|
-
field[patchKey] =
|
|
1852
|
-
result;
|
|
1853
|
-
},
|
|
1854
|
-
}, { position: options?.addPosition ?? 'bottom' }, rawField);
|
|
1855
|
-
});
|
|
1856
|
-
}
|
|
1857
|
-
const patchAsyncInputs = patchAsyncFn('inputs');
|
|
1858
|
-
|
|
1859
|
-
function setAttributes(attributes) {
|
|
1860
|
-
return rawConfig((field) => {
|
|
1861
|
-
field.attributes = attributes;
|
|
1862
|
-
});
|
|
1863
|
-
}
|
|
1864
|
-
function patchAttributes(attributes) {
|
|
1865
|
-
return rawConfig((field) => {
|
|
1866
|
-
field.attributes = {
|
|
1867
|
-
...field.attributes,
|
|
1868
|
-
...attributes,
|
|
1869
|
-
};
|
|
1870
|
-
});
|
|
1871
|
-
}
|
|
1872
|
-
function removeAttributes(list) {
|
|
1873
|
-
return rawConfig((field) => {
|
|
1874
|
-
const oldValue = unWrapSignal(field.attributes);
|
|
1875
|
-
if (!oldValue) {
|
|
1876
|
-
return;
|
|
1877
|
-
}
|
|
1878
|
-
list.forEach((item) => {
|
|
1879
|
-
delete oldValue[item];
|
|
1880
|
-
});
|
|
1881
|
-
field.attributes = oldValue;
|
|
1882
|
-
});
|
|
1883
|
-
}
|
|
1884
|
-
const patchAsyncAttributes = patchAsyncFn('attributes');
|
|
1885
|
-
|
|
1886
|
-
function setProps(props) {
|
|
1887
|
-
return rawConfig((field) => {
|
|
1888
|
-
field.props = props;
|
|
1889
|
-
});
|
|
1890
|
-
}
|
|
1891
|
-
function patchProps(props) {
|
|
1892
|
-
return rawConfig((field) => {
|
|
1893
|
-
field.props = {
|
|
1894
|
-
...field.props,
|
|
1895
|
-
...props,
|
|
1896
|
-
};
|
|
1897
|
-
});
|
|
1898
|
-
}
|
|
1899
|
-
function removeProps(list) {
|
|
1900
|
-
return rawConfig((field) => {
|
|
1901
|
-
const oldValue = unWrapSignal(field.props);
|
|
1902
|
-
if (!oldValue) {
|
|
1903
|
-
return;
|
|
1904
|
-
}
|
|
1905
|
-
list.forEach((item) => {
|
|
1906
|
-
delete oldValue[item];
|
|
1907
|
-
});
|
|
1908
|
-
field.props = oldValue;
|
|
1909
|
-
});
|
|
1910
|
-
}
|
|
1911
|
-
const patchAsyncProps = patchAsyncFn('props');
|
|
1912
|
-
|
|
1913
|
-
function createOutputListener(outputs, options) {
|
|
1914
|
-
return rawConfig((field) => {
|
|
1915
|
-
mergeHooksFn({
|
|
1916
|
-
allFieldsResolved: (field) => {
|
|
1917
|
-
field.outputs.update((originOutputs) => {
|
|
1918
|
-
originOutputs = options.setOutputs ? {} : { ...originOutputs };
|
|
1919
|
-
for (const key in outputs) {
|
|
1920
|
-
const oldFn = originOutputs[key];
|
|
1921
|
-
originOutputs[key] = (...args) => {
|
|
1922
|
-
if (options.mergeOutput && oldFn) {
|
|
1923
|
-
oldFn(...args, field);
|
|
1924
|
-
}
|
|
1925
|
-
return outputs[key](...args, field);
|
|
1926
|
-
};
|
|
1927
|
-
}
|
|
1928
|
-
return originOutputs;
|
|
1929
|
-
});
|
|
1930
|
-
},
|
|
1931
|
-
}, { position: 'bottom' }, field);
|
|
1932
|
-
});
|
|
1933
|
-
}
|
|
1934
|
-
function setOutputs(outputs) {
|
|
1935
|
-
return createOutputListener(outputs, {
|
|
1936
|
-
setOutputs: true,
|
|
1937
|
-
mergeOutput: false,
|
|
1938
|
-
});
|
|
1939
|
-
}
|
|
1940
|
-
function patchOutputs(outputs) {
|
|
1941
|
-
return createOutputListener(outputs, {
|
|
1942
|
-
setOutputs: false,
|
|
1943
|
-
mergeOutput: false,
|
|
1944
|
-
});
|
|
1945
|
-
}
|
|
1946
|
-
function removeOutputs(list) {
|
|
1947
|
-
return rawConfig((field) => {
|
|
1948
|
-
mergeHooksFn({
|
|
1949
|
-
allFieldsResolved: (field) => {
|
|
1950
|
-
field.outputs.update((originOutputs) => {
|
|
1951
|
-
originOutputs = { ...originOutputs };
|
|
1952
|
-
list.forEach((key) => {
|
|
1953
|
-
if (key in originOutputs) {
|
|
1954
|
-
delete originOutputs[key];
|
|
1955
|
-
}
|
|
1956
|
-
});
|
|
1957
|
-
return originOutputs;
|
|
1958
|
-
});
|
|
1959
|
-
},
|
|
1960
|
-
}, { position: 'bottom' }, field);
|
|
1961
|
-
});
|
|
1962
|
-
}
|
|
1963
1777
|
function mergeOutputFn(field, outputs) {
|
|
1964
1778
|
field.outputs.update((originOutputs) => {
|
|
1965
1779
|
originOutputs = { ...originOutputs };
|
|
@@ -1973,9 +1787,40 @@ function mergeOutputFn(field, outputs) {
|
|
|
1973
1787
|
return originOutputs;
|
|
1974
1788
|
});
|
|
1975
1789
|
}
|
|
1976
|
-
const mergeOutputs = (outputs) =>
|
|
1977
|
-
|
|
1978
|
-
|
|
1790
|
+
const mergeOutputs = (outputs) => rawConfig((field) => {
|
|
1791
|
+
field.outputs.update((originOutputs) => {
|
|
1792
|
+
originOutputs = { ...originOutputs };
|
|
1793
|
+
for (const key in outputs) {
|
|
1794
|
+
const oldFn = originOutputs[key];
|
|
1795
|
+
originOutputs[key] = (...args) => {
|
|
1796
|
+
if (oldFn) {
|
|
1797
|
+
oldFn(...args);
|
|
1798
|
+
}
|
|
1799
|
+
return outputs[key](...args);
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1802
|
+
return originOutputs;
|
|
1803
|
+
});
|
|
1804
|
+
});
|
|
1805
|
+
const asyncMergeOutputs = (outputs) => rawConfig((field) => {
|
|
1806
|
+
mergeHooksFn({
|
|
1807
|
+
allFieldsResolved: (field) => {
|
|
1808
|
+
field.outputs.update((originOutputs) => {
|
|
1809
|
+
originOutputs = { ...originOutputs };
|
|
1810
|
+
for (const key in outputs) {
|
|
1811
|
+
const fn = outputs[key](field);
|
|
1812
|
+
const oldFn = originOutputs[key];
|
|
1813
|
+
originOutputs[key] = (...args) => {
|
|
1814
|
+
if (oldFn) {
|
|
1815
|
+
oldFn(...args);
|
|
1816
|
+
}
|
|
1817
|
+
return fn(...args);
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
return originOutputs;
|
|
1821
|
+
});
|
|
1822
|
+
},
|
|
1823
|
+
}, { position: 'bottom' }, field);
|
|
1979
1824
|
});
|
|
1980
1825
|
function outputChangeFn(rawField, fn) {
|
|
1981
1826
|
mergeHooksFn({
|
|
@@ -2006,89 +1851,6 @@ function outputChange(fn) {
|
|
|
2006
1851
|
return rawConfig((field) => outputChangeFn(field, fn));
|
|
2007
1852
|
}
|
|
2008
1853
|
|
|
2009
|
-
function setWrappers(wrappers) {
|
|
2010
|
-
return rawConfig((field) => {
|
|
2011
|
-
field.wrappers = wrappers;
|
|
2012
|
-
});
|
|
2013
|
-
}
|
|
2014
|
-
const defaultValue = {
|
|
2015
|
-
position: 'tail',
|
|
2016
|
-
};
|
|
2017
|
-
function patchWrappers(wrappers, options = defaultValue) {
|
|
2018
|
-
return rawConfig((field) => {
|
|
2019
|
-
const list = toArray(wrappers);
|
|
2020
|
-
field.wrappers ??= [];
|
|
2021
|
-
if (options.position === 'tail') {
|
|
2022
|
-
field.wrappers.push(...list);
|
|
2023
|
-
}
|
|
2024
|
-
else {
|
|
2025
|
-
field.wrappers.unshift(...list);
|
|
2026
|
-
}
|
|
2027
|
-
});
|
|
2028
|
-
}
|
|
2029
|
-
function patchAsyncWrapper(inputWrapper, options = defaultValue) {
|
|
2030
|
-
return rawConfig((field) => {
|
|
2031
|
-
mergeHooksFn({
|
|
2032
|
-
allFieldsResolved: (field) => {
|
|
2033
|
-
const findConfig = field.injector.get(FindConfigToken);
|
|
2034
|
-
let inputs$ = signal({});
|
|
2035
|
-
if (inputWrapper.inputs && Object.keys(inputWrapper.inputs).length) {
|
|
2036
|
-
inputs$ = asyncInputMerge(Object.entries(inputWrapper.inputs).reduce((obj, [key, value]) => {
|
|
2037
|
-
obj[key] = value(field);
|
|
2038
|
-
return obj;
|
|
2039
|
-
}, {}), inputs$);
|
|
2040
|
-
}
|
|
2041
|
-
let attributes$ = signal({});
|
|
2042
|
-
if (inputWrapper.attributes &&
|
|
2043
|
-
Object.keys(inputWrapper.attributes).length) {
|
|
2044
|
-
attributes$ = asyncInputMerge(Object.entries(inputWrapper.attributes).reduce((obj, [key, value]) => {
|
|
2045
|
-
obj[key] = value(field);
|
|
2046
|
-
return obj;
|
|
2047
|
-
}, {}), attributes$);
|
|
2048
|
-
}
|
|
2049
|
-
const oldOutputs = inputWrapper.outputs;
|
|
2050
|
-
const outputs = {};
|
|
2051
|
-
if (oldOutputs && Object.keys(oldOutputs).length) {
|
|
2052
|
-
for (const key in oldOutputs) {
|
|
2053
|
-
const oldFn = oldOutputs[key];
|
|
2054
|
-
outputs[key] = (...args) => oldFn(...args, field);
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
const defaultWrapperConfig = findConfig.findWrapper(inputWrapper);
|
|
2058
|
-
const newWrapper = {
|
|
2059
|
-
...defaultWrapperConfig,
|
|
2060
|
-
inputs: inputs$,
|
|
2061
|
-
outputs,
|
|
2062
|
-
attributes: attributes$,
|
|
2063
|
-
};
|
|
2064
|
-
field.wrappers.update((wrappers) => options.position === 'tail'
|
|
2065
|
-
? [...wrappers, newWrapper]
|
|
2066
|
-
: [newWrapper, ...wrappers]);
|
|
2067
|
-
},
|
|
2068
|
-
}, { position: 'bottom' }, field);
|
|
2069
|
-
});
|
|
2070
|
-
}
|
|
2071
|
-
function removeWrappers(list) {
|
|
2072
|
-
return rawConfig((field) => {
|
|
2073
|
-
if (!field.wrappers) {
|
|
2074
|
-
return;
|
|
2075
|
-
}
|
|
2076
|
-
const wrappers = field.wrappers;
|
|
2077
|
-
for (let i = 0; i < list.length; i++) {
|
|
2078
|
-
const name = list[i];
|
|
2079
|
-
for (let j = 0; j < wrappers.length; j++) {
|
|
2080
|
-
const config = wrappers[j];
|
|
2081
|
-
const name2 = typeof config === 'string' ? config : config.type;
|
|
2082
|
-
if (name2 === name) {
|
|
2083
|
-
wrappers.splice(j, 1);
|
|
2084
|
-
break;
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
field.wrappers = wrappers;
|
|
2089
|
-
});
|
|
2090
|
-
}
|
|
2091
|
-
|
|
2092
1854
|
function setAlias(alias) {
|
|
2093
1855
|
return rawConfig((field) => {
|
|
2094
1856
|
field.alias = alias;
|
|
@@ -2167,6 +1929,302 @@ function disableWhen(options) {
|
|
|
2167
1929
|
});
|
|
2168
1930
|
}
|
|
2169
1931
|
|
|
1932
|
+
function nonFieldControl(value = true) {
|
|
1933
|
+
return {
|
|
1934
|
+
kind: 'metadata',
|
|
1935
|
+
type: 'nonFieldControl',
|
|
1936
|
+
reference: nonFieldControl,
|
|
1937
|
+
value: value,
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
const CustomDataSymbol = Symbol();
|
|
1942
|
+
const createRemovePropertyFn = (key) => (list) => rawConfig((rawField, _, ...args) => mergeHooksFn({
|
|
1943
|
+
allFieldsResolved: (field) => {
|
|
1944
|
+
let data$;
|
|
1945
|
+
if (args.length > 0 &&
|
|
1946
|
+
typeof args[args.length - 1] === 'object' &&
|
|
1947
|
+
CustomDataSymbol in args[args.length - 1]) {
|
|
1948
|
+
data$ = args[args.length - 1][CustomDataSymbol];
|
|
1949
|
+
}
|
|
1950
|
+
else {
|
|
1951
|
+
data$ = (() => field);
|
|
1952
|
+
}
|
|
1953
|
+
const obj$ = data$()[key];
|
|
1954
|
+
list.forEach((key) => {
|
|
1955
|
+
obj$.disconnect(key);
|
|
1956
|
+
obj$.update((object) => {
|
|
1957
|
+
object = { ...object };
|
|
1958
|
+
delete object[key];
|
|
1959
|
+
return object;
|
|
1960
|
+
});
|
|
1961
|
+
});
|
|
1962
|
+
},
|
|
1963
|
+
}, { position: 'bottom' }, rawField));
|
|
1964
|
+
function createPatchAsyncPropertyFn(key) {
|
|
1965
|
+
return (dataObj) => rawConfig((rawField, _, ...args) => {
|
|
1966
|
+
let data$;
|
|
1967
|
+
if (args.length > 0 &&
|
|
1968
|
+
typeof args[args.length - 1] === 'object' &&
|
|
1969
|
+
CustomDataSymbol in args[args.length - 1]) {
|
|
1970
|
+
data$ = args[args.length - 1][CustomDataSymbol];
|
|
1971
|
+
}
|
|
1972
|
+
else {
|
|
1973
|
+
data$ = (() => rawField);
|
|
1974
|
+
}
|
|
1975
|
+
const content$ = data$()[key];
|
|
1976
|
+
const inputList = Object.keys(dataObj);
|
|
1977
|
+
// 设置初始值
|
|
1978
|
+
content$.update((content) => ({
|
|
1979
|
+
...content,
|
|
1980
|
+
...inputList.reduce((obj, item) => {
|
|
1981
|
+
obj[item] = content?.[item] ?? undefined;
|
|
1982
|
+
return obj;
|
|
1983
|
+
}, {}),
|
|
1984
|
+
}));
|
|
1985
|
+
return mergeHooksFn({
|
|
1986
|
+
allFieldsResolved: (field) => {
|
|
1987
|
+
Object.entries(dataObj).forEach(([key, value]) => {
|
|
1988
|
+
const result = value(field);
|
|
1989
|
+
content$.connect(key, result);
|
|
1990
|
+
});
|
|
1991
|
+
},
|
|
1992
|
+
}, { position: 'bottom' }, rawField);
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
function createSetOrPatchPropertyFn(key, isPatch) {
|
|
1996
|
+
return (value) => rawConfig((rawField, _, ...args) => {
|
|
1997
|
+
let data$;
|
|
1998
|
+
if (args.length > 0 &&
|
|
1999
|
+
typeof args[args.length - 1] === 'object' &&
|
|
2000
|
+
CustomDataSymbol in args[args.length - 1]) {
|
|
2001
|
+
data$ = args[args.length - 1][CustomDataSymbol];
|
|
2002
|
+
}
|
|
2003
|
+
else {
|
|
2004
|
+
data$ = (() => rawField);
|
|
2005
|
+
}
|
|
2006
|
+
const content$ = data$()[key];
|
|
2007
|
+
if (isPatch) {
|
|
2008
|
+
content$.update((data) => ({
|
|
2009
|
+
...data,
|
|
2010
|
+
...value,
|
|
2011
|
+
}));
|
|
2012
|
+
}
|
|
2013
|
+
else {
|
|
2014
|
+
content$.set(value);
|
|
2015
|
+
}
|
|
2016
|
+
});
|
|
2017
|
+
}
|
|
2018
|
+
function createMapPropertyFn(key) {
|
|
2019
|
+
return (fn) => rawConfig((rawField, _, ...args) => {
|
|
2020
|
+
let data$;
|
|
2021
|
+
if (args.length > 0 &&
|
|
2022
|
+
typeof args[args.length - 1] === 'object' &&
|
|
2023
|
+
CustomDataSymbol in args[args.length - 1]) {
|
|
2024
|
+
data$ = args[args.length - 1][CustomDataSymbol];
|
|
2025
|
+
}
|
|
2026
|
+
else {
|
|
2027
|
+
data$ = (() => rawField);
|
|
2028
|
+
}
|
|
2029
|
+
const content$ = data$()[key];
|
|
2030
|
+
content$.map(fn);
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
function createMapAsyncPropertyFn(key) {
|
|
2034
|
+
return (fn) => rawConfig((rawField, _, ...args) => {
|
|
2035
|
+
return mergeHooksFn({
|
|
2036
|
+
allFieldsResolved: (field) => {
|
|
2037
|
+
let data$;
|
|
2038
|
+
if (args.length > 0 &&
|
|
2039
|
+
typeof args[args.length - 1] === 'object' &&
|
|
2040
|
+
CustomDataSymbol in args[args.length - 1]) {
|
|
2041
|
+
data$ = args[args.length - 1][CustomDataSymbol];
|
|
2042
|
+
}
|
|
2043
|
+
else {
|
|
2044
|
+
data$ = (() => field);
|
|
2045
|
+
}
|
|
2046
|
+
const content$ = data$()[key];
|
|
2047
|
+
content$.map(fn(field));
|
|
2048
|
+
},
|
|
2049
|
+
}, { position: 'bottom' }, rawField);
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
const __actions = {
|
|
2053
|
+
inputs: {
|
|
2054
|
+
patch: createSetOrPatchPropertyFn('inputs', true),
|
|
2055
|
+
set: createSetOrPatchPropertyFn('inputs'),
|
|
2056
|
+
patchAsync: createPatchAsyncPropertyFn('inputs'),
|
|
2057
|
+
remove: createRemovePropertyFn('inputs'),
|
|
2058
|
+
map: createMapPropertyFn('inputs'),
|
|
2059
|
+
mapAsync: createMapAsyncPropertyFn('inputs'),
|
|
2060
|
+
},
|
|
2061
|
+
outputs: {
|
|
2062
|
+
patch: createSetOrPatchPropertyFn('outputs', true),
|
|
2063
|
+
set: createSetOrPatchPropertyFn('outputs'),
|
|
2064
|
+
patchAsync: createPatchAsyncPropertyFn('outputs'),
|
|
2065
|
+
remove: createRemovePropertyFn('outputs'),
|
|
2066
|
+
merge: mergeOutputs,
|
|
2067
|
+
mergeAsync: asyncMergeOutputs,
|
|
2068
|
+
map: createMapPropertyFn('outputs'),
|
|
2069
|
+
mapAsync: createMapAsyncPropertyFn('outputs'),
|
|
2070
|
+
},
|
|
2071
|
+
attributes: {
|
|
2072
|
+
patch: createSetOrPatchPropertyFn('attributes', true),
|
|
2073
|
+
set: createSetOrPatchPropertyFn('attributes'),
|
|
2074
|
+
patchAsync: createPatchAsyncPropertyFn('attributes'),
|
|
2075
|
+
remove: createRemovePropertyFn('attributes'),
|
|
2076
|
+
map: createMapPropertyFn('attributes'),
|
|
2077
|
+
mapAsync: createMapAsyncPropertyFn('attributes'),
|
|
2078
|
+
},
|
|
2079
|
+
events: {
|
|
2080
|
+
patch: createSetOrPatchPropertyFn('events', true),
|
|
2081
|
+
set: createSetOrPatchPropertyFn('events'),
|
|
2082
|
+
patchAsync: createPatchAsyncPropertyFn('events'),
|
|
2083
|
+
remove: createRemovePropertyFn('events'),
|
|
2084
|
+
map: createMapPropertyFn('events'),
|
|
2085
|
+
mapAsync: createMapAsyncPropertyFn('events'),
|
|
2086
|
+
},
|
|
2087
|
+
props: {
|
|
2088
|
+
patch: createSetOrPatchPropertyFn('props', true),
|
|
2089
|
+
set: createSetOrPatchPropertyFn('props'),
|
|
2090
|
+
patchAsync: createPatchAsyncPropertyFn('props'),
|
|
2091
|
+
remove: createRemovePropertyFn('props'),
|
|
2092
|
+
map: createMapPropertyFn('props'),
|
|
2093
|
+
mapAsync: createMapAsyncPropertyFn('props'),
|
|
2094
|
+
},
|
|
2095
|
+
};
|
|
2096
|
+
|
|
2097
|
+
function setWrappers(wrappers) {
|
|
2098
|
+
return rawConfig((rawField, _) => {
|
|
2099
|
+
const wrapperConfig = rawField.globalConfig.additionalData['defaultWrapperMetadataGroup'];
|
|
2100
|
+
const injector = rawField.globalConfig.additionalData['injector'];
|
|
2101
|
+
const OptionDefine = {
|
|
2102
|
+
pipe: pipe(map((item) => {
|
|
2103
|
+
if (typeof item.type === 'string') {
|
|
2104
|
+
const type = wrapperConfig[item.type].type;
|
|
2105
|
+
if (!type) {
|
|
2106
|
+
throw new Error(`🈳wrapper:[${type}]❗`);
|
|
2107
|
+
}
|
|
2108
|
+
return { ...item, type: type };
|
|
2109
|
+
}
|
|
2110
|
+
return item;
|
|
2111
|
+
})),
|
|
2112
|
+
injector: injector,
|
|
2113
|
+
};
|
|
2114
|
+
rawField.wrappers.clean();
|
|
2115
|
+
wrappers.forEach((item) => {
|
|
2116
|
+
if (typeof item === 'string') {
|
|
2117
|
+
const defaultActions = wrapperConfig[item]?.actions ?? [];
|
|
2118
|
+
const define = observableSignal({
|
|
2119
|
+
type: item,
|
|
2120
|
+
inputs: asyncObjectSignal({}),
|
|
2121
|
+
outputs: asyncObjectSignal({}),
|
|
2122
|
+
attributes: asyncObjectSignal({}),
|
|
2123
|
+
events: asyncObjectSignal({}),
|
|
2124
|
+
}, OptionDefine);
|
|
2125
|
+
rawField.wrappers.add(define);
|
|
2126
|
+
defaultActions.forEach((item) => {
|
|
2127
|
+
item.value(rawField, _, {
|
|
2128
|
+
[CustomDataSymbol]: define,
|
|
2129
|
+
});
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
else {
|
|
2133
|
+
rawField.wrappers.add(observableSignal({
|
|
2134
|
+
type: item.type,
|
|
2135
|
+
inputs: asyncObjectSignal(item.inputs ?? {}),
|
|
2136
|
+
outputs: asyncObjectSignal(item.outputs ?? {}),
|
|
2137
|
+
attributes: asyncObjectSignal(item.attributes ?? {}),
|
|
2138
|
+
events: asyncObjectSignal(item.events ?? {}),
|
|
2139
|
+
}, OptionDefine));
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
function removeWrappers(removeList) {
|
|
2145
|
+
return rawConfig((field) => {
|
|
2146
|
+
mergeHooksFn({
|
|
2147
|
+
allFieldsResolved: (field) => {
|
|
2148
|
+
let list;
|
|
2149
|
+
if (typeof removeList === 'function') {
|
|
2150
|
+
list = removeList(field.wrappers.items());
|
|
2151
|
+
}
|
|
2152
|
+
else {
|
|
2153
|
+
list = field.wrappers.items().filter((item) => {
|
|
2154
|
+
const type = item.input().type;
|
|
2155
|
+
return removeList.every((name) => name !== type);
|
|
2156
|
+
});
|
|
2157
|
+
}
|
|
2158
|
+
field.wrappers.update(() => list);
|
|
2159
|
+
},
|
|
2160
|
+
}, { position: 'bottom' }, field);
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
function patchAsyncWrapper(type, actions, options) {
|
|
2164
|
+
return rawConfig((rawFiled) => {
|
|
2165
|
+
// 在这里增加要处理的wrapper类型
|
|
2166
|
+
mergeHooksFn({
|
|
2167
|
+
allFieldsResolved: (field) => {
|
|
2168
|
+
const findConfig = field.injector.get(FindConfigToken);
|
|
2169
|
+
const initData = observableSignal({
|
|
2170
|
+
type,
|
|
2171
|
+
attributes: asyncObjectSignal({}),
|
|
2172
|
+
events: asyncObjectSignal({}),
|
|
2173
|
+
inputs: asyncObjectSignal({}),
|
|
2174
|
+
outputs: asyncObjectSignal({}),
|
|
2175
|
+
}, {
|
|
2176
|
+
pipe: pipe(map((item) => {
|
|
2177
|
+
const defaultWrapperConfig = findConfig.findWrapperComponent(item.type);
|
|
2178
|
+
return { ...item, type: defaultWrapperConfig };
|
|
2179
|
+
})),
|
|
2180
|
+
injector: field.injector,
|
|
2181
|
+
});
|
|
2182
|
+
field.wrappers.add(initData, options?.insertIndex);
|
|
2183
|
+
const defaultConfig = field.injector.get(PI_VIEW_CONFIG_TOKEN);
|
|
2184
|
+
let defaultActions = [];
|
|
2185
|
+
if (typeof type === 'string') {
|
|
2186
|
+
defaultActions = defaultConfig.wrappers?.[type]?.actions ?? [];
|
|
2187
|
+
}
|
|
2188
|
+
const allActions = [...defaultActions, ...(actions ?? [])];
|
|
2189
|
+
for (const item of allActions) {
|
|
2190
|
+
const tempField = {};
|
|
2191
|
+
item.value(tempField, undefined, {
|
|
2192
|
+
[CustomDataSymbol]: initData,
|
|
2193
|
+
});
|
|
2194
|
+
tempField.hooks?.allFieldsResolved?.(field);
|
|
2195
|
+
}
|
|
2196
|
+
},
|
|
2197
|
+
}, { position: 'bottom' }, rawFiled);
|
|
2198
|
+
});
|
|
2199
|
+
}
|
|
2200
|
+
function changeAsyncWrapper(indexFn, actions) {
|
|
2201
|
+
return rawConfig((rawFiled) => {
|
|
2202
|
+
mergeHooksFn({
|
|
2203
|
+
allFieldsResolved: (field) => {
|
|
2204
|
+
const initData = indexFn(field.wrappers
|
|
2205
|
+
.items()
|
|
2206
|
+
.map((item) => item.input));
|
|
2207
|
+
if (!initData) {
|
|
2208
|
+
throw new Error(`change wrapper not found`);
|
|
2209
|
+
}
|
|
2210
|
+
for (const item of actions) {
|
|
2211
|
+
const tempField = {};
|
|
2212
|
+
item.value(tempField, undefined, {
|
|
2213
|
+
[CustomDataSymbol]: initData,
|
|
2214
|
+
});
|
|
2215
|
+
tempField.hooks?.allFieldsResolved?.(field);
|
|
2216
|
+
}
|
|
2217
|
+
},
|
|
2218
|
+
}, { position: 'bottom' }, rawFiled);
|
|
2219
|
+
});
|
|
2220
|
+
}
|
|
2221
|
+
const wrappers = {
|
|
2222
|
+
set: setWrappers,
|
|
2223
|
+
patchAsync: patchAsyncWrapper,
|
|
2224
|
+
remove: removeWrappers,
|
|
2225
|
+
changeAsync: changeAsyncWrapper,
|
|
2226
|
+
};
|
|
2227
|
+
|
|
2170
2228
|
/** 必须防止到所有wrappers操作后面,防止设置错误
|
|
2171
2229
|
* 设置到顶层,可能是wrapper,也可能是component
|
|
2172
2230
|
*
|
|
@@ -2174,7 +2232,7 @@ function disableWhen(options) {
|
|
|
2174
2232
|
function topClass(className, merge) {
|
|
2175
2233
|
return rawConfig((rawField) => {
|
|
2176
2234
|
mergeHooksFn({
|
|
2177
|
-
|
|
2235
|
+
allFieldsResolved: (field) => {
|
|
2178
2236
|
const wrappers = field.wrappers();
|
|
2179
2237
|
if (wrappers?.length) {
|
|
2180
2238
|
wrappers[0].attributes.update((attributes) => ({
|
|
@@ -2197,35 +2255,63 @@ function topClass(className, merge) {
|
|
|
2197
2255
|
});
|
|
2198
2256
|
}
|
|
2199
2257
|
/** 仅设置在组件上 */
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
}
|
|
2258
|
+
const componentClass = (className, merge) => rawConfig((rawField, _, ...args) => {
|
|
2259
|
+
let data$;
|
|
2260
|
+
if (args.length > 0 &&
|
|
2261
|
+
typeof args[args.length - 1] === 'object' &&
|
|
2262
|
+
CustomDataSymbol in args[args.length - 1]) {
|
|
2263
|
+
data$ = args[args.length - 1][CustomDataSymbol];
|
|
2264
|
+
}
|
|
2265
|
+
else {
|
|
2266
|
+
data$ = (() => rawField);
|
|
2267
|
+
}
|
|
2268
|
+
const content$ = data$()['attributes'];
|
|
2269
|
+
content$.update((data) => ({
|
|
2270
|
+
...data,
|
|
2271
|
+
class: merge ? clsx(data?.['class'], className) : clsx(className),
|
|
2272
|
+
}));
|
|
2273
|
+
});
|
|
2210
2274
|
const bottomClass = componentClass;
|
|
2211
2275
|
function patchAsyncClass(fn) {
|
|
2212
|
-
return
|
|
2276
|
+
return __actions.attributes.patchAsync({ class: fn });
|
|
2213
2277
|
}
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2278
|
+
function asyncTopClass(classNameFn) {
|
|
2279
|
+
return rawConfig((rawField) => {
|
|
2280
|
+
mergeHooksFn({
|
|
2281
|
+
allFieldsResolved: (field) => {
|
|
2282
|
+
const wrappers = field.wrappers();
|
|
2283
|
+
if (wrappers?.length) {
|
|
2284
|
+
wrappers[0].attributes.connect('class', classNameFn(field));
|
|
2285
|
+
}
|
|
2286
|
+
else {
|
|
2287
|
+
field.attributes.connect('class', classNameFn(field));
|
|
2288
|
+
}
|
|
2289
|
+
},
|
|
2290
|
+
}, { position: 'bottom' }, rawField);
|
|
2291
|
+
});
|
|
2222
2292
|
}
|
|
2293
|
+
const classAction = {
|
|
2294
|
+
top: topClass,
|
|
2295
|
+
bottom: bottomClass,
|
|
2296
|
+
component: componentClass,
|
|
2297
|
+
asyncTop: asyncTopClass,
|
|
2298
|
+
asyncBottom: patchAsyncClass,
|
|
2299
|
+
asyncComponent: patchAsyncClass,
|
|
2300
|
+
};
|
|
2301
|
+
|
|
2302
|
+
const actions = {
|
|
2303
|
+
...__actions,
|
|
2304
|
+
class: classAction,
|
|
2305
|
+
wrappers,
|
|
2306
|
+
};
|
|
2223
2307
|
|
|
2224
2308
|
class CoreSchemaHandle extends BaseSchemaHandle {
|
|
2225
|
-
inputs;
|
|
2226
|
-
outputs;
|
|
2227
|
-
|
|
2228
|
-
|
|
2309
|
+
inputs = asyncObjectSignal({});
|
|
2310
|
+
outputs = asyncObjectSignal({});
|
|
2311
|
+
attributes = asyncObjectSignal({});
|
|
2312
|
+
events = asyncObjectSignal({});
|
|
2313
|
+
wrappers = combineSignal([]);
|
|
2314
|
+
props = asyncObjectSignal({});
|
|
2229
2315
|
alias;
|
|
2230
2316
|
movePath;
|
|
2231
2317
|
renderConfig;
|
|
@@ -2311,8 +2397,16 @@ class CoreSchemaHandle extends BaseSchemaHandle {
|
|
|
2311
2397
|
this.formConfig.groupMode = 'reset';
|
|
2312
2398
|
}
|
|
2313
2399
|
enumSchema(schema) {
|
|
2314
|
-
this.props
|
|
2315
|
-
|
|
2400
|
+
this.props.update((data) => ({
|
|
2401
|
+
...data,
|
|
2402
|
+
options: data['options'] ?? schema.options,
|
|
2403
|
+
}));
|
|
2404
|
+
}
|
|
2405
|
+
updateProps(key, value) {
|
|
2406
|
+
this.props.update((data) => ({
|
|
2407
|
+
...data,
|
|
2408
|
+
[key]: value,
|
|
2409
|
+
}));
|
|
2316
2410
|
}
|
|
2317
2411
|
intersectBefore(schema) {
|
|
2318
2412
|
if (this.childrenAsVirtualGroup) {
|
|
@@ -2414,8 +2508,12 @@ function convert(obj, options) {
|
|
|
2414
2508
|
}, {
|
|
2415
2509
|
...options,
|
|
2416
2510
|
handle: options?.handle ?? CoreSchemaHandle,
|
|
2511
|
+
additionalData: {
|
|
2512
|
+
defaultWrapperMetadataGroup: options.fieldGlobalConfig?.wrappers,
|
|
2513
|
+
injector,
|
|
2514
|
+
},
|
|
2417
2515
|
defaultMetadataActionsGroup: Object.keys(options.fieldGlobalConfig?.types ?? {}).reduce((obj, item) => {
|
|
2418
|
-
|
|
2516
|
+
const { actions } = options.fieldGlobalConfig.types[item];
|
|
2419
2517
|
if (actions) {
|
|
2420
2518
|
obj[item] = actions;
|
|
2421
2519
|
}
|
|
@@ -2431,5 +2529,5 @@ const NFCSchema = v.optional(v.void());
|
|
|
2431
2529
|
* Generated bundle index. Do not edit.
|
|
2432
2530
|
*/
|
|
2433
2531
|
|
|
2434
|
-
export { AbstractControl, CoreSchemaHandle, FieldArray, FieldControl, FieldGroup, FieldLogicGroup, FormBuilder, INVALID, NFCSchema, PENDING, PI_CONTEXT_TOKEN, PI_FORM_BUILDER_ALIAS_MAP, PI_FORM_BUILDER_OPTIONS_TOKEN, PI_VIEW_CONFIG_TOKEN, SortedArray, UpdateType, VALID, arrayStartsWith,
|
|
2532
|
+
export { AbstractControl, CoreSchemaHandle, CustomDataSymbol, FieldArray, FieldControl, FieldGroup, FieldLogicGroup, FormBuilder, INVALID, NFCSchema, PENDING, PI_CONTEXT_TOKEN, PI_FORM_BUILDER_ALIAS_MAP, PI_FORM_BUILDER_OPTIONS_TOKEN, PI_VIEW_CONFIG_TOKEN, SortedArray, UpdateType, VALID, actions, arrayStartsWith, asyncMergeOutputs, asyncObjectSignal, clone, combineSignal, controlStatusList, convert, createViewControlLink, disableWhen, effectListen, fieldControlStatusClass, findComponent, formConfig, getDeepError, getLazyImport, hideWhen, initListen, isArray, isFieldArray, isFieldControl, isFieldGroup, isFieldLogicGroup, isGroup, isLazyMark, layout, lazyMark, mergeHooks, mergeHooksFn, mergeOutputFn, mergeOutputs, nonFieldControl, observableSignal, outputChange, outputChangeFn, patchHooks, rawConfig, removeHooks, renderConfig, setAlias, setComponent, setHooks, toArray, toObservable, valueChange, valueChangeFn, classAction as ɵclassAction, wrappers as ɵwrappers };
|
|
2435
2533
|
//# sourceMappingURL=piying-view-angular-core.mjs.map
|