@3mo/date-time-fields 0.15.0 → 0.15.1

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.
@@ -55,168 +55,168 @@ let Calendar = Calendar_1 = class Calendar extends Component {
55
55
  const month = unsafeCSS(FieldDateTimePrecision.Month.key);
56
56
  const week = unsafeCSS(FieldDateTimePrecision.Week.key);
57
57
  const day = unsafeCSS(FieldDateTimePrecision.Day.key);
58
- return css `
59
- :host {
60
- --mo-calendar-item-size: 2.25rem;
61
- flex: 1;
62
- }
63
-
64
- .scroller {
65
- height: min(450px, 100vh);
66
-
67
- display: grid;
68
- position: relative;
69
- scrollbar-width: none;
70
- overflow-x: hidden;
71
- scroll-behavior: smooth;
72
-
73
- &[data-view=${week}], &[data-view=${day}] {
74
- grid-template-columns: repeat(1, 1fr);
75
- }
76
-
77
- &[data-view=${month}] {
78
- grid-template-columns: repeat(3, 1fr);
79
- }
80
-
81
- &[data-view=${year}] {
82
- grid-template-columns: repeat(5, 1fr);
83
- }
84
- }
85
-
86
- .year, .month, .day {
87
- display: flex;
88
- align-items: center;
89
- justify-content: center;
90
- text-align: center;
91
- font-weight: 500;
92
- user-select: none;
93
- }
94
-
95
- .year, .month, .week[data-view=${week}], .day:not([data-view=${week}]) {
96
- transition: 0.2s;
97
- border-radius: var(--mo-border-radius);
98
-
99
- &:hover {
100
- background: var(--mo-color-transparent-gray-3);
101
- }
102
-
103
- &[data-now] {
104
- outline: 2px dashed var(--mo-color-gray-transparent);
105
- }
106
-
107
- &[data-start], &[data-end] {
108
- background: var(--mo-color-accent-transparent);
109
- opacity: 1;
110
- color: color-mix(in srgb, var(--mo-color-accent), var(--mo-color-foreground)) !important;
111
- }
112
-
113
- &[data-in-range] {
114
- background: color-mix(in srgb, var(--mo-color-accent), transparent 92%);
115
- }
116
-
117
- &[data-disabled] {
118
- opacity: 0.38;
119
- pointer-events: none;
120
- }
121
- }
122
-
123
- /* Headings */
124
- .year[data-view=${month}], .month[data-view=${week}], .month[data-view=${day}] {
125
- font-size: 1.125rem;
126
- font-weight: 500;
127
- height: 2rem;
128
- padding: 0.5rem;
129
- }
130
-
131
- /* Selection */
132
- .year[data-view=${year}], .month[data-view=${month}], .week[data-view=${week}], .day[data-view=${day}] {
133
- opacity: 0.875;
134
- font-size: 0.94rem;
135
- cursor: pointer;
136
- height: var(--mo-calendar-item-size);
137
- }
138
-
139
- .year {
140
- &[data-view=${week}], &[data-view=${day}] {
141
- display: none;
142
- }
143
- &:not([data-view=${year}]) {
144
- grid-column: -1 / 1;
145
- border-block-start: 1px solid var(--mo-color-transparent-gray-3);
146
- }
147
- padding-inline: 0.5rem;
148
- }
149
-
150
- .month-container {
151
- width: 100%;
152
- position: relative;
153
- &[data-view=${week}], &[data-view=${day}] {
154
- &::before {
155
- content: ' ';
156
- position: absolute;
157
- display: inline-block;
158
- width: 1px;
159
- height: 100%;
160
- inset-block: 0;
161
- background: var(--mo-color-transparent-gray-3);
162
- }
163
- &::after {
164
- content: ' ';
165
- position: absolute;
166
- display: inline-block;
167
- height: 1px;
168
- width: 100%;
169
- inset-inline: 0;
170
- background: var(--mo-color-transparent-gray-3);
171
- }
172
- }
173
-
174
- & > mo-grid {
175
- padding-inline: 0.5rem;
176
- padding-block-end: 0.5rem;
177
- margin-block-start: -0.375rem;
178
- }
179
-
180
- &[data-view=${month}] {
181
- & > mo-grid {
182
- display: none;
183
- }
184
- }
185
- }
186
-
187
- .weekdays {
188
- text-align: center;
189
- opacity: 0.5;
190
- font-size: 0.75rem;
191
- font-weight: 500;
192
- grid-column: -1 / 1;
193
- user-select: none;
194
- span {
195
- display: flex;
196
- align-items: center;
197
- justify-content: center;
198
- }
199
- }
200
-
201
- .month {
202
- padding-inline: 0.5rem;
203
- }
204
-
205
- .week {
206
- grid-column: 1 / -1;
207
- }
208
-
209
- .week-number {
210
- opacity: 0.5;
211
- display: flex;
212
- align-items: center;
213
- justify-content: center;
214
- }
215
-
216
- .day {
217
- width: var(--mo-calendar-item-size);
218
- height: var(--mo-calendar-item-size);
219
- }
58
+ return css `
59
+ :host {
60
+ --mo-calendar-item-size: 2.25rem;
61
+ flex: 1;
62
+ }
63
+
64
+ .scroller {
65
+ height: min(450px, 100vh);
66
+
67
+ display: grid;
68
+ position: relative;
69
+ scrollbar-width: none;
70
+ overflow-x: hidden;
71
+ scroll-behavior: smooth;
72
+
73
+ &[data-view=${week}], &[data-view=${day}] {
74
+ grid-template-columns: repeat(1, 1fr);
75
+ }
76
+
77
+ &[data-view=${month}] {
78
+ grid-template-columns: repeat(3, 1fr);
79
+ }
80
+
81
+ &[data-view=${year}] {
82
+ grid-template-columns: repeat(5, 1fr);
83
+ }
84
+ }
85
+
86
+ .year, .month, .day {
87
+ display: flex;
88
+ align-items: center;
89
+ justify-content: center;
90
+ text-align: center;
91
+ font-weight: 500;
92
+ user-select: none;
93
+ }
94
+
95
+ .year, .month, .week[data-view=${week}], .day:not([data-view=${week}]) {
96
+ transition: 0.2s;
97
+ border-radius: var(--mo-border-radius);
98
+
99
+ &:hover {
100
+ background: var(--mo-color-transparent-gray-3);
101
+ }
102
+
103
+ &[data-now] {
104
+ outline: 2px dashed var(--mo-color-gray-transparent);
105
+ }
106
+
107
+ &[data-start], &[data-end] {
108
+ background: var(--mo-color-accent-transparent);
109
+ opacity: 1;
110
+ color: color-mix(in srgb, var(--mo-color-accent), var(--mo-color-foreground)) !important;
111
+ }
112
+
113
+ &[data-in-range] {
114
+ background: color-mix(in srgb, var(--mo-color-accent), transparent 92%);
115
+ }
116
+
117
+ &[data-disabled] {
118
+ opacity: 0.38;
119
+ pointer-events: none;
120
+ }
121
+ }
122
+
123
+ /* Headings */
124
+ .year[data-view=${month}], .month[data-view=${week}], .month[data-view=${day}] {
125
+ font-size: 1.125rem;
126
+ font-weight: 500;
127
+ height: 2rem;
128
+ padding: 0.5rem;
129
+ }
130
+
131
+ /* Selection */
132
+ .year[data-view=${year}], .month[data-view=${month}], .week[data-view=${week}], .day[data-view=${day}] {
133
+ opacity: 0.875;
134
+ font-size: 0.94rem;
135
+ cursor: pointer;
136
+ height: var(--mo-calendar-item-size);
137
+ }
138
+
139
+ .year {
140
+ &[data-view=${week}], &[data-view=${day}] {
141
+ display: none;
142
+ }
143
+ &:not([data-view=${year}]) {
144
+ grid-column: -1 / 1;
145
+ border-block-start: 1px solid var(--mo-color-transparent-gray-3);
146
+ }
147
+ padding-inline: 0.5rem;
148
+ }
149
+
150
+ .month-container {
151
+ width: 100%;
152
+ position: relative;
153
+ &[data-view=${week}], &[data-view=${day}] {
154
+ &::before {
155
+ content: ' ';
156
+ position: absolute;
157
+ display: inline-block;
158
+ width: 1px;
159
+ height: 100%;
160
+ inset-block: 0;
161
+ background: var(--mo-color-transparent-gray-3);
162
+ }
163
+ &::after {
164
+ content: ' ';
165
+ position: absolute;
166
+ display: inline-block;
167
+ height: 1px;
168
+ width: 100%;
169
+ inset-inline: 0;
170
+ background: var(--mo-color-transparent-gray-3);
171
+ }
172
+ }
173
+
174
+ & > mo-grid {
175
+ padding-inline: 0.5rem;
176
+ padding-block-end: 0.5rem;
177
+ margin-block-start: -0.375rem;
178
+ }
179
+
180
+ &[data-view=${month}] {
181
+ & > mo-grid {
182
+ display: none;
183
+ }
184
+ }
185
+ }
186
+
187
+ .weekdays {
188
+ text-align: center;
189
+ opacity: 0.5;
190
+ font-size: 0.75rem;
191
+ font-weight: 500;
192
+ grid-column: -1 / 1;
193
+ user-select: none;
194
+ span {
195
+ display: flex;
196
+ align-items: center;
197
+ justify-content: center;
198
+ }
199
+ }
200
+
201
+ .month {
202
+ padding-inline: 0.5rem;
203
+ }
204
+
205
+ .week {
206
+ grid-column: 1 / -1;
207
+ }
208
+
209
+ .week-number {
210
+ opacity: 0.5;
211
+ display: flex;
212
+ align-items: center;
213
+ justify-content: center;
214
+ }
215
+
216
+ .day {
217
+ width: var(--mo-calendar-item-size);
218
+ height: var(--mo-calendar-item-size);
219
+ }
220
220
  `;
221
221
  }
222
222
  get includeWeekNumber() {
@@ -232,74 +232,74 @@ let Calendar = Calendar_1 = class Calendar extends Component {
232
232
  return `day-${date.dayOfWeek}`;
233
233
  }
234
234
  get template() {
235
- return html `
236
- <div class='scroller' data-view=${this.view.key}>
237
- ${repeat(this.datesController.data, d => d.toString(), d => this.getYearTemplate(d))}
238
- </div>
235
+ return html `
236
+ <div class='scroller' data-view=${this.view.key}>
237
+ ${repeat(this.datesController.data, d => d.toString(), d => this.getYearTemplate(d))}
238
+ </div>
239
239
  `;
240
240
  }
241
241
  getYearTemplate(date) {
242
- return html `
243
- ${date.dayOfYear !== 1 ? html.nothing : html `
244
- <div class='year' role='button'
245
- data-view=${this.view.key}
246
- ?data-navigating=${this.isNavigating(date, FieldDateTimePrecision.Year)}
247
- ?data-now=${this.isNow(date, FieldDateTimePrecision.Year)}
248
- ?data-start=${this.isStart(date, FieldDateTimePrecision.Year)}
249
- ?data-end=${this.isEnd(date, FieldDateTimePrecision.Year)}
250
- ?data-in-range=${this.isInRange(date, FieldDateTimePrecision.Year)}
251
- ?data-disabled=${this.isDisabled(date, FieldDateTimePrecision.Year)}
252
- @click=${this.handleItemClick(date, FieldDateTimePrecision.Year)}
253
- ${this.datesController.observerIntersectionNavigation(date, FieldDateTimePrecision.Month, FieldDateTimePrecision.Year)}
254
- >
255
- ${date.format({ year: 'numeric' })}
256
- </div>
257
- `}
258
-
259
- ${this.view < FieldDateTimePrecision.Month || date.day !== 1 ? html.nothing : this.getMonthTemplate(date)}
242
+ return html `
243
+ ${date.dayOfYear !== 1 ? html.nothing : html `
244
+ <div class='year' role='button'
245
+ data-view=${this.view.key}
246
+ ?data-navigating=${this.isNavigating(date, FieldDateTimePrecision.Year)}
247
+ ?data-now=${this.isNow(date, FieldDateTimePrecision.Year)}
248
+ ?data-start=${this.isStart(date, FieldDateTimePrecision.Year)}
249
+ ?data-end=${this.isEnd(date, FieldDateTimePrecision.Year)}
250
+ ?data-in-range=${this.isInRange(date, FieldDateTimePrecision.Year)}
251
+ ?data-disabled=${this.isDisabled(date, FieldDateTimePrecision.Year)}
252
+ @click=${this.handleItemClick(date, FieldDateTimePrecision.Year)}
253
+ ${this.datesController.observerIntersectionNavigation(date, FieldDateTimePrecision.Month, FieldDateTimePrecision.Year)}
254
+ >
255
+ ${date.format({ year: 'numeric' })}
256
+ </div>
257
+ `}
258
+
259
+ ${this.view < FieldDateTimePrecision.Month || date.day !== 1 ? html.nothing : this.getMonthTemplate(date)}
260
260
  `;
261
261
  }
262
262
  static get weekDaysTemplate() {
263
- return html `
264
- <mo-grid class='weekdays' columns='subgrid'>
263
+ return html `
264
+ <mo-grid class='weekdays' columns='subgrid'>
265
265
  ${CalendarDatesController.sampleWeek.map((day, index) => {
266
266
  const { narrow, short, long } = {
267
267
  narrow: day.format({ weekday: 'narrow' }),
268
268
  short: day.format({ weekday: 'short' }),
269
269
  long: day.format({ weekday: 'long' }),
270
270
  };
271
- return html `
272
- <span style='grid-column: day-${index + 1}' title=${long}>
273
- ${long === short ? narrow : short}
274
- </span>
271
+ return html `
272
+ <span style='grid-column: day-${index + 1}' title=${long}>
273
+ ${long === short ? narrow : short}
274
+ </span>
275
275
  `;
276
- })}
277
- </mo-grid>
276
+ })}
277
+ </mo-grid>
278
278
  `;
279
279
  }
280
280
  getMonthTemplate(date) {
281
- return html `
282
- <mo-flex class='month-container' data-view=${this.view.key}>
283
- <div class='month' role='button'
284
- data-view=${this.view.key}
285
- ?data-navigating=${this.isNavigating(date, FieldDateTimePrecision.Month)}
286
- ?data-now=${this.isNow(date, FieldDateTimePrecision.Month)}
287
- ?data-start=${this.isStart(date, FieldDateTimePrecision.Month)}
288
- ?data-end=${this.isEnd(date, FieldDateTimePrecision.Month)}
289
- ?data-in-range=${this.isInRange(date, FieldDateTimePrecision.Month)}
290
- ?data-disabled=${this.isDisabled(date, FieldDateTimePrecision.Month)}
291
- @click=${this.handleItemClick(date, FieldDateTimePrecision.Month)}
292
- ${this.datesController.observerIntersectionNavigation(date, FieldDateTimePrecision.Day)}
293
- >
294
- ${date.format(this.view > FieldDateTimePrecision.Month ? { year: 'numeric', month: 'long' } : { month: 'long' })}
295
- </div>
296
- ${this.view < FieldDateTimePrecision.Week ? html.nothing : html `
297
- <mo-grid justifyContent='center' autoRows='var(--mo-calendar-item-size)' columns=${this.view > FieldDateTimePrecision.Month ? this.columns : 'auto'}>
298
- ${Calendar_1.weekDaysTemplate}
299
- ${this.datesController.data.filter(d => d.year === date.year && d.month === date.month).map((day, _, month) => this.getWeekTemplate(day, month))}
300
- </mo-grid>
301
- `}
302
- </mo-flex>
281
+ return html `
282
+ <mo-flex class='month-container' data-view=${this.view.key}>
283
+ <div class='month' role='button'
284
+ data-view=${this.view.key}
285
+ ?data-navigating=${this.isNavigating(date, FieldDateTimePrecision.Month)}
286
+ ?data-now=${this.isNow(date, FieldDateTimePrecision.Month)}
287
+ ?data-start=${this.isStart(date, FieldDateTimePrecision.Month)}
288
+ ?data-end=${this.isEnd(date, FieldDateTimePrecision.Month)}
289
+ ?data-in-range=${this.isInRange(date, FieldDateTimePrecision.Month)}
290
+ ?data-disabled=${this.isDisabled(date, FieldDateTimePrecision.Month)}
291
+ @click=${this.handleItemClick(date, FieldDateTimePrecision.Month)}
292
+ ${this.datesController.observerIntersectionNavigation(date, FieldDateTimePrecision.Day)}
293
+ >
294
+ ${date.format(this.view > FieldDateTimePrecision.Month ? { year: 'numeric', month: 'long' } : { month: 'long' })}
295
+ </div>
296
+ ${this.view < FieldDateTimePrecision.Week ? html.nothing : html `
297
+ <mo-grid justifyContent='center' autoRows='var(--mo-calendar-item-size)' columns=${this.view > FieldDateTimePrecision.Month ? this.columns : 'auto'}>
298
+ ${Calendar_1.weekDaysTemplate}
299
+ ${this.datesController.data.filter(d => d.year === date.year && d.month === date.month).map((day, _, month) => this.getWeekTemplate(day, month))}
300
+ </mo-grid>
301
+ `}
302
+ </mo-flex>
303
303
  `;
304
304
  }
305
305
  getWeekTemplate(date, month) {
@@ -309,40 +309,40 @@ let Calendar = Calendar_1 = class Calendar extends Component {
309
309
  if (date !== month.find(d => d.weekOfYear === date.weekOfYear && d.yearOfWeek === date.yearOfWeek)) {
310
310
  return html.nothing;
311
311
  }
312
- return html `
313
- <mo-grid class='week' columns='subgrid'
314
- data-view=${this.view.key}
315
- ?data-navigating=${this.isNavigating(date, FieldDateTimePrecision.Week)}
316
- ?data-now=${this.isNow(date, FieldDateTimePrecision.Week)}
317
- ?data-start=${this.isStart(date, FieldDateTimePrecision.Week)}
318
- ?data-end=${this.isEnd(date, FieldDateTimePrecision.Week)}
319
- ?data-in-range=${this.isInRange(date, FieldDateTimePrecision.Week)}
320
- ?data-disabled=${this.isDisabled(date, FieldDateTimePrecision.Week)}
321
- @click=${this.precision === FieldDateTimePrecision.Day ? html.nothing : this.handleItemClick(date, FieldDateTimePrecision.Week)}
322
- ${this.datesController.observerIntersectionNavigation(date, FieldDateTimePrecision.Week)}
323
- >
324
- ${month.filter(d => d.weekOfYear === date.weekOfYear && d.yearOfWeek === date.yearOfWeek).map(day => this.getDayTemplate(day))}
325
- </mo-grid>
312
+ return html `
313
+ <mo-grid class='week' columns='subgrid'
314
+ data-view=${this.view.key}
315
+ ?data-navigating=${this.isNavigating(date, FieldDateTimePrecision.Week)}
316
+ ?data-now=${this.isNow(date, FieldDateTimePrecision.Week)}
317
+ ?data-start=${this.isStart(date, FieldDateTimePrecision.Week)}
318
+ ?data-end=${this.isEnd(date, FieldDateTimePrecision.Week)}
319
+ ?data-in-range=${this.isInRange(date, FieldDateTimePrecision.Week)}
320
+ ?data-disabled=${this.isDisabled(date, FieldDateTimePrecision.Week)}
321
+ @click=${this.precision === FieldDateTimePrecision.Day ? html.nothing : this.handleItemClick(date, FieldDateTimePrecision.Week)}
322
+ ${this.datesController.observerIntersectionNavigation(date, FieldDateTimePrecision.Week)}
323
+ >
324
+ ${month.filter(d => d.weekOfYear === date.weekOfYear && d.yearOfWeek === date.yearOfWeek).map(day => this.getDayTemplate(day))}
325
+ </mo-grid>
326
326
  `;
327
327
  }
328
328
  getDayTemplate(day) {
329
- return html `
330
- ${this.includeWeekNumber === false || day.dayOfWeek !== 1 ? html.nothing : html `
331
- <div class='week-number' style='grid-column: week-number'>${day.weekOfYear?.format()}</div>
332
- `}
333
- <div tabindex='0' role='button' class='day'
334
- style='grid-column: ${this.getColumnName(day)}'
335
- data-view=${this.view.key}
336
- ?data-navigating=${this.isNavigating(day, FieldDateTimePrecision.Day)}
337
- ?data-now=${this.isNow(day, FieldDateTimePrecision.Day)}
338
- ?data-start=${this.isStart(day, FieldDateTimePrecision.Day)}
339
- ?data-end=${this.isEnd(day, FieldDateTimePrecision.Day)}
340
- ?data-in-range=${this.isInRange(day, FieldDateTimePrecision.Day)}
341
- ?data-disabled=${this.isDisabled(day, FieldDateTimePrecision.Day)}
342
- @click=${this.precision === FieldDateTimePrecision.Week ? html.nothing : this.handleItemClick(day, FieldDateTimePrecision.Day)}
343
- >
344
- ${day.format({ day: 'numeric' })}
345
- </div>
329
+ return html `
330
+ ${this.includeWeekNumber === false || day.dayOfWeek !== 1 ? html.nothing : html `
331
+ <div class='week-number' style='grid-column: week-number'>${day.weekOfYear?.format()}</div>
332
+ `}
333
+ <div tabindex='0' role='button' class='day'
334
+ style='grid-column: ${this.getColumnName(day)}'
335
+ data-view=${this.view.key}
336
+ ?data-navigating=${this.isNavigating(day, FieldDateTimePrecision.Day)}
337
+ ?data-now=${this.isNow(day, FieldDateTimePrecision.Day)}
338
+ ?data-start=${this.isStart(day, FieldDateTimePrecision.Day)}
339
+ ?data-end=${this.isEnd(day, FieldDateTimePrecision.Day)}
340
+ ?data-in-range=${this.isInRange(day, FieldDateTimePrecision.Day)}
341
+ ?data-disabled=${this.isDisabled(day, FieldDateTimePrecision.Day)}
342
+ @click=${this.precision === FieldDateTimePrecision.Week ? html.nothing : this.handleItemClick(day, FieldDateTimePrecision.Day)}
343
+ >
344
+ ${day.format({ day: 'numeric' })}
345
+ </div>
346
346
  `;
347
347
  }
348
348
  isDisabled(date, precision) {
@@ -3,11 +3,17 @@ import type { Calendar } from './Calendar.js';
3
3
  import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
4
4
  export declare class CalendarDatesController extends Controller {
5
5
  readonly host: Calendar;
6
+ private static readonly cacheKey;
6
7
  static get today(): import("@3mo/date-time/DateTime.js").DateTime;
7
8
  private static generate;
8
- private static _sampleWeek;
9
- static get sampleWeek(): ReadonlyArray<DateTime>;
9
+ private static _sampleWeek?;
10
+ static get sampleWeek(): readonly import("@3mo/date-time/DateTime.js").DateTime[];
10
11
  private static generateWeek;
12
+ private static readonly connectedControllers;
13
+ hostConnected(): void;
14
+ hostDisconnected(): void;
15
+ /** Discards every generated date and regenerates them for the current calendar. */
16
+ private invalidate;
11
17
  disableObservers: boolean;
12
18
  observerIntersectionNavigation(date: DateTime, ...views: Array<FieldDateTimePrecision>): DirectiveResult<any>;
13
19
  constructor(host: Calendar);
@@ -1 +1 @@
1
- {"version":3,"file":"CalendarDatesController.d.ts","sourceRoot":"","sources":["../../selection/CalendarDatesController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAGlE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAErE,qBAAa,uBAAwB,SAAQ,UAAU;aAkCxB,IAAI,EAAE,QAAQ;IAhC5C,MAAM,KAAK,KAAK,kDAAqC;IAErD,OAAO,CAAC,MAAM,CAAE,QAAQ;IAMxB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAwB;IAClD,MAAM,KAAK,UAAU,IAAgC,aAAa,CAAC,QAAQ,CAAC,CAAE;IAE9E,OAAO,CAAC,MAAM,CAAC,YAAY;IAW3B,gBAAgB,UAAQ;IAExB,8BAA8B,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,KAAK,CAAC,sBAAsB,CAAC;gBAQxD,IAAI,EAAE,QAAQ;IAK5C,OAAO,CAAC,IAAI,CAAwB;IACpC,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,KAAK,CAAwB;IAErC,IAAI,IAAI,oDASP;IAED,OAAO,CAAC,eAAe,CAAW;IAClC,IAAI,cAAc,kDAAkC;IACpD,IAAI,cAAc,CAAC,KAAK,+CAAA,EAsCvB;CACD"}
1
+ {"version":3,"file":"CalendarDatesController.d.ts","sourceRoot":"","sources":["../../selection/CalendarDatesController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAIlE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAErE,qBAAa,uBAAwB,SAAQ,UAAU;aAoExB,IAAI,EAAE,QAAQ;IAnE5C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAA4B;IAG5D,MAAM,KAAK,KAAK,kDAAqC;IAErD,OAAO,CAAC,MAAM,CAAE,QAAQ;IAMxB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAyB;IACpD,MAAM,KAAK,UAAU,6DAA4F;IAEjH,OAAO,CAAC,MAAM,CAAC,YAAY;IAO3B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAqC;IAoBxE,aAAa;IAIb,gBAAgB;IAIzB,mFAAmF;IACnF,OAAO,CAAC,UAAU;IAOlB,gBAAgB,UAAQ;IAExB,8BAA8B,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,KAAK,CAAC,sBAAsB,CAAC;gBAQxD,IAAI,EAAE,QAAQ;IAK5C,OAAO,CAAC,IAAI,CAAwB;IACpC,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,KAAK,CAAwB;IAErC,IAAI,IAAI,oDASP;IAED,OAAO,CAAC,eAAe,CAAW;IAClC,IAAI,cAAc,kDAAkC;IACpD,IAAI,cAAc,CAAC,KAAK,+CAAA,EAsCvB;CACD"}
@@ -1,25 +1,54 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { Controller, html } from '@a11d/lit';
3
3
  import { observeIntersection } from '@3mo/intersection-observer';
4
- import { MemoizeExpiring as memoizeExpiring } from 'typescript-memoize';
4
+ import { Memoize as memoize, clear } from 'typescript-memoize';
5
+ import { Localizer } from '@3mo/localization';
5
6
  import { FieldDateTimePrecision } from '../FieldDateTimePrecision.js';
6
7
  export class CalendarDatesController extends Controller {
8
+ static { this.cacheKey = 'CalendarDatesController'; }
7
9
  static get today() { return new DateTime().dayStart; }
8
10
  static *generate(start, count, step) {
9
11
  for (let i = 0; i < count; i++) {
10
12
  yield start.add({ [step]: i });
11
13
  }
12
14
  }
13
- static { this._sampleWeek = new Array(); }
14
- static get sampleWeek() { return this._sampleWeek; }
15
+ static get sampleWeek() { return CalendarDatesController._sampleWeek ??= CalendarDatesController.generateWeek(); }
15
16
  static generateWeek() {
16
17
  const sample = [...CalendarDatesController.generate(CalendarDatesController.today, CalendarDatesController.today.daysInWeek * 2, 'days')];
17
18
  const indexOfFirstWeekStart = sample.findIndex(d => d.dayOfWeek === 1);
18
19
  const daysInWeek = sample[0].daysInWeek;
19
- CalendarDatesController._sampleWeek = sample.slice(indexOfFirstWeekStart, indexOfFirstWeekStart + daysInWeek).map(d => d.dayStart);
20
+ return sample.slice(indexOfFirstWeekStart, indexOfFirstWeekStart + daysInWeek).map(d => d.dayStart);
20
21
  }
22
+ static { this.connectedControllers = new Set(); }
21
23
  static {
22
- CalendarDatesController.generateWeek();
24
+ // `DateTime` freezes its calendar and time zone at construction, so every date which has already
25
+ // been generated still belongs to the previous language's calendar. Without discarding them,
26
+ // switching language only re-formats the existing Gregorian grid instead of rebuilding it.
27
+ Localizer.languages.change.subscribe(() => {
28
+ // Deferred so that every other subscriber has run first — in particular `DateTime`, which
29
+ // clears its own memoized calendar and time zone on the very same event. Regenerating any
30
+ // date before that happens would just reproduce the outgoing calendar.
31
+ queueMicrotask(() => {
32
+ clear([CalendarDatesController.cacheKey]);
33
+ CalendarDatesController._sampleWeek = undefined;
34
+ for (const controller of CalendarDatesController.connectedControllers) {
35
+ controller.invalidate();
36
+ }
37
+ });
38
+ });
39
+ }
40
+ hostConnected() {
41
+ CalendarDatesController.connectedControllers.add(this);
42
+ }
43
+ hostDisconnected() {
44
+ CalendarDatesController.connectedControllers.delete(this);
45
+ }
46
+ /** Discards every generated date and regenerates them for the current calendar. */
47
+ invalidate() {
48
+ this.days = [];
49
+ this.months = [];
50
+ this.years = [];
51
+ this.navigationDate = DateTime.from(this._navigationDate.valueOf());
23
52
  }
24
53
  observerIntersectionNavigation(date, ...views) {
25
54
  return !views.includes(this.host.view) ? html.nothing : observeIntersection(data => {
@@ -72,5 +101,5 @@ export class CalendarDatesController extends Controller {
72
101
  }
73
102
  }
74
103
  __decorate([
75
- memoizeExpiring(60_000)
104
+ memoize({ expiring: 60_000, tags: [CalendarDatesController.cacheKey] })
76
105
  ], CalendarDatesController, "today", null);