@piying/view-core 2.6.2 → 2.6.3

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.
@@ -134,6 +134,7 @@ const InitPendingValue = {
134
134
  value: undefined,
135
135
  };
136
136
  class AbstractControl {
137
+ skipValuePath;
137
138
  pendingStatus = signal(InitPendingValue);
138
139
  emptyValue$$ = computed(() => clone(this.config$().emptyValue));
139
140
  /** 父级取值时,当前子级是否包含在内 */
@@ -187,6 +188,15 @@ class AbstractControl {
187
188
  /** validator */
188
189
  #validators$$ = computed(() => this.config$().validators ?? []);
189
190
  #asyncValidators$$ = computed(() => this.config$().asyncValidators ?? []);
191
+ #undefinedable$$ = computed(() => this.config$().undefinedable);
192
+ #nullable$$ = computed(() => this.config$().nullable);
193
+ #isOptionalEmpty = computed(() => {
194
+ if (this.required$$()) {
195
+ return false;
196
+ }
197
+ return ((this.#undefinedable$$() && this.originValue$$() === undefined) ||
198
+ (this.#nullable$$() && this.originValue$$() === null));
199
+ });
190
200
  resetIndex$ = signal(0);
191
201
  syncError$ = linkedSignal(computed(() => {
192
202
  const disabled = this.disabled$$();
@@ -195,23 +205,24 @@ class AbstractControl {
195
205
  }
196
206
  // 请求同级
197
207
  this.resetIndex$();
198
- this.originValue$$();
199
- const childrenResult = this.reduceChildren([], (child, value, key) => {
200
- if ((!child.selfDisabled$$() ||
201
- (child.selfDisabled$$() &&
202
- child.config$().disabledValue === 'reserve')) &&
203
- child.errors) {
204
- value.push({
205
- kind: 'descendant',
206
- key: key,
207
- metadata: child.errors,
208
- field: child,
209
- });
208
+ if (!this.#isOptionalEmpty()) {
209
+ const childrenResult = this.reduceChildren([], (child, value, key) => {
210
+ if ((!child.selfDisabled$$() ||
211
+ (child.selfDisabled$$() &&
212
+ child.config$().disabledValue === 'reserve')) &&
213
+ child.errors) {
214
+ value.push({
215
+ kind: 'descendant',
216
+ key: key,
217
+ metadata: child.errors,
218
+ field: child,
219
+ });
220
+ }
221
+ return value;
222
+ });
223
+ if (childrenResult.length) {
224
+ return childrenResult;
210
225
  }
211
- return value;
212
- });
213
- if (childrenResult.length) {
214
- return childrenResult;
215
226
  }
216
227
  const result = this.#validators$$().flatMap((item) => {
217
228
  const result = untracked(() => item(this));
@@ -325,6 +336,40 @@ class AbstractControl {
325
336
  get parent() {
326
337
  return this._parent;
327
338
  }
339
+ #getPath(parentPath, skip) {
340
+ if (!this.parent) {
341
+ return [];
342
+ }
343
+ if (skip()) {
344
+ return parentPath();
345
+ }
346
+ const parentChildren = this.parent.children$$();
347
+ let index;
348
+ if (Array.isArray(parentChildren)) {
349
+ index = parentChildren.findIndex((item) => item === this);
350
+ if (index === -1) {
351
+ throw new Error('child index not found');
352
+ }
353
+ }
354
+ else {
355
+ for (const key in parentChildren) {
356
+ if (parentChildren[key] === this) {
357
+ index = key;
358
+ break;
359
+ }
360
+ }
361
+ if (!index) {
362
+ throw new Error('child index not found');
363
+ }
364
+ }
365
+ return [...parentPath(), index];
366
+ }
367
+ get valuePath() {
368
+ return this.#getPath(() => this.parent.valuePath, () => !!this.parent.skipValuePath);
369
+ }
370
+ get formPath() {
371
+ return this.#getPath(() => this.parent.formPath, () => false);
372
+ }
328
373
  get value() {
329
374
  return this.value$$();
330
375
  }
@@ -455,15 +500,18 @@ class AbstractControl {
455
500
  if (this.disabled$$()) {
456
501
  return VALID;
457
502
  }
458
- const childStatus = this.reduceChildren(VALID, (child, value) => {
459
- if (value === INVALID || child.status$$() === INVALID) {
460
- return INVALID;
461
- }
462
- else if (value === PENDING || child.status$$() === PENDING) {
463
- return PENDING;
464
- }
465
- return VALID;
466
- }, (v) => v === INVALID || v === PENDING);
503
+ let childStatus = VALID;
504
+ if (!this.#isOptionalEmpty()) {
505
+ childStatus = this.reduceChildren(VALID, (child, value) => {
506
+ if (value === INVALID || child.status$$() === INVALID) {
507
+ return INVALID;
508
+ }
509
+ else if (value === PENDING || child.status$$() === PENDING) {
510
+ return PENDING;
511
+ }
512
+ return VALID;
513
+ }, (v) => v === INVALID || v === PENDING);
514
+ }
467
515
  if (childStatus === VALID) {
468
516
  if (this.rawError$$()) {
469
517
  if (this.rawError$$() !== PENDING) {
@@ -848,6 +896,7 @@ class FieldArray extends FieldGroupbase {
848
896
 
849
897
  // 切换索引后,理论上应该触发下值变更,否则不知道值是什么
850
898
  class FieldLogicGroup extends FieldArray {
899
+ skipValuePath = true;
851
900
  activateIndex$ = signal(0);
852
901
  type = signal('and');
853
902
  /** 过滤激活控件 */
@@ -2530,7 +2579,7 @@ function AnyDefault(input, schemahandle) {
2530
2579
  : input;
2531
2580
  }
2532
2581
  const checkOverride = {
2533
- logicGroup: (schemahandle) => v.pipe(AnyDefault(v.pipe(AnyDefine, v.check(Boolean)), schemahandle)),
2582
+ logicGroup: (schemahandle) => v.pipe(AnyDefault(AnyDefine, schemahandle)),
2534
2583
  array: (schemahandle) => {
2535
2584
  const source = schemahandle.coreSchema;
2536
2585
  const length = source &&
@@ -2707,6 +2756,8 @@ class CoreSchemaHandle extends BaseSchemaHandle {
2707
2756
  beforeSchemaType(schema) {
2708
2757
  super.beforeSchemaType(schema);
2709
2758
  this.formConfig.required = !this.undefinedable && !this.nullable;
2759
+ this.formConfig.undefinedable = this.undefinedable;
2760
+ this.formConfig.nullable = this.nullable;
2710
2761
  }
2711
2762
  voidSchema(schema) {
2712
2763
  this.nonFieldControl = true;