@piying/view-core 2.6.1 → 2.6.2

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.
@@ -147,8 +147,6 @@ class AbstractControl {
147
147
  const result = this.#schemaCheck$$();
148
148
  return result.success ? result.output : value;
149
149
  });
150
- /** 已激活的子级,用于校验获得返回值之类 */
151
- activatedChildren$$;
152
150
  /** 通用的子级,用于查询之类 */
153
151
  children$$;
154
152
  /** disabled */
@@ -428,27 +426,20 @@ class AbstractControl {
428
426
  return null;
429
427
  }
430
428
  setControl(name, control) { }
429
+ *activatedChildrenIterable() { }
431
430
  /** 校验和获得值用 */
432
431
  reduceChildren(initialValue, fn, shortCircuit) {
433
- const childrenMap = (this.activatedChildren$$ ?? this.children$$)?.();
434
- if (!childrenMap) {
435
- return initialValue;
436
- }
437
- let value = initialValue;
438
- const list = Object.entries(childrenMap);
439
- const isArray = Array.isArray(childrenMap);
440
- for (let index = 0; index < list.length; index++) {
441
- if (!list[index][1]) {
432
+ let result = initialValue;
433
+ for (const [key, child] of this.activatedChildrenIterable()) {
434
+ if (!child) {
442
435
  continue;
443
436
  }
444
- const key = isArray ? index : list[index][0];
445
- const item = list[index][1];
446
- if (shortCircuit?.(value)) {
437
+ if (shortCircuit?.(result)) {
447
438
  break;
448
439
  }
449
- value = fn(item, value, key);
440
+ result = fn(child, result, key);
450
441
  }
451
- return value;
442
+ return result;
452
443
  }
453
444
  #valueChange;
454
445
  get valueChanges() {
@@ -622,6 +613,12 @@ class FieldGroup extends FieldGroupbase {
622
613
  return this.#controls$$();
623
614
  }
624
615
  children$$ = computed(() => this.#controls$$());
616
+ *activatedChildrenIterable() {
617
+ const children = this.children$$();
618
+ for (const key in children) {
619
+ yield [key, children[key]];
620
+ }
621
+ }
625
622
  removeRestControl(key) {
626
623
  if (!this.resetControls$()[key]) {
627
624
  return;
@@ -793,6 +790,12 @@ class FieldArray extends FieldGroupbase {
793
790
  get controls() {
794
791
  return this.children$$();
795
792
  }
793
+ *activatedChildrenIterable() {
794
+ const children = this.children$$();
795
+ for (let index = 0; index < children.length; index++) {
796
+ yield [index, children[index]];
797
+ }
798
+ }
796
799
  removeRestControl(key) {
797
800
  if (!this.resetControls$()[key]) {
798
801
  return;
@@ -847,7 +850,8 @@ class FieldArray extends FieldGroupbase {
847
850
  class FieldLogicGroup extends FieldArray {
848
851
  activateIndex$ = signal(0);
849
852
  type = signal('and');
850
- activateControls$ = signal(undefined);
853
+ /** 过滤激活控件 */
854
+ filterActivateControl$ = signal(undefined);
851
855
  #childUpdate() {
852
856
  const returnResult = this.getValue(false);
853
857
  return this.transformToModel(returnResult, this);
@@ -861,8 +865,9 @@ class FieldLogicGroup extends FieldArray {
861
865
  });
862
866
  #getActivateControls() {
863
867
  let list;
864
- if (this.activateControls$()) {
865
- list = this.activateControls$();
868
+ const fn = this.filterActivateControl$();
869
+ if (fn) {
870
+ list = this.children$$().filter(fn);
866
871
  }
867
872
  else if (this.type() === 'and') {
868
873
  list = this.fixedControls$();
@@ -876,6 +881,26 @@ class FieldLogicGroup extends FieldArray {
876
881
  return list;
877
882
  }
878
883
  activatedChildren$$ = computed(() => this.#getActivateControls());
884
+ activatedChildrenIterable = computed(() => {
885
+ const filterFn = this.filterActivateControl$();
886
+ const type = this.type();
887
+ if (filterFn) {
888
+ const children = this.children$$();
889
+ return children
890
+ .map((element, index) => [index, element])
891
+ .filter(([index, item]) => !!filterFn(item, index, children));
892
+ }
893
+ else if (type === 'and') {
894
+ return this.fixedControls$().map((control, index) => [index, control]);
895
+ }
896
+ else if (type === 'or') {
897
+ const index = this.activateIndex$();
898
+ return [
899
+ [index, this.fixedControls$()[index]],
900
+ ];
901
+ }
902
+ return [];
903
+ });
879
904
  getValue(rawData) {
880
905
  const controls = rawData
881
906
  ? this.activatedChildren$$()