@omegagrid/calendar 0.11.0 → 0.11.2

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.
@@ -27,6 +27,10 @@ export declare class CalendarDropdown extends Dropdown {
27
27
  parseDate(value: string): Date;
28
28
  isWithinBounds(date: Date): boolean;
29
29
  get inputDateText(): string;
30
+ get inputTime(): {
31
+ hours: number;
32
+ minutes: number;
33
+ };
30
34
  _onInputBlur: () => void;
31
35
  _onInput: () => void;
32
36
  _onInputKeydown: (e: KeyboardEvent) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"dropdown.d.ts","sourceRoot":"","sources":["../../src/ui/dropdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAe,MAAM,iBAAiB,CAAC;AAErF,OAAO,EAAe,OAAO,EAAE,MAAM,YAAY,CAAC;AAIlD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,qBACa,gBAAiB,SAAQ,QAAQ;;IAE7C,MAAM,CAAC,MAAM,4BAA+B;IAG5C,eAAe,EAAE,OAAO,CAErB;IAGH,WAAW,UAAS;IAEpB,qIAAqI;IAErI,QAAQ,UAAS;IAGjB,IACI,KAAK,IACQ,IAAI,CADa;IAClC,IAAI,KAAK,CAAC,KAAK,EAAE,IAAI,EAMpB;IAGD,KAAK,UAAS;IAGd,OAAO,EAAE,MAAM,CAAC;IAGhB,WAAW,EAAE,MAAM,CAAC;IAGpB,KAAK,EAAE,KAAK,CAAC;IASb,IAAI,SAAS,WAAuE;IACpF,IAAI,WAAW,WAA2E;IAO1F,IAAI,cAAc,YAEjB;IAED,IAAI,QAAQ,aAeX;IAED,IAAI,OAAO,iBAkBV;IAEK,IAAI,CAAC,YAAY,GAAE,MAAa;IAQtC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,MA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AE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAQnC,UAAU,CAAC,aAAa,UAAO;IAQ/B,aAAa,aAEZ;IAED,SAAS,CAAC,KAAK,EAAE,MAAM;IAIvB,cAAc,CAAC,IAAI,EAAE,IAAI;IAOzB,IAAI,aAAa,WAEhB;IAGD,IAAI,SAAS;;;MAOZ;IAED,YAAY,aAaX;IAED,QAAQ,aAGP;IAED,eAAe,GAAI,GAAG,aAAa,UAKlC;IAED,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa;IAK9B,IAAI,iBAAiB,gCAEpB;IAED,IAAI,cAAc,WAGjB;IAED,oBAAoB;IAUpB,MAAM,6CAiCJ;CACF"}
@@ -44,8 +44,10 @@ let CalendarDropdown = class CalendarDropdown extends Dropdown {
44
44
  };
45
45
  this._onInputBlur = () => {
46
46
  let newDate = this.parseDate(this.inputDateText);
47
- if (newDate != null && this.withTime)
48
- newDate = set(newDate, { hours: this.timeHours, minutes: this.timeMinutes, seconds: 0, milliseconds: 0 });
47
+ if (newDate != null && this.withTime) {
48
+ const time = this.inputTime ?? { hours: this.timeHours, minutes: this.timeMinutes };
49
+ newDate = set(newDate, { ...time, seconds: 0, milliseconds: 0 });
50
+ }
49
51
  if (newDate != null && !this.isWithinBounds(newDate))
50
52
  newDate = null;
51
53
  if (newDate == null)
@@ -54,6 +56,8 @@ let CalendarDropdown = class CalendarDropdown extends Dropdown {
54
56
  __classPrivateFieldSet(this, _CalendarDropdown_value, newDate, "f");
55
57
  this.dispatchEvent(new events.ChangeEvent({ value: this.value }));
56
58
  }
59
+ if (this.withTime)
60
+ this.input.value = this.formattedValue || '';
57
61
  };
58
62
  this._onInput = () => {
59
63
  const newDate = this.parseDate(this.inputDateText);
@@ -186,10 +190,20 @@ let CalendarDropdown = class CalendarDropdown extends Dropdown {
186
190
  date = startOfDay(date); // bounds are day-granular
187
191
  return (!minDate || date >= minDate) && (!maxDate || date <= maxDate);
188
192
  }
189
- // with time enabled only the first token is the date, the typed time is ignored (the spinners own the time)
193
+ // with time enabled the first token is the date, the second an optional time
190
194
  get inputDateText() {
191
195
  return this.withTime ? this.input.value.trim().split(/\s+/)[0] ?? '' : this.input.value;
192
196
  }
197
+ // time of day typed after the date; null when missing or invalid (the currently selected time is kept then)
198
+ get inputTime() {
199
+ const token = this.input.value.trim().split(/\s+/)[1];
200
+ const match = token?.match(/^(\d{1,2}):(\d{1,2})(?::\d{1,2})?$/);
201
+ if (!match)
202
+ return null;
203
+ const hours = Number(match[1]);
204
+ const minutes = Number(match[2]);
205
+ return hours < 24 && minutes < 60 ? { hours, minutes } : null;
206
+ }
193
207
  layout(options) {
194
208
  super.layout(options);
195
209
  __classPrivateFieldGet(this, _CalendarDropdown_calendar, "f")?.layout();
@@ -1 +1 @@
1
- {"version":3,"file":"dropdown.js","sourceRoot":"","sources":["../../src/ui/dropdown.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAwB,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAW,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAKlC,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,QAAQ;IAAvC;;;QAKN,oBAAe,GAAY,WAAW,CAAC;YACtC,gBAAgB,EAAE,QAAQ;SAC1B,CAAC,CAAC;QAGH,gBAAW,GAAG,KAAK,CAAC;QAEpB,qIAAqI;QAErI,aAAQ,GAAG,KAAK,CAAC;QAEjB,0CAAa;QAYb,UAAK,GAAG,KAAK,CAAC;QAWd,6CAAoB;QACpB,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AAI,EAAE,MAAM,EAAC,CAAC;yDAGtB;AAGH;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;qDACN;AAIpB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;kDACT;AAIjB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAC,CAAC;6CACT;AAUlC;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;+CAC3B;AAGd;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;iDACT;AAGhB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;qDACL;AAGpB;IADC,KAAK,CAAC,UAAU,CAAC;+CACL;AArCD,gBAAgB;IAD5B,aAAa,CAAC,sBAAsB,CAAC;GACzB,gBAAgB,CA2N5B","sourcesContent":["import { Dropdown, Input, LayoutOptions, dates, dom, events } from \"@omegagrid/core\";\nimport { customElement, property, query } from \"lit/decorators.js\";\nimport { initOptions, Options } from \"../options\";\nimport { html } from \"lit\";\nimport { set, startOfDay } from \"date-fns\";\nimport { style } from \"./dropdown.style\";\nimport { Calendar } from \"./calendar\";\nimport { CalendarTime } from \"./timeRow\";\n\n@customElement('og-calendar-dropdown')\nexport class CalendarDropdown extends Dropdown {\n\n\tstatic styles = [...Dropdown.styles, style];\n\n\t@property({type: Object})\n\tcalendarOptions: Options = initOptions({\n\t\tcontrolsPosition: 'bottom'\n\t});\n\n\t@property({type: Boolean})\n\tbuttonInput = false;\n\n\t/** enables time of day (hours and minutes) selection below the calendar; a day pick then keeps the dropdown open, default `false` */\n\t@property({type: Boolean})\n\twithTime = false;\n\n\t#value: Date;\n\t@property({type: Object, noAccessor: true})\n\tget value() { return this.#value }\n\tset value(value: Date) {\n\t\tthis.#value = this.#normalizeTime(value);\n\t\tif (this.#calendar) {\n\t\t\tthis.#calendar.date = this.#value;\n\t\t\tthis.requestUpdate();\n\t\t}\n\t}\n\n\t@property({type: Boolean, reflect: true})\n\tcross = false;\n\n\t@property({type: String})\n\tcaption: string;\n\n\t@property({type: String})\n\tplaceholder: string;\n\n\t@query('og-input')\n\tinput: Input;\n\n\t#calendar: Calendar;\n\t#timeRow: CalendarTime;\n\n\t// time of day selected before any date is picked (merged into the next day pick)\n\t#pendingHours = 0;\n\t#pendingMinutes = 0;\n\n\tget timeHours() { return this.#value ? this.#value.getHours() : this.#pendingHours }\n\tget timeMinutes() { return this.#value ? this.#value.getMinutes() : this.#pendingMinutes }\n\n\t#normalizeTime(value: Date) {\n\t\tif (value == null || !this.withTime) return value;\n\t\treturn set(value, {seconds: 0, milliseconds: 0});\n\t}\n\n\tget hasCrossButton() {\n\t\treturn this.cross && this.#value != null;\n\t}\n\n\tget calendar() {\n\t\tif (this.#calendar) return this.#calendar;\n\t\tthis.#calendar = dom.createElement<Calendar>('og-calendar');\n\t\tthis.#calendar.date = this.#value;\n\t\tthis.#calendar.options = this.calendarOptions;\n\t\tthis.#calendar.slot = 'inner-content';\n\t\tthis.#calendar.addEventListener('change', (e: events.ChangeEvent<Date>) => {\n\t\t\tthis.#value = this.withTime\n\t\t\t\t? set(e.value, {hours: this.timeHours, minutes: this.timeMinutes})\n\t\t\t\t: e.value;\n\t\t\tif (!this.withTime) this.close();\n\t\t\tthis.dispatchEvent(new events.ChangeEvent({value: this.#value}));\n\t\t\tthis.requestUpdate();\n\t\t});\n\t\treturn this.#calendar;\n\t}\n\n\tget timeRow() {\n\t\tif (this.#timeRow) return this.#timeRow;\n\t\tthis.#timeRow = dom.createElement<CalendarTime>('og-calendar-time');\n\t\tthis.#timeRow.slot = 'inner-content';\n\t\tthis.#timeRow.style.flex = '0 0 auto'; // the container stretches slotted children by default\n\t\tthis.#timeRow.hours = this.timeHours;\n\t\tthis.#timeRow.minutes = this.timeMinutes;\n\t\tthis.#timeRow.addEventListener('change', (e: events.ChangeEvent<{hours: number, minutes: number}>) => {\n\t\t\tif (this.#value) {\n\t\t\t\tthis.#value = set(this.#value, {...e.value, seconds: 0, milliseconds: 0});\n\t\t\t\tthis.dispatchEvent(new events.ChangeEvent({value: this.#value}));\n\t\t\t\tthis.requestUpdate();\n\t\t\t} else {\n\t\t\t\tthis.#pendingHours = e.value.hours;\n\t\t\t\tthis.#pendingMinutes = e.value.minutes;\n\t\t\t}\n\t\t});\n\t\treturn this.#timeRow;\n\t}\n\n\tasync open(initialValue: string = null) {\n\t\tif (initialValue != null) this.input.value = initialValue;\n\n\t\tif (this.calendar.parentElement != this.dropdown) this.dropdown.appendChild(this.calendar);\n\t\tif (this.withTime && this.timeRow.parentElement != this.dropdown) this.dropdown.appendChild(this.timeRow);\n\t\tawait super.open();\n\t}\n\n\tupdated(props: Map<string, unknown>) {\n\t\tsuper.updated(props);\n\t\tif (this.withTime && this.#timeRow) {\n\t\t\tthis.#timeRow.hours = this.timeHours;\n\t\t\tthis.#timeRow.minutes = this.timeMinutes;\n\t\t}\n\t}\n\n\tclearValue(dispatchEvent = true) {\n\t\tthis.#pendingHours = 0;\n\t\tthis.#pendingMinutes = 0;\n\t\tthis.value = null;\n\t\tthis.close();\n\t\tif (dispatchEvent) this.dispatchEvent(new events.ChangeEvent({value: null}));\n\t}\n\n\t_onInputFocus = () => {\n\t\tthis.open();\n\t}\n\n\tparseDate(value: string) {\n\t\treturn dates.parse(value, this.calendarOptions.locale);\n\t}\n\n\tisWithinBounds(date: Date) {\n\t\tconst { minDate, maxDate } = this.calendarOptions;\n\t\tif (this.withTime) date = startOfDay(date); // bounds are day-granular\n\t\treturn (!minDate || date >= minDate) && (!maxDate || date <= maxDate);\n\t}\n\n\t// with time enabled only the first token is the date, the typed time is ignored (the spinners own the time)\n\tget inputDateText() {\n\t\treturn this.withTime ? this.input.value.trim().split(/\\s+/)[0] ?? '' : this.input.value;\n\t}\n\n\t_onInputBlur = () => {\n\t\tlet newDate = this.parseDate(this.inputDateText);\n\t\tif (newDate != null && this.withTime) newDate = set(newDate, {hours: this.timeHours, minutes: this.timeMinutes, seconds: 0, milliseconds: 0});\n\t\tif (newDate != null && !this.isWithinBounds(newDate)) newDate = null;\n\t\tif (newDate == null) this.input.value = '';\n\t\tif (newDate?.getTime() !== this.#value?.getTime()) {\n\t\t\tthis.#value = newDate;\n\t\t\tthis.dispatchEvent(new events.ChangeEvent({value: this.value}));\n\t\t}\n\t}\n\n\t_onInput = () => {\n\t\tconst newDate = this.parseDate(this.inputDateText);\n\t\tif (newDate && this.isWithinBounds(newDate)) this.#calendar.date = newDate;\n\t}\n\n\t_onInputKeydown = (e: KeyboardEvent) => {\n\t\tif (e.key === 'Enter') {\n\t\t\tthis.input.blur();\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tlayout(options?: LayoutOptions) {\n\t\tsuper.layout(options);\n\t\tthis.#calendar?.layout();\n\t}\n\n\tget dateTimeFormatter() {\n\t\treturn dates.getDateFormatter(this.calendarOptions.locale, this.calendarOptions.dateFormat + ' HH:mm');\n\t}\n\n\tget formattedValue() {\n\t\tif (!this.withTime) return this.calendar?.formattedDate;\n\t\treturn this.#value ? this.dateTimeFormatter(this.#value) : '';\n\t}\n\n\tgetButtonContentHtml() {\n\t\tconst caption = this.caption ? html`<div class=\"caption\">${this.caption}</div>` : null;\n\t\tconst placeholder = this.placeholder ? html`<div class=\"placeholder\">${this.placeholder}</div>` : null;\n\t\tconst formattedDate = this.formattedValue;\n\t\treturn formattedDate ? html`${caption ? html`${caption}:` : ``}<div class=\"itm\">${formattedDate}</div>` : (caption\n\t\t\t? html`${caption}${placeholder ? html`:&nbsp;${placeholder}` : ``}`\n\t\t\t: (placeholder ? html`${placeholder}` : html`&nbsp;`)\n\t\t);\n\t}\n\n\trender = () => html`\n\t\t${this.buttonInput ? html`\n\t\t\t<og-input\n\t\t\t\t@keydown=\"${this._onInputKeydown}\"\n\t\t\t\t@focus=\"${this._onInputFocus}\"\n\t\t\t\t@input=\"${this._onInput}\"\n\t\t\t\t@blur=\"${this._onInputBlur}\"\n\t\t\t\tplaceholder=\"${this.placeholder || ''}\"\n\t\t\t\t.value=\"${this.formattedValue || ''}\">\n\t\t\t</og-input>\n\t\t` : html`\n\t\t\t<og-button\n\t\t\t\t.caret=\"${this.noCaret ? 'none' : 'down'}\"\n\t\t\t\tcolor=\"${this.color}\"\n\t\t\t\tclass=\"main\"\n\t\t\t\tstyle=\"flex: 1; text-align: center;\" \n\t\t\t\t@mousedown=\"${this._onMousedown}\">\n\t\t\t\t<div class=\"content\" slot=\"content\">\n\t\t\t\t\t${this.getButtonContentHtml()}\n\t\t\t\t</div>\n\t\t\t</og-button>\n\t\t`}\n\n\t\t${this.hasCrossButton ? html`\n\t\t\t<og-button\n\t\t\t\tclass=\"cross\"\n\t\t\t\t@mousedown=\"${() => this.clearValue(true)}\"\n\t\t\t\ticon=\"xmark\"\n\t\t\t\tcolor=\"red\">\n\t\t\t</og-button>\n\t\t` : ``}\n\n\t\t${this.renderDropdown()}\n\t`;\n}\n"]}
1
+ {"version":3,"file":"dropdown.js","sourceRoot":"","sources":["../../src/ui/dropdown.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAwB,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAW,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAKlC,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,QAAQ;IAAvC;;;QAKN,oBAAe,GAAY,WAAW,CAAC;YACtC,gBAAgB,EAAE,QAAQ;S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IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;+CAC3B;AAGd;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;iDACT;AAGhB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;qDACL;AAGpB;IADC,KAAK,CAAC,UAAU,CAAC;+CACL;AArCD,gBAAgB;IAD5B,aAAa,CAAC,sBAAsB,CAAC;GACzB,gBAAgB,CAyO5B","sourcesContent":["import { Dropdown, Input, LayoutOptions, dates, dom, events } from \"@omegagrid/core\";\nimport { customElement, property, query } from \"lit/decorators.js\";\nimport { initOptions, Options } from \"../options\";\nimport { html } from \"lit\";\nimport { set, startOfDay } from \"date-fns\";\nimport { style } from \"./dropdown.style\";\nimport { Calendar } from \"./calendar\";\nimport { CalendarTime } from \"./timeRow\";\n\n@customElement('og-calendar-dropdown')\nexport class CalendarDropdown extends Dropdown {\n\n\tstatic styles = [...Dropdown.styles, style];\n\n\t@property({type: Object})\n\tcalendarOptions: Options = initOptions({\n\t\tcontrolsPosition: 'bottom'\n\t});\n\n\t@property({type: Boolean})\n\tbuttonInput = false;\n\n\t/** enables time of day (hours and minutes) selection below the calendar; a day pick then keeps the dropdown open, default `false` */\n\t@property({type: Boolean})\n\twithTime = false;\n\n\t#value: Date;\n\t@property({type: Object, noAccessor: true})\n\tget value() { return this.#value }\n\tset value(value: Date) {\n\t\tthis.#value = this.#normalizeTime(value);\n\t\tif (this.#calendar) {\n\t\t\tthis.#calendar.date = this.#value;\n\t\t\tthis.requestUpdate();\n\t\t}\n\t}\n\n\t@property({type: Boolean, reflect: true})\n\tcross = false;\n\n\t@property({type: String})\n\tcaption: string;\n\n\t@property({type: String})\n\tplaceholder: string;\n\n\t@query('og-input')\n\tinput: Input;\n\n\t#calendar: Calendar;\n\t#timeRow: CalendarTime;\n\n\t// time of day selected before any date is picked (merged into the next day pick)\n\t#pendingHours = 0;\n\t#pendingMinutes = 0;\n\n\tget timeHours() { return this.#value ? this.#value.getHours() : this.#pendingHours }\n\tget timeMinutes() { return this.#value ? this.#value.getMinutes() : this.#pendingMinutes }\n\n\t#normalizeTime(value: Date) {\n\t\tif (value == null || !this.withTime) return value;\n\t\treturn set(value, {seconds: 0, milliseconds: 0});\n\t}\n\n\tget hasCrossButton() {\n\t\treturn this.cross && this.#value != null;\n\t}\n\n\tget calendar() {\n\t\tif (this.#calendar) return this.#calendar;\n\t\tthis.#calendar = dom.createElement<Calendar>('og-calendar');\n\t\tthis.#calendar.date = this.#value;\n\t\tthis.#calendar.options = this.calendarOptions;\n\t\tthis.#calendar.slot = 'inner-content';\n\t\tthis.#calendar.addEventListener('change', (e: events.ChangeEvent<Date>) => {\n\t\t\tthis.#value = this.withTime\n\t\t\t\t? set(e.value, {hours: this.timeHours, minutes: this.timeMinutes})\n\t\t\t\t: e.value;\n\t\t\tif (!this.withTime) this.close();\n\t\t\tthis.dispatchEvent(new events.ChangeEvent({value: this.#value}));\n\t\t\tthis.requestUpdate();\n\t\t});\n\t\treturn this.#calendar;\n\t}\n\n\tget timeRow() {\n\t\tif (this.#timeRow) return this.#timeRow;\n\t\tthis.#timeRow = dom.createElement<CalendarTime>('og-calendar-time');\n\t\tthis.#timeRow.slot = 'inner-content';\n\t\tthis.#timeRow.style.flex = '0 0 auto'; // the container stretches slotted children by default\n\t\tthis.#timeRow.hours = this.timeHours;\n\t\tthis.#timeRow.minutes = this.timeMinutes;\n\t\tthis.#timeRow.addEventListener('change', (e: events.ChangeEvent<{hours: number, minutes: number}>) => {\n\t\t\tif (this.#value) {\n\t\t\t\tthis.#value = set(this.#value, {...e.value, seconds: 0, milliseconds: 0});\n\t\t\t\tthis.dispatchEvent(new events.ChangeEvent({value: this.#value}));\n\t\t\t\tthis.requestUpdate();\n\t\t\t} else {\n\t\t\t\tthis.#pendingHours = e.value.hours;\n\t\t\t\tthis.#pendingMinutes = e.value.minutes;\n\t\t\t}\n\t\t});\n\t\treturn this.#timeRow;\n\t}\n\n\tasync open(initialValue: string = null) {\n\t\tif (initialValue != null) this.input.value = initialValue;\n\n\t\tif (this.calendar.parentElement != this.dropdown) this.dropdown.appendChild(this.calendar);\n\t\tif (this.withTime && this.timeRow.parentElement != this.dropdown) this.dropdown.appendChild(this.timeRow);\n\t\tawait super.open();\n\t}\n\n\tupdated(props: Map<string, unknown>) {\n\t\tsuper.updated(props);\n\t\tif (this.withTime && this.#timeRow) {\n\t\t\tthis.#timeRow.hours = this.timeHours;\n\t\t\tthis.#timeRow.minutes = this.timeMinutes;\n\t\t}\n\t}\n\n\tclearValue(dispatchEvent = true) {\n\t\tthis.#pendingHours = 0;\n\t\tthis.#pendingMinutes = 0;\n\t\tthis.value = null;\n\t\tthis.close();\n\t\tif (dispatchEvent) this.dispatchEvent(new events.ChangeEvent({value: null}));\n\t}\n\n\t_onInputFocus = () => {\n\t\tthis.open();\n\t}\n\n\tparseDate(value: string) {\n\t\treturn dates.parse(value, this.calendarOptions.locale);\n\t}\n\n\tisWithinBounds(date: Date) {\n\t\tconst { minDate, maxDate } = this.calendarOptions;\n\t\tif (this.withTime) date = startOfDay(date); // bounds are day-granular\n\t\treturn (!minDate || date >= minDate) && (!maxDate || date <= maxDate);\n\t}\n\n\t// with time enabled the first token is the date, the second an optional time\n\tget inputDateText() {\n\t\treturn this.withTime ? this.input.value.trim().split(/\\s+/)[0] ?? '' : this.input.value;\n\t}\n\n\t// time of day typed after the date; null when missing or invalid (the currently selected time is kept then)\n\tget inputTime() {\n\t\tconst token = this.input.value.trim().split(/\\s+/)[1];\n\t\tconst match = token?.match(/^(\\d{1,2}):(\\d{1,2})(?::\\d{1,2})?$/);\n\t\tif (!match) return null;\n\t\tconst hours = Number(match[1]);\n\t\tconst minutes = Number(match[2]);\n\t\treturn hours < 24 && minutes < 60 ? {hours, minutes} : null;\n\t}\n\n\t_onInputBlur = () => {\n\t\tlet newDate = this.parseDate(this.inputDateText);\n\t\tif (newDate != null && this.withTime) {\n\t\t\tconst time = this.inputTime ?? {hours: this.timeHours, minutes: this.timeMinutes};\n\t\t\tnewDate = set(newDate, {...time, seconds: 0, milliseconds: 0});\n\t\t}\n\t\tif (newDate != null && !this.isWithinBounds(newDate)) newDate = null;\n\t\tif (newDate == null) this.input.value = '';\n\t\tif (newDate?.getTime() !== this.#value?.getTime()) {\n\t\t\tthis.#value = newDate;\n\t\t\tthis.dispatchEvent(new events.ChangeEvent({value: this.value}));\n\t\t}\n\t\tif (this.withTime) this.input.value = this.formattedValue || '';\n\t}\n\n\t_onInput = () => {\n\t\tconst newDate = this.parseDate(this.inputDateText);\n\t\tif (newDate && this.isWithinBounds(newDate)) this.#calendar.date = newDate;\n\t}\n\n\t_onInputKeydown = (e: KeyboardEvent) => {\n\t\tif (e.key === 'Enter') {\n\t\t\tthis.input.blur();\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tlayout(options?: LayoutOptions) {\n\t\tsuper.layout(options);\n\t\tthis.#calendar?.layout();\n\t}\n\n\tget dateTimeFormatter() {\n\t\treturn dates.getDateFormatter(this.calendarOptions.locale, this.calendarOptions.dateFormat + ' HH:mm');\n\t}\n\n\tget formattedValue() {\n\t\tif (!this.withTime) return this.calendar?.formattedDate;\n\t\treturn this.#value ? this.dateTimeFormatter(this.#value) : '';\n\t}\n\n\tgetButtonContentHtml() {\n\t\tconst caption = this.caption ? html`<div class=\"caption\">${this.caption}</div>` : null;\n\t\tconst placeholder = this.placeholder ? html`<div class=\"placeholder\">${this.placeholder}</div>` : null;\n\t\tconst formattedDate = this.formattedValue;\n\t\treturn formattedDate ? html`${caption ? html`${caption}:` : ``}<div class=\"itm\">${formattedDate}</div>` : (caption\n\t\t\t? html`${caption}${placeholder ? html`:&nbsp;${placeholder}` : ``}`\n\t\t\t: (placeholder ? html`${placeholder}` : html`&nbsp;`)\n\t\t);\n\t}\n\n\trender = () => html`\n\t\t${this.buttonInput ? html`\n\t\t\t<og-input\n\t\t\t\t@keydown=\"${this._onInputKeydown}\"\n\t\t\t\t@focus=\"${this._onInputFocus}\"\n\t\t\t\t@input=\"${this._onInput}\"\n\t\t\t\t@blur=\"${this._onInputBlur}\"\n\t\t\t\tplaceholder=\"${this.placeholder || ''}\"\n\t\t\t\t.value=\"${this.formattedValue || ''}\">\n\t\t\t</og-input>\n\t\t` : html`\n\t\t\t<og-button\n\t\t\t\t.caret=\"${this.noCaret ? 'none' : 'down'}\"\n\t\t\t\tcolor=\"${this.color}\"\n\t\t\t\tclass=\"main\"\n\t\t\t\tstyle=\"flex: 1; text-align: center;\" \n\t\t\t\t@mousedown=\"${this._onMousedown}\">\n\t\t\t\t<div class=\"content\" slot=\"content\">\n\t\t\t\t\t${this.getButtonContentHtml()}\n\t\t\t\t</div>\n\t\t\t</og-button>\n\t\t`}\n\n\t\t${this.hasCrossButton ? html`\n\t\t\t<og-button\n\t\t\t\tclass=\"cross\"\n\t\t\t\t@mousedown=\"${() => this.clearValue(true)}\"\n\t\t\t\ticon=\"xmark\"\n\t\t\t\tcolor=\"red\">\n\t\t\t</og-button>\n\t\t` : ``}\n\n\t\t${this.renderDropdown()}\n\t`;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omegagrid/calendar",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Calendar component",
6
6
  "main": "./dist/index.js",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@fortawesome/fontawesome-svg-core": "^7.0.1",
31
- "@omegagrid/core": "^0.11.0",
32
- "@omegagrid/grid": "^0.11.0",
33
- "@omegagrid/grid-core": "^0.11.0",
34
- "@omegagrid/localize": "^0.11.0",
31
+ "@omegagrid/core": "^0.11.2",
32
+ "@omegagrid/grid": "^0.11.2",
33
+ "@omegagrid/grid-core": "^0.11.2",
34
+ "@omegagrid/localize": "^0.11.2",
35
35
  "date-fns": "^3.2.0",
36
36
  "lit": "^3.1.1",
37
37
  "ts-debounce": "^4.0.0"