@piying/view-angular-core 2.2.3 → 2.3.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,4 +1,4 @@
1
- import { signal, computed, InjectionToken, effect, inject, Injector, untracked, DestroyRef, linkedSignal, isSignal, EnvironmentInjector } from '@angular/core';
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';
@@ -548,9 +548,7 @@ class FieldGroup extends FieldGroupbase {
548
548
  value$$ = computed(() => {
549
549
  if (this.updateOn$$() === 'submit') {
550
550
  this.submitIndex$();
551
- return untracked(() => {
552
- return this.#childUpdate();
553
- });
551
+ return untracked(() => this.#childUpdate());
554
552
  }
555
553
  return this.#childUpdate();
556
554
  });
@@ -739,9 +737,7 @@ class FieldArray extends FieldGroupbase {
739
737
  value$$ = computed(() => {
740
738
  if (this.updateOn$$() === 'submit') {
741
739
  this.submitIndex$();
742
- return untracked(() => {
743
- return this.#childUpdate();
744
- });
740
+ return untracked(() => this.#childUpdate());
745
741
  }
746
742
  return this.#childUpdate();
747
743
  });
@@ -816,9 +812,7 @@ class FieldLogicGroup extends FieldArray {
816
812
  value$$ = computed(() => {
817
813
  if (this.updateOn$$() === 'submit') {
818
814
  this.submitIndex$();
819
- return untracked(() => {
820
- return this.#childUpdate();
821
- });
815
+ return untracked(() => this.#childUpdate());
822
816
  }
823
817
  return this.#childUpdate();
824
818
  });
@@ -1198,12 +1192,12 @@ function observableSignal(initialValue, options) {
1198
1192
 
1199
1193
  function asyncObjectSignal(initialValue, options) {
1200
1194
  const data$ = signal(initialValue);
1201
- let mapFn$ = signal(undefined);
1195
+ const mapFn$ = signal(undefined);
1202
1196
  const signalList$ = signal([]);
1203
1197
  const value$$ = computed(() => {
1204
1198
  const signalList = signalList$();
1205
1199
  const data = data$();
1206
- let mapFn = mapFn$();
1200
+ const mapFn = mapFn$();
1207
1201
  if (!signalList.length) {
1208
1202
  return mapFn ? mapFn(data) : data;
1209
1203
  }
@@ -1406,12 +1400,11 @@ class FormBuilder {
1406
1400
  new ParentMap();
1407
1401
  #options = inject(PI_FORM_BUILDER_OPTIONS_TOKEN);
1408
1402
  #injector = inject(Injector);
1409
- #envInjector = inject(EnvironmentInjector);
1410
1403
  #allFieldInitHookList = [];
1411
1404
  buildRoot(item) {
1412
1405
  const field = this.#buildControl({
1413
1406
  type: 'root',
1414
- field: { fullPath: [] },
1407
+ field: { fullPath: [], injector: this.#injector },
1415
1408
  form: undefined,
1416
1409
  resolvedField$: item.resolvedField$,
1417
1410
  append: () => { },
@@ -1446,7 +1439,7 @@ class FormBuilder {
1446
1439
  #buildControl(parent,
1447
1440
  // 单独一项
1448
1441
  field, index) {
1449
- let define = !field.type
1442
+ const define = !field.type
1450
1443
  ? undefined
1451
1444
  : typeof field.type !== 'string'
1452
1445
  ? field.type
@@ -1466,10 +1459,19 @@ class FormBuilder {
1466
1459
  keyPath ??= index;
1467
1460
  }
1468
1461
  const isRoot = parent.type === 'root';
1462
+ const injector = Injector.create({
1463
+ providers: field.providers ?? [],
1464
+ parent: parent.field.injector,
1465
+ });
1466
+ parent.field.injector.get(DestroyRef).onDestroy(() => {
1467
+ if (resolvedConfig.injector) {
1468
+ resolvedConfig.injector.destroy();
1469
+ }
1470
+ });
1469
1471
  if (!field.nonFieldControl && (keyPath !== undefined || isRoot)) {
1470
1472
  control = createField(parent.form, field, keyPath,
1471
1473
  // 这里也是fullPath
1472
- formConfig$, isRoot, this.#injector);
1474
+ formConfig$, isRoot, injector);
1473
1475
  }
1474
1476
  const rootForm = this.#options.form$$;
1475
1477
  let resolvedConfig = {
@@ -1515,7 +1517,7 @@ class FormBuilder {
1515
1517
  ? signal({ type: define, inputs, outputs, attributes, events })
1516
1518
  : undefined,
1517
1519
  wrappers: field.wrappers,
1518
- injector: this.#envInjector,
1520
+ injector: injector,
1519
1521
  };
1520
1522
  resolvedConfig =
1521
1523
  this.afterResolveConfig(field, resolvedConfig) ?? resolvedConfig;
@@ -1719,17 +1721,15 @@ class FormBuilder {
1719
1721
  provide: PI_FORM_BUILDER_ALIAS_MAP,
1720
1722
  useValue: new ParentMap(this.#scopeMap),
1721
1723
  },
1722
- { provide: EnvironmentInjector, useFactory: () => injector },
1723
1724
  ],
1724
- parent: this.#envInjector,
1725
+ parent: parent.field.injector,
1725
1726
  });
1726
- this.#envInjector.get(DestroyRef).onDestroy(() => {
1727
- result.injector?.destroy();
1727
+ parent.field.injector.get(DestroyRef).onDestroy(() => {
1728
+ injector.destroy();
1728
1729
  });
1729
1730
  const instance = injector.get(Builder);
1730
1731
  const result = instance.#buildControl({ ...parent, skipAppend: true }, field, index);
1731
1732
  this.#allFieldInitHookList.push(() => instance.allFieldInitHookCall());
1732
- result.injector = injector.get(EnvironmentInjector);
1733
1733
  return result;
1734
1734
  }
1735
1735
  #moveViewField(key, inputField) {
@@ -2065,23 +2065,21 @@ function createMapPropertyFn(key) {
2065
2065
  });
2066
2066
  }
2067
2067
  function createMapAsyncPropertyFn(key) {
2068
- return (fn) => rawConfig((rawField, _, ...args) => {
2069
- return mergeHooksFn({
2070
- allFieldsResolved: (field) => {
2071
- let data$;
2072
- if (args.length > 0 &&
2073
- typeof args[args.length - 1] === 'object' &&
2074
- CustomDataSymbol in args[args.length - 1]) {
2075
- data$ = args[args.length - 1][CustomDataSymbol];
2076
- }
2077
- else {
2078
- data$ = (() => field);
2079
- }
2080
- const content$ = data$()[key];
2081
- content$.map(fn(field));
2082
- },
2083
- }, { position: 'bottom' }, rawField);
2084
- });
2068
+ return (fn) => rawConfig((rawField, _, ...args) => mergeHooksFn({
2069
+ allFieldsResolved: (field) => {
2070
+ let data$;
2071
+ if (args.length > 0 &&
2072
+ typeof args[args.length - 1] === 'object' &&
2073
+ CustomDataSymbol in args[args.length - 1]) {
2074
+ data$ = args[args.length - 1][CustomDataSymbol];
2075
+ }
2076
+ else {
2077
+ data$ = (() => field);
2078
+ }
2079
+ const content$ = data$()[key];
2080
+ content$.map(fn(field));
2081
+ },
2082
+ }, { position: 'bottom' }, rawField));
2085
2083
  }
2086
2084
  const __actions = {
2087
2085
  inputs: {
@@ -2129,55 +2127,53 @@ const __actions = {
2129
2127
  };
2130
2128
 
2131
2129
  function createSetOrPatchWrappersFn(isPatch) {
2132
- return (wrappers) => {
2133
- return rawConfig((rawField, _) => {
2134
- const wrapperConfig = rawField.globalConfig.additionalData['defaultWrapperMetadataGroup'];
2135
- const injector = rawField.globalConfig.additionalData['injector'];
2136
- const OptionDefine = {
2137
- pipe: pipe(map((item) => {
2138
- if (typeof item.type === 'string') {
2139
- const type = wrapperConfig[item.type]?.type;
2140
- if (!type) {
2141
- throw new Error(`🈳wrapper:[${item.type}]❗`);
2142
- }
2143
- return { ...item, type: type };
2130
+ return (wrappers) => rawConfig((rawField, _) => {
2131
+ const wrapperConfig = rawField.globalConfig.additionalData['defaultWrapperMetadataGroup'];
2132
+ const injector = rawField.globalConfig.additionalData['injector'];
2133
+ const OptionDefine = {
2134
+ pipe: pipe(map((item) => {
2135
+ if (typeof item.type === 'string') {
2136
+ const type = wrapperConfig[item.type]?.type;
2137
+ if (!type) {
2138
+ throw new Error(`🈳wrapper:[${item.type}]❗`);
2144
2139
  }
2145
- return item;
2146
- })),
2147
- injector: injector,
2148
- };
2149
- if (!isPatch) {
2150
- rawField.wrappers.clean();
2151
- }
2152
- wrappers.forEach((item) => {
2153
- if (typeof item === 'string') {
2154
- const defaultActions = wrapperConfig[item]?.actions ?? [];
2155
- const define = observableSignal({
2156
- type: item,
2157
- inputs: asyncObjectSignal({}),
2158
- outputs: asyncObjectSignal({}),
2159
- attributes: asyncObjectSignal({}),
2160
- events: asyncObjectSignal({}),
2161
- }, OptionDefine);
2162
- rawField.wrappers.add(define);
2163
- defaultActions.forEach((item) => {
2164
- item.value(rawField, _, {
2165
- [CustomDataSymbol]: define,
2166
- });
2167
- });
2140
+ return { ...item, type: type };
2168
2141
  }
2169
- else {
2170
- rawField.wrappers.add(observableSignal({
2171
- type: item.type,
2172
- inputs: asyncObjectSignal(item.inputs ?? {}),
2173
- outputs: asyncObjectSignal(item.outputs ?? {}),
2174
- attributes: asyncObjectSignal(item.attributes ?? {}),
2175
- events: asyncObjectSignal(item.events ?? {}),
2176
- }, OptionDefine));
2177
- }
2178
- });
2142
+ return item;
2143
+ })),
2144
+ injector: injector,
2145
+ };
2146
+ if (!isPatch) {
2147
+ rawField.wrappers.clean();
2148
+ }
2149
+ wrappers.forEach((item) => {
2150
+ if (typeof item === 'string') {
2151
+ const defaultActions = wrapperConfig[item]?.actions ?? [];
2152
+ const define = observableSignal({
2153
+ type: item,
2154
+ inputs: asyncObjectSignal({}),
2155
+ outputs: asyncObjectSignal({}),
2156
+ attributes: asyncObjectSignal({}),
2157
+ events: asyncObjectSignal({}),
2158
+ }, OptionDefine);
2159
+ rawField.wrappers.add(define);
2160
+ defaultActions.forEach((item) => {
2161
+ item.value(rawField, _, {
2162
+ [CustomDataSymbol]: define,
2163
+ });
2164
+ });
2165
+ }
2166
+ else {
2167
+ rawField.wrappers.add(observableSignal({
2168
+ type: item.type,
2169
+ inputs: asyncObjectSignal(item.inputs ?? {}),
2170
+ outputs: asyncObjectSignal(item.outputs ?? {}),
2171
+ attributes: asyncObjectSignal(item.attributes ?? {}),
2172
+ events: asyncObjectSignal(item.events ?? {}),
2173
+ }, OptionDefine));
2174
+ }
2179
2175
  });
2180
- };
2176
+ });
2181
2177
  }
2182
2178
  function removeWrappers(removeList) {
2183
2179
  return rawConfig((field) => {
@@ -2338,6 +2334,24 @@ const classAction = {
2338
2334
  asyncComponent: patchAsyncClass,
2339
2335
  };
2340
2336
 
2337
+ function setProviders(providers) {
2338
+ return rawConfig((field) => {
2339
+ field.providers = providers;
2340
+ });
2341
+ }
2342
+ function patchProviders(providers) {
2343
+ return rawConfig((field) => {
2344
+ field.providers ??= [];
2345
+ field.providers.push(providers);
2346
+ });
2347
+ }
2348
+ function changeProviders(providersFn) {
2349
+ return rawConfig((field) => {
2350
+ const result = providersFn(field.providers ?? []);
2351
+ field.providers = result;
2352
+ });
2353
+ }
2354
+
2341
2355
  const actions = {
2342
2356
  ...__actions,
2343
2357
  class: classAction,
@@ -2348,6 +2362,11 @@ const actions = {
2348
2362
  set: setHooks,
2349
2363
  patch: patchHooks,
2350
2364
  },
2365
+ providers: {
2366
+ set: setProviders,
2367
+ patch: patchProviders,
2368
+ change: changeProviders,
2369
+ },
2351
2370
  };
2352
2371
 
2353
2372
  class CoreSchemaHandle extends BaseSchemaHandle {
@@ -2369,6 +2388,7 @@ class CoreSchemaHandle extends BaseSchemaHandle {
2369
2388
  isTuple = false;
2370
2389
  nonFieldControl = false;
2371
2390
  hooks;
2391
+ providers;
2372
2392
  lazySchema(schema) {
2373
2393
  super.lazySchema(schema);
2374
2394
  if (this.parent) {
@@ -2534,12 +2554,11 @@ function convert(obj, options) {
2534
2554
  },
2535
2555
  { provide: FindConfigToken, useFactory: FindConfigFactory },
2536
2556
  options.builder,
2537
- { provide: EnvironmentInjector, useFactory: () => injector },
2538
2557
  ],
2539
2558
  parent: options.injector,
2540
2559
  });
2541
- options.registerOnDestroy?.(() => {
2542
- injector.get(EnvironmentInjector).destroy();
2560
+ options.injector.get(DestroyRef).onDestroy(() => {
2561
+ injector.destroy();
2543
2562
  });
2544
2563
  return convertCore(obj, (item) => {
2545
2564
  // todo
@@ -2572,5 +2591,5 @@ const NFCSchema = v.optional(v.void());
2572
2591
  * Generated bundle index. Do not edit.
2573
2592
  */
2574
2593
 
2575
- 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 };
2594
+ 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, changeProviders as ɵchangeProviders, classAction as ɵclassAction, patchProviders as ɵpatchProviders, setProviders as ɵsetProviders, wrappers as ɵwrappers };
2576
2595
  //# sourceMappingURL=piying-view-angular-core.mjs.map