@3mo/date-time-fields 0.10.1 → 0.10.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"FieldDateTime.d.ts","sourceRoot":"","sources":["../FieldDateTime.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAOpE;;;;GAIG;AACH,qBACa,aAAc,SAAQ,iBAAiB,CAAC,IAAI,GAAG,SAAS,CAAC;IACrE,SAAS,KAAK,YAAY,8DAA+D;IAEpE,KAAK,SAAmB;IACjB,KAAK,CAAC,EAAE,IAAI,CAAA;IAExC,cACuB,WAAW,WAEjC;IAED,SAAS,CAAC,mBAAmB;IAI7B,SAAS,KAAK,gBAAgB,0CAQ7B;cAEkB,wBAAwB,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,sBAAsB;IAK7F,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,IAAI,GAAG,SAAS;IAInD,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM;CAGzC;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,oBAAoB,EAAE,aAAa,CAAA;KACnC;CACD"}
1
+ {"version":3,"file":"FieldDateTime.d.ts","sourceRoot":"","sources":["../FieldDateTime.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAOpE;;;;GAIG;AACH,qBACa,aAAc,SAAQ,iBAAiB,CAAC,IAAI,GAAG,SAAS,CAAC;IACrE,SAAS,KAAK,YAAY,8DAQzB;IAEoB,KAAK,SAAmB;IACjB,KAAK,CAAC,EAAE,IAAI,CAAA;IAExC,cACuB,WAAW,WAEjC;IAED,SAAS,CAAC,mBAAmB;IAI7B,SAAS,KAAK,gBAAgB,0CAQ7B;cAEkB,wBAAwB,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,sBAAsB;IAK7F,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,IAAI,GAAG,SAAS;IAInD,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM;CAGzC;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,oBAAoB,EAAE,aAAa,CAAA;KACnC;CACD"}
@@ -17,7 +17,15 @@ let FieldDateTime = class FieldDateTime extends FieldDateTimeBase {
17
17
  super(...arguments);
18
18
  this.label = t('Date & Time');
19
19
  }
20
- get selectedDate() { return this.value ? new DateTime(this.value) : undefined; }
20
+ get selectedDate() {
21
+ if (!this.value) {
22
+ return undefined;
23
+ }
24
+ if (this.value instanceof Date) {
25
+ return new DateTime(this.value);
26
+ }
27
+ return this.value;
28
+ }
21
29
  get placeholder() {
22
30
  return new DateTime().format(this.formatOptions);
23
31
  }
@@ -28,8 +36,8 @@ let FieldDateTime = class FieldDateTime extends FieldDateTimeBase {
28
36
  return html `
29
37
  <mo-selectable-calendar
30
38
  .navigatingValue=${this.navigatingDate}
31
- .value=${this.selectedDate}
32
- @change=${(e) => this.handleSelectedDateChange(e.detail, FieldDateTimePrecision.Day)}
39
+ .value=${new DateTimeRange(this.selectedDate, this.selectedDate)}
40
+ @dayClick=${(e) => this.handleSelectedDateChange(e.detail, FieldDateTimePrecision.Day)}
33
41
  ></mo-selectable-calendar>
34
42
  `;
35
43
  }
@@ -14,6 +14,9 @@ export declare abstract class FieldDateTimeBase<T> extends InputFieldComponent<T
14
14
  shortcutReferenceDate: import("@3mo/date-time/DateTime.js").DateTime;
15
15
  precision: FieldDateTimePrecision;
16
16
  navigatingDate: import("@3mo/date-time/DateTime.js").DateTime;
17
+ protected connected(): void;
18
+ protected disconnected(): void;
19
+ private handleLanguageChange;
17
20
  protected readonly calendarIconButtonIcon: MaterialIcon;
18
21
  protected abstract get selectedDate(): DateTime | undefined;
19
22
  protected get formatOptions(): Intl.DateTimeFormatOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"FieldDateTimeBase.d.ts","sourceRoot":"","sources":["../FieldDateTimeBase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAAwD,MAAM,WAAW,CAAA;AACzG,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAEpE;;;;;GAKG;AACH,8BAAsB,iBAAiB,CAAC,CAAC,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IAC5B,IAAI,UAAQ;IAC3B,YAAY,UAAQ;IACrB,qBAAqB,gDAAe;IACkC,SAAS,yBAAgC;IAElI,cAAc,gDAAiB;IAExC,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,YAAY,CAAU;IAEjE,SAAS,CAAC,QAAQ,KAAK,YAAY,IAAI,QAAQ,GAAG,SAAS,CAAA;IAE3D,SAAS,KAAK,aAAa,IAAI,IAAI,CAAC,qBAAqB,CAMxD;cAEkB,YAAY;IAK/B,SAAS,CAAC,QAAQ,CAAC,mBAAmB,IAAI,IAAI;cAE3B,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK;IAKpD,cAAuB,QAAQ,YAE9B;IAED,SAAS,KAAK,WAAW,WAExB;IAED,WAAoB,MAAM,kCA8CzB;IAED,cAAuB,QAAQ,uBAK9B;IAED,cAAuB,eAAe,uBAMrC;IAED,cAAuB,aAAa,uBAanC;IAED,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;uBACtC,iBAAiB,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,MAAM;IAE3E,OAAO,KAAK,uBAAuB,GAYlC;IAED,SAAS,KAAK,0BAA0B,uBAOvC;IAED,SAAS,KAAK,eAAe,uBAM5B;IAED,SAAS,KAAK,sBAAsB,uBAOnC;IAED,SAAS,KAAK,YAAY,uBAMzB;IAED,OAAO,KAAK,gBAAgB,GAQ3B;IAED,OAAO,KAAK,iBAAiB,GAQ5B;IAED,OAAO,KAAK,WAAW,GAEtB;IAED,SAAS,CAAC,QAAQ,KAAK,gBAAgB,IAAI,kBAAkB,CAAA;IAE7D,OAAO,KAAK,YAAY,GAcvB;IAED,OAAO,KAAK,gBAAgB,GAQ3B;IAED,OAAO,KAAK,kBAAkB,GAQ7B;IAED,OAAO,KAAK,kBAAkB,GAQ7B;IAED,SAAS,CAAC,wBAAwB,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,sBAAsB;CAMpF"}
1
+ {"version":3,"file":"FieldDateTimeBase.d.ts","sourceRoot":"","sources":["../FieldDateTimeBase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAAwD,MAAM,WAAW,CAAA;AACzG,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAEpE;;;;;GAKG;AACH,8BAAsB,iBAAiB,CAAC,CAAC,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IAC5B,IAAI,UAAQ;IAC3B,YAAY,UAAQ;IACrB,qBAAqB,gDAAe;IACkC,SAAS,yBAAgC;IAElI,cAAc,gDAAiB;cAErB,SAAS;cAIT,YAAY;IAI/B,OAAO,CAAC,oBAAoB,CAE3B;IAED,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,YAAY,CAAU;IAEjE,SAAS,CAAC,QAAQ,KAAK,YAAY,IAAI,QAAQ,GAAG,SAAS,CAAA;IAE3D,SAAS,KAAK,aAAa,IAAI,IAAI,CAAC,qBAAqB,CAMxD;cAEkB,YAAY;IAK/B,SAAS,CAAC,QAAQ,CAAC,mBAAmB,IAAI,IAAI;cAE3B,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK;IAKpD,cAAuB,QAAQ,YAE9B;IAED,SAAS,KAAK,WAAW,WAExB;IAED,WAAoB,MAAM,kCA8CzB;IAED,cAAuB,QAAQ,uBAK9B;IAED,cAAuB,eAAe,uBAMrC;IAED,cAAuB,aAAa,uBAanC;IAED,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;uBACtC,iBAAiB,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,MAAM;IAE3E,OAAO,KAAK,uBAAuB,GAYlC;IAED,SAAS,KAAK,0BAA0B,uBAOvC;IAED,SAAS,KAAK,eAAe,uBAM5B;IAED,SAAS,KAAK,sBAAsB,uBAOnC;IAED,SAAS,KAAK,YAAY,uBAMzB;IAED,OAAO,KAAK,gBAAgB,GAQ3B;IAED,OAAO,KAAK,iBAAiB,GAQ5B;IAED,OAAO,KAAK,WAAW,GAEtB;IAED,SAAS,CAAC,QAAQ,KAAK,gBAAgB,IAAI,kBAAkB,CAAA;IAE7D,OAAO,KAAK,YAAY,GAcvB;IAED,OAAO,KAAK,gBAAgB,GAQ3B;IAED,OAAO,KAAK,kBAAkB,GAQ7B;IAED,OAAO,KAAK,kBAAkB,GAQ7B;IAED,SAAS,CAAC,wBAAwB,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,sBAAsB;CAMpF"}
@@ -16,8 +16,17 @@ export class FieldDateTimeBase extends InputFieldComponent {
16
16
  this.shortcutReferenceDate = new DateTime;
17
17
  this.precision = FieldDateTimePrecision.Minute;
18
18
  this.navigatingDate = new DateTime();
19
+ this.handleLanguageChange = () => {
20
+ this.navigatingDate = new DateTime(this.navigatingDate);
21
+ };
19
22
  this.calendarIconButtonIcon = 'today';
20
23
  }
24
+ connected() {
25
+ Localizer.languages.change.subscribe(this.handleLanguageChange);
26
+ }
27
+ disconnected() {
28
+ Localizer.languages.change.unsubscribe(this.handleLanguageChange);
29
+ }
21
30
  get formatOptions() {
22
31
  return {
23
32
  calendar: this.selectedDate?.calendarId,
@@ -59,12 +59,12 @@ let FieldDateTimeRange = class FieldDateTimeRange extends FieldDateTimeBase {
59
59
  }
60
60
  get calendarTemplate() {
61
61
  return html `
62
- <mo-selectable-range-calendar
62
+ <mo-selectable-calendar
63
63
  data-selection=${this.selection}
64
64
  .navigatingValue=${this.navigatingDate}
65
- .dateRange=${this.value}
66
- @change=${(e) => this.handleSelectedDateChange(e.detail, FieldDateTimePrecision.Day)}
67
- ></mo-selectable-range-calendar>
65
+ .value=${this.value}
66
+ @dayClick=${(e) => this.handleSelectedDateChange(e.detail, FieldDateTimePrecision.Day)}
67
+ ></mo-selectable-calendar>
68
68
  `;
69
69
  }
70
70
  get popoverContentTemplate() {
@@ -3579,29 +3579,11 @@
3579
3579
  "path": ".\\packages\\DateTimeFields\\dist\\selection\\calendar\\Calendar.d.ts",
3580
3580
  "properties": [
3581
3581
  {
3582
- "name": "includeWeekNumbers",
3583
- "type": "boolean"
3584
- },
3585
- {
3586
- "name": "navigatingValue",
3587
- "type": "DateTime"
3588
- }
3589
- ]
3590
- },
3591
- {
3592
- "name": "mo-selectable-calendar",
3593
- "path": ".\\packages\\DateTimeFields\\dist\\selection\\calendar\\SelectableCalendar.d.ts",
3594
- "properties": [
3595
- {
3596
- "name": "change",
3582
+ "name": "dayClick",
3597
3583
  "type": "EventDispatcher<DateTime>"
3598
3584
  },
3599
3585
  {
3600
- "name": "value",
3601
- "type": "DateTime | undefined"
3602
- },
3603
- {
3604
- "name": "includeWeekNumbers",
3586
+ "name": "includeWeek",
3605
3587
  "type": "boolean"
3606
3588
  },
3607
3589
  {
@@ -3611,29 +3593,26 @@
3611
3593
  ],
3612
3594
  "events": [
3613
3595
  {
3614
- "name": "change",
3596
+ "name": "dayClick",
3597
+ "description": "Dispatched when a day is clicked, with the clicked date as detail.",
3615
3598
  "type": "CustomEvent<DateTime>"
3616
3599
  }
3617
3600
  ]
3618
3601
  },
3619
3602
  {
3620
- "name": "mo-selectable-range-calendar",
3621
- "path": ".\\packages\\DateTimeFields\\dist\\selection\\calendar\\SelectableRangeCalendar.d.ts",
3603
+ "name": "mo-selectable-calendar",
3604
+ "path": ".\\packages\\DateTimeFields\\dist\\selection\\calendar\\SelectableCalendar.d.ts",
3622
3605
  "properties": [
3623
3606
  {
3624
- "name": "dateRange",
3607
+ "name": "value",
3625
3608
  "type": "DateTimeRange | undefined"
3626
3609
  },
3627
3610
  {
3628
- "name": "change",
3611
+ "name": "dayClick",
3629
3612
  "type": "EventDispatcher<DateTime>"
3630
3613
  },
3631
3614
  {
3632
- "name": "value",
3633
- "type": "DateTime | undefined"
3634
- },
3635
- {
3636
- "name": "includeWeekNumbers",
3615
+ "name": "includeWeek",
3637
3616
  "type": "boolean"
3638
3617
  },
3639
3618
  {
@@ -3643,7 +3622,8 @@
3643
3622
  ],
3644
3623
  "events": [
3645
3624
  {
3646
- "name": "change",
3625
+ "name": "dayClick",
3626
+ "description": "Dispatched when a day is clicked, with the clicked date as detail.",
3647
3627
  "type": "CustomEvent<DateTime>"
3648
3628
  }
3649
3629
  ]
@@ -3893,41 +3873,7 @@
3893
3873
  "path": ".\\packages\\DateTimeFields\\selection\\calendar\\Calendar.ts",
3894
3874
  "attributes": [
3895
3875
  {
3896
- "name": "includeWeekNumbers",
3897
- "type": "boolean",
3898
- "default": "false"
3899
- },
3900
- {
3901
- "name": "navigatingValue",
3902
- "type": "DateTime",
3903
- "default": "\"new DateTime\""
3904
- }
3905
- ],
3906
- "properties": [
3907
- {
3908
- "name": "includeWeekNumbers",
3909
- "attribute": "includeWeekNumbers",
3910
- "type": "boolean",
3911
- "default": "false"
3912
- },
3913
- {
3914
- "name": "navigatingValue",
3915
- "attribute": "navigatingValue",
3916
- "type": "DateTime",
3917
- "default": "\"new DateTime\""
3918
- }
3919
- ]
3920
- },
3921
- {
3922
- "name": "mo-selectable-calendar",
3923
- "path": ".\\packages\\DateTimeFields\\selection\\calendar\\SelectableCalendar.ts",
3924
- "attributes": [
3925
- {
3926
- "name": "value",
3927
- "type": "DateTime | undefined"
3928
- },
3929
- {
3930
- "name": "includeWeekNumbers",
3876
+ "name": "includeWeek",
3931
3877
  "type": "boolean",
3932
3878
  "default": "false"
3933
3879
  },
@@ -3939,17 +3885,12 @@
3939
3885
  ],
3940
3886
  "properties": [
3941
3887
  {
3942
- "name": "change",
3888
+ "name": "dayClick",
3943
3889
  "type": "EventDispatcher<DateTime>"
3944
3890
  },
3945
3891
  {
3946
- "name": "value",
3947
- "attribute": "value",
3948
- "type": "DateTime | undefined"
3949
- },
3950
- {
3951
- "name": "includeWeekNumbers",
3952
- "attribute": "includeWeekNumbers",
3892
+ "name": "includeWeek",
3893
+ "attribute": "includeWeek",
3953
3894
  "type": "boolean",
3954
3895
  "default": "false"
3955
3896
  },
@@ -3962,25 +3903,22 @@
3962
3903
  ],
3963
3904
  "events": [
3964
3905
  {
3965
- "name": "change",
3906
+ "name": "dayClick",
3907
+ "description": "Dispatched when a day is clicked, with the clicked date as detail.",
3966
3908
  "type": "CustomEvent<DateTime>"
3967
3909
  }
3968
3910
  ]
3969
3911
  },
3970
3912
  {
3971
- "name": "mo-selectable-range-calendar",
3972
- "path": ".\\packages\\DateTimeFields\\selection\\calendar\\SelectableRangeCalendar.ts",
3913
+ "name": "mo-selectable-calendar",
3914
+ "path": ".\\packages\\DateTimeFields\\selection\\calendar\\SelectableCalendar.ts",
3973
3915
  "attributes": [
3974
- {
3975
- "name": "dateRange",
3976
- "type": "DateTimeRange | undefined"
3977
- },
3978
3916
  {
3979
3917
  "name": "value",
3980
- "type": "DateTime | undefined"
3918
+ "type": "DateTimeRange | undefined"
3981
3919
  },
3982
3920
  {
3983
- "name": "includeWeekNumbers",
3921
+ "name": "includeWeek",
3984
3922
  "type": "boolean",
3985
3923
  "default": "false"
3986
3924
  },
@@ -3992,22 +3930,17 @@
3992
3930
  ],
3993
3931
  "properties": [
3994
3932
  {
3995
- "name": "dateRange",
3996
- "attribute": "dateRange",
3933
+ "name": "value",
3934
+ "attribute": "value",
3997
3935
  "type": "DateTimeRange | undefined"
3998
3936
  },
3999
3937
  {
4000
- "name": "change",
3938
+ "name": "dayClick",
4001
3939
  "type": "EventDispatcher<DateTime>"
4002
3940
  },
4003
3941
  {
4004
- "name": "value",
4005
- "attribute": "value",
4006
- "type": "DateTime | undefined"
4007
- },
4008
- {
4009
- "name": "includeWeekNumbers",
4010
- "attribute": "includeWeekNumbers",
3942
+ "name": "includeWeek",
3943
+ "attribute": "includeWeek",
4011
3944
  "type": "boolean",
4012
3945
  "default": "false"
4013
3946
  },
@@ -4020,7 +3953,8 @@
4020
3953
  ],
4021
3954
  "events": [
4022
3955
  {
4023
- "name": "change",
3956
+ "name": "dayClick",
3957
+ "description": "Dispatched when a day is clicked, with the clicked date as detail.",
4024
3958
  "type": "CustomEvent<DateTime>"
4025
3959
  }
4026
3960
  ]
@@ -1,16 +1,20 @@
1
1
  import { Component, type ClassInfo } from '@a11d/lit';
2
2
  import '@a11d/array.prototype.group';
3
+ /**
4
+ * @fires dayClick - Dispatched when a day is clicked, with the clicked date as detail.
5
+ */
3
6
  export declare class Calendar extends Component {
4
- includeWeekNumbers: boolean;
7
+ readonly dayClick: EventDispatcher<DateTime>;
8
+ private static rangeOf;
9
+ includeWeek: boolean;
5
10
  navigatingValue: import("@3mo/date-time/DateTime.js").DateTime;
6
11
  private days;
7
12
  static get styles(): import("@a11d/lit").CSSResult;
13
+ private get columns();
14
+ private getColumnName;
8
15
  protected get template(): import("lit-html").HTMLTemplateResult;
9
- private rangeOf;
10
- protected getDayTemplate(day: DateTime): import("lit-html").HTMLTemplateResult;
11
- protected handleDayClick(day: DateTime): void;
12
- private get today();
13
16
  protected getDayElementClasses(day: DateTime): ClassInfo;
17
+ private get today();
14
18
  }
15
19
  declare global {
16
20
  interface HTMLElementTagNameMap {
@@ -1 +1 @@
1
- {"version":3,"file":"Calendar.d.ts","sourceRoot":"","sources":["../../../selection/calendar/Calendar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA4C,KAAK,SAAS,EAAS,MAAM,WAAW,CAAA;AACtG,OAAO,6BAA6B,CAAA;AAGpC,qBACa,QAAS,SAAQ,SAAS;IACM,kBAAkB,UAAQ;IAUnE,eAAe,gDAAe;IAExB,OAAO,CAAC,IAAI,CAA2D;IAEhF,WAAoB,MAAM,kCAyDzB;IAED,cAAuB,QAAQ,0CAyB9B;IAED,OAAO,CAAG,OAAO;IAOjB,SAAS,CAAC,cAAc,CAAC,GAAG,EAAE,QAAQ;IAQtC,SAAS,CAAC,cAAc,CAAC,GAAG,EAAE,QAAQ;IAKtC,OAAO,KAAK,KAAK,GAAqC;IAEtD,SAAS,CAAC,oBAAoB,CAAC,GAAG,EAAE,QAAQ,GAAG,SAAS;CAOxD;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,aAAa,EAAE,QAAQ,CAAA;KACvB;CACD"}
1
+ {"version":3,"file":"Calendar.d.ts","sourceRoot":"","sources":["../../../selection/calendar/Calendar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA4C,KAAK,SAAS,EAAgB,MAAM,WAAW,CAAA;AAC7G,OAAO,6BAA6B,CAAA;AAGpC;;GAEG;AACH,qBACa,QAAS,SAAQ,SAAS;IAC7B,QAAQ,CAAC,QAAQ,EAAG,eAAe,CAAC,QAAQ,CAAC,CAAA;IAEtD,OAAO,CAAC,MAAM,CAAE,OAAO;IAOqB,WAAW,UAAQ;IAQ5D,eAAe,gDAAe;IAExB,OAAO,CAAC,IAAI,CAAwB;IAE7C,WAAoB,MAAM,kCA2DzB;IAED,OAAO,KAAK,OAAO,GAMlB;IAED,OAAO,CAAC,aAAa;IAIrB,cAAuB,QAAQ,0CAkC9B;IAED,SAAS,CAAC,oBAAoB,CAAC,GAAG,EAAE,QAAQ,GAAG,SAAS;IASxD,OAAO,KAAK,KAAK,GAAqC;CACtD;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,aAAa,EAAE,QAAQ,CAAA;KACvB;CACD"}
@@ -1,24 +1,32 @@
1
1
  import { __decorate } from "tslib";
2
- import { Component, css, component, html, property, classMap, state } from '@a11d/lit';
2
+ import { Component, css, component, html, property, classMap, state, event } from '@a11d/lit';
3
3
  import '@a11d/array.prototype.group';
4
4
  import { MemoizeExpiring as memoizeExpiring } from 'typescript-memoize';
5
+ /**
6
+ * @fires dayClick - Dispatched when a day is clicked, with the clicked date as detail.
7
+ */
5
8
  let Calendar = class Calendar extends Component {
6
9
  constructor() {
7
10
  super(...arguments);
8
- this.includeWeekNumbers = false;
11
+ this.includeWeek = false;
9
12
  this.navigatingValue = new DateTime;
10
13
  this.days = new Array();
11
14
  }
15
+ static *rangeOf(start, end) {
16
+ while (!start.isAfter(end)) {
17
+ yield start;
18
+ start = start.add({ days: 1 });
19
+ }
20
+ }
12
21
  static get styles() {
13
22
  return css `
14
23
  :host {
15
24
  --mo-calendar-day-size: 36px;
16
25
  --mo-calendar-week-number-width: var(--mo-calendar-day-size);
17
- padding-inline: 10px;
26
+ padding: 0.5rem;
18
27
  }
19
28
 
20
29
  .month {
21
- min-height: 270px;
22
30
  place-items: center;
23
31
 
24
32
  .heading {
@@ -28,11 +36,14 @@ let Calendar = class Calendar extends Component {
28
36
  place-self: stretch;
29
37
  display: flex;
30
38
  align-items: center;
31
- margin-inline-start: 6px;
39
+ padding-inline-start: 6px;
40
+ padding-block-end: 0.5rem;
32
41
  }
33
42
 
34
43
  .header {
44
+ text-align: center;
35
45
  color: var(--mo-color-gray);
46
+ padding-block: 0.25rem
36
47
  }
37
48
  }
38
49
 
@@ -67,49 +78,51 @@ let Calendar = class Calendar extends Component {
67
78
  }
68
79
  `;
69
80
  }
81
+ get columns() {
82
+ const daysInWeek = this.days[0]?.daysInWeek ?? 7;
83
+ return [
84
+ !this.includeWeek ? undefined : '[week] var(--mo-calendar-week-number-width)',
85
+ ...this.days.slice(0, daysInWeek).map(day => `[${this.getColumnName(day)}] var(--mo-calendar-day-size)`),
86
+ ].join(' ');
87
+ }
88
+ getColumnName(date) {
89
+ return `day-${date.dayOfWeek}`;
90
+ }
70
91
  get template() {
71
92
  return html `
72
93
  <mo-grid class='month'
73
94
  rows='repeat(auto-fill, var(--mo-calendar-day-size))'
74
- columns=${this.includeWeekNumbers ? 'var(--mo-calendar-week-number-width) repeat(7, var(--mo-calendar-day-size))' : 'repeat(7, var(--mo-calendar-day-size))'}
95
+ columns=${this.columns}
75
96
  >
76
97
  <div class='heading' style='grid-column: 1 / -1'>
77
98
  ${this.navigatingValue.format({ year: 'numeric' })}
78
99
  ${this.navigatingValue.format({ month: 'long' })}
79
100
  </div>
80
101
 
81
- ${this.includeWeekNumbers === false ? html.nothing : html `<div></div>`}
82
-
83
- ${this.navigatingValue.weekDayNames.map(dayName => html `
84
- <div class='header'>
85
- ${dayName.charAt(0).toUpperCase() + dayName.charAt(1)}
86
- </div>
87
- `)}
102
+ <mo-grid class='header' columns='subgrid' style='grid-column: 1 / -1'>
103
+ ${this.includeWeek === false ? html.nothing : html `<div></div>`}
104
+ ${this.days.slice(0, this.days[0]?.daysInWeek).map(day => html `
105
+ <span style='grid-column: ${this.getColumnName(day)}' title=${day.format({ weekday: 'long' })}>
106
+ ${day.format({ weekday: 'narrow' })}
107
+ </span>
108
+ `)}
109
+ </mo-grid>
88
110
 
89
- ${this.days.map(([weekNumber, days]) => html `
90
- ${this.includeWeekNumbers === false ? html.nothing : html `<div class='week'>${weekNumber}</div>`}
91
- ${days.map(day => this.getDayTemplate(day))}
111
+ ${this.days.map(day => html `
112
+ ${this.includeWeek === false || day.dayOfWeek !== 1 ? html.nothing : html `
113
+ <div class='week' style='grid-column: week'>${day.weekOfYear}</div>
114
+ `}
115
+ <mo-flex tabindex='0'
116
+ style='grid-column: ${this.getColumnName(day)}'
117
+ class=${classMap(this.getDayElementClasses(day))}
118
+ @click=${() => this.dayClick.dispatch(day)}
119
+ >
120
+ ${day.format({ day: 'numeric' })}
121
+ </mo-flex>
92
122
  `)}
93
123
  </mo-grid>
94
124
  `;
95
125
  }
96
- *rangeOf(start, end) {
97
- while (!start.isAfter(end)) {
98
- yield start;
99
- start = start.add({ days: 1 });
100
- }
101
- }
102
- getDayTemplate(day) {
103
- return html `
104
- <mo-flex tabindex='0' class=${classMap(this.getDayElementClasses(day))} @click=${() => this.handleDayClick(day)}>
105
- ${day.format({ day: 'numeric' })}
106
- </mo-flex>
107
- `;
108
- }
109
- handleDayClick(day) {
110
- day;
111
- }
112
- get today() { return new DateTime().dayStart; }
113
126
  getDayElementClasses(day) {
114
127
  return {
115
128
  day: true,
@@ -117,19 +130,21 @@ let Calendar = class Calendar extends Component {
117
130
  outsideMonth: day.month !== this.navigatingValue.month
118
131
  };
119
132
  }
133
+ get today() { return new DateTime().dayStart; }
120
134
  };
135
+ __decorate([
136
+ event()
137
+ ], Calendar.prototype, "dayClick", void 0);
121
138
  __decorate([
122
139
  property({ type: Boolean, reflect: true })
123
- ], Calendar.prototype, "includeWeekNumbers", void 0);
140
+ ], Calendar.prototype, "includeWeek", void 0);
124
141
  __decorate([
125
142
  property({
126
143
  type: Object,
127
144
  updated() {
128
145
  const start = this.navigatingValue.monthStart.weekStart;
129
146
  const end = this.navigatingValue.monthEnd.weekEnd;
130
- const range = [...this.rangeOf(start, end)];
131
- this.days = [...range.groupToMap(d => String(d.weekOfYear))]
132
- .sort(([, dates1], [, dates2]) => dates1[0]?.isBefore(dates2[0]) ? -1 : +1);
147
+ this.days = [...Calendar.rangeOf(start, end)];
133
148
  }
134
149
  })
135
150
  ], Calendar.prototype, "navigatingValue", void 0);
@@ -1,13 +1,14 @@
1
+ import { type PropertyValues } from '@a11d/lit';
1
2
  import { Calendar } from './Calendar.js';
2
3
  import { type DateTime } from '@3mo/date-time';
3
- /** @fires change */
4
4
  export declare class SelectableCalendar extends Calendar {
5
- readonly change: EventDispatcher<DateTime>;
6
- value?: DateTime;
5
+ value?: DateTimeRange;
6
+ private readonly monthElement;
7
+ protected updated(pops: PropertyValues<this>): void;
7
8
  static get styles(): import("@a11d/lit").CSSResult;
8
- protected static get calendarStyles(): import("@a11d/lit").CSSResult;
9
- protected handleDayClick(day: DateTime): void;
10
9
  protected getDayElementClasses(day: DateTime): {
10
+ start: boolean;
11
+ end: boolean;
11
12
  selected: boolean;
12
13
  };
13
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SelectableCalendar.d.ts","sourceRoot":"","sources":["../../../selection/calendar/SelectableCalendar.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE9C,oBAAoB;AACpB,qBACa,kBAAmB,SAAQ,QAAQ;IACtC,QAAQ,CAAC,MAAM,EAAG,eAAe,CAAC,QAAQ,CAAC,CAAA;IAExB,KAAK,CAAC,EAAE,QAAQ,CAAA;IAE5C,WAAoB,MAAM,kCAKzB;IAED,SAAS,CAAC,MAAM,KAAK,cAAc,kCAOlC;cAEkB,cAAc,CAAC,GAAG,EAAE,QAAQ;cAK5B,oBAAoB,CAAC,GAAG,EAAE,QAAQ;;;CAMrD;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,wBAAwB,EAAE,kBAAkB,CAAA;KAC5C;CACD"}
1
+ {"version":3,"file":"SelectableCalendar.d.ts","sourceRoot":"","sources":["../../../selection/calendar/SelectableCalendar.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,KAAK,cAAc,EAAE,MAAM,WAAW,CAAA;AAC3F,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE9C,qBACa,kBAAmB,SAAQ,QAAQ;IACnB,KAAK,CAAC,EAAE,aAAa,CAAA;IAEhC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;cAEzC,OAAO,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC;IASrD,WAAoB,MAAM,kCA0CzB;cAEkB,oBAAoB,CAAC,GAAG,EAAE,QAAQ;;;;;CAUrD;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,wBAAwB,EAAE,kBAAkB,CAAA;KAC5C;CACD"}
@@ -1,39 +1,75 @@
1
1
  import { __decorate } from "tslib";
2
- import { component, css, event, property } from '@a11d/lit';
2
+ import { component, css, property, query, unsafeCSS } from '@a11d/lit';
3
3
  import { Calendar } from './Calendar.js';
4
- /** @fires change */
5
4
  let SelectableCalendar = class SelectableCalendar extends Calendar {
5
+ updated(pops) {
6
+ super.updated(pops);
7
+ this.monthElement.dataset.selection = this.dataset.selection;
8
+ this.monthElement.toggleAttribute('data-start-exists', !!this.value?.start);
9
+ this.monthElement.toggleAttribute('data-end-exists', !!this.value?.end);
10
+ this.monthElement.toggleAttribute('data-start-behind', this.value?.start?.isBefore(this.navigatingValue.monthEnd.weekEnd) ?? false);
11
+ this.monthElement.toggleAttribute('data-end-ahead', this.value?.end?.isAfter(this.navigatingValue.monthEnd.weekEnd) ?? false);
12
+ }
6
13
  static get styles() {
14
+ const getRangeStyles = ({ start, end }) => {
15
+ return css `
16
+ .day${unsafeCSS(start)}, .day${unsafeCSS(end)} {
17
+ background: var(--mo-color-accent-transparent) !important;
18
+ color: color-mix(in srgb, var(--mo-color-accent), var(--mo-color-foreground));
19
+ }
20
+
21
+ .day${unsafeCSS(start)} ~ :not(${unsafeCSS(end)}):not(${unsafeCSS(end)} ~ *), /* Start is visible, end is visible or not */
22
+ &[data-start-exists]:has(${unsafeCSS(end)}):not(:has(${unsafeCSS(start)})) .day:not(${unsafeCSS(end)}):not(${unsafeCSS(end)} ~ *), /* Start is not visible, end is visible */
23
+ &[data-start-before][data-end-ahead] .day /* Start is before, end is after */
24
+ {
25
+ background: color-mix(in srgb, var(--mo-color-accent), transparent 92%);
26
+ }
27
+ `;
28
+ };
7
29
  return css `
8
30
  ${super.styles}
9
- ${this.calendarStyles}
10
- `;
11
- }
12
- static get calendarStyles() {
13
- return css `
31
+
14
32
  .day.selected {
15
33
  background: var(--mo-color-accent-transparent);
16
- color: var(--mo-color-accent) !important;
34
+ color: color-mix(in srgb, var(--mo-color-accent), var(--mo-color-foreground)) !important;
35
+ }
36
+
37
+ .month {
38
+ &:not(:hover) {
39
+ ${getRangeStyles({ start: '.selected.start', end: '.selected.end' })};
40
+ }
41
+
42
+ &:hover {
43
+ /* After start is selected: */
44
+ &[data-selection=end] {
45
+ ${getRangeStyles({ start: '.selected.start', end: ':hover' })};
46
+ }
47
+
48
+ /* After end is selected: */
49
+ &[data-selection=start] {
50
+ ${getRangeStyles({ start: ':hover', end: '.selected.end' })};
51
+ }
52
+ }
17
53
  }
18
54
  `;
19
55
  }
20
- handleDayClick(day) {
21
- this.value = day;
22
- this.change.dispatch(day);
23
- }
24
56
  getDayElementClasses(day) {
57
+ const start = this.value?.start?.dayStart.equals(day.dayStart) ?? false;
58
+ const end = this.value?.end?.dayStart.equals(day.dayStart) ?? false;
25
59
  return {
26
60
  ...super.getDayElementClasses(day),
27
- selected: !!this.value && day.equals(this.value),
61
+ start,
62
+ end,
63
+ selected: start || end,
28
64
  };
29
65
  }
30
66
  };
31
- __decorate([
32
- event()
33
- ], SelectableCalendar.prototype, "change", void 0);
34
67
  __decorate([
35
68
  property({ type: Object })
36
69
  ], SelectableCalendar.prototype, "value", void 0);
70
+ __decorate([
71
+ query('.month')
72
+ ], SelectableCalendar.prototype, "monthElement", void 0);
37
73
  SelectableCalendar = __decorate([
38
74
  component('mo-selectable-calendar')
39
75
  ], SelectableCalendar);
@@ -1,4 +1,3 @@
1
1
  export * from './Calendar.js';
2
2
  export * from './SelectableCalendar.js';
3
- export * from './SelectableRangeCalendar.js';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../selection/calendar/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,yBAAyB,CAAA;AACvC,cAAc,8BAA8B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../selection/calendar/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,yBAAyB,CAAA"}
@@ -1,3 +1,2 @@
1
1
  export * from './Calendar.js';
2
2
  export * from './SelectableCalendar.js';
3
- export * from './SelectableRangeCalendar.js';