@piying/view-angular-core 2.2.4 → 2.3.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,4 +1,4 @@
|
|
|
1
|
-
import { signal, computed, InjectionToken, effect, inject, Injector, untracked, DestroyRef, linkedSignal, isSignal
|
|
1
|
+
import { signal, computed, InjectionToken, effect, inject, Injector, untracked, DestroyRef, linkedSignal, isSignal } from '@angular/core';
|
|
2
2
|
import * as v from 'valibot';
|
|
3
3
|
import { isObservable, BehaviorSubject, Subject, tap, pipe, shareReplay, combineLatest, startWith, skip, map } from 'rxjs';
|
|
4
4
|
import rfdc from 'rfdc';
|
|
@@ -60,6 +60,7 @@ const PI_FORM_BUILDER_OPTIONS_TOKEN = new InjectionToken('PI_FORM_BUILDER_OPTION
|
|
|
60
60
|
const PI_FORM_BUILDER_ALIAS_MAP = new InjectionToken('PI_FORM_BUILDER_ALIAS_MAP');
|
|
61
61
|
/** 上下文注入 */
|
|
62
62
|
const PI_CONTEXT_TOKEN = new InjectionToken('PI_CONTEXT');
|
|
63
|
+
const PI_VIEW_FIELD_TOKEN = new InjectionToken('PI_VIEW_FIELD_TOKEN');
|
|
63
64
|
|
|
64
65
|
const clone = rfdc({ proto: false, circles: false });
|
|
65
66
|
|
|
@@ -1400,12 +1401,11 @@ class FormBuilder {
|
|
|
1400
1401
|
new ParentMap();
|
|
1401
1402
|
#options = inject(PI_FORM_BUILDER_OPTIONS_TOKEN);
|
|
1402
1403
|
#injector = inject(Injector);
|
|
1403
|
-
#envInjector = inject(EnvironmentInjector);
|
|
1404
1404
|
#allFieldInitHookList = [];
|
|
1405
1405
|
buildRoot(item) {
|
|
1406
1406
|
const field = this.#buildControl({
|
|
1407
1407
|
type: 'root',
|
|
1408
|
-
field: { fullPath: [] },
|
|
1408
|
+
field: { fullPath: [], injector: this.#injector },
|
|
1409
1409
|
form: undefined,
|
|
1410
1410
|
resolvedField$: item.resolvedField$,
|
|
1411
1411
|
append: () => { },
|
|
@@ -1460,10 +1460,25 @@ class FormBuilder {
|
|
|
1460
1460
|
keyPath ??= index;
|
|
1461
1461
|
}
|
|
1462
1462
|
const isRoot = parent.type === 'root';
|
|
1463
|
+
const injector = Injector.create({
|
|
1464
|
+
providers: [
|
|
1465
|
+
...(field.providers ?? []),
|
|
1466
|
+
{
|
|
1467
|
+
provide: PI_VIEW_FIELD_TOKEN,
|
|
1468
|
+
useValue: () => resolvedConfig,
|
|
1469
|
+
},
|
|
1470
|
+
],
|
|
1471
|
+
parent: parent.field.injector,
|
|
1472
|
+
});
|
|
1473
|
+
parent.field.injector.get(DestroyRef).onDestroy(() => {
|
|
1474
|
+
if (resolvedConfig.injector) {
|
|
1475
|
+
resolvedConfig.injector.destroy();
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1463
1478
|
if (!field.nonFieldControl && (keyPath !== undefined || isRoot)) {
|
|
1464
1479
|
control = createField(parent.form, field, keyPath,
|
|
1465
1480
|
// 这里也是fullPath
|
|
1466
|
-
formConfig$, isRoot,
|
|
1481
|
+
formConfig$, isRoot, injector);
|
|
1467
1482
|
}
|
|
1468
1483
|
const rootForm = this.#options.form$$;
|
|
1469
1484
|
let resolvedConfig = {
|
|
@@ -1509,7 +1524,7 @@ class FormBuilder {
|
|
|
1509
1524
|
? signal({ type: define, inputs, outputs, attributes, events })
|
|
1510
1525
|
: undefined,
|
|
1511
1526
|
wrappers: field.wrappers,
|
|
1512
|
-
injector:
|
|
1527
|
+
injector: injector,
|
|
1513
1528
|
};
|
|
1514
1529
|
resolvedConfig =
|
|
1515
1530
|
this.afterResolveConfig(field, resolvedConfig) ?? resolvedConfig;
|
|
@@ -1713,17 +1728,15 @@ class FormBuilder {
|
|
|
1713
1728
|
provide: PI_FORM_BUILDER_ALIAS_MAP,
|
|
1714
1729
|
useValue: new ParentMap(this.#scopeMap),
|
|
1715
1730
|
},
|
|
1716
|
-
{ provide: EnvironmentInjector, useFactory: () => injector },
|
|
1717
1731
|
],
|
|
1718
|
-
parent:
|
|
1732
|
+
parent: parent.field.injector,
|
|
1719
1733
|
});
|
|
1720
|
-
|
|
1721
|
-
|
|
1734
|
+
parent.field.injector.get(DestroyRef).onDestroy(() => {
|
|
1735
|
+
injector.destroy();
|
|
1722
1736
|
});
|
|
1723
1737
|
const instance = injector.get(Builder);
|
|
1724
1738
|
const result = instance.#buildControl({ ...parent, skipAppend: true }, field, index);
|
|
1725
1739
|
this.#allFieldInitHookList.push(() => instance.allFieldInitHookCall());
|
|
1726
|
-
result.injector = injector.get(EnvironmentInjector);
|
|
1727
1740
|
return result;
|
|
1728
1741
|
}
|
|
1729
1742
|
#moveViewField(key, inputField) {
|
|
@@ -2328,6 +2341,24 @@ const classAction = {
|
|
|
2328
2341
|
asyncComponent: patchAsyncClass,
|
|
2329
2342
|
};
|
|
2330
2343
|
|
|
2344
|
+
function setProviders(providers) {
|
|
2345
|
+
return rawConfig((field) => {
|
|
2346
|
+
field.providers = providers;
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2349
|
+
function patchProviders(providers) {
|
|
2350
|
+
return rawConfig((field) => {
|
|
2351
|
+
field.providers ??= [];
|
|
2352
|
+
field.providers.push(providers);
|
|
2353
|
+
});
|
|
2354
|
+
}
|
|
2355
|
+
function changeProviders(providersFn) {
|
|
2356
|
+
return rawConfig((field) => {
|
|
2357
|
+
const result = providersFn(field.providers ?? []);
|
|
2358
|
+
field.providers = result;
|
|
2359
|
+
});
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2331
2362
|
const actions = {
|
|
2332
2363
|
...__actions,
|
|
2333
2364
|
class: classAction,
|
|
@@ -2338,6 +2369,11 @@ const actions = {
|
|
|
2338
2369
|
set: setHooks,
|
|
2339
2370
|
patch: patchHooks,
|
|
2340
2371
|
},
|
|
2372
|
+
providers: {
|
|
2373
|
+
set: setProviders,
|
|
2374
|
+
patch: patchProviders,
|
|
2375
|
+
change: changeProviders,
|
|
2376
|
+
},
|
|
2341
2377
|
};
|
|
2342
2378
|
|
|
2343
2379
|
class CoreSchemaHandle extends BaseSchemaHandle {
|
|
@@ -2359,6 +2395,7 @@ class CoreSchemaHandle extends BaseSchemaHandle {
|
|
|
2359
2395
|
isTuple = false;
|
|
2360
2396
|
nonFieldControl = false;
|
|
2361
2397
|
hooks;
|
|
2398
|
+
providers;
|
|
2362
2399
|
lazySchema(schema) {
|
|
2363
2400
|
super.lazySchema(schema);
|
|
2364
2401
|
if (this.parent) {
|
|
@@ -2524,12 +2561,11 @@ function convert(obj, options) {
|
|
|
2524
2561
|
},
|
|
2525
2562
|
{ provide: FindConfigToken, useFactory: FindConfigFactory },
|
|
2526
2563
|
options.builder,
|
|
2527
|
-
{ provide: EnvironmentInjector, useFactory: () => injector },
|
|
2528
2564
|
],
|
|
2529
2565
|
parent: options.injector,
|
|
2530
2566
|
});
|
|
2531
|
-
options.
|
|
2532
|
-
injector.
|
|
2567
|
+
options.injector.get(DestroyRef).onDestroy(() => {
|
|
2568
|
+
injector.destroy();
|
|
2533
2569
|
});
|
|
2534
2570
|
return convertCore(obj, (item) => {
|
|
2535
2571
|
// todo
|
|
@@ -2562,5 +2598,5 @@ const NFCSchema = v.optional(v.void());
|
|
|
2562
2598
|
* Generated bundle index. Do not edit.
|
|
2563
2599
|
*/
|
|
2564
2600
|
|
|
2565
|
-
export { AbstractControl, CoreSchemaHandle, CustomDataSymbol, FieldArray, FieldControl, FieldGroup, FieldLogicGroup, FormBuilder, INVALID, InitPendingValue, 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 };
|
|
2601
|
+
export { AbstractControl, CoreSchemaHandle, CustomDataSymbol, FieldArray, FieldControl, FieldGroup, FieldLogicGroup, FormBuilder, INVALID, InitPendingValue, NFCSchema, PENDING, PI_CONTEXT_TOKEN, PI_FORM_BUILDER_ALIAS_MAP, PI_FORM_BUILDER_OPTIONS_TOKEN, PI_VIEW_CONFIG_TOKEN, PI_VIEW_FIELD_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, changeProviders as ɵchangeProviders, classAction as ɵclassAction, patchProviders as ɵpatchProviders, setProviders as ɵsetProviders, wrappers as ɵwrappers };
|
|
2566
2602
|
//# sourceMappingURL=piying-view-angular-core.mjs.map
|