@triptease/tt-multi-date-picker 0.2.0
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/dist/cjs/package.json +3 -0
- package/dist/cjs/src/TtMultiDatePicker.js +220 -0
- package/dist/cjs/src/TtMultiDatePicker.js.map +1 -0
- package/dist/cjs/src/index.js +21 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/selection-model.js +72 -0
- package/dist/cjs/src/selection-model.js.map +1 -0
- package/dist/cjs/src/styles.js +56 -0
- package/dist/cjs/src/styles.js.map +1 -0
- package/dist/cjs/src/tt-multi-date-picker.js +11 -0
- package/dist/cjs/src/tt-multi-date-picker.js.map +1 -0
- package/dist/cjs/src/types.js +3 -0
- package/dist/cjs/src/types.js.map +1 -0
- package/dist/esm/src/TtMultiDatePicker.d.ts +33 -0
- package/dist/esm/src/TtMultiDatePicker.js +207 -0
- package/dist/esm/src/TtMultiDatePicker.js.map +1 -0
- package/dist/esm/src/index.d.ts +2 -0
- package/dist/esm/src/index.js +3 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/selection-model.d.ts +4 -0
- package/dist/esm/src/selection-model.js +68 -0
- package/dist/esm/src/selection-model.js.map +1 -0
- package/dist/esm/src/styles.d.ts +1 -0
- package/dist/esm/src/styles.js +53 -0
- package/dist/esm/src/styles.js.map +1 -0
- package/dist/esm/src/tt-multi-date-picker.d.ts +2 -0
- package/dist/esm/src/tt-multi-date-picker.js +8 -0
- package/dist/esm/src/tt-multi-date-picker.js.map +1 -0
- package/dist/esm/src/types.d.ts +35 -0
- package/dist/esm/src/types.js +2 -0
- package/dist/esm/src/types.js.map +1 -0
- package/dist/esm/test/selection-model.test.d.ts +1 -0
- package/dist/esm/test/selection-model.test.js +60 -0
- package/dist/esm/test/selection-model.test.js.map +1 -0
- package/dist/esm/test/tt-multi-date-picker.test.d.ts +1 -0
- package/dist/esm/test/tt-multi-date-picker.test.js +173 -0
- package/dist/esm/test/tt-multi-date-picker.test.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TtMultiDatePicker = void 0;
|
|
10
|
+
const lit_1 = require("lit");
|
|
11
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
12
|
+
const luxon_1 = require("luxon");
|
|
13
|
+
const unsafe_svg_js_1 = require("lit/directives/unsafe-svg.js");
|
|
14
|
+
const icons_1 = require("@triptease/icons");
|
|
15
|
+
require("@triptease/tt-calendar/tt-calendar.js");
|
|
16
|
+
const styles_js_1 = require("./styles.js");
|
|
17
|
+
const selection_model_js_1 = require("./selection-model.js");
|
|
18
|
+
class TtMultiDatePicker extends lit_1.LitElement {
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
this.months = 6;
|
|
22
|
+
this.value = [];
|
|
23
|
+
this.name = '';
|
|
24
|
+
this.required = false;
|
|
25
|
+
this._currentStartMonth = luxon_1.DateTime.local().startOf('month');
|
|
26
|
+
this._focusedDate = luxon_1.DateTime.local();
|
|
27
|
+
this._internals = this.attachInternals();
|
|
28
|
+
}
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
super.connectedCallback();
|
|
31
|
+
if (this.startMonth) {
|
|
32
|
+
this._currentStartMonth = luxon_1.DateTime.fromISO(this.startMonth + '-01');
|
|
33
|
+
}
|
|
34
|
+
this._syncForm();
|
|
35
|
+
}
|
|
36
|
+
_syncForm() {
|
|
37
|
+
const val = this.value.length > 0 ? JSON.stringify(this.value) : null;
|
|
38
|
+
this._internals.setFormValue(val);
|
|
39
|
+
if (this.required && this.value.length === 0) {
|
|
40
|
+
this._internals.setValidity({ valueMissing: true }, 'Please select at least one date');
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this._internals.setValidity({});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
formResetCallback() {
|
|
47
|
+
this.value = [];
|
|
48
|
+
this._lastClickedDate = undefined;
|
|
49
|
+
this._syncForm();
|
|
50
|
+
}
|
|
51
|
+
_getMonthList() {
|
|
52
|
+
return Array.from({ length: this.months }, (_, i) => this._currentStartMonth.plus({ months: i }));
|
|
53
|
+
}
|
|
54
|
+
_previousPage() {
|
|
55
|
+
this._currentStartMonth = this._currentStartMonth.minus({ months: this.months });
|
|
56
|
+
}
|
|
57
|
+
_nextPage() {
|
|
58
|
+
this._currentStartMonth = this._currentStartMonth.plus({ months: this.months });
|
|
59
|
+
}
|
|
60
|
+
_getDateRangeLabel() {
|
|
61
|
+
const first = this._currentStartMonth;
|
|
62
|
+
const last = this._currentStartMonth.plus({ months: this.months - 1 });
|
|
63
|
+
return `${first.toFormat('MMMM yyyy')} — ${last.toFormat('MMMM yyyy')}`;
|
|
64
|
+
}
|
|
65
|
+
_getCalendarForDate(date) {
|
|
66
|
+
const monthStr = date.toFormat('yyyy-MM');
|
|
67
|
+
const calendars = this.shadowRoot.querySelectorAll('tt-calendar');
|
|
68
|
+
for (const cal of calendars) {
|
|
69
|
+
if (cal.getAttribute('month') === monthStr)
|
|
70
|
+
return cal;
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
_moveFocus(date) {
|
|
75
|
+
this._focusedDate = date;
|
|
76
|
+
this.updateComplete.then(() => {
|
|
77
|
+
const cal = this._getCalendarForDate(date);
|
|
78
|
+
cal?.focusDay(date);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
_handleDayClick(event) {
|
|
82
|
+
const target = event.composedPath()[0];
|
|
83
|
+
const dayCell = target.closest?.('.day') ?? (target.classList?.contains('day') ? target : null);
|
|
84
|
+
const dateStr = dayCell?.getAttribute('data-date');
|
|
85
|
+
if (!dateStr)
|
|
86
|
+
return;
|
|
87
|
+
this._focusedDate = luxon_1.DateTime.fromISO(dateStr);
|
|
88
|
+
if (event.shiftKey && this._lastClickedDate) {
|
|
89
|
+
this.value = (0, selection_model_js_1.extendRange)(this.value, this._lastClickedDate, dateStr);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.value = (0, selection_model_js_1.toggleDate)(this.value, dateStr);
|
|
93
|
+
}
|
|
94
|
+
this._lastClickedDate = dateStr;
|
|
95
|
+
this._syncForm();
|
|
96
|
+
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
97
|
+
}
|
|
98
|
+
_handleKeyDown(event) {
|
|
99
|
+
switch (event.key) {
|
|
100
|
+
case 'ArrowRight':
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
this._moveFocus(this._focusedDate.plus({ days: 1 }));
|
|
103
|
+
break;
|
|
104
|
+
case 'ArrowLeft':
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
this._moveFocus(this._focusedDate.minus({ days: 1 }));
|
|
107
|
+
break;
|
|
108
|
+
case 'ArrowDown':
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
this._moveFocus(this._focusedDate.plus({ weeks: 1 }));
|
|
111
|
+
break;
|
|
112
|
+
case 'ArrowUp':
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
this._moveFocus(this._focusedDate.minus({ weeks: 1 }));
|
|
115
|
+
break;
|
|
116
|
+
case 'Home':
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
this._moveFocus(this._focusedDate.startOf('week'));
|
|
119
|
+
break;
|
|
120
|
+
case 'End':
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
this._moveFocus(this._focusedDate.endOf('week'));
|
|
123
|
+
break;
|
|
124
|
+
case 'PageDown':
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
this._nextPage();
|
|
127
|
+
break;
|
|
128
|
+
case 'PageUp':
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
this._previousPage();
|
|
131
|
+
break;
|
|
132
|
+
case 'Enter':
|
|
133
|
+
case ' ': {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
const dateStr = this._focusedDate.toISODate();
|
|
136
|
+
if (event.shiftKey && this._lastClickedDate) {
|
|
137
|
+
this.value = (0, selection_model_js_1.extendRange)(this.value, this._lastClickedDate, dateStr);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
this.value = (0, selection_model_js_1.toggleDate)(this.value, dateStr);
|
|
141
|
+
}
|
|
142
|
+
this._lastClickedDate = dateStr;
|
|
143
|
+
this._syncForm();
|
|
144
|
+
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
_clearAll() {
|
|
150
|
+
this.value = [];
|
|
151
|
+
this._lastClickedDate = undefined;
|
|
152
|
+
this._syncForm();
|
|
153
|
+
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
154
|
+
}
|
|
155
|
+
render() {
|
|
156
|
+
const monthList = this._getMonthList();
|
|
157
|
+
return (0, lit_1.html) `
|
|
158
|
+
<div class="navigation">
|
|
159
|
+
<button @click=${this._previousPage} aria-label="Previous ${this.months} months">${(0, unsafe_svg_js_1.unsafeSVG)(icons_1.chevron)}</button>
|
|
160
|
+
<h2>${this._getDateRangeLabel()}</h2>
|
|
161
|
+
<button @click=${this._nextPage} aria-label="Next ${this.months} months" class="right">
|
|
162
|
+
${(0, unsafe_svg_js_1.unsafeSVG)(icons_1.chevron)}
|
|
163
|
+
</button>
|
|
164
|
+
</div>
|
|
165
|
+
<div class="calendar-grid" @click=${this._handleDayClick} @keydown=${this._handleKeyDown} tabindex="0">
|
|
166
|
+
${monthList.map((month) => (0, lit_1.html) `
|
|
167
|
+
<tt-calendar
|
|
168
|
+
display-only
|
|
169
|
+
month="${month.toFormat('yyyy-MM')}"
|
|
170
|
+
.highlightedRanges=${this.value}
|
|
171
|
+
min-date="${this.minDate ?? ''}"
|
|
172
|
+
max-date="${this.maxDate ?? ''}"
|
|
173
|
+
></tt-calendar>
|
|
174
|
+
`)}
|
|
175
|
+
</div>
|
|
176
|
+
${this.value.length > 0
|
|
177
|
+
? (0, lit_1.html) `
|
|
178
|
+
<div class="footer">
|
|
179
|
+
<span class="selection-summary">${this.value.length} selection${this.value.length > 1 ? 's' : ''}</span>
|
|
180
|
+
<button data-action="clear" data-theme="secondary" @click=${this._clearAll}>Clear all</button>
|
|
181
|
+
</div>
|
|
182
|
+
`
|
|
183
|
+
: lit_1.nothing}
|
|
184
|
+
`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.TtMultiDatePicker = TtMultiDatePicker;
|
|
188
|
+
TtMultiDatePicker.formAssociated = true;
|
|
189
|
+
TtMultiDatePicker.styles = styles_js_1.styles;
|
|
190
|
+
__decorate([
|
|
191
|
+
(0, decorators_js_1.property)({ type: Number })
|
|
192
|
+
], TtMultiDatePicker.prototype, "months", void 0);
|
|
193
|
+
__decorate([
|
|
194
|
+
(0, decorators_js_1.property)({ attribute: 'start-month' })
|
|
195
|
+
], TtMultiDatePicker.prototype, "startMonth", void 0);
|
|
196
|
+
__decorate([
|
|
197
|
+
(0, decorators_js_1.property)({ attribute: false })
|
|
198
|
+
], TtMultiDatePicker.prototype, "value", void 0);
|
|
199
|
+
__decorate([
|
|
200
|
+
(0, decorators_js_1.property)({ reflect: true })
|
|
201
|
+
], TtMultiDatePicker.prototype, "name", void 0);
|
|
202
|
+
__decorate([
|
|
203
|
+
(0, decorators_js_1.property)({ type: Boolean, reflect: true })
|
|
204
|
+
], TtMultiDatePicker.prototype, "required", void 0);
|
|
205
|
+
__decorate([
|
|
206
|
+
(0, decorators_js_1.property)({ attribute: 'min-date' })
|
|
207
|
+
], TtMultiDatePicker.prototype, "minDate", void 0);
|
|
208
|
+
__decorate([
|
|
209
|
+
(0, decorators_js_1.property)({ attribute: 'max-date' })
|
|
210
|
+
], TtMultiDatePicker.prototype, "maxDate", void 0);
|
|
211
|
+
__decorate([
|
|
212
|
+
(0, decorators_js_1.state)()
|
|
213
|
+
], TtMultiDatePicker.prototype, "_currentStartMonth", void 0);
|
|
214
|
+
__decorate([
|
|
215
|
+
(0, decorators_js_1.state)()
|
|
216
|
+
], TtMultiDatePicker.prototype, "_lastClickedDate", void 0);
|
|
217
|
+
__decorate([
|
|
218
|
+
(0, decorators_js_1.state)()
|
|
219
|
+
], TtMultiDatePicker.prototype, "_focusedDate", void 0);
|
|
220
|
+
//# sourceMappingURL=TtMultiDatePicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TtMultiDatePicker.js","sourceRoot":"","sources":["../../../src/TtMultiDatePicker.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6BAAgD;AAChD,qDAAoD;AACpD,iCAAiC;AACjC,gEAAyD;AACzD,4CAA2C;AAC3C,iDAA+C;AAC/C,2CAAqC;AACrC,6DAA+D;AAK/D,MAAa,iBAAkB,SAAQ,gBAAU;IA6B/C;QACE,KAAK,EAAE,CAAC;QAvBV,WAAM,GAAe,CAAC,CAAC;QAMvB,UAAK,GAAc,EAAE,CAAC;QAEO,SAAI,GAAW,EAAE,CAAC;QACH,aAAQ,GAAY,KAAK,CAAC;QAK9D,uBAAkB,GAAa,gBAAQ,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAMjE,iBAAY,GAAa,gBAAQ,CAAC,KAAK,EAAE,CAAC;QAIhD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;IAC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E;IADP,IAAA,qBAAK,GAAE;2DAC0B;AAG1B;IADP,IAAA,qBAAK,GAAE;uDAC0C","sourcesContent":["import { html, LitElement, nothing } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { DateTime } from 'luxon';\nimport { unsafeSVG } from 'lit/directives/unsafe-svg.js';\nimport { chevron } from '@triptease/icons';\nimport '@triptease/tt-calendar/tt-calendar.js';\nimport { styles } from './styles.js';\nimport { toggleDate, extendRange } from './selection-model.js';\nimport type { DateRange } from '@triptease/tt-calendar/date-selection-context.js';\n\ntype Selection = Required<DateRange>[];\n\nexport class TtMultiDatePicker extends LitElement {\n static formAssociated = true;\n static override styles = styles;\n\n private _internals: ElementInternals;\n\n @property({ type: Number })\n months: 3 | 6 | 12 = 6;\n\n @property({ attribute: 'start-month' })\n startMonth?: string;\n\n @property({ attribute: false })\n value: Selection = [];\n\n @property({ reflect: true }) name: string = '';\n @property({ type: Boolean, reflect: true }) required: boolean = false;\n @property({ attribute: 'min-date' }) minDate?: string;\n @property({ attribute: 'max-date' }) maxDate?: string;\n\n @state()\n private _currentStartMonth: DateTime = DateTime.local().startOf('month');\n\n @state()\n private _lastClickedDate?: string;\n\n @state()\n private _focusedDate: DateTime = DateTime.local();\n\n constructor() {\n super();\n this._internals = this.attachInternals();\n }\n\n override connectedCallback() {\n super.connectedCallback();\n if (this.startMonth) {\n this._currentStartMonth = DateTime.fromISO(this.startMonth + '-01');\n }\n this._syncForm();\n }\n\n private _syncForm() {\n const val = this.value.length > 0 ? JSON.stringify(this.value) : null;\n this._internals.setFormValue(val);\n if (this.required && this.value.length === 0) {\n this._internals.setValidity({ valueMissing: true }, 'Please select at least one date');\n } else {\n this._internals.setValidity({});\n }\n }\n\n formResetCallback() {\n this.value = [];\n this._lastClickedDate = undefined;\n this._syncForm();\n }\n\n private _getMonthList(): DateTime[] {\n return Array.from({ length: this.months }, (_, i) => this._currentStartMonth.plus({ months: i }));\n }\n\n private _previousPage() {\n this._currentStartMonth = this._currentStartMonth.minus({ months: this.months });\n }\n\n private _nextPage() {\n this._currentStartMonth = this._currentStartMonth.plus({ months: this.months });\n }\n\n private _getDateRangeLabel(): string {\n const first = this._currentStartMonth;\n const last = this._currentStartMonth.plus({ months: this.months - 1 });\n return `${first.toFormat('MMMM yyyy')} — ${last.toFormat('MMMM yyyy')}`;\n }\n\n private _getCalendarForDate(date: DateTime): Element | undefined {\n const monthStr = date.toFormat('yyyy-MM');\n const calendars = this.shadowRoot!.querySelectorAll('tt-calendar');\n for (const cal of calendars) {\n if (cal.getAttribute('month') === monthStr) return cal;\n }\n return undefined;\n }\n\n private _moveFocus(date: DateTime) {\n this._focusedDate = date;\n this.updateComplete.then(() => {\n const cal = this._getCalendarForDate(date) as (Element & { focusDay: (d: DateTime) => void }) | undefined;\n cal?.focusDay(date);\n });\n }\n\n private _handleDayClick(event: MouseEvent) {\n const target = event.composedPath()[0] as HTMLElement;\n const dayCell = target.closest?.('.day') ?? (target.classList?.contains('day') ? target : null);\n const dateStr = dayCell?.getAttribute('data-date');\n if (!dateStr) return;\n\n this._focusedDate = DateTime.fromISO(dateStr);\n\n if (event.shiftKey && this._lastClickedDate) {\n this.value = extendRange(this.value, this._lastClickedDate, dateStr);\n } else {\n this.value = toggleDate(this.value, dateStr);\n }\n\n this._lastClickedDate = dateStr;\n this._syncForm();\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));\n }\n\n private _handleKeyDown(event: KeyboardEvent) {\n switch (event.key) {\n case 'ArrowRight':\n event.preventDefault();\n this._moveFocus(this._focusedDate.plus({ days: 1 }));\n break;\n case 'ArrowLeft':\n event.preventDefault();\n this._moveFocus(this._focusedDate.minus({ days: 1 }));\n break;\n case 'ArrowDown':\n event.preventDefault();\n this._moveFocus(this._focusedDate.plus({ weeks: 1 }));\n break;\n case 'ArrowUp':\n event.preventDefault();\n this._moveFocus(this._focusedDate.minus({ weeks: 1 }));\n break;\n case 'Home':\n event.preventDefault();\n this._moveFocus(this._focusedDate.startOf('week'));\n break;\n case 'End':\n event.preventDefault();\n this._moveFocus(this._focusedDate.endOf('week'));\n break;\n case 'PageDown':\n event.preventDefault();\n this._nextPage();\n break;\n case 'PageUp':\n event.preventDefault();\n this._previousPage();\n break;\n case 'Enter':\n case ' ': {\n event.preventDefault();\n const dateStr = this._focusedDate.toISODate()!;\n if (event.shiftKey && this._lastClickedDate) {\n this.value = extendRange(this.value, this._lastClickedDate, dateStr);\n } else {\n this.value = toggleDate(this.value, dateStr);\n }\n this._lastClickedDate = dateStr;\n this._syncForm();\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));\n break;\n }\n }\n }\n\n private _clearAll() {\n this.value = [];\n this._lastClickedDate = undefined;\n this._syncForm();\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));\n }\n\n override render() {\n const monthList = this._getMonthList();\n\n return html`\n <div class=\"navigation\">\n <button @click=${this._previousPage} aria-label=\"Previous ${this.months} months\">${unsafeSVG(chevron)}</button>\n <h2>${this._getDateRangeLabel()}</h2>\n <button @click=${this._nextPage} aria-label=\"Next ${this.months} months\" class=\"right\">\n ${unsafeSVG(chevron)}\n </button>\n </div>\n <div class=\"calendar-grid\" @click=${this._handleDayClick} @keydown=${this._handleKeyDown} tabindex=\"0\">\n ${monthList.map(\n (month) => html`\n <tt-calendar\n display-only\n month=\"${month.toFormat('yyyy-MM')}\"\n .highlightedRanges=${this.value}\n min-date=\"${this.minDate ?? ''}\"\n max-date=\"${this.maxDate ?? ''}\"\n ></tt-calendar>\n `\n )}\n </div>\n ${this.value.length > 0\n ? html`\n <div class=\"footer\">\n <span class=\"selection-summary\">${this.value.length} selection${this.value.length > 1 ? 's' : ''}</span>\n <button data-action=\"clear\" data-theme=\"secondary\" @click=${this._clearAll}>Clear all</button>\n </div>\n `\n : nothing}\n `;\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.TtMultiDatePicker = void 0;
|
|
18
|
+
var tt_multi_date_picker_js_1 = require("./tt-multi-date-picker.js");
|
|
19
|
+
Object.defineProperty(exports, "TtMultiDatePicker", { enumerable: true, get: function () { return tt_multi_date_picker_js_1.TtMultiDatePicker; } });
|
|
20
|
+
__exportStar(require("./types.js"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qEAA8D;AAArD,4HAAA,iBAAiB,OAAA;AAC1B,6CAA2B","sourcesContent":["export { TtMultiDatePicker } from './tt-multi-date-picker.js';\nexport * from './types.js';\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toggleDate = toggleDate;
|
|
4
|
+
exports.extendRange = extendRange;
|
|
5
|
+
const luxon_1 = require("luxon");
|
|
6
|
+
function toggleDate(selections, isoDate) {
|
|
7
|
+
const date = luxon_1.DateTime.fromISO(isoDate);
|
|
8
|
+
const result = [];
|
|
9
|
+
let handled = false;
|
|
10
|
+
for (const range of selections) {
|
|
11
|
+
const start = luxon_1.DateTime.fromISO(range.startDate);
|
|
12
|
+
const end = luxon_1.DateTime.fromISO(range.endDate);
|
|
13
|
+
if (date < start || date > end) {
|
|
14
|
+
result.push(range);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
handled = true;
|
|
18
|
+
if (start.equals(end)) {
|
|
19
|
+
continue; // remove single-date selection
|
|
20
|
+
}
|
|
21
|
+
if (date.equals(start)) {
|
|
22
|
+
result.push({ startDate: start.plus({ days: 1 }).toISODate(), endDate: range.endDate });
|
|
23
|
+
}
|
|
24
|
+
else if (date.equals(end)) {
|
|
25
|
+
result.push({ startDate: range.startDate, endDate: end.minus({ days: 1 }).toISODate() });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
result.push({ startDate: range.startDate, endDate: date.minus({ days: 1 }).toISODate() });
|
|
29
|
+
result.push({ startDate: date.plus({ days: 1 }).toISODate(), endDate: range.endDate });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (!handled) {
|
|
33
|
+
result.push({ startDate: isoDate, endDate: isoDate });
|
|
34
|
+
}
|
|
35
|
+
return sortSelections(result);
|
|
36
|
+
}
|
|
37
|
+
function sortSelections(selections) {
|
|
38
|
+
return [...selections].sort((a, b) => a.startDate.localeCompare(b.startDate));
|
|
39
|
+
}
|
|
40
|
+
function extendRange(selections, anchorDate, targetDate) {
|
|
41
|
+
const anchor = luxon_1.DateTime.fromISO(anchorDate);
|
|
42
|
+
const target = luxon_1.DateTime.fromISO(targetDate);
|
|
43
|
+
const start = anchor < target ? anchor : target;
|
|
44
|
+
const end = anchor < target ? target : anchor;
|
|
45
|
+
const newRange = {
|
|
46
|
+
startDate: start.toISODate(),
|
|
47
|
+
endDate: end.toISODate(),
|
|
48
|
+
};
|
|
49
|
+
return mergeIntoSelections(selections, newRange);
|
|
50
|
+
}
|
|
51
|
+
function mergeIntoSelections(selections, newRange) {
|
|
52
|
+
const all = sortSelections([...selections, newRange]);
|
|
53
|
+
const result = [all[0]];
|
|
54
|
+
for (let i = 1; i < all.length; i++) {
|
|
55
|
+
const prev = result[result.length - 1];
|
|
56
|
+
const curr = all[i];
|
|
57
|
+
const prevEnd = luxon_1.DateTime.fromISO(prev.endDate);
|
|
58
|
+
const currStart = luxon_1.DateTime.fromISO(curr.startDate);
|
|
59
|
+
if (currStart <= prevEnd.plus({ days: 1 })) {
|
|
60
|
+
const currEnd = luxon_1.DateTime.fromISO(curr.endDate);
|
|
61
|
+
result[result.length - 1] = {
|
|
62
|
+
startDate: prev.startDate,
|
|
63
|
+
endDate: currEnd > prevEnd ? curr.endDate : prev.endDate,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
result.push(curr);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=selection-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection-model.js","sourceRoot":"","sources":["../../../src/selection-model.ts"],"names":[],"mappings":";;AAKA,gCAmCC;AAMD,kCAYC;AA1DD,iCAAiC;AAKjC,SAAgB,UAAU,CAAC,UAAqB,EAAE,OAAe;IAC/D,MAAM,IAAI,GAAG,gBAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,MAAM,GAAc,EAAE,CAAC;IAC7B,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAG,gBAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAChD,MAAM,GAAG,GAAG,gBAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAE5C,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,GAAG,EAAE,CAA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AAC,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACpB,MAAM,OAAO,GAAG,gBAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG,gBAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAEnD,IAAI,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;YAC3C,MAAM,OAAO,GAAG,gBAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC/C,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG;gBAC1B,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO;aACzD,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { DateTime } from 'luxon';\nimport type { DateRange } from '@triptease/tt-calendar/date-selection-context.js';\n\ntype Selection = Required<DateRange>[];\n\nexport function toggleDate(selections: Selection, isoDate: string): Selection {\n const date = DateTime.fromISO(isoDate);\n const result: Selection = [];\n let handled = false;\n\n for (const range of selections) {\n const start = DateTime.fromISO(range.startDate);\n const end = DateTime.fromISO(range.endDate);\n\n if (date < start || date > end) {\n result.push(range);\n continue;\n }\n\n handled = true;\n\n if (start.equals(end)) {\n continue; // remove single-date selection\n }\n\n if (date.equals(start)) {\n result.push({ startDate: start.plus({ days: 1 }).toISODate()!, endDate: range.endDate });\n } else if (date.equals(end)) {\n result.push({ startDate: range.startDate, endDate: end.minus({ days: 1 }).toISODate()! });\n } else {\n result.push({ startDate: range.startDate, endDate: date.minus({ days: 1 }).toISODate()! });\n result.push({ startDate: date.plus({ days: 1 }).toISODate()!, endDate: range.endDate });\n }\n }\n\n if (!handled) {\n result.push({ startDate: isoDate, endDate: isoDate });\n }\n\n return sortSelections(result);\n}\n\nfunction sortSelections(selections: Selection): Selection {\n return [...selections].sort((a, b) => a.startDate.localeCompare(b.startDate));\n}\n\nexport function extendRange(selections: Selection, anchorDate: string, targetDate: string): Selection {\n const anchor = DateTime.fromISO(anchorDate);\n const target = DateTime.fromISO(targetDate);\n const start = anchor < target ? anchor : target;\n const end = anchor < target ? target : anchor;\n\n const newRange: Required<DateRange> = {\n startDate: start.toISODate()!,\n endDate: end.toISODate()!,\n };\n\n return mergeIntoSelections(selections, newRange);\n}\n\nfunction mergeIntoSelections(selections: Selection, newRange: Required<DateRange>): Selection {\n const all = sortSelections([...selections, newRange]);\n const result: Selection = [all[0]];\n\n for (let i = 1; i < all.length; i++) {\n const prev = result[result.length - 1];\n const curr = all[i];\n const prevEnd = DateTime.fromISO(prev.endDate);\n const currStart = DateTime.fromISO(curr.startDate);\n\n if (currStart <= prevEnd.plus({ days: 1 })) {\n const currEnd = DateTime.fromISO(curr.endDate);\n result[result.length - 1] = {\n startDate: prev.startDate,\n endDate: currEnd > prevEnd ? curr.endDate : prev.endDate,\n };\n } else {\n result.push(curr);\n }\n }\n\n return result;\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.styles = void 0;
|
|
4
|
+
const lit_1 = require("lit");
|
|
5
|
+
const lit_2 = require("@triptease/stylesheet/lit");
|
|
6
|
+
exports.styles = [
|
|
7
|
+
lit_2.styles,
|
|
8
|
+
(0, lit_1.css) `
|
|
9
|
+
:host {
|
|
10
|
+
display: block;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.navigation {
|
|
14
|
+
display: flex;
|
|
15
|
+
justify-content: space-between;
|
|
16
|
+
align-items: center;
|
|
17
|
+
padding: var(--space-scale-2) var(--space-scale-3);
|
|
18
|
+
border-bottom: 1px solid var(--color-border-200);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.navigation button svg {
|
|
22
|
+
display: block;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.navigation button.right svg {
|
|
26
|
+
transform: rotate(180deg);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.navigation h2 {
|
|
30
|
+
font-weight: var(--font-weight-semibold);
|
|
31
|
+
font-size: var(--font-size-400);
|
|
32
|
+
color: var(--color-text-500);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.calendar-grid {
|
|
36
|
+
display: grid;
|
|
37
|
+
grid-template-columns: repeat(3, 1fr);
|
|
38
|
+
gap: var(--space-scale-3);
|
|
39
|
+
padding: var(--space-scale-3);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.footer {
|
|
43
|
+
display: flex;
|
|
44
|
+
justify-content: space-between;
|
|
45
|
+
align-items: center;
|
|
46
|
+
padding: var(--space-scale-2) var(--space-scale-3);
|
|
47
|
+
border-top: 1px solid var(--color-border-200);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.selection-summary {
|
|
51
|
+
font-size: var(--font-size-100);
|
|
52
|
+
color: var(--color-text-400);
|
|
53
|
+
}
|
|
54
|
+
`,
|
|
55
|
+
];
|
|
56
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../src/styles.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;AAC1B,mDAAiE;AAEpD,QAAA,MAAM,GAAG;IACpB,YAAU;IACV,IAAA,SAAG,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CF;CACF,CAAC","sourcesContent":["import { css } from 'lit';\nimport { styles as baseStyles } from '@triptease/stylesheet/lit';\n\nexport const styles = [\n baseStyles,\n css`\n :host {\n display: block;\n }\n\n .navigation {\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding: var(--space-scale-2) var(--space-scale-3);\n border-bottom: 1px solid var(--color-border-200);\n }\n\n .navigation button svg {\n display: block;\n }\n\n .navigation button.right svg {\n transform: rotate(180deg);\n }\n\n .navigation h2 {\n font-weight: var(--font-weight-semibold);\n font-size: var(--font-size-400);\n color: var(--color-text-500);\n }\n\n .calendar-grid {\n display: grid;\n grid-template-columns: repeat(3, 1fr);\n gap: var(--space-scale-3);\n padding: var(--space-scale-3);\n }\n\n .footer {\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding: var(--space-scale-2) var(--space-scale-3);\n border-top: 1px solid var(--color-border-200);\n }\n\n .selection-summary {\n font-size: var(--font-size-100);\n color: var(--color-text-400);\n }\n `,\n];\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TtMultiDatePicker = void 0;
|
|
4
|
+
const TtMultiDatePicker_js_1 = require("./TtMultiDatePicker.js");
|
|
5
|
+
Object.defineProperty(exports, "TtMultiDatePicker", { enumerable: true, get: function () { return TtMultiDatePicker_js_1.TtMultiDatePicker; } });
|
|
6
|
+
if (typeof window !== 'undefined') {
|
|
7
|
+
if (!window.customElements.get('tt-multi-date-picker')) {
|
|
8
|
+
window.customElements.define('tt-multi-date-picker', TtMultiDatePicker_js_1.TtMultiDatePicker);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=tt-multi-date-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tt-multi-date-picker.js","sourceRoot":"","sources":["../../../src/tt-multi-date-picker.ts"],"names":[],"mappings":";;;AAAA,iEAA2D;AAQlD,kGARA,wCAAiB,OAQA;AAN1B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,sBAAsB,CAAC,EAAE,CAAC;QACvD,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,sBAAsB,EAAE,wCAAiB,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC","sourcesContent":["import { TtMultiDatePicker } from './TtMultiDatePicker.js';\n\nif (typeof window !== 'undefined') {\n if (!window.customElements.get('tt-multi-date-picker')) {\n window.customElements.define('tt-multi-date-picker', TtMultiDatePicker);\n }\n}\n\nexport { TtMultiDatePicker };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { TtMultiDatePicker } from './TtMultiDatePicker.js';\n\ninterface TtMultiDatePickerExternalAttributes {\n months?: '3' | '6' | '12';\n 'start-month'?: string;\n name?: string;\n required?: boolean;\n 'min-date'?: string;\n 'max-date'?: string;\n id?: string;\n 'data-testid'?: string;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'tt-multi-date-picker': TtMultiDatePicker;\n }\n namespace JSX {\n interface IntrinsicElements {\n 'tt-multi-date-picker': TtMultiDatePickerExternalAttributes & { style?: string };\n }\n }\n namespace React {\n namespace JSX {\n interface IntrinsicElements {\n 'tt-multi-date-picker': TtMultiDatePickerExternalAttributes & {\n key?: string;\n ref?: React.Ref<unknown>;\n style?: React.CSSProperties;\n };\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import '@triptease/tt-calendar/tt-calendar.js';
|
|
3
|
+
import type { Selection } from './selection-model.js';
|
|
4
|
+
export declare class TtMultiDatePicker extends LitElement {
|
|
5
|
+
static formAssociated: boolean;
|
|
6
|
+
static styles: import("lit").CSSResult[];
|
|
7
|
+
private _internals;
|
|
8
|
+
months: 3 | 6 | 12;
|
|
9
|
+
startMonth?: string;
|
|
10
|
+
value: Selection;
|
|
11
|
+
name: string;
|
|
12
|
+
required: boolean;
|
|
13
|
+
minDate?: string;
|
|
14
|
+
maxDate?: string;
|
|
15
|
+
private _currentStartMonth;
|
|
16
|
+
private _lastClickedDate?;
|
|
17
|
+
private _focusedDate;
|
|
18
|
+
constructor();
|
|
19
|
+
connectedCallback(): void;
|
|
20
|
+
private _syncForm;
|
|
21
|
+
formResetCallback(): void;
|
|
22
|
+
private _getMonthList;
|
|
23
|
+
private _previousPage;
|
|
24
|
+
private _nextPage;
|
|
25
|
+
private _getDateRangeLabel;
|
|
26
|
+
private _getCalendarForDate;
|
|
27
|
+
private _moveFocus;
|
|
28
|
+
private _applySelection;
|
|
29
|
+
private _handleDayClick;
|
|
30
|
+
private _handleKeyDown;
|
|
31
|
+
private _clearAll;
|
|
32
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
33
|
+
}
|