@dereekb/dbx-form 9.23.10 → 9.23.11

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.
@@ -7,8 +7,8 @@ import { Injectable, SkipSelf, Directive, Injector, Optional, Component, Inject,
7
7
  import { FieldType } from '@ngx-formly/material';
8
8
  import { map, distinctUntilChanged, shareReplay, BehaviorSubject, switchMap, of, startWith, filter, throttleTime, first } from 'rxjs';
9
9
  import { filterMaybe, SubscriptionObject, asObservable } from '@dereekb/rxjs';
10
- import { DateScheduleDayCode, expandDateScheduleDayCodesToDayOfWeekSet, dateTimingRelativeIndexFactory, dateBlockDayOfWeekFactory, findMaxDate, findMinDate, isSameDate, isSameDateRange, isSameDateScheduleRange, isSameDateDay, copyDateScheduleDateFilterConfig, dateScheduleDateFilter, expandDateScheduleDayCodes, isDateInDateRangeFunction, isDateWithinDateBlockRangeFunction, dateScheduleEncodedWeek, dateBlockTimingDateFactory, enabledDaysFromDateScheduleDayCodes, dateScheduleDayCodesFromEnabledDays, formatToMonthDayString } from '@dereekb/date';
11
- import { setsAreEquivalent, range, iterableToArray, toggleInSet, addToSet, isIndexNumberInIndexRangeFunction, minAndMaxNumber, randomNumberFactory, getDaysOfWeekNames } from '@dereekb/util';
10
+ import { DateScheduleDayCode, expandDateScheduleDayCodesToDayOfWeekSet, dateTimingRelativeIndexFactory, dateBlockDayOfWeekFactory, findMaxDate, findMinDate, isSameDate, isSameDateRange, isSameDateScheduleRange, isSameDateDay, dateTimingRelativeIndexArrayFactory, copyDateScheduleDateFilterConfig, dateScheduleDateFilter, expandDateScheduleDayCodes, isDateInDateRangeFunction, isDateWithinDateBlockRangeFunction, dateScheduleEncodedWeek, dateBlockTimingDateFactory, enabledDaysFromDateScheduleDayCodes, dateScheduleDayCodesFromEnabledDays, formatToMonthDayString } from '@dereekb/date';
11
+ import { setsAreEquivalent, unique, mergeArrays, range, iterableToArray, toggleInSet, addToSet, isIndexNumberInIndexRangeFunction, minAndMaxNumber, randomNumberFactory, getDaysOfWeekNames } from '@dereekb/util';
12
12
  import { ComponentStore } from '@ngrx/component-store';
13
13
  import { startOfDay } from 'date-fns';
14
14
  import * as i1 from '@dereekb/dbx-web/calendar';
@@ -36,7 +36,7 @@ import { MatButtonToggleModule } from '@angular/material/button-toggle';
36
36
  import { FlexLayoutModule } from '@angular/flex-layout';
37
37
 
38
38
  function dateScheduleRangeField(config = {}) {
39
- const { key = 'schedule', filter, initialSelectionState, computeSelectionResultRelativeToFilter } = config;
39
+ const { key = 'schedule', filter, initialSelectionState, computeSelectionResultRelativeToFilter, exclusions } = config;
40
40
  const fieldConfig = {
41
41
  ...formlyField({
42
42
  key,
@@ -45,7 +45,8 @@ function dateScheduleRangeField(config = {}) {
45
45
  label: config.label ?? 'Schedule',
46
46
  filter,
47
47
  computeSelectionResultRelativeToFilter,
48
- initialSelectionState
48
+ initialSelectionState,
49
+ exclusions
49
50
  })
50
51
  })
51
52
  };
@@ -149,6 +150,7 @@ class DbxCalendarScheduleSelectionStore extends ComponentStore {
149
150
  this.isCustomized$ = this.state$.pipe(map((x) => x.selectedIndexes.size > 0), distinctUntilChanged(), shareReplay(1));
150
151
  // MARK: State Changes
151
152
  this.setFilter = this.updater((state, filter) => updateStateWithFilter(state, filter));
153
+ this.setExclusions = this.updater((state, exclusions) => updateStateWithExclusions(state, exclusions));
152
154
  this.setComputeSelectionResultRelativeToFilter = this.updater((state, computeSelectionResultRelativeToFilter) => updateStateWithComputeSelectionResultRelativeToFilter(state, computeSelectionResultRelativeToFilter));
153
155
  this.clearFilter = this.updater((state) => updateStateWithFilter(state, undefined));
154
156
  this.setTimezone = this.updater((state, timezone) => ({ ...state, timezone }));
@@ -184,12 +186,41 @@ function updateStateWithComputeSelectionResultRelativeToFilter(currentState, com
184
186
  }
185
187
  return state;
186
188
  }
189
+ function updateStateWithExclusions(state, inputExclusions) {
190
+ let computedExclusions;
191
+ if (inputExclusions) {
192
+ const { indexFactory } = state;
193
+ const indexArrayFactory = dateTimingRelativeIndexArrayFactory(indexFactory);
194
+ computedExclusions = indexArrayFactory(inputExclusions);
195
+ }
196
+ state = { ...state, inputExclusions, computedExclusions };
197
+ return updateStateWithFilter(state, state.filter);
198
+ }
187
199
  function updateStateWithFilter(state, inputFilter) {
200
+ const { computedExclusions: exclusions } = state;
188
201
  let isEnabledFilterDay = () => true;
189
202
  let filter = null;
190
- if (inputFilter) {
191
- filter = copyDateScheduleDateFilterConfig(inputFilter); // copy filter
192
- isEnabledFilterDay = dateScheduleDateFilter(filter);
203
+ if (inputFilter || exclusions?.length) {
204
+ let enabledFilter;
205
+ if (inputFilter) {
206
+ filter = copyDateScheduleDateFilterConfig(inputFilter); // copy filter
207
+ if (exclusions?.length) {
208
+ enabledFilter = {
209
+ ...filter,
210
+ ex: unique(mergeArrays([filter.ex, exclusions]))
211
+ };
212
+ }
213
+ else {
214
+ enabledFilter = filter;
215
+ }
216
+ }
217
+ else {
218
+ enabledFilter = {
219
+ w: '89',
220
+ ex: exclusions
221
+ };
222
+ }
223
+ isEnabledFilterDay = dateScheduleDateFilter(enabledFilter);
193
224
  }
194
225
  state = { ...state, filter, isEnabledFilterDay };
195
226
  // attempt to re-apply the initial selection state once filter is applied
@@ -889,6 +920,7 @@ class DbxFormCalendarDateScheduleRangeFieldComponent extends FieldType {
889
920
  this._syncSub = new SubscriptionObject();
890
921
  this._valueSub = new SubscriptionObject();
891
922
  this._filterSub = new SubscriptionObject();
923
+ this._exclusionsSub = new SubscriptionObject();
892
924
  this._formControlObs = new BehaviorSubject(undefined);
893
925
  this.formControl$ = this._formControlObs.pipe(filterMaybe());
894
926
  this.value$ = this.formControl$.pipe(switchMap((control) => control.valueChanges.pipe(startWith(control.value))), shareReplay(1));
@@ -914,6 +946,9 @@ class DbxFormCalendarDateScheduleRangeFieldComponent extends FieldType {
914
946
  get filter() {
915
947
  return this.props.filter;
916
948
  }
949
+ get exclusions() {
950
+ return this.props.exclusions;
951
+ }
917
952
  get initialSelectionState() {
918
953
  return this.props.initialSelectionState;
919
954
  }
@@ -928,23 +963,28 @@ class DbxFormCalendarDateScheduleRangeFieldComponent extends FieldType {
928
963
  this._valueSub.subscription = this.dbxCalendarScheduleSelectionStore.currentDateScheduleRangeValue$.subscribe((x) => {
929
964
  this.formControl.setValue(x);
930
965
  });
931
- const filter = this.filter;
966
+ const { filter, exclusions } = this;
932
967
  if (filter != null) {
933
968
  this._filterSub.subscription = this.dbxCalendarScheduleSelectionStore.setFilter(asObservable(filter));
934
969
  }
970
+ if (exclusions != null) {
971
+ this._exclusionsSub.subscription = this.dbxCalendarScheduleSelectionStore.setExclusions(asObservable(exclusions));
972
+ }
935
973
  if (this.initialSelectionState !== undefined) {
936
974
  this.dbxCalendarScheduleSelectionStore.setInitialSelectionState(this.initialSelectionState);
937
975
  }
938
976
  if (this.computeSelectionResultRelativeToFilter != null) {
939
977
  this.dbxCalendarScheduleSelectionStore.setComputeSelectionResultRelativeToFilter(this.computeSelectionResultRelativeToFilter);
940
978
  }
979
+ // TODO: Also add ability to set min/max dates independent of the filter
941
980
  }
942
981
  ngOnDestroy() {
943
982
  super.ngOnDestroy();
944
983
  this._syncSub.destroy();
945
984
  this._valueSub.destroy();
946
- this._formControlObs.complete();
947
985
  this._filterSub.destroy();
986
+ this._exclusionsSub.destroy();
987
+ this._formControlObs.complete();
948
988
  }
949
989
  }
950
990
  DbxFormCalendarDateScheduleRangeFieldComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: DbxFormCalendarDateScheduleRangeFieldComponent, deps: [{ token: i1$1.CompactContextStore, optional: true }, { token: DbxCalendarScheduleSelectionStore }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
@@ -1132,5 +1172,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImpo
1132
1172
  * Generated bundle index. Do not edit.
1133
1173
  */
1134
1174
 
1135
- export { CalendarScheduleSelectionDayState, DEFAULT_SCHEDULE_SELECTION_CALENDAR_DATE_POPOVER_KEY, DbxCalendarScheduleSelectionStore, DbxCalendarScheduleSelectionStoreInjectionBlockDirective, DbxCalendarScheduleSelectionStoreProviderBlock, DbxFormCalendarDateScheduleRangeFieldComponent, DbxFormCalendarModule, DbxFormDateScheduleRangeFieldModule, DbxScheduleSelectionCalendarCellComponent, DbxScheduleSelectionCalendarComponent, DbxScheduleSelectionCalendarDateDaysComponent, DbxScheduleSelectionCalendarDateDaysFormComponent, DbxScheduleSelectionCalendarDateDialogButtonComponent, DbxScheduleSelectionCalendarDateDialogComponent, DbxScheduleSelectionCalendarDatePopoverButtonComponent, DbxScheduleSelectionCalendarDatePopoverComponent, DbxScheduleSelectionCalendarDatePopoverContentComponent, DbxScheduleSelectionCalendarDateRangeComponent, calendarScheduleMaxDate, calendarScheduleMinAndMaxDate, calendarScheduleMinDate, computeCalendarScheduleSelectionDateBlockRange, computeCalendarScheduleSelectionRange, computeScheduleSelectionRangeAndExclusion, computeScheduleSelectionValue, dateScheduleRangeField, dbxScheduleSelectionCalendarDateDaysFormDayFields, dbxScheduleSelectionCalendarDateDaysFormFields, defaultCalendarScheduleSelectionCellContentFactory, finalizeNewCalendarScheduleSelectionState, initialCalendarScheduleSelectionState, isEnabledDayInCalendarScheduleSelectionState, noSelectionCalendarScheduleSelectionState, provideCalendarScheduleSelectionStoreIfParentIsUnavailable, updateStateWithChangedDates, updateStateWithChangedRange, updateStateWithChangedScheduleDays, updateStateWithComputeSelectionResultRelativeToFilter, updateStateWithDateScheduleRangeValue, updateStateWithFilter, updateStateWithInitialSelectionState };
1175
+ export { CalendarScheduleSelectionDayState, DEFAULT_SCHEDULE_SELECTION_CALENDAR_DATE_POPOVER_KEY, DbxCalendarScheduleSelectionStore, DbxCalendarScheduleSelectionStoreInjectionBlockDirective, DbxCalendarScheduleSelectionStoreProviderBlock, DbxFormCalendarDateScheduleRangeFieldComponent, DbxFormCalendarModule, DbxFormDateScheduleRangeFieldModule, DbxScheduleSelectionCalendarCellComponent, DbxScheduleSelectionCalendarComponent, DbxScheduleSelectionCalendarDateDaysComponent, DbxScheduleSelectionCalendarDateDaysFormComponent, DbxScheduleSelectionCalendarDateDialogButtonComponent, DbxScheduleSelectionCalendarDateDialogComponent, DbxScheduleSelectionCalendarDatePopoverButtonComponent, DbxScheduleSelectionCalendarDatePopoverComponent, DbxScheduleSelectionCalendarDatePopoverContentComponent, DbxScheduleSelectionCalendarDateRangeComponent, calendarScheduleMaxDate, calendarScheduleMinAndMaxDate, calendarScheduleMinDate, computeCalendarScheduleSelectionDateBlockRange, computeCalendarScheduleSelectionRange, computeScheduleSelectionRangeAndExclusion, computeScheduleSelectionValue, dateScheduleRangeField, dbxScheduleSelectionCalendarDateDaysFormDayFields, dbxScheduleSelectionCalendarDateDaysFormFields, defaultCalendarScheduleSelectionCellContentFactory, finalizeNewCalendarScheduleSelectionState, initialCalendarScheduleSelectionState, isEnabledDayInCalendarScheduleSelectionState, noSelectionCalendarScheduleSelectionState, provideCalendarScheduleSelectionStoreIfParentIsUnavailable, updateStateWithChangedDates, updateStateWithChangedRange, updateStateWithChangedScheduleDays, updateStateWithComputeSelectionResultRelativeToFilter, updateStateWithDateScheduleRangeValue, updateStateWithExclusions, updateStateWithFilter, updateStateWithInitialSelectionState };
1136
1176
  //# sourceMappingURL=dereekb-dbx-form-calendar.mjs.map