@dereekb/dbx-form 8.7.4 → 8.7.5

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.
@@ -10,7 +10,7 @@ import { AbstractSubscriptionDirective, safeDetectChanges, DbxInjectionComponent
10
10
  import * as i1$1 from '@dereekb/dbx-web';
11
11
  import { DbxActionTransitionSafetyDirective, DbxTextModule, DbxLoadingModule, DbxFlexLayoutModule, DbxSectionLayoutModule, DbxRouterAnchorModule, AbstractDbxSelectionListWrapperDirective, DEFAULT_LIST_WRAPPER_DIRECTIVE_TEMPLATE, AbstractDbxSelectionListViewDirective, addConfigToValueListItems, provideDbxListView, AbstractDbxValueListViewItemComponent, DbxButtonModule, DbxListLayoutModule, mapCompactModeObs, DbxBarLayoutModule } from '@dereekb/dbx-web';
12
12
  import { isPast, addSeconds, isSameMinute, startOfDay, isSameDay, addMinutes } from 'date-fns';
13
- import { BehaviorSubject, switchMap, first, exhaustMap, of, catchError, delay, filter, combineLatest, map, distinctUntilChanged, mergeMap, shareReplay, startWith, debounceTime, Subject, skipWhile, interval, tap, merge, throttleTime, scan } from 'rxjs';
13
+ import { BehaviorSubject, switchMap, first, exhaustMap, of, catchError, delay, filter, combineLatest, map, distinctUntilChanged, mergeMap, shareReplay, startWith, debounceTime, Subject, skipWhile, interval, tap, merge, throttleTime, scan, timer } from 'rxjs';
14
14
  import { LockSet, SubscriptionObject, asObservable, loadingStateHasFinishedLoading, switchMapMaybeObs, filterMaybe, switchMapMaybeDefault, SimpleLoadingContext, startWithBeginLoading, mapLoadingStateResults, successResult, ListLoadingStateContextInstance, isListLoadingStateEmpty, LoadingStateContextInstance, skipFirstMaybe, asyncPusherCache, scanCount } from '@dereekb/rxjs';
15
15
  import * as i1$4 from '@ngx-formly/core';
16
16
  import { FieldType, FieldWrapper, FormlyModule, FieldArrayType } from '@ngx-formly/core';
@@ -159,7 +159,8 @@ class DbxActionFormDirective {
159
159
  return this.form.getValue().pipe(first(), exhaustMap((value) => {
160
160
  // Use both changes count and whether or not something was in the past to guage whether or not the item has been touched.
161
161
  // Angular Form's untouched is whether or not focus has been lost but we can still receive value updates.
162
- // More than a certain amount of updates implies that it is being typed into.
162
+ // More than a certain amount of updates implies that it is being typed into/used.
163
+ // 3 changes and 2 seconds are arbitrary values derived from guesses about any slow/late changes that may come from external directives for setup.
163
164
  const isProbablyTouched = !event.untouched || ((event.changesCount ?? 0) > 3 && isPast(addSeconds(event.lastResetAt ?? new Date(), 2)));
164
165
  let validatorObs;
165
166
  const initialIsValidCheck = event.isComplete;
@@ -601,7 +602,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImpor
601
602
 
602
603
  class DbxFormInfoWrapperComponent extends FieldWrapper {
603
604
  get infoWrapper() {
604
- return this.props.infoWrapper;
605
+ return this.props;
605
606
  }
606
607
  onInfoClick() {
607
608
  this.infoWrapper.onInfoClick();
@@ -640,10 +641,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImpor
640
641
 
641
642
  class DbxFormSectionWrapperComponent extends FieldWrapper {
642
643
  get header() {
643
- return this.props.sectionWrapper?.header;
644
+ return this.props.header;
644
645
  }
645
646
  get hint() {
646
- return this.props.sectionWrapper?.hint;
647
+ return this.props.hint;
647
648
  }
648
649
  }
649
650
  DbxFormSectionWrapperComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: DbxFormSectionWrapperComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
@@ -665,13 +666,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImpor
665
666
 
666
667
  class DbxFormFlexWrapperComponent extends FieldWrapper {
667
668
  get flexWrapper() {
668
- return this.props.flexWrapper;
669
+ return this.props;
669
670
  }
670
671
  get breakpoint() {
671
- return this.flexWrapper?.breakpoint;
672
+ return this.flexWrapper.breakpoint;
672
673
  }
673
674
  get relative() {
674
- return this.flexWrapper?.relative ?? false;
675
+ return this.flexWrapper.relative ?? false;
675
676
  }
676
677
  }
677
678
  DbxFormFlexWrapperComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: DbxFormFlexWrapperComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
@@ -693,10 +694,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImpor
693
694
 
694
695
  class DbxFormSubsectionWrapperComponent extends FieldWrapper {
695
696
  get header() {
696
- return this.props.subsectionWrapper?.header;
697
+ return this.props.header;
697
698
  }
698
699
  get hint() {
699
- return this.props.subsectionWrapper?.hint;
700
+ return this.props.hint;
700
701
  }
701
702
  }
702
703
  DbxFormSubsectionWrapperComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: DbxFormSubsectionWrapperComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
@@ -730,19 +731,19 @@ class AbstractFormExpandableSectionWrapperDirective extends FieldWrapper {
730
731
  else {
731
732
  return this.hasValue$;
732
733
  }
733
- }), shareReplay(1));
734
+ }), distinctUntilChanged(), shareReplay(1));
734
735
  this.hasValue$ = this.formControl$.pipe(switchMap((x) => x.valueChanges.pipe(startWith(x.value), map((value) => {
735
736
  return this.hasValueFn(value);
736
737
  }), shareReplay(1))));
737
738
  }
738
739
  get expandableSection() {
739
- return this.props.expandWrapper;
740
+ return this.props;
740
741
  }
741
742
  get hasValueFn() {
742
- return this.expandableSection?.hasValueFn ?? DEFAULT_HAS_VALUE_FN;
743
+ return this.expandableSection.hasValueFn ?? DEFAULT_HAS_VALUE_FN;
743
744
  }
744
745
  get expandLabel() {
745
- let label = this.expandableSection?.expandLabel ?? this.field?.props?.label;
746
+ let label = this.expandableSection.expandLabel ?? this.field.props?.label;
746
747
  if (label == null) {
747
748
  const firstFieldGroup = this.field.fieldGroup?.[0];
748
749
  if (firstFieldGroup) {
@@ -773,7 +774,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImpor
773
774
  */
774
775
  class DbxFormExpandWrapperComponent extends AbstractFormExpandableSectionWrapperDirective {
775
776
  get buttonType() {
776
- return this.expandableSection?.buttonType ?? 'button';
777
+ return this.expandableSection.buttonType ?? 'button';
777
778
  }
778
779
  }
779
780
  DbxFormExpandWrapperComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: DbxFormExpandWrapperComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
@@ -783,7 +784,7 @@ DbxFormExpandWrapperComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "1
783
784
  <ng-container #fieldComponent></ng-container>
784
785
  </ng-container>
785
786
  <ng-container *ngSwitchCase="false">
786
- <span class="dbx-form-expandable-section-button" (click)="open()">{{ expandLabel }}</span>
787
+ <span class="dbx-form-expand-wrapper-button" (click)="open()">{{ expandLabel }}</span>
787
788
  </ng-container>
788
789
  </ng-container>
789
790
  `, isInline: true, directives: [{ type: i5.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { type: i5.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }], pipes: { "async": i5.AsyncPipe } });
@@ -796,7 +797,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImpor
796
797
  <ng-container #fieldComponent></ng-container>
797
798
  </ng-container>
798
799
  <ng-container *ngSwitchCase="false">
799
- <span class="dbx-form-expandable-section-button" (click)="open()">{{ expandLabel }}</span>
800
+ <span class="dbx-form-expand-wrapper-button" (click)="open()">{{ expandLabel }}</span>
800
801
  </ng-container>
801
802
  </ng-container>
802
803
  `
@@ -1009,10 +1010,8 @@ function flexLayoutWrapper(fieldConfigs, { relative, breakpoint, size: defaultSi
1009
1010
  fieldGroupClassName: 'dbx-flex-group',
1010
1011
  // fieldGroupClassName: 'field-layout-group',
1011
1012
  props: {
1012
- flexWrapper: {
1013
- breakpoint,
1014
- relative
1015
- }
1013
+ breakpoint,
1014
+ relative
1016
1015
  },
1017
1016
  fieldGroup: fieldConfigs.map((inputConfig) => {
1018
1017
  const fieldConfig = checkIsFieldFlexLayoutGroupFieldConfig(inputConfig)
@@ -2797,7 +2796,7 @@ function repeatArrayField(config) {
2797
2796
  removeText
2798
2797
  }),
2799
2798
  fieldArray: {
2800
- fieldGroup: repeatFieldGroup
2799
+ fieldGroup: asArray(repeatFieldGroup)
2801
2800
  }
2802
2801
  });
2803
2802
  }
@@ -4079,23 +4078,39 @@ class DbxFormlyFormComponent extends AbstractSubscriptionDirective {
4079
4078
  changesSinceLastResetCount: 0,
4080
4079
  isFormValid: false,
4081
4080
  isFormDisabled: false
4082
- }), map(({ changesSinceLastResetCount, isFormValid, isFormDisabled }) => {
4083
- const isReset = changesSinceLastResetCount <= 1; // first emission after reset is the first value.
4084
- const complete = isFormValid;
4085
- const nextState = {
4086
- isComplete: complete,
4087
- state: isReset ? DbxFormState.RESET : DbxFormState.USED,
4088
- status: this.form.status,
4089
- untouched: this.form.untouched,
4090
- pristine: this.form.pristine,
4091
- changesCount: changesSinceLastResetCount,
4092
- lastResetAt,
4093
- disabled: this.disabled,
4094
- isDisabled: isFormDisabled
4081
+ }), switchMap(({ changesSinceLastResetCount, isFormValid, isFormDisabled }) => {
4082
+ const nextState = () => {
4083
+ const isReset = changesSinceLastResetCount <= 1; // first emission after reset is the first value.
4084
+ const complete = isFormValid;
4085
+ const nextState = {
4086
+ isComplete: complete,
4087
+ state: isReset ? DbxFormState.RESET : DbxFormState.USED,
4088
+ status: this.form.status,
4089
+ untouched: this.form.untouched,
4090
+ pristine: this.form.pristine,
4091
+ changesCount: changesSinceLastResetCount,
4092
+ lastResetAt,
4093
+ disabled: this.disabled,
4094
+ isDisabled: isFormDisabled
4095
+ };
4096
+ return nextState;
4095
4097
  };
4096
- // console.log('Change: ', nextState);
4097
- return nextState;
4098
- }))), shareReplay(1));
4098
+ const state = nextState();
4099
+ if (isFormValid && this.form.untouched) {
4100
+ return timer(150, 200).pipe(
4101
+ // every 200 ms check if the form is now marked touched, then push a new state
4102
+ filter(() => this.form.touched), map(() => nextState()),
4103
+ // only push the new state once
4104
+ first(),
4105
+ // send the first value immediately
4106
+ startWith(state));
4107
+ }
4108
+ else {
4109
+ return of(state);
4110
+ }
4111
+ })
4112
+ // tapLog('Change: ')
4113
+ )), shareReplay(1));
4099
4114
  }
4100
4115
  ngOnInit() {
4101
4116
  this.context.setDelegate(this);