@piying/view-angular-core 1.10.4 → 2.0.0
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,168 @@ 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
|
+
const signalList$ = signal([]);
|
|
1164
|
+
const value$$ = computed(() => {
|
|
1165
|
+
const signalList = signalList$();
|
|
1166
|
+
const data = data$();
|
|
1167
|
+
if (!signalList.length) {
|
|
1168
|
+
return data;
|
|
1169
|
+
}
|
|
1170
|
+
const data2 = { ...data };
|
|
1171
|
+
signalList.forEach(([key, value]) => {
|
|
1172
|
+
data2[key] = value();
|
|
1173
|
+
});
|
|
1174
|
+
return data2;
|
|
1175
|
+
}, options);
|
|
1176
|
+
const disposeMap = new Map();
|
|
1177
|
+
const changed$ = value$$;
|
|
1178
|
+
changed$.connect = (key, value) => {
|
|
1179
|
+
changed$.disconnect(key);
|
|
1180
|
+
let dispose;
|
|
1181
|
+
if (isPromise(value)) {
|
|
1182
|
+
// promise
|
|
1183
|
+
let isDestroy = false;
|
|
1184
|
+
value.then((value) => {
|
|
1185
|
+
if (isDestroy) {
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
data$.update((lastData) => ({ ...lastData, [key]: value }));
|
|
1189
|
+
});
|
|
1190
|
+
dispose = () => {
|
|
1191
|
+
isDestroy = true;
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
else if (isSubscribable(value)) {
|
|
1195
|
+
// rxjs
|
|
1196
|
+
const ref = value.subscribe({
|
|
1197
|
+
next: (value) => {
|
|
1198
|
+
data$.update((lastData) => ({ ...lastData, [key]: value }));
|
|
1199
|
+
},
|
|
1200
|
+
});
|
|
1201
|
+
dispose = () => {
|
|
1202
|
+
ref.unsubscribe();
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
else if (isSignal(value)) {
|
|
1206
|
+
signalList$.update((list) => {
|
|
1207
|
+
list = list.slice();
|
|
1208
|
+
list.push([key, value]);
|
|
1209
|
+
return list;
|
|
1210
|
+
});
|
|
1211
|
+
dispose = () => {
|
|
1212
|
+
signalList$.update((list) => {
|
|
1213
|
+
const index = list.findIndex((item) => value === item[1]);
|
|
1214
|
+
if (index !== -1) {
|
|
1215
|
+
list = list.slice();
|
|
1216
|
+
list.splice(index, 1);
|
|
1217
|
+
}
|
|
1218
|
+
return list;
|
|
1219
|
+
});
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
else {
|
|
1223
|
+
// 普通类型
|
|
1224
|
+
data$.update((lastData) => ({ ...lastData, [key]: value }));
|
|
1225
|
+
}
|
|
1226
|
+
if (dispose) {
|
|
1227
|
+
disposeMap.set(key, dispose);
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
changed$.disconnect = (key) => {
|
|
1231
|
+
untracked(() => {
|
|
1232
|
+
disposeMap.get(key)?.();
|
|
1233
|
+
disposeMap.delete(key);
|
|
1234
|
+
});
|
|
1235
|
+
};
|
|
1236
|
+
changed$.set = (key) => {
|
|
1237
|
+
data$.set(key);
|
|
1238
|
+
};
|
|
1239
|
+
changed$.update = (fn) => {
|
|
1240
|
+
const result = fn(changed$());
|
|
1241
|
+
data$.set(result);
|
|
1242
|
+
};
|
|
1243
|
+
return changed$;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
function combineSignal(initialValue = [], options) {
|
|
1247
|
+
const list$ = signal(initialValue);
|
|
1248
|
+
const input$$ = computed(() => list$().map((item) => item()), options);
|
|
1249
|
+
const changed$ = input$$;
|
|
1250
|
+
changed$.add = (item, index) => {
|
|
1251
|
+
list$.update((list) => {
|
|
1252
|
+
if (typeof index === 'number') {
|
|
1253
|
+
list = list.slice();
|
|
1254
|
+
list.splice(index, 0, item);
|
|
1255
|
+
return list;
|
|
1256
|
+
}
|
|
1257
|
+
return [...list, item];
|
|
1258
|
+
});
|
|
1259
|
+
};
|
|
1260
|
+
changed$.remove = (item) => {
|
|
1261
|
+
list$.update((list) => {
|
|
1262
|
+
const index = list.indexOf(item);
|
|
1263
|
+
if (index === -1) {
|
|
1264
|
+
return list;
|
|
1265
|
+
}
|
|
1266
|
+
list = list.slice();
|
|
1267
|
+
list.splice(index, 1);
|
|
1268
|
+
return list;
|
|
1269
|
+
});
|
|
1270
|
+
};
|
|
1271
|
+
changed$.items = () => list$();
|
|
1272
|
+
changed$.clean = () => list$.set([]);
|
|
1273
|
+
changed$.update = (fn) => {
|
|
1274
|
+
const list = fn(list$());
|
|
1275
|
+
list$.set(list);
|
|
1276
|
+
};
|
|
1277
|
+
return changed$;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1137
1280
|
function* groupGenerator(list) {
|
|
1138
1281
|
for (const item of list) {
|
|
1139
1282
|
if (!item.keyPath?.length && item.fixedChildren?.().length) {
|
|
@@ -1187,86 +1330,40 @@ const FindConfigToken = new InjectionToken('FindConfig');
|
|
|
1187
1330
|
function FindConfigFactory() {
|
|
1188
1331
|
const globalConfig = inject(PI_VIEW_CONFIG_TOKEN);
|
|
1189
1332
|
return {
|
|
1190
|
-
|
|
1333
|
+
findWrapperComponent: (wrapper) => {
|
|
1191
1334
|
let config;
|
|
1192
1335
|
let type;
|
|
1193
1336
|
if (typeof wrapper === 'string') {
|
|
1194
1337
|
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
|
-
};
|
|
1338
|
+
if (!config) {
|
|
1339
|
+
throw new Error(`🈳wrapper:[${type}]❗`);
|
|
1206
1340
|
}
|
|
1207
|
-
|
|
1341
|
+
return config?.type;
|
|
1208
1342
|
}
|
|
1209
|
-
|
|
1210
|
-
config = wrapper;
|
|
1211
|
-
}
|
|
1212
|
-
if (!config) {
|
|
1213
|
-
throw new Error(`🈳wrapper:[${type}]❗`);
|
|
1214
|
-
}
|
|
1215
|
-
return config;
|
|
1343
|
+
return wrapper;
|
|
1216
1344
|
},
|
|
1217
1345
|
findComponentConfig: (type) => {
|
|
1218
|
-
let define;
|
|
1219
|
-
let defaultConfig;
|
|
1220
1346
|
if (typeof type === 'string') {
|
|
1221
1347
|
const config = globalConfig?.types?.[type];
|
|
1222
1348
|
if (!config) {
|
|
1223
1349
|
throw new Error(`🈳define:[${type}]❗`);
|
|
1224
1350
|
}
|
|
1225
|
-
|
|
1226
|
-
if (Object.keys(config).length) {
|
|
1227
|
-
define = {
|
|
1228
|
-
...config,
|
|
1229
|
-
};
|
|
1230
|
-
return {
|
|
1231
|
-
define: { ...config },
|
|
1232
|
-
defaultConfig,
|
|
1233
|
-
};
|
|
1234
|
-
}
|
|
1351
|
+
return config.type;
|
|
1235
1352
|
}
|
|
1236
1353
|
else {
|
|
1237
|
-
return
|
|
1354
|
+
return type;
|
|
1238
1355
|
}
|
|
1239
|
-
return {
|
|
1240
|
-
define,
|
|
1241
|
-
defaultConfig,
|
|
1242
|
-
};
|
|
1243
1356
|
},
|
|
1244
1357
|
};
|
|
1245
1358
|
}
|
|
1246
1359
|
|
|
1247
1360
|
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
1361
|
class FormBuilder {
|
|
1264
1362
|
#scopeMap = inject(PI_FORM_BUILDER_ALIAS_MAP, { optional: true }) ??
|
|
1265
1363
|
new ParentMap();
|
|
1266
1364
|
#options = inject(PI_FORM_BUILDER_OPTIONS_TOKEN);
|
|
1267
1365
|
#injector = inject(Injector);
|
|
1268
1366
|
#envInjector = inject(EnvironmentInjector);
|
|
1269
|
-
#globalConfig = inject(PI_VIEW_CONFIG_TOKEN);
|
|
1270
1367
|
#allFieldInitHookList = [];
|
|
1271
1368
|
buildRoot(item) {
|
|
1272
1369
|
const field = this.#buildControl({
|
|
@@ -1307,51 +1404,17 @@ class FormBuilder {
|
|
|
1307
1404
|
// 单独一项
|
|
1308
1405
|
field, index) {
|
|
1309
1406
|
// 利用类型查引用,
|
|
1310
|
-
let viewDefaultConfig;
|
|
1311
1407
|
const type = field.type;
|
|
1312
1408
|
let define;
|
|
1313
1409
|
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);
|
|
1410
|
+
define = this.#findConfig.findComponentConfig(type);
|
|
1411
|
+
}
|
|
1412
|
+
const inputs = field.inputs;
|
|
1413
|
+
const outputs = field.outputs;
|
|
1414
|
+
const attributes = field.attributes;
|
|
1415
|
+
const events = field.events;
|
|
1416
|
+
const formConfig$ = signal(field.formConfig ?? {});
|
|
1417
|
+
const renderConfig = signal(field.renderConfig ?? {});
|
|
1355
1418
|
let control;
|
|
1356
1419
|
let keyPath = field.key;
|
|
1357
1420
|
if (isFieldLogicGroup(parent.form)) {
|
|
@@ -1388,23 +1451,31 @@ class FormBuilder {
|
|
|
1388
1451
|
origin: field,
|
|
1389
1452
|
renderConfig: renderConfig,
|
|
1390
1453
|
formConfig: formConfig$,
|
|
1391
|
-
props,
|
|
1454
|
+
props: field.props,
|
|
1392
1455
|
context: this.#options.context,
|
|
1393
1456
|
priority: field.priority,
|
|
1394
1457
|
hooks: field.hooks,
|
|
1395
1458
|
alias: field.alias,
|
|
1396
|
-
inputs
|
|
1397
|
-
|
|
1398
|
-
|
|
1459
|
+
get inputs() {
|
|
1460
|
+
return resolvedConfig.define().inputs;
|
|
1461
|
+
},
|
|
1462
|
+
get outputs() {
|
|
1463
|
+
return resolvedConfig.define().outputs;
|
|
1464
|
+
},
|
|
1465
|
+
get events() {
|
|
1466
|
+
return resolvedConfig.define().events;
|
|
1467
|
+
},
|
|
1468
|
+
get attributes() {
|
|
1469
|
+
return resolvedConfig.define().attributes;
|
|
1470
|
+
},
|
|
1399
1471
|
define: define
|
|
1400
|
-
? signal({
|
|
1472
|
+
? signal({ type: define, inputs, outputs, attributes, events })
|
|
1401
1473
|
: undefined,
|
|
1402
|
-
wrappers,
|
|
1474
|
+
wrappers: field.wrappers,
|
|
1403
1475
|
injector: this.#envInjector,
|
|
1404
1476
|
};
|
|
1405
1477
|
resolvedConfig =
|
|
1406
1478
|
this.afterResolveConfig(field, resolvedConfig) ?? resolvedConfig;
|
|
1407
|
-
defineSync(resolvedConfig);
|
|
1408
1479
|
if (field.movePath) {
|
|
1409
1480
|
this.#moveViewField(field.movePath, resolvedConfig);
|
|
1410
1481
|
}
|
|
@@ -1618,38 +1689,6 @@ class FormBuilder {
|
|
|
1618
1689
|
result.injector = injector.get(EnvironmentInjector);
|
|
1619
1690
|
return result;
|
|
1620
1691
|
}
|
|
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
1692
|
#moveViewField(key, inputField) {
|
|
1654
1693
|
const parent = fieldQuery(key, inputField, this.#scopeMap, this.#options.resolvedField$());
|
|
1655
1694
|
if (!parent) {
|
|
@@ -1661,18 +1700,6 @@ class FormBuilder {
|
|
|
1661
1700
|
parent.fixedChildren().push(inputField);
|
|
1662
1701
|
}
|
|
1663
1702
|
#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
1703
|
}
|
|
1677
1704
|
_a = FormBuilder;
|
|
1678
1705
|
|
|
@@ -1703,8 +1730,7 @@ function setComponent(type) {
|
|
|
1703
1730
|
});
|
|
1704
1731
|
}
|
|
1705
1732
|
function findComponent(field, type) {
|
|
1706
|
-
return field.injector.get(FindConfigToken).findComponentConfig(type)
|
|
1707
|
-
.type;
|
|
1733
|
+
return field.injector.get(FindConfigToken).findComponentConfig(type);
|
|
1708
1734
|
}
|
|
1709
1735
|
|
|
1710
1736
|
const setHooks = (hooks) => rawConfig((field) => {
|
|
@@ -1743,223 +1769,6 @@ function removeHooks(list) {
|
|
|
1743
1769
|
});
|
|
1744
1770
|
}
|
|
1745
1771
|
|
|
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
1772
|
function mergeOutputFn(field, outputs) {
|
|
1964
1773
|
field.outputs.update((originOutputs) => {
|
|
1965
1774
|
originOutputs = { ...originOutputs };
|
|
@@ -1973,9 +1782,40 @@ function mergeOutputFn(field, outputs) {
|
|
|
1973
1782
|
return originOutputs;
|
|
1974
1783
|
});
|
|
1975
1784
|
}
|
|
1976
|
-
const mergeOutputs = (outputs) =>
|
|
1977
|
-
|
|
1978
|
-
|
|
1785
|
+
const mergeOutputs = (outputs) => rawConfig((field) => {
|
|
1786
|
+
field.outputs.update((originOutputs) => {
|
|
1787
|
+
originOutputs = { ...originOutputs };
|
|
1788
|
+
for (const key in outputs) {
|
|
1789
|
+
const oldFn = originOutputs[key];
|
|
1790
|
+
originOutputs[key] = (...args) => {
|
|
1791
|
+
if (oldFn) {
|
|
1792
|
+
oldFn(...args);
|
|
1793
|
+
}
|
|
1794
|
+
return outputs[key](...args);
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
return originOutputs;
|
|
1798
|
+
});
|
|
1799
|
+
});
|
|
1800
|
+
const asyncMergeOutputs = (outputs) => rawConfig((field) => {
|
|
1801
|
+
mergeHooksFn({
|
|
1802
|
+
allFieldsResolved: (field) => {
|
|
1803
|
+
field.outputs.update((originOutputs) => {
|
|
1804
|
+
originOutputs = { ...originOutputs };
|
|
1805
|
+
for (const key in outputs) {
|
|
1806
|
+
const fn = outputs[key](field);
|
|
1807
|
+
const oldFn = originOutputs[key];
|
|
1808
|
+
originOutputs[key] = (...args) => {
|
|
1809
|
+
if (oldFn) {
|
|
1810
|
+
oldFn(...args);
|
|
1811
|
+
}
|
|
1812
|
+
return fn(...args);
|
|
1813
|
+
};
|
|
1814
|
+
}
|
|
1815
|
+
return originOutputs;
|
|
1816
|
+
});
|
|
1817
|
+
},
|
|
1818
|
+
}, { position: 'bottom' }, field);
|
|
1979
1819
|
});
|
|
1980
1820
|
function outputChangeFn(rawField, fn) {
|
|
1981
1821
|
mergeHooksFn({
|
|
@@ -2006,89 +1846,6 @@ function outputChange(fn) {
|
|
|
2006
1846
|
return rawConfig((field) => outputChangeFn(field, fn));
|
|
2007
1847
|
}
|
|
2008
1848
|
|
|
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
1849
|
function setAlias(alias) {
|
|
2093
1850
|
return rawConfig((field) => {
|
|
2094
1851
|
field.alias = alias;
|
|
@@ -2167,6 +1924,257 @@ function disableWhen(options) {
|
|
|
2167
1924
|
});
|
|
2168
1925
|
}
|
|
2169
1926
|
|
|
1927
|
+
function nonFieldControl(value = true) {
|
|
1928
|
+
return {
|
|
1929
|
+
kind: 'metadata',
|
|
1930
|
+
type: 'nonFieldControl',
|
|
1931
|
+
reference: nonFieldControl,
|
|
1932
|
+
value: value,
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
const CustomDataSymbol = Symbol();
|
|
1937
|
+
const createRemovePropertyFn = (key) => (list) => rawConfig((rawField, _, ...args) => mergeHooksFn({
|
|
1938
|
+
allFieldsResolved: (field) => {
|
|
1939
|
+
let data$;
|
|
1940
|
+
if (args.length > 0 &&
|
|
1941
|
+
typeof args[args.length - 1] === 'object' &&
|
|
1942
|
+
CustomDataSymbol in args[args.length - 1]) {
|
|
1943
|
+
data$ = args[args.length - 1][CustomDataSymbol];
|
|
1944
|
+
}
|
|
1945
|
+
else {
|
|
1946
|
+
data$ = (() => field);
|
|
1947
|
+
}
|
|
1948
|
+
const obj$ = data$()[key];
|
|
1949
|
+
list.forEach((key) => {
|
|
1950
|
+
obj$.disconnect(key);
|
|
1951
|
+
obj$.update((object) => {
|
|
1952
|
+
object = { ...object };
|
|
1953
|
+
delete object[key];
|
|
1954
|
+
return object;
|
|
1955
|
+
});
|
|
1956
|
+
});
|
|
1957
|
+
},
|
|
1958
|
+
}, { position: 'bottom' }, rawField));
|
|
1959
|
+
function createPatchAsyncPropertyFn(key) {
|
|
1960
|
+
return (dataObj) => rawConfig((rawField, _, ...args) => {
|
|
1961
|
+
let data$;
|
|
1962
|
+
if (args.length > 0 &&
|
|
1963
|
+
typeof args[args.length - 1] === 'object' &&
|
|
1964
|
+
CustomDataSymbol in args[args.length - 1]) {
|
|
1965
|
+
data$ = args[args.length - 1][CustomDataSymbol];
|
|
1966
|
+
}
|
|
1967
|
+
else {
|
|
1968
|
+
data$ = (() => rawField);
|
|
1969
|
+
}
|
|
1970
|
+
const content$ = data$()[key];
|
|
1971
|
+
const inputList = Object.keys(dataObj);
|
|
1972
|
+
// 设置初始值
|
|
1973
|
+
content$.update((content) => ({
|
|
1974
|
+
...content,
|
|
1975
|
+
...inputList.reduce((obj, item) => {
|
|
1976
|
+
obj[item] = content?.[item] ?? undefined;
|
|
1977
|
+
return obj;
|
|
1978
|
+
}, {}),
|
|
1979
|
+
}));
|
|
1980
|
+
return mergeHooksFn({
|
|
1981
|
+
allFieldsResolved: (field) => {
|
|
1982
|
+
Object.entries(dataObj).forEach(([key, value]) => {
|
|
1983
|
+
const result = value(field);
|
|
1984
|
+
content$.connect(key, result);
|
|
1985
|
+
});
|
|
1986
|
+
},
|
|
1987
|
+
}, { position: 'bottom' }, rawField);
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
function createSetOrPatchPropertyFn(key, isPatch) {
|
|
1991
|
+
return (value) => rawConfig((rawField, _, ...args) => {
|
|
1992
|
+
let data$;
|
|
1993
|
+
if (args.length > 0 &&
|
|
1994
|
+
typeof args[args.length - 1] === 'object' &&
|
|
1995
|
+
CustomDataSymbol in args[args.length - 1]) {
|
|
1996
|
+
data$ = args[args.length - 1][CustomDataSymbol];
|
|
1997
|
+
}
|
|
1998
|
+
else {
|
|
1999
|
+
data$ = (() => rawField);
|
|
2000
|
+
}
|
|
2001
|
+
const content$ = data$()[key];
|
|
2002
|
+
if (isPatch) {
|
|
2003
|
+
content$.update((data) => ({
|
|
2004
|
+
...data,
|
|
2005
|
+
...value,
|
|
2006
|
+
}));
|
|
2007
|
+
}
|
|
2008
|
+
else {
|
|
2009
|
+
content$.set(value);
|
|
2010
|
+
}
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
const __actions = {
|
|
2014
|
+
inputs: {
|
|
2015
|
+
patch: createSetOrPatchPropertyFn('inputs', true),
|
|
2016
|
+
set: createSetOrPatchPropertyFn('inputs'),
|
|
2017
|
+
patchAsync: createPatchAsyncPropertyFn('inputs'),
|
|
2018
|
+
remove: createRemovePropertyFn('inputs'),
|
|
2019
|
+
},
|
|
2020
|
+
outputs: {
|
|
2021
|
+
patch: createSetOrPatchPropertyFn('outputs', true),
|
|
2022
|
+
set: createSetOrPatchPropertyFn('outputs'),
|
|
2023
|
+
patchAsync: createPatchAsyncPropertyFn('outputs'),
|
|
2024
|
+
remove: createRemovePropertyFn('outputs'),
|
|
2025
|
+
merge: mergeOutputs,
|
|
2026
|
+
mergeAsync: asyncMergeOutputs,
|
|
2027
|
+
},
|
|
2028
|
+
attributes: {
|
|
2029
|
+
patch: createSetOrPatchPropertyFn('attributes', true),
|
|
2030
|
+
set: createSetOrPatchPropertyFn('attributes'),
|
|
2031
|
+
patchAsync: createPatchAsyncPropertyFn('attributes'),
|
|
2032
|
+
remove: createRemovePropertyFn('attributes'),
|
|
2033
|
+
},
|
|
2034
|
+
events: {
|
|
2035
|
+
patch: createSetOrPatchPropertyFn('events', true),
|
|
2036
|
+
set: createSetOrPatchPropertyFn('events'),
|
|
2037
|
+
patchAsync: createPatchAsyncPropertyFn('events'),
|
|
2038
|
+
remove: createRemovePropertyFn('events'),
|
|
2039
|
+
},
|
|
2040
|
+
props: {
|
|
2041
|
+
patch: createSetOrPatchPropertyFn('props', true),
|
|
2042
|
+
set: createSetOrPatchPropertyFn('props'),
|
|
2043
|
+
patchAsync: createPatchAsyncPropertyFn('props'),
|
|
2044
|
+
remove: createRemovePropertyFn('props'),
|
|
2045
|
+
},
|
|
2046
|
+
};
|
|
2047
|
+
|
|
2048
|
+
function setWrappers(wrappers) {
|
|
2049
|
+
return rawConfig((rawField, _) => {
|
|
2050
|
+
const wrapperConfig = rawField.globalConfig.additionalData['defaultWrapperMetadataGroup'];
|
|
2051
|
+
const injector = rawField.globalConfig.additionalData['injector'];
|
|
2052
|
+
const OptionDefine = {
|
|
2053
|
+
pipe: pipe(map((item) => {
|
|
2054
|
+
if (typeof item.type === 'string') {
|
|
2055
|
+
const type = wrapperConfig[item.type].type;
|
|
2056
|
+
if (!type) {
|
|
2057
|
+
throw new Error(`🈳wrapper:[${type}]❗`);
|
|
2058
|
+
}
|
|
2059
|
+
return { ...item, type: type };
|
|
2060
|
+
}
|
|
2061
|
+
return item;
|
|
2062
|
+
})),
|
|
2063
|
+
injector: injector,
|
|
2064
|
+
};
|
|
2065
|
+
wrappers.forEach((item) => {
|
|
2066
|
+
if (typeof item === 'string') {
|
|
2067
|
+
const defaultActions = wrapperConfig[item]?.actions ?? [];
|
|
2068
|
+
const define = observableSignal({
|
|
2069
|
+
type: item,
|
|
2070
|
+
inputs: asyncObjectSignal({}),
|
|
2071
|
+
outputs: asyncObjectSignal({}),
|
|
2072
|
+
attributes: asyncObjectSignal({}),
|
|
2073
|
+
events: asyncObjectSignal({}),
|
|
2074
|
+
}, OptionDefine);
|
|
2075
|
+
rawField.wrappers.add(define);
|
|
2076
|
+
defaultActions.forEach((item) => {
|
|
2077
|
+
item.value(rawField, _, {
|
|
2078
|
+
[CustomDataSymbol]: define,
|
|
2079
|
+
});
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
else {
|
|
2083
|
+
rawField.wrappers.add(observableSignal({
|
|
2084
|
+
type: item.type,
|
|
2085
|
+
inputs: asyncObjectSignal(item.inputs ?? {}),
|
|
2086
|
+
outputs: asyncObjectSignal(item.outputs ?? {}),
|
|
2087
|
+
attributes: asyncObjectSignal(item.attributes ?? {}),
|
|
2088
|
+
events: asyncObjectSignal(item.events ?? {}),
|
|
2089
|
+
}, OptionDefine));
|
|
2090
|
+
}
|
|
2091
|
+
});
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
function removeWrappers(removeList) {
|
|
2095
|
+
return rawConfig((field) => {
|
|
2096
|
+
mergeHooksFn({
|
|
2097
|
+
allFieldsResolved: (field) => {
|
|
2098
|
+
let list;
|
|
2099
|
+
if (typeof removeList === 'function') {
|
|
2100
|
+
list = removeList(field.wrappers.items());
|
|
2101
|
+
}
|
|
2102
|
+
else {
|
|
2103
|
+
list = field.wrappers.items().filter((item) => {
|
|
2104
|
+
const type = item.input().type;
|
|
2105
|
+
return removeList.every((name) => name !== type);
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
field.wrappers.update(() => list);
|
|
2109
|
+
},
|
|
2110
|
+
}, { position: 'bottom' }, field);
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
function patchAsyncWrapper(type, actions, options) {
|
|
2114
|
+
return rawConfig((rawFiled) => {
|
|
2115
|
+
// 在这里增加要处理的wrapper类型
|
|
2116
|
+
mergeHooksFn({
|
|
2117
|
+
allFieldsResolved: (field) => {
|
|
2118
|
+
const findConfig = field.injector.get(FindConfigToken);
|
|
2119
|
+
const initData = observableSignal({
|
|
2120
|
+
type,
|
|
2121
|
+
attributes: asyncObjectSignal({}),
|
|
2122
|
+
events: asyncObjectSignal({}),
|
|
2123
|
+
inputs: asyncObjectSignal({}),
|
|
2124
|
+
outputs: asyncObjectSignal({}),
|
|
2125
|
+
}, {
|
|
2126
|
+
pipe: pipe(map((item) => {
|
|
2127
|
+
const defaultWrapperConfig = findConfig.findWrapperComponent(item.type);
|
|
2128
|
+
return { ...item, type: defaultWrapperConfig };
|
|
2129
|
+
})),
|
|
2130
|
+
injector: field.injector,
|
|
2131
|
+
});
|
|
2132
|
+
field.wrappers.add(initData, options?.insertIndex);
|
|
2133
|
+
const defaultConfig = field.injector.get(PI_VIEW_CONFIG_TOKEN);
|
|
2134
|
+
let defaultActions = [];
|
|
2135
|
+
if (typeof type === 'string') {
|
|
2136
|
+
defaultActions = defaultConfig.wrappers?.[type]?.actions ?? [];
|
|
2137
|
+
}
|
|
2138
|
+
const allActions = [...defaultActions, ...(actions ?? [])];
|
|
2139
|
+
for (const item of allActions) {
|
|
2140
|
+
const tempField = {};
|
|
2141
|
+
item.value(tempField, undefined, {
|
|
2142
|
+
[CustomDataSymbol]: initData,
|
|
2143
|
+
});
|
|
2144
|
+
tempField.hooks?.allFieldsResolved?.(field);
|
|
2145
|
+
}
|
|
2146
|
+
},
|
|
2147
|
+
}, { position: 'bottom' }, rawFiled);
|
|
2148
|
+
});
|
|
2149
|
+
}
|
|
2150
|
+
function changeAsyncWrapper(indexFn, actions) {
|
|
2151
|
+
return rawConfig((rawFiled) => {
|
|
2152
|
+
mergeHooksFn({
|
|
2153
|
+
allFieldsResolved: (field) => {
|
|
2154
|
+
const initData = indexFn(field.wrappers
|
|
2155
|
+
.items()
|
|
2156
|
+
.map((item) => item.input));
|
|
2157
|
+
if (!initData) {
|
|
2158
|
+
throw new Error(`change wrapper not found`);
|
|
2159
|
+
}
|
|
2160
|
+
for (const item of actions) {
|
|
2161
|
+
const tempField = {};
|
|
2162
|
+
item.value(tempField, undefined, {
|
|
2163
|
+
[CustomDataSymbol]: initData,
|
|
2164
|
+
});
|
|
2165
|
+
tempField.hooks?.allFieldsResolved?.(field);
|
|
2166
|
+
}
|
|
2167
|
+
},
|
|
2168
|
+
}, { position: 'bottom' }, rawFiled);
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
const wrappers = {
|
|
2172
|
+
set: setWrappers,
|
|
2173
|
+
patchAsync: patchAsyncWrapper,
|
|
2174
|
+
remove: removeWrappers,
|
|
2175
|
+
changeAsync: changeAsyncWrapper,
|
|
2176
|
+
};
|
|
2177
|
+
|
|
2170
2178
|
/** 必须防止到所有wrappers操作后面,防止设置错误
|
|
2171
2179
|
* 设置到顶层,可能是wrapper,也可能是component
|
|
2172
2180
|
*
|
|
@@ -2174,7 +2182,7 @@ function disableWhen(options) {
|
|
|
2174
2182
|
function topClass(className, merge) {
|
|
2175
2183
|
return rawConfig((rawField) => {
|
|
2176
2184
|
mergeHooksFn({
|
|
2177
|
-
|
|
2185
|
+
allFieldsResolved: (field) => {
|
|
2178
2186
|
const wrappers = field.wrappers();
|
|
2179
2187
|
if (wrappers?.length) {
|
|
2180
2188
|
wrappers[0].attributes.update((attributes) => ({
|
|
@@ -2197,35 +2205,63 @@ function topClass(className, merge) {
|
|
|
2197
2205
|
});
|
|
2198
2206
|
}
|
|
2199
2207
|
/** 仅设置在组件上 */
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
}
|
|
2208
|
+
const componentClass = (className, merge) => rawConfig((rawField, _, ...args) => {
|
|
2209
|
+
let data$;
|
|
2210
|
+
if (args.length > 0 &&
|
|
2211
|
+
typeof args[args.length - 1] === 'object' &&
|
|
2212
|
+
CustomDataSymbol in args[args.length - 1]) {
|
|
2213
|
+
data$ = args[args.length - 1][CustomDataSymbol];
|
|
2214
|
+
}
|
|
2215
|
+
else {
|
|
2216
|
+
data$ = (() => rawField);
|
|
2217
|
+
}
|
|
2218
|
+
const content$ = data$()['attributes'];
|
|
2219
|
+
content$.update((data) => ({
|
|
2220
|
+
...data,
|
|
2221
|
+
class: merge ? clsx(data?.['class'], className) : clsx(className),
|
|
2222
|
+
}));
|
|
2223
|
+
});
|
|
2210
2224
|
const bottomClass = componentClass;
|
|
2211
2225
|
function patchAsyncClass(fn) {
|
|
2212
|
-
return
|
|
2226
|
+
return __actions.attributes.patchAsync({ class: fn });
|
|
2213
2227
|
}
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2228
|
+
function asyncTopClass(classNameFn) {
|
|
2229
|
+
return rawConfig((rawField) => {
|
|
2230
|
+
mergeHooksFn({
|
|
2231
|
+
allFieldsResolved: (field) => {
|
|
2232
|
+
const wrappers = field.wrappers();
|
|
2233
|
+
if (wrappers?.length) {
|
|
2234
|
+
wrappers[0].attributes.connect('class', classNameFn(field));
|
|
2235
|
+
}
|
|
2236
|
+
else {
|
|
2237
|
+
field.attributes.connect('class', classNameFn(field));
|
|
2238
|
+
}
|
|
2239
|
+
},
|
|
2240
|
+
}, { position: 'bottom' }, rawField);
|
|
2241
|
+
});
|
|
2222
2242
|
}
|
|
2243
|
+
const classAction = {
|
|
2244
|
+
top: topClass,
|
|
2245
|
+
bottom: bottomClass,
|
|
2246
|
+
component: componentClass,
|
|
2247
|
+
asyncTop: asyncTopClass,
|
|
2248
|
+
asyncBottom: patchAsyncClass,
|
|
2249
|
+
asyncComponent: patchAsyncClass,
|
|
2250
|
+
};
|
|
2251
|
+
|
|
2252
|
+
const actions = {
|
|
2253
|
+
...__actions,
|
|
2254
|
+
class: classAction,
|
|
2255
|
+
wrappers,
|
|
2256
|
+
};
|
|
2223
2257
|
|
|
2224
2258
|
class CoreSchemaHandle extends BaseSchemaHandle {
|
|
2225
|
-
inputs;
|
|
2226
|
-
outputs;
|
|
2227
|
-
|
|
2228
|
-
|
|
2259
|
+
inputs = asyncObjectSignal({});
|
|
2260
|
+
outputs = asyncObjectSignal({});
|
|
2261
|
+
attributes = asyncObjectSignal({});
|
|
2262
|
+
events = asyncObjectSignal({});
|
|
2263
|
+
wrappers = combineSignal([]);
|
|
2264
|
+
props = asyncObjectSignal({});
|
|
2229
2265
|
alias;
|
|
2230
2266
|
movePath;
|
|
2231
2267
|
renderConfig;
|
|
@@ -2311,8 +2347,16 @@ class CoreSchemaHandle extends BaseSchemaHandle {
|
|
|
2311
2347
|
this.formConfig.groupMode = 'reset';
|
|
2312
2348
|
}
|
|
2313
2349
|
enumSchema(schema) {
|
|
2314
|
-
this.props
|
|
2315
|
-
|
|
2350
|
+
this.props.update((data) => ({
|
|
2351
|
+
...data,
|
|
2352
|
+
options: data['options'] ?? schema.options,
|
|
2353
|
+
}));
|
|
2354
|
+
}
|
|
2355
|
+
updateProps(key, value) {
|
|
2356
|
+
this.props.update((data) => ({
|
|
2357
|
+
...data,
|
|
2358
|
+
[key]: value,
|
|
2359
|
+
}));
|
|
2316
2360
|
}
|
|
2317
2361
|
intersectBefore(schema) {
|
|
2318
2362
|
if (this.childrenAsVirtualGroup) {
|
|
@@ -2414,8 +2458,12 @@ function convert(obj, options) {
|
|
|
2414
2458
|
}, {
|
|
2415
2459
|
...options,
|
|
2416
2460
|
handle: options?.handle ?? CoreSchemaHandle,
|
|
2461
|
+
additionalData: {
|
|
2462
|
+
defaultWrapperMetadataGroup: options.fieldGlobalConfig?.wrappers,
|
|
2463
|
+
injector,
|
|
2464
|
+
},
|
|
2417
2465
|
defaultMetadataActionsGroup: Object.keys(options.fieldGlobalConfig?.types ?? {}).reduce((obj, item) => {
|
|
2418
|
-
|
|
2466
|
+
const { actions } = options.fieldGlobalConfig.types[item];
|
|
2419
2467
|
if (actions) {
|
|
2420
2468
|
obj[item] = actions;
|
|
2421
2469
|
}
|
|
@@ -2431,5 +2479,5 @@ const NFCSchema = v.optional(v.void());
|
|
|
2431
2479
|
* Generated bundle index. Do not edit.
|
|
2432
2480
|
*/
|
|
2433
2481
|
|
|
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,
|
|
2482
|
+
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
2483
|
//# sourceMappingURL=piying-view-angular-core.mjs.map
|