@dereekb/dbx-form 9.24.4 → 9.24.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.
- package/calendar/lib/calendar.schedule.selection.store.d.ts +14 -5
- package/esm2020/calendar/lib/calendar.schedule.selection.dialog.component.mjs +3 -3
- package/esm2020/calendar/lib/calendar.schedule.selection.store.mjs +68 -32
- package/fesm2015/dereekb-dbx-form-calendar.mjs +69 -33
- package/fesm2015/dereekb-dbx-form-calendar.mjs.map +1 -1
- package/fesm2020/dereekb-dbx-form-calendar.mjs +69 -33
- package/fesm2020/dereekb-dbx-form-calendar.mjs.map +1 -1
- package/mapbox/package.json +4 -4
- package/package.json +4 -4
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as i4$1 from '@dereekb/dbx-form';
|
|
2
2
|
import { formlyField, propsAndConfigForFieldConfig, flexLayoutWrapper, toggleField, AbstractSyncFormlyFormDirective, provideFormlyContext, DbxFormModule, DbxFormlyModule } from '@dereekb/dbx-form';
|
|
3
3
|
import * as i1$1 from '@dereekb/dbx-web';
|
|
4
|
-
import { AbstractPopoverDirective, AbstractDialogDirective, DbxActionModule, DbxButtonModule, DbxDialogInteractionModule, DbxPopoverInteractionModule, DbxTextModule } from '@dereekb/dbx-web';
|
|
4
|
+
import { AbstractPopoverDirective, AbstractDialogDirective, sanitizeDbxDialogContentConfig, DbxActionModule, DbxButtonModule, DbxDialogInteractionModule, DbxPopoverInteractionModule, DbxTextModule } from '@dereekb/dbx-web';
|
|
5
5
|
import * as i0 from '@angular/core';
|
|
6
6
|
import { Injectable, SkipSelf, Directive, Injector, Optional, Component, Inject, Input, ElementRef, ViewChild, ChangeDetectionStrategy, EventEmitter, Output, InjectionToken, NgModule } from '@angular/core';
|
|
7
7
|
import { FieldType } from '@ngx-formly/material';
|
|
8
8
|
import { switchMap, first, tap, map, distinctUntilChanged, shareReplay, combineLatestWith, BehaviorSubject, of, startWith, filter, throttleTime, combineLatest } from 'rxjs';
|
|
9
|
-
import { filterMaybe, SubscriptionObject, asObservable } from '@dereekb/rxjs';
|
|
9
|
+
import { filterMaybe, distinctUntilHasDifferentValues, SubscriptionObject, asObservable } from '@dereekb/rxjs';
|
|
10
10
|
import { DateScheduleDayCode, expandDateScheduleDayCodesToDayOfWeekSet, dateTimingRelativeIndexFactory, dateBlockDayOfWeekFactory, findMaxDate, findMinDate, isSameDateRange, isSameDateDay, isSameDate, expandDateScheduleRange, isSameDateScheduleRange, dateTimingRelativeIndexArrayFactory, isInfiniteDateRange, copyDateScheduleDateFilterConfig, dateScheduleDateFilter, dateTimezoneUtcNormal, expandDateScheduleDayCodes, isDateInDateRangeFunction, isDateWithinDateBlockRangeFunction, copyHoursAndMinutesFromDate, dateScheduleEncodedWeek, dateBlockTimingDateFactory, enabledDaysFromDateScheduleDayCodes, dateScheduleDayCodesFromEnabledDays, formatToMonthDayString } from '@dereekb/date';
|
|
11
|
-
import { setsAreEquivalent, unique, mergeArrays, iterableToArray, toggleInSet, addToSet, isIndexNumberInIndexRangeFunction,
|
|
11
|
+
import { setsAreEquivalent, unique, mergeArrays, iterableToArray, range, toggleInSet, removeFromSet, addToSet, isIndexNumberInIndexRangeFunction, minAndMaxNumber, getDaysOfWeekNames, mergeObjects, KeyValueTypleValueFilter } from '@dereekb/util';
|
|
12
12
|
import { ComponentStore } from '@ngrx/component-store';
|
|
13
13
|
import { startOfDay, endOfDay, isBefore } from 'date-fns';
|
|
14
14
|
import * as i1 from '@dereekb/dbx-web/calendar';
|
|
@@ -100,7 +100,7 @@ function initialCalendarScheduleSelectionState() {
|
|
|
100
100
|
return {
|
|
101
101
|
start,
|
|
102
102
|
indexFactory,
|
|
103
|
-
|
|
103
|
+
toggledIndexes: new Set(),
|
|
104
104
|
scheduleDays,
|
|
105
105
|
allowedDaysOfWeek,
|
|
106
106
|
indexDayOfWeek,
|
|
@@ -154,7 +154,7 @@ class DbxCalendarScheduleSelectionStore extends ComponentStore {
|
|
|
154
154
|
/**
|
|
155
155
|
* @deprecated This is not the same as the current selection value. This is the set of manually togged off dates. It will be removed in a future update.
|
|
156
156
|
*/
|
|
157
|
-
this.selectedDates$ = this.state$.pipe(map((x) => x.
|
|
157
|
+
this.selectedDates$ = this.state$.pipe(map((x) => x.toggledIndexes), distinctUntilChanged(), shareReplay(1));
|
|
158
158
|
this.isEnabledFilterDayFunction$ = this.state$.pipe(map((x) => x.isEnabledFilterDay), shareReplay(1));
|
|
159
159
|
this.isEnabledDayFunction$ = this.state$.pipe(map((x) => x.isEnabledDay), shareReplay(1));
|
|
160
160
|
this.currentDateRange$ = this.state$.pipe(map(computeCalendarScheduleSelectionRange), distinctUntilChanged((a, b) => isSameDateRange(a, b)), shareReplay(1));
|
|
@@ -168,6 +168,9 @@ class DbxCalendarScheduleSelectionStore extends ComponentStore {
|
|
|
168
168
|
this.effectiveTimezone$ = this.state$.pipe(map((x) => (!calendarScheduleStartBeingUsedFromFilter(x) && x.timezone ? x.timezone : undefined)), distinctUntilChanged(), shareReplay(1));
|
|
169
169
|
this.effectiveTimezoneNormal$ = this.state$.pipe(map((x) => (!calendarScheduleStartBeingUsedFromFilter(x) && x.timezoneNormal ? x.timezoneNormal : undefined)), distinctUntilChanged(), shareReplay(1));
|
|
170
170
|
this.currentSelectionValue$ = this.state$.pipe(map((x) => x.currentSelectionValue), shareReplay(1));
|
|
171
|
+
this.currentSelectionValueDateBlockDurationSpan$ = this.currentSelectionValue$.pipe(map((x) => (x ? expandDateScheduleRange(x) : [])), shareReplay(1));
|
|
172
|
+
this.selectionValueSelectedIndexes$ = this.currentSelectionValueDateBlockDurationSpan$.pipe(map((x) => new Set(x.map((y) => y.i))), distinctUntilHasDifferentValues(), shareReplay(1));
|
|
173
|
+
this.selectionValue$ = this.currentSelectionValue$.pipe(filterMaybe(), shareReplay(1));
|
|
171
174
|
this.currentSelectionValueWithTimezone$ = this.currentSelectionValue$.pipe(combineLatestWith(this.effectiveTimezoneNormal$), map(([x, timezoneNormal]) => {
|
|
172
175
|
if (x && timezoneNormal) {
|
|
173
176
|
x = {
|
|
@@ -180,6 +183,8 @@ class DbxCalendarScheduleSelectionStore extends ComponentStore {
|
|
|
180
183
|
}
|
|
181
184
|
return x;
|
|
182
185
|
}), distinctUntilChanged(), shareReplay(1));
|
|
186
|
+
this.selectionValueWithTimezone$ = this.currentSelectionValueWithTimezone$.pipe(filterMaybe(), shareReplay(1));
|
|
187
|
+
this.selectionValueWithTimezoneDateBlockDurationSpan$ = this.selectionValueWithTimezone$.pipe(map((x) => expandDateScheduleRange(x)), shareReplay(1));
|
|
183
188
|
this.nextToggleSelection$ = this.hasConfiguredMinMaxRange$.pipe(switchMap((hasConfiguredMinMaxRange) => {
|
|
184
189
|
let obs;
|
|
185
190
|
if (hasConfiguredMinMaxRange) {
|
|
@@ -190,13 +195,10 @@ class DbxCalendarScheduleSelectionStore extends ComponentStore {
|
|
|
190
195
|
}
|
|
191
196
|
return obs;
|
|
192
197
|
}), shareReplay(1));
|
|
193
|
-
this.selectionValue$ = this.currentSelectionValueWithTimezone$.pipe(filterMaybe(), shareReplay(1));
|
|
194
|
-
this.selectionValueDateBlockDurationSpan$ = this.selectionValue$.pipe(map((x) => expandDateScheduleRange(x)), shareReplay(1));
|
|
195
|
-
this.selectionValueSelectedIndexes$ = this.selectionValueDateBlockDurationSpan$.pipe(map((x) => new Set(x.map((y) => y.i))), shareReplay(1));
|
|
196
198
|
this.currentDateScheduleRangeValue$ = this.currentSelectionValueWithTimezone$.pipe(map((x) => x?.dateScheduleRange), distinctUntilChanged(isSameDateScheduleRange), shareReplay(1));
|
|
197
199
|
this.dateScheduleRangeValue$ = this.currentDateScheduleRangeValue$.pipe(filterMaybe(), shareReplay(1));
|
|
198
200
|
this.cellContentFactory$ = this.state$.pipe(map((x) => x.cellContentFactory), distinctUntilChanged(), shareReplay(1));
|
|
199
|
-
this.isCustomized$ = this.state$.pipe(map((x) => x.
|
|
201
|
+
this.isCustomized$ = this.state$.pipe(map((x) => x.toggledIndexes.size > 0), distinctUntilChanged(), shareReplay(1));
|
|
200
202
|
// MARK: State Changes
|
|
201
203
|
this.setMinMaxDateRange = this.updater(updateStateWithMinMaxDateRange);
|
|
202
204
|
this.setFilter = this.updater(updateStateWithFilter);
|
|
@@ -205,10 +207,13 @@ class DbxCalendarScheduleSelectionStore extends ComponentStore {
|
|
|
205
207
|
this.clearFilter = this.updater((state) => updateStateWithFilter(state, undefined));
|
|
206
208
|
this.setTimezone = this.updater(updateStateWithTimezoneValue);
|
|
207
209
|
this.setInputRange = this.updater(updateStateWithChangedRange);
|
|
210
|
+
// NOTE: Selected dates are NOT selected indexes. They are the internal selected dates that are excluded from the selection.
|
|
208
211
|
this.toggleSelectedDates = this.updater((state, toggle) => updateStateWithChangedDates(state, { toggle }));
|
|
209
212
|
this.addSelectedDates = this.updater((state, add) => updateStateWithChangedDates(state, { add }));
|
|
210
213
|
this.removeSelectedDates = this.updater((state, remove) => updateStateWithChangedDates(state, { remove }));
|
|
211
214
|
this.setSelectedDates = this.updater((state, set) => updateStateWithChangedDates(state, { set }));
|
|
215
|
+
// NOTE: Selected indexes are the typical/expected indexes that are selected or not.
|
|
216
|
+
this.setSelectedIndexes = this.updater((state, set) => updateStateWithChangedDates(state, { set, invertSetBehavior: true }));
|
|
212
217
|
this.selectAllDates = this.updater((state, selectAll = 'all') => updateStateWithChangedDates(state, { selectAll }));
|
|
213
218
|
this.setInitialSelectionState = this.updater(updateStateWithInitialSelectionState);
|
|
214
219
|
this.setScheduleDays = this.updater(updateStateWithChangedScheduleDays);
|
|
@@ -223,8 +228,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImpo
|
|
|
223
228
|
type: Injectable
|
|
224
229
|
}], ctorParameters: function () { return []; } });
|
|
225
230
|
function updateStateWithInitialSelectionState(state, initialSelectionState) {
|
|
226
|
-
const {
|
|
227
|
-
if (
|
|
231
|
+
const { toggledIndexes } = state;
|
|
232
|
+
if (toggledIndexes.size === 0 && initialSelectionState === 'all') {
|
|
228
233
|
state = updateStateWithChangedDates(state, { selectAll: initialSelectionState });
|
|
229
234
|
}
|
|
230
235
|
return { ...state, initialSelectionState };
|
|
@@ -354,7 +359,7 @@ function updateStateWithDateScheduleRangeValue(state, change) {
|
|
|
354
359
|
}
|
|
355
360
|
else {
|
|
356
361
|
if (change != null) {
|
|
357
|
-
const nextState = { ...state, inputStart: change.start, inputEnd: change.end,
|
|
362
|
+
const nextState = { ...state, inputStart: change.start, inputEnd: change.end, toggledIndexes: new Set(change.ex) };
|
|
358
363
|
return updateStateWithChangedScheduleDays(finalizeNewCalendarScheduleSelectionState(nextState), expandDateScheduleDayCodes(change.w || '89'));
|
|
359
364
|
}
|
|
360
365
|
else {
|
|
@@ -375,12 +380,20 @@ function updateStateWithChangedScheduleDays(state, change) {
|
|
|
375
380
|
}
|
|
376
381
|
}
|
|
377
382
|
function updateStateWithChangedDates(state, change) {
|
|
378
|
-
const { indexFactory, allowedDaysOfWeek, indexDayOfWeek, inputStart: currentInputStart, inputEnd: currentInputEnd, minMaxDateRange } = state;
|
|
383
|
+
const { indexFactory, allowedDaysOfWeek, indexDayOfWeek, inputStart: currentInputStart, inputEnd: currentInputEnd, minMaxDateRange, filter } = state;
|
|
379
384
|
const { start: minDate, end: maxDate } = calendarScheduleMinAndMaxDateRange(state);
|
|
380
385
|
let inputStart = currentInputStart;
|
|
381
386
|
let inputEnd = currentInputEnd;
|
|
382
|
-
|
|
383
|
-
|
|
387
|
+
/**
|
|
388
|
+
* This is a set of indexes that are internally "selected" so that they are excluded from the inputStart/inputEnd date range.
|
|
389
|
+
*
|
|
390
|
+
* Do not confuse this with the actual indexes that are selected.
|
|
391
|
+
*/
|
|
392
|
+
let toggledIndexes;
|
|
393
|
+
function asIndexes(indexes) {
|
|
394
|
+
return iterableToArray(indexes).map(indexFactory);
|
|
395
|
+
}
|
|
396
|
+
if (change.reset || change.selectAll != null || change.set != null) {
|
|
384
397
|
let set = change.set ?? [];
|
|
385
398
|
const selectAll = change.reset === true ? state.initialSelectionState : change.selectAll;
|
|
386
399
|
switch (selectAll) {
|
|
@@ -397,29 +410,52 @@ function updateStateWithChangedDates(state, change) {
|
|
|
397
410
|
set = [];
|
|
398
411
|
break;
|
|
399
412
|
}
|
|
400
|
-
|
|
413
|
+
toggledIndexes = new Set(asIndexes(set));
|
|
414
|
+
if (change.invertSetBehavior && minDate && maxDate && !selectAll) {
|
|
415
|
+
const minIndex = indexFactory(minDate);
|
|
416
|
+
const maxIndex = indexFactory(maxDate);
|
|
417
|
+
inputStart = minDate;
|
|
418
|
+
inputEnd = maxDate;
|
|
419
|
+
toggledIndexes = new Set(range(minIndex, maxIndex + 1).filter((x) => !toggledIndexes.has(x)));
|
|
420
|
+
}
|
|
401
421
|
}
|
|
402
422
|
else {
|
|
403
|
-
|
|
423
|
+
toggledIndexes = new Set(state.toggledIndexes);
|
|
404
424
|
if (change.toggle) {
|
|
405
|
-
const allowedToToggle =
|
|
406
|
-
|
|
407
|
-
.filter((i) => allowedDaysOfWeek.has(indexDayOfWeek(i)));
|
|
408
|
-
toggleInSet(selectedIndexes, allowedToToggle);
|
|
425
|
+
const allowedToToggle = asIndexes(change.toggle).filter((i) => allowedDaysOfWeek.has(indexDayOfWeek(i)));
|
|
426
|
+
toggleInSet(toggledIndexes, allowedToToggle);
|
|
409
427
|
}
|
|
428
|
+
let addToExclusion;
|
|
429
|
+
let removeFromExclusion;
|
|
410
430
|
if (change.add) {
|
|
411
|
-
|
|
431
|
+
if (change.invertSetBehavior) {
|
|
432
|
+
addToExclusion = change.add;
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
removeFromExclusion = change.add;
|
|
436
|
+
}
|
|
412
437
|
}
|
|
413
438
|
if (change.remove) {
|
|
414
|
-
|
|
439
|
+
if (change.invertSetBehavior) {
|
|
440
|
+
removeFromExclusion = change.remove;
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
addToExclusion = change.remove;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (addToExclusion) {
|
|
447
|
+
removeFromSet(toggledIndexes, asIndexes(addToExclusion));
|
|
448
|
+
}
|
|
449
|
+
if (removeFromExclusion) {
|
|
450
|
+
addToSet(toggledIndexes, asIndexes(removeFromExclusion));
|
|
415
451
|
}
|
|
416
452
|
}
|
|
417
|
-
const nextState = { ...state, inputStart, inputEnd,
|
|
453
|
+
const nextState = { ...state, inputStart, inputEnd, toggledIndexes };
|
|
418
454
|
nextState.isEnabledDay = isEnabledDayInCalendarScheduleSelectionState(nextState);
|
|
419
455
|
// Recalculate the range and simplified to exclusions
|
|
420
456
|
const rangeAndExclusion = computeScheduleSelectionRangeAndExclusion(nextState);
|
|
421
457
|
if (rangeAndExclusion) {
|
|
422
|
-
return finalizeNewCalendarScheduleSelectionState({ ...nextState,
|
|
458
|
+
return finalizeNewCalendarScheduleSelectionState({ ...nextState, toggledIndexes: new Set(rangeAndExclusion.excluded), inputStart: rangeAndExclusion.start, inputEnd: rangeAndExclusion.end });
|
|
423
459
|
}
|
|
424
460
|
else {
|
|
425
461
|
// no selected days
|
|
@@ -427,7 +463,7 @@ function updateStateWithChangedDates(state, change) {
|
|
|
427
463
|
}
|
|
428
464
|
}
|
|
429
465
|
function noSelectionCalendarScheduleSelectionState(state) {
|
|
430
|
-
return finalizeNewCalendarScheduleSelectionState({ ...state,
|
|
466
|
+
return finalizeNewCalendarScheduleSelectionState({ ...state, toggledIndexes: new Set(), inputStart: null, inputEnd: null });
|
|
431
467
|
}
|
|
432
468
|
function updateStateWithChangedRange(state, change) {
|
|
433
469
|
const { inputStart: currentInputStart, inputEnd: currentInputEnd, indexFactory, minMaxDateRange } = state;
|
|
@@ -441,11 +477,11 @@ function updateStateWithChangedRange(state, change) {
|
|
|
441
477
|
// retain all indexes that are within the new range
|
|
442
478
|
const minIndex = indexFactory(inputStart);
|
|
443
479
|
const maxIndex = indexFactory(inputEnd) + 1;
|
|
444
|
-
const currentIndexes = Array.from(state.
|
|
480
|
+
const currentIndexes = Array.from(state.toggledIndexes);
|
|
445
481
|
const isInCurrentRange = isIndexNumberInIndexRangeFunction({ minIndex, maxIndex });
|
|
446
482
|
const excludedIndexesInNewRange = currentIndexes.filter(isInCurrentRange);
|
|
447
|
-
const
|
|
448
|
-
const nextState = { ...state,
|
|
483
|
+
const toggledIndexes = new Set(excludedIndexesInNewRange);
|
|
484
|
+
const nextState = { ...state, toggledIndexes, inputStart, inputEnd };
|
|
449
485
|
return finalizeNewCalendarScheduleSelectionState(nextState);
|
|
450
486
|
}
|
|
451
487
|
function finalizeNewCalendarScheduleSelectionState(nextState) {
|
|
@@ -466,7 +502,7 @@ function isEnabledDayInCalendarScheduleSelectionState(state) {
|
|
|
466
502
|
const index = indexFactory(input);
|
|
467
503
|
const dayOfWeek = indexDayOfWeek(index);
|
|
468
504
|
const isInSelectedRange = isInStartAndEndRange(input);
|
|
469
|
-
const isSelected = state.
|
|
505
|
+
const isSelected = state.toggledIndexes.has(index);
|
|
470
506
|
const isAllowedDayOfWeek = allowedDaysOfWeek.has(dayOfWeek);
|
|
471
507
|
const result = isAllowedDayOfWeek && ((isInSelectedRange && !isSelected) || (isSelected && !isInSelectedRange));
|
|
472
508
|
return result;
|
|
@@ -548,8 +584,8 @@ function computeCalendarScheduleSelectionRange(state) {
|
|
|
548
584
|
}
|
|
549
585
|
function computeCalendarScheduleSelectionDateBlockRange(state) {
|
|
550
586
|
const { indexFactory, inputStart, inputEnd, allowedDaysOfWeek, indexDayOfWeek, isEnabledDay, isEnabledFilterDay } = state;
|
|
551
|
-
const
|
|
552
|
-
const minAndMaxSelectedValues = minAndMaxNumber(
|
|
587
|
+
const enabledExclusionIndexes = Array.from(state.toggledIndexes).filter((i) => allowedDaysOfWeek.has(indexDayOfWeek(i)));
|
|
588
|
+
const minAndMaxSelectedValues = minAndMaxNumber(enabledExclusionIndexes);
|
|
553
589
|
let startRange;
|
|
554
590
|
let endRange;
|
|
555
591
|
if (minAndMaxSelectedValues) {
|
|
@@ -1134,7 +1170,7 @@ class DbxScheduleSelectionCalendarDateDialogComponent extends AbstractDialogDire
|
|
|
1134
1170
|
width: '80vw',
|
|
1135
1171
|
minHeight: 400,
|
|
1136
1172
|
minWidth: 360,
|
|
1137
|
-
...contentConfig.dialogConfig,
|
|
1173
|
+
...sanitizeDbxDialogContentConfig(contentConfig.dialogConfig),
|
|
1138
1174
|
injector,
|
|
1139
1175
|
data: {
|
|
1140
1176
|
config,
|