1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.DateRangeSelectionStrategy = void 0;
|
19 | var core_1 = require("@blueprintjs/core");
|
20 | var dateUtils_1 = require("./common/dateUtils");
|
21 |
|
22 | var DateRangeSelectionStrategy = (function () {
|
23 | function DateRangeSelectionStrategy() {
|
24 | }
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | DateRangeSelectionStrategy.getNextState = function (currentRange, day, allowSingleDayRange, boundary) {
|
32 | if (boundary != null) {
|
33 | return this.getNextStateForBoundary(currentRange, day, allowSingleDayRange, boundary);
|
34 | }
|
35 | else {
|
36 | return this.getDefaultNextState(currentRange, day, allowSingleDayRange);
|
37 | }
|
38 | };
|
39 | DateRangeSelectionStrategy.getNextStateForBoundary = function (currentRange, day, allowSingleDayRange, boundary) {
|
40 | var boundaryDate = this.getBoundaryDate(boundary, currentRange);
|
41 | var otherBoundary = this.getOtherBoundary(boundary);
|
42 | var otherBoundaryDate = this.getBoundaryDate(otherBoundary, currentRange);
|
43 | var nextBoundary;
|
44 | var nextDateRange;
|
45 | if (boundaryDate == null && otherBoundaryDate == null) {
|
46 | nextBoundary = boundary;
|
47 | nextDateRange = this.createRangeForBoundary(boundary, day, null);
|
48 | }
|
49 | else if (boundaryDate != null && otherBoundaryDate == null) {
|
50 | var nextBoundaryDate = (0, dateUtils_1.areSameDay)(boundaryDate, day) ? null : day;
|
51 | nextBoundary = boundary;
|
52 | nextDateRange = this.createRangeForBoundary(boundary, nextBoundaryDate, null);
|
53 | }
|
54 | else if (boundaryDate == null && otherBoundaryDate != null) {
|
55 | if ((0, dateUtils_1.areSameDay)(day, otherBoundaryDate)) {
|
56 | var nextDate = void 0;
|
57 | if (allowSingleDayRange) {
|
58 | nextBoundary = boundary;
|
59 | nextDate = otherBoundaryDate;
|
60 | }
|
61 | else {
|
62 | nextBoundary = otherBoundary;
|
63 | nextDate = null;
|
64 | }
|
65 | nextDateRange = this.createRangeForBoundary(boundary, nextDate, nextDate);
|
66 | }
|
67 | else if (this.isOverlappingOtherBoundary(boundary, day, otherBoundaryDate)) {
|
68 | nextBoundary = otherBoundary;
|
69 | nextDateRange = this.createRangeForBoundary(boundary, otherBoundaryDate, day);
|
70 | }
|
71 | else {
|
72 | nextBoundary = boundary;
|
73 | nextDateRange = this.createRangeForBoundary(boundary, day, otherBoundaryDate);
|
74 | }
|
75 | }
|
76 | else {
|
77 |
|
78 | if ((0, dateUtils_1.areSameDay)(boundaryDate, day)) {
|
79 | var isSingleDayRangeSelected = (0, dateUtils_1.areSameDay)(boundaryDate, otherBoundaryDate);
|
80 | var nextOtherBoundaryDate = isSingleDayRangeSelected ? null : otherBoundaryDate;
|
81 | nextBoundary = boundary;
|
82 | nextDateRange = this.createRangeForBoundary(boundary, null, nextOtherBoundaryDate);
|
83 | }
|
84 | else if ((0, dateUtils_1.areSameDay)(day, otherBoundaryDate)) {
|
85 | var _a = allowSingleDayRange
|
86 | ? [otherBoundaryDate, otherBoundaryDate]
|
87 | : [boundaryDate, null], nextBoundaryDate = _a[0], nextOtherBoundaryDate = _a[1];
|
88 | nextBoundary = allowSingleDayRange ? boundary : otherBoundary;
|
89 | nextDateRange = this.createRangeForBoundary(boundary, nextBoundaryDate, nextOtherBoundaryDate);
|
90 | }
|
91 | else if (this.isOverlappingOtherBoundary(boundary, day, otherBoundaryDate)) {
|
92 | nextBoundary = boundary;
|
93 | nextDateRange = this.createRangeForBoundary(boundary, day, null);
|
94 | }
|
95 | else {
|
96 |
|
97 | nextBoundary = boundary;
|
98 | nextDateRange = this.createRangeForBoundary(boundary, day, otherBoundaryDate);
|
99 | }
|
100 | }
|
101 | return { dateRange: nextDateRange, boundary: nextBoundary };
|
102 | };
|
103 | DateRangeSelectionStrategy.getDefaultNextState = function (selectedRange, day, allowSingleDayRange) {
|
104 | var start = selectedRange[0], end = selectedRange[1];
|
105 | var nextDateRange;
|
106 | if (start == null && end == null) {
|
107 | nextDateRange = [day, null];
|
108 | }
|
109 | else if (start != null && end == null) {
|
110 | nextDateRange = this.createRange(day, start, allowSingleDayRange);
|
111 | }
|
112 | else if (start == null && end != null) {
|
113 | nextDateRange = this.createRange(day, end, allowSingleDayRange);
|
114 | }
|
115 | else {
|
116 | var isStart = (0, dateUtils_1.areSameDay)(start, day);
|
117 | var isEnd = (0, dateUtils_1.areSameDay)(end, day);
|
118 | if (isStart && isEnd) {
|
119 | nextDateRange = [null, null];
|
120 | }
|
121 | else if (isStart) {
|
122 | nextDateRange = [null, end];
|
123 | }
|
124 | else if (isEnd) {
|
125 | nextDateRange = [start, null];
|
126 | }
|
127 | else {
|
128 | nextDateRange = [day, null];
|
129 | }
|
130 | }
|
131 | return { dateRange: nextDateRange };
|
132 | };
|
133 | DateRangeSelectionStrategy.getOtherBoundary = function (boundary) {
|
134 | return boundary === core_1.Boundary.START ? core_1.Boundary.END : core_1.Boundary.START;
|
135 | };
|
136 | DateRangeSelectionStrategy.getBoundaryDate = function (boundary, dateRange) {
|
137 | return boundary === core_1.Boundary.START ? dateRange[0] : dateRange[1];
|
138 | };
|
139 | DateRangeSelectionStrategy.isOverlappingOtherBoundary = function (boundary, boundaryDate, otherBoundaryDate) {
|
140 | return boundary === core_1.Boundary.START ? boundaryDate > otherBoundaryDate : boundaryDate < otherBoundaryDate;
|
141 | };
|
142 | DateRangeSelectionStrategy.createRangeForBoundary = function (boundary, boundaryDate, otherBoundaryDate) {
|
143 | return boundary === core_1.Boundary.START
|
144 | ? [boundaryDate, otherBoundaryDate]
|
145 | : [otherBoundaryDate, boundaryDate];
|
146 | };
|
147 | DateRangeSelectionStrategy.createRange = function (a, b, allowSingleDayRange) {
|
148 |
|
149 | if (!allowSingleDayRange && (0, dateUtils_1.areSameDay)(a, b)) {
|
150 | return [null, null];
|
151 | }
|
152 | return a < b ? [a, b] : [b, a];
|
153 | };
|
154 | return DateRangeSelectionStrategy;
|
155 | }());
|
156 | exports.DateRangeSelectionStrategy = DateRangeSelectionStrategy;
|
157 |
|
\ | No newline at end of file |