@dereekb/dbx-form 9.25.3 → 9.25.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/esm2020/calendar/lib/calendar.schedule.selection.store.mjs +57 -11
- package/fesm2015/dereekb-dbx-form-calendar.mjs +56 -11
- package/fesm2015/dereekb-dbx-form-calendar.mjs.map +1 -1
- package/fesm2020/dereekb-dbx-form-calendar.mjs +56 -10
- package/fesm2020/dereekb-dbx-form-calendar.mjs.map +1 -1
- package/mapbox/package.json +4 -4
- package/package.json +4 -4
|
@@ -5,7 +5,7 @@ import { Injectable, SkipSelf, Directive, Injector, Optional, Component, Inject,
|
|
|
5
5
|
import { FieldType } from '@ngx-formly/material';
|
|
6
6
|
import { switchMap, first, tap, map, distinctUntilChanged, shareReplay, of, combineLatestWith, BehaviorSubject, filter, combineLatest, EMPTY, startWith, throttleTime } from 'rxjs';
|
|
7
7
|
import { filterMaybe, distinctUntilHasDifferentValues, SubscriptionObject, asObservableFromGetter, asObservable } from '@dereekb/rxjs';
|
|
8
|
-
import { DateCellScheduleDayCode, expandDateCellScheduleDayCodesToDayOfWeekSet, dateCellTimingStartsAtForStartOfDay, dateCellTimingRelativeIndexFactory, dateCellDayOfWeekFactory, findMaxDate, findMinDate, isSameDateRange, isSameDateDay, isSameDate, dateCellTimingDateFactory, expandDateCellScheduleRange, formatToISO8601DayString, changeDateCellScheduleDateRangeToTimezone, isSameDateCellScheduleDateRange, dateCellTimingRelativeIndexArrayFactory, isInfiniteDateRange, copyDateCellScheduleDateFilterConfig, dateTimezoneUtcNormal, dateCellScheduleDateFilter, fullDateCellScheduleRange, dateCellTimingTimezoneNormalInstance, expandDateCellScheduleDayCodes, fullWeekDateCellScheduleDayCodes, dateCellScheduleDayCodesAreSetsEquivalent, simplifyDateCellScheduleDayCodes, isDateInDateRangeFunction, isDateWithinDateCellRangeFunction, dateCellScheduleEncodedWeek, dateCellTimingStartDateFactory, enabledDaysFromDateCellScheduleDayCodes, dateCellScheduleDayCodesFromEnabledDays, formatToMonthDayString, dateRange, DateRangeType } from '@dereekb/date';
|
|
8
|
+
import { DateCellScheduleDayCode, expandDateCellScheduleDayCodesToDayOfWeekSet, dateCellTimingStartsAtForStartOfDay, dateCellTimingRelativeIndexFactory, dateCellDayOfWeekFactory, findMaxDate, findMinDate, isSameDateRange, isSameDateDay, isSameDate, dateCellTimingDateFactory, expandDateCellScheduleRange, formatToISO8601DayString, changeDateCellScheduleDateRangeToTimezone, isSameDateCellScheduleDateRange, dateCellTimingRelativeIndexArrayFactory, isInfiniteDateRange, copyDateCellScheduleDateFilterConfig, SYSTEM_DATE_TIMEZONE_UTC_NORMAL_INSTANCE, dateTimezoneUtcNormal, dateCellScheduleDateFilter, fullDateCellScheduleRange, dateCellTimingTimezoneNormalInstance, expandDateCellScheduleDayCodes, fullWeekDateCellScheduleDayCodes, dateCellScheduleDayCodesAreSetsEquivalent, simplifyDateCellScheduleDayCodes, isDateInDateRangeFunction, isDateWithinDateCellRangeFunction, dateCellScheduleEncodedWeek, dateCellTimingStartDateFactory, enabledDaysFromDateCellScheduleDayCodes, dateCellScheduleDayCodesFromEnabledDays, formatToMonthDayString, dateRange, DateRangeType } from '@dereekb/date';
|
|
9
9
|
import { isInAllowedDaysOfWeekSet, mapValuesToSet, unique, mergeArrays, iterableToArray, range, toggleInSet, removeFromSet, addToSet, isIndexNumberInIndexRangeFunction, minAndMaxNumber, getDaysOfWeekNames, reduceBooleansWithAnd, mergeObjects, KeyValueTypleValueFilter } from '@dereekb/util';
|
|
10
10
|
import { ComponentStore } from '@ngrx/component-store';
|
|
11
11
|
import { startOfDay, endOfDay, isBefore, endOfWeek } from 'date-fns';
|
|
@@ -322,7 +322,6 @@ function updateStateWithMinMaxDateRange(state, minMaxDateRange) {
|
|
|
322
322
|
return updateStateWithFilter(state, state.filter);
|
|
323
323
|
}
|
|
324
324
|
function updateStateWithFilter(state, inputFilter) {
|
|
325
|
-
var _a, _b;
|
|
326
325
|
const { computedExclusions: exclusions, minMaxDateRange, systemTimezone } = state;
|
|
327
326
|
let isEnabledFilterDay = () => true;
|
|
328
327
|
let filter = null;
|
|
@@ -332,21 +331,34 @@ function updateStateWithFilter(state, inputFilter) {
|
|
|
332
331
|
let filterStart = null; // the start date that will be used/set on the filter.
|
|
333
332
|
if (inputFilter) {
|
|
334
333
|
filter = copyDateCellScheduleDateFilterConfig(inputFilter); // copy filter
|
|
334
|
+
let nextFilterTimezone; // only set if inputFilter.start or inputFilter.startsAt
|
|
335
335
|
// configure filter start
|
|
336
336
|
if (inputFilter.start) {
|
|
337
337
|
filterStart = inputFilter.start;
|
|
338
|
+
// if no timezone is specified, then use the system timezone and align filterStart to the start of the day.
|
|
339
|
+
if (!inputFilter.timezone) {
|
|
340
|
+
filterStart = SYSTEM_DATE_TIMEZONE_UTC_NORMAL_INSTANCE.startOfDayInTargetTimezone(inputFilter.startsAt);
|
|
341
|
+
nextFilterTimezone = systemTimezone;
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
nextFilterTimezone = inputFilter.timezone;
|
|
345
|
+
}
|
|
338
346
|
}
|
|
339
347
|
else if (inputFilter.startsAt) {
|
|
340
348
|
if (inputFilter.timezone) {
|
|
349
|
+
// if no timezone is provided, use startsAt as-is
|
|
341
350
|
const timezoneNormal = dateTimezoneUtcNormal(inputFilter.timezone);
|
|
342
351
|
filterStart = timezoneNormal.startOfDayInTargetTimezone(inputFilter.startsAt);
|
|
352
|
+
nextFilterTimezone = inputFilter.timezone;
|
|
343
353
|
}
|
|
344
354
|
else {
|
|
345
|
-
|
|
346
|
-
|
|
355
|
+
// set to the start of today in the system timezone.
|
|
356
|
+
filterStart = SYSTEM_DATE_TIMEZONE_UTC_NORMAL_INSTANCE.startOfDayInTargetTimezone(inputFilter.startsAt);
|
|
357
|
+
nextFilterTimezone = systemTimezone;
|
|
347
358
|
}
|
|
348
359
|
}
|
|
349
360
|
filter.start = filterStart !== null && filterStart !== void 0 ? filterStart : undefined;
|
|
361
|
+
filter.timezone = nextFilterTimezone;
|
|
350
362
|
// configure exclusions
|
|
351
363
|
if (exclusions === null || exclusions === void 0 ? void 0 : exclusions.length) {
|
|
352
364
|
enabledFilter = Object.assign(Object.assign({}, filter), { ex: unique(mergeArrays([filter.ex, exclusions])) });
|
|
@@ -369,17 +381,46 @@ function updateStateWithFilter(state, inputFilter) {
|
|
|
369
381
|
* If the input filter has a start date, use that as the relative start to ensure indexes are compared the same,
|
|
370
382
|
* otherwise use the state's start. This is important for the index calculations.
|
|
371
383
|
*/
|
|
372
|
-
|
|
384
|
+
let finalEnabledStart;
|
|
385
|
+
let finalEnabledTimezone;
|
|
386
|
+
// filter?.start ?? state.start;
|
|
387
|
+
if (!enabledFilter.start) {
|
|
388
|
+
// use the current state's start, but make sure it is in the proper timezone.
|
|
389
|
+
if (enabledFilter.timezone) {
|
|
390
|
+
const timezoneNormal = dateTimezoneUtcNormal(enabledFilter.timezone);
|
|
391
|
+
finalEnabledStart = timezoneNormal.startOfDayInTargetTimezone(state.start); // get the start of the day for the current start
|
|
392
|
+
finalEnabledTimezone = enabledFilter.timezone;
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
finalEnabledStart = state.start;
|
|
396
|
+
finalEnabledTimezone = systemTimezone;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
else if (!enabledFilter.timezone) {
|
|
400
|
+
finalEnabledTimezone = systemTimezone;
|
|
401
|
+
const timezoneNormal = dateTimezoneUtcNormal(finalEnabledTimezone);
|
|
402
|
+
finalEnabledStart = timezoneNormal.startOfDayInTargetTimezone(enabledFilter.start); // get the start of the day for the target timezone
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
finalEnabledStart = enabledFilter.start;
|
|
406
|
+
finalEnabledTimezone = enabledFilter.timezone;
|
|
407
|
+
}
|
|
408
|
+
enabledFilter.start = finalEnabledStart;
|
|
409
|
+
enabledFilter.timezone = finalEnabledTimezone;
|
|
373
410
|
// create the filter
|
|
374
411
|
isEnabledFilterDay = dateCellScheduleDateFilter(enabledFilter);
|
|
375
412
|
}
|
|
376
413
|
state = Object.assign(Object.assign({}, state), { filter, isEnabledFilterDay });
|
|
377
414
|
// For the same reason as above, use the filter's start date as the relative start if applicable.
|
|
378
415
|
if (filter && filter.start) {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
416
|
+
let startForSystemTimezone = filter.start;
|
|
417
|
+
if (filter.timezone) {
|
|
418
|
+
const timezoneNormal = dateTimezoneUtcNormal(filter.timezone);
|
|
419
|
+
startForSystemTimezone = timezoneNormal.systemDateToTargetDate(filter.start); // get the start of the day for the system timezone
|
|
420
|
+
}
|
|
421
|
+
state.start = startForSystemTimezone;
|
|
422
|
+
state.indexFactory = dateCellTimingRelativeIndexFactory({ startsAt: startForSystemTimezone, timezone: systemTimezone });
|
|
423
|
+
state.indexDayOfWeek = dateCellDayOfWeekFactory(startForSystemTimezone);
|
|
383
424
|
}
|
|
384
425
|
// attempt to re-apply the initial selection state once filter is applied
|
|
385
426
|
if (state.initialSelectionState) {
|
|
@@ -625,7 +666,7 @@ function isEnabledDayInCalendarScheduleSelectionState(state) {
|
|
|
625
666
|
};
|
|
626
667
|
}
|
|
627
668
|
function computeScheduleSelectionValue(state) {
|
|
628
|
-
const { indexFactory, allowedDaysOfWeek, effectiveScheduleDays, indexDayOfWeek, computeSelectionResultRelativeToFilter, filter, systemTimezone } = state;
|
|
669
|
+
const { indexFactory: systemIndexFactory, allowedDaysOfWeek, effectiveScheduleDays, indexDayOfWeek, computeSelectionResultRelativeToFilter, filter, systemTimezone } = state;
|
|
629
670
|
let timezone = systemTimezone;
|
|
630
671
|
const rangeAndExclusion = computeScheduleSelectionRangeAndExclusion(state);
|
|
631
672
|
if (rangeAndExclusion == null) {
|
|
@@ -639,12 +680,16 @@ function computeScheduleSelectionValue(state) {
|
|
|
639
680
|
// If computeSelectionResultRelativeToFilter is true, then we need to offset the values to be relative to that start.
|
|
640
681
|
if (computeSelectionResultRelativeToFilter && (filter === null || filter === void 0 ? void 0 : filter.start)) {
|
|
641
682
|
start = filter.start; // always start at the filter's start date
|
|
683
|
+
let startInSystemTimezone = start;
|
|
642
684
|
if (filter.timezone) {
|
|
643
685
|
timezone = filter.timezone;
|
|
644
686
|
const filterNormal = dateTimezoneUtcNormal(timezone);
|
|
645
687
|
end = filterNormal.startOfDayInTargetTimezone(end);
|
|
688
|
+
startInSystemTimezone = filterNormal.systemDateToTargetDate(start); // convert the start to the system timezone normal for deriving the index
|
|
646
689
|
}
|
|
647
|
-
const
|
|
690
|
+
const rangeStartIndex = systemIndexFactory(rangeStart);
|
|
691
|
+
const startIndex = systemIndexFactory(startInSystemTimezone);
|
|
692
|
+
const filterStartIndexOffset = rangeStartIndex - startIndex;
|
|
648
693
|
filterOffsetExcludedRange = range(0, filterStartIndexOffset);
|
|
649
694
|
indexOffset = indexOffset - filterStartIndexOffset;
|
|
650
695
|
}
|