@digital-realty/ix-date 1.1.22 → 1.1.24

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/IxDate.d.ts CHANGED
@@ -3,16 +3,34 @@ import { MobxLitElement } from '@adobe/lit-mobx';
3
3
  export declare const NativeInputDateFormat = "yyyy-MM-dd";
4
4
  export declare class IxDate extends MobxLitElement {
5
5
  static get styles(): import("lit").CSSResult[];
6
- type: string;
6
+ type: 'default' | 'static';
7
+ variant: 'date' | 'time' | 'date-time';
7
8
  format: string;
8
9
  timeFormat: string;
9
- variant: string;
10
+ timezone: string;
10
11
  label: string;
11
12
  dateTimeText: string;
13
+ /**
14
+ * For `type='default'`, should be any value that is accepted by [new Date()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date).
15
+ *
16
+ * For `type='static'`, should be a date string that can be parsed by [parseISO](https://date-fns.org/v2.0.0/docs/parseISO), e.g.
17
+ * - `2025-01-01`
18
+ * - `2025-01-01 12:30Z`
19
+ * - `2025-01-01T12:30:00.000+02:00`
20
+ * */
12
21
  value: string;
13
22
  showCalendarOnMouseDown: boolean;
14
23
  min: string;
15
24
  max: string;
25
+ /**
26
+ * Applies when type=static. Defaults to `false`.
27
+ *
28
+ * If `true`, the value is formatted but no time zone conversions are applied.
29
+ *
30
+ * If `false`, values that do not specify a time zone are interpreted as being in the
31
+ * user's local time zone and all values are displayed in the user's local time zone.
32
+ */
33
+ noTimeZoneConversion: boolean;
16
34
  /** @nocollapse */
17
35
  static shadowRootOptions: {
18
36
  delegatesFocus: boolean;
@@ -93,8 +111,14 @@ export declare class IxDate extends MobxLitElement {
93
111
  handleChange: (e: InputEvent) => void;
94
112
  validateDate: () => void;
95
113
  focusOut: () => void;
96
- formatDate: (date: string | Date) => string;
97
- formatTime: (date: string | Date) => string;
114
+ parseValue: () => Date;
115
+ getTimezoneDateTime: (date: Date) => Date;
116
+ formatValueAsDate: (date: Date) => string;
117
+ formatValueAsTime: (date: Date) => string;
118
+ formatValueAsDateTime: (date: Date) => string;
119
+ formatValue: () => string;
98
120
  get nativeInputValue(): string;
121
+ renderStaticDate(): import("lit-html").TemplateResult<1>;
122
+ renderDateInput(): import("lit-html").TemplateResult<1>;
99
123
  render(): import("lit-html").TemplateResult<1>;
100
124
  }
package/dist/IxDate.js CHANGED
@@ -9,22 +9,40 @@ import { isValid } from 'date-fns/isValid.js';
9
9
  import { parse } from 'date-fns/parse.js';
10
10
  import { parseISO } from 'date-fns/parseISO.js';
11
11
  import { MobxLitElement } from '@adobe/lit-mobx';
12
- import { dateFormatState } from './state/date-format-state.js';
12
+ import { dateFormatState, defaultDateFormat, defaultTimeFormat, } from './state/date-format-state.js';
13
13
  import { IxDateStyles } from './ix-date-styles.js';
14
14
  export const NativeInputDateFormat = 'yyyy-MM-dd';
15
15
  export class IxDate extends MobxLitElement {
16
16
  constructor() {
17
17
  super(...arguments);
18
18
  this.type = 'default';
19
- this.format = 'dd/MM/yyyy';
20
- this.timeFormat = 'HH:mm';
21
19
  this.variant = 'date';
20
+ this.format = defaultDateFormat;
21
+ this.timeFormat = defaultTimeFormat;
22
+ this.timezone = 'UTC';
22
23
  this.label = '';
23
24
  this.dateTimeText = '';
25
+ /**
26
+ * For `type='default'`, should be any value that is accepted by [new Date()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date).
27
+ *
28
+ * For `type='static'`, should be a date string that can be parsed by [parseISO](https://date-fns.org/v2.0.0/docs/parseISO), e.g.
29
+ * - `2025-01-01`
30
+ * - `2025-01-01 12:30Z`
31
+ * - `2025-01-01T12:30:00.000+02:00`
32
+ * */
24
33
  this.value = '';
25
34
  this.showCalendarOnMouseDown = false;
26
35
  this.min = '';
27
36
  this.max = '9999-12-31';
37
+ /**
38
+ * Applies when type=static. Defaults to `false`.
39
+ *
40
+ * If `true`, the value is formatted but no time zone conversions are applied.
41
+ *
42
+ * If `false`, values that do not specify a time zone are interpreted as being in the
43
+ * user's local time zone and all values are displayed in the user's local time zone.
44
+ */
45
+ this.noTimeZoneConversion = false;
28
46
  this.internals = this /* needed for closure */
29
47
  .attachInternals();
30
48
  this.disabled = false;
@@ -39,6 +57,7 @@ export class IxDate extends MobxLitElement {
39
57
  await dateFormatState.hydrateStore();
40
58
  this.format = dateFormatState.preferredDateFormat;
41
59
  this.timeFormat = dateFormatState.preferredTimeFormat;
60
+ this.timezone = dateFormatState.preferredTimezone;
42
61
  };
43
62
  this.handleMouseDown = (e) => {
44
63
  if (this.showCalendarOnMouseDown) {
@@ -71,17 +90,61 @@ export class IxDate extends MobxLitElement {
71
90
  this.focusOut = () => {
72
91
  this.focused = false;
73
92
  };
74
- this.formatDate = (date) => {
75
- const parsedDate = typeof date === 'string' ? parseISO(date) : date;
76
- return isValid(parsedDate)
77
- ? format(parsedDate, this.format || 'dd/MM/yyyy')
78
- : '';
93
+ this.parseValue = () => {
94
+ if (typeof this.value !== 'string') {
95
+ return this.value;
96
+ }
97
+ if (this.noTimeZoneConversion) {
98
+ // Matches the time zone designator, e.g. `Z` or `-02:00`.
99
+ // Note: does not match `-02` and `-0200`, which are valid ISO 8601 but rarely used.
100
+ const timeZoneRegex = /Z|([+-]\d\d:\d\d)/;
101
+ const valueWithoutTimeZone = this.value.split(timeZoneRegex)[0];
102
+ return parseISO(valueWithoutTimeZone);
103
+ }
104
+ return parseISO(this.value);
105
+ };
106
+ this.getTimezoneDateTime = (date) => {
107
+ const parts = new Intl.DateTimeFormat('en-GB', {
108
+ timeZone: this.timezone,
109
+ year: 'numeric',
110
+ month: '2-digit',
111
+ day: '2-digit',
112
+ hour: '2-digit',
113
+ minute: '2-digit',
114
+ second: '2-digit',
115
+ hour12: false,
116
+ }).formatToParts(new Date(date));
117
+ const get = (type) => { var _a; return (_a = parts.find(p => p.type === type)) === null || _a === void 0 ? void 0 : _a.value; };
118
+ const year = get('year');
119
+ const month = get('month');
120
+ const day = get('day');
121
+ const hour = get('hour');
122
+ const minute = get('minute');
123
+ const second = get('second');
124
+ return new Date(`${year}-${month}-${day}T${hour}:${minute}:${second}`);
125
+ };
126
+ this.formatValueAsDate = (date) => {
127
+ if (new Date(date).toISOString().includes('T')) {
128
+ return format(this.getTimezoneDateTime(date), this.format || defaultDateFormat);
129
+ }
130
+ return format(date, this.format || defaultDateFormat);
79
131
  };
80
- this.formatTime = (date) => {
81
- const parsedDate = typeof date === 'string' ? parseISO(date) : date;
82
- return isValid(parsedDate)
83
- ? format(parsedDate, this.timeFormat || 'HH:mm')
84
- : '';
132
+ this.formatValueAsTime = (date) => format(this.getTimezoneDateTime(date), this.timeFormat || defaultTimeFormat);
133
+ this.formatValueAsDateTime = (date) => `${this.formatValueAsDate(date)}${this.dateTimeText ? ` ${this.dateTimeText} ` : ' '}${this.formatValueAsTime(date)}`;
134
+ this.formatValue = () => {
135
+ const parsedDate = this.parseValue();
136
+ if (!isValid(parsedDate))
137
+ return '';
138
+ switch (this.variant) {
139
+ case 'date':
140
+ return this.formatValueAsDate(parsedDate);
141
+ case 'time':
142
+ return this.formatValueAsTime(parsedDate);
143
+ case 'date-time':
144
+ return this.formatValueAsDateTime(parsedDate);
145
+ default:
146
+ return '';
147
+ }
85
148
  };
86
149
  }
87
150
  static get styles() {
@@ -198,6 +261,7 @@ export class IxDate extends MobxLitElement {
198
261
  this.validateDate();
199
262
  this.format = dateFormatState.preferredDateFormat;
200
263
  this.timeFormat = dateFormatState.preferredTimeFormat;
264
+ this.timezone = dateFormatState.preferredTimezone;
201
265
  if (this.datePicker) {
202
266
  const formatDateIso8601 = (dateParts) => {
203
267
  const { year, month, day } = dateParts;
@@ -227,43 +291,43 @@ export class IxDate extends MobxLitElement {
227
291
  return this.value;
228
292
  }
229
293
  }
230
- render() {
294
+ renderStaticDate() {
295
+ return html `<span>${this.formatValue()}</span>`;
296
+ }
297
+ renderDateInput() {
231
298
  const classes = {
232
299
  disabled: this.disabled,
233
300
  error: !this.disabled && this.error,
234
301
  };
302
+ return html ` <ix-field
303
+ class="${classMap(classes)}"
304
+ ?focused=${this.focused}
305
+ ?populated=${this.value}
306
+ ?disabled=${this.disabled}
307
+ ?required=${this.required}
308
+ ?error=${this.error && !this.hideError}
309
+ error-text=${this.errorText}
310
+ label=${this.label}
311
+ @focusin=${this.focusin}
312
+ @focusout=${this.focusOut}
313
+ >
314
+ ${html `<input
315
+ id="date-input"
316
+ @change=${this.handleChange}
317
+ @mousedown=${this.handleMouseDown}
318
+ .value=${this.nativeInputValue}
319
+ class="flex-fill"
320
+ type="date"
321
+ min=${this.min}
322
+ max=${this.max}
323
+ ?disabled=${this.disabled}
324
+ />`}
325
+ </ix-field>`;
326
+ }
327
+ render() {
235
328
  return this.type === 'static'
236
- ? html `
237
- <span
238
- >${this.formatDate(this.value)}${this.variant === 'date-time'
239
- ? `${this.dateTimeText ? ` ${this.dateTimeText} ` : ' '}${this.formatTime(this.value)}`
240
- : ''}</span
241
- >
242
- `
243
- : html `<ix-field
244
- class="${classMap(classes)}"
245
- ?focused=${this.focused}
246
- ?populated=${this.value}
247
- ?disabled=${this.disabled}
248
- ?required=${this.required}
249
- ?error=${this.error && !this.hideError}
250
- error-text=${this.errorText}
251
- label=${this.label}
252
- @focusin=${this.focusin}
253
- @focusout=${this.focusOut}
254
- >
255
- ${html `<input
256
- id="date-input"
257
- @change=${this.handleChange}
258
- @mousedown=${this.handleMouseDown}
259
- .value=${this.nativeInputValue}
260
- class="flex-fill"
261
- type="date"
262
- min=${this.min}
263
- max=${this.max}
264
- ?disabled=${this.disabled}
265
- />`}
266
- </ix-field> `;
329
+ ? this.renderStaticDate()
330
+ : this.renderDateInput();
267
331
  }
268
332
  }
269
333
  (() => {
@@ -280,6 +344,9 @@ IxDate.formAssociated = true;
280
344
  __decorate([
281
345
  property({ type: String })
282
346
  ], IxDate.prototype, "type", void 0);
347
+ __decorate([
348
+ property({ type: String })
349
+ ], IxDate.prototype, "variant", void 0);
283
350
  __decorate([
284
351
  property({ type: String })
285
352
  ], IxDate.prototype, "format", void 0);
@@ -288,7 +355,7 @@ __decorate([
288
355
  ], IxDate.prototype, "timeFormat", void 0);
289
356
  __decorate([
290
357
  property({ type: String })
291
- ], IxDate.prototype, "variant", void 0);
358
+ ], IxDate.prototype, "timezone", void 0);
292
359
  __decorate([
293
360
  property({ type: String })
294
361
  ], IxDate.prototype, "label", void 0);
@@ -307,6 +374,9 @@ __decorate([
307
374
  __decorate([
308
375
  property({ type: String })
309
376
  ], IxDate.prototype, "max", void 0);
377
+ __decorate([
378
+ property({ type: Boolean, attribute: 'no-time-zone-conversion' })
379
+ ], IxDate.prototype, "noTimeZoneConversion", void 0);
310
380
  __decorate([
311
381
  query('#date-input')
312
382
  ], IxDate.prototype, "dateInput", void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"IxDate.js","sourceRoot":"","sources":["../src/IxDate.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,sCAAsC,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAElD,MAAM,OAAO,MAAO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A5B,KAAK,CAAC,oBAAoB,CAAC;0CAAkB;AAEF;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;wCAAkB;AAYR;IAApD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;yCAAgB;AAExB;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;wCAAkB;AAEjB;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;yCAAmB;AAG9D;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,CAAC;kDACrC;AAqGI;IAA7B,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;yCAA2B;AAE/C;IAAR,KAAK,EAAE;uCAAyB","sourcesContent":["import { html, LitElement } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport '@digital-realty/ix-field/ix-field.js';\nimport { requestUpdateOnAriaChange } from '@material/web/internal/aria/delegate.js';\nimport { format } from 'date-fns/format.js';\nimport { isValid } from 'date-fns/isValid.js';\nimport { parse } from 'date-fns/parse.js';\nimport { parseISO } from 'date-fns/parseISO.js';\nimport { MobxLitElement } from '@adobe/lit-mobx';\nimport { dateFormatState } from './state/date-format-state.js';\nimport { IxDateStyles } from './ix-date-styles.js';\n\nexport const NativeInputDateFormat = 'yyyy-MM-dd';\n\nexport class IxDate extends MobxLitElement {\n static {\n requestUpdateOnAriaChange(IxDate);\n }\n\n static get styles() {\n return [IxDateStyles];\n }\n\n @property({ type: String }) type = 'default';\n\n @property({ type: String }) format = 'dd/MM/yyyy';\n\n @property({ type: String }) timeFormat = 'HH:mm';\n\n @property({ type: String }) variant = 'date';\n\n @property({ type: String }) label = '';\n\n @property({ type: String }) dateTimeText = '';\n\n @property({ type: String }) value = '';\n\n @property({ type: Boolean }) showCalendarOnMouseDown = false;\n\n @property({ type: String }) min = '';\n\n @property({ type: String }) max = '9999-12-31';\n\n // Form association\n\n /** @nocollapse */\n static override shadowRootOptions = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n /** @nocollapse */\n static readonly formAssociated = true;\n\n private readonly internals = (this as HTMLElement) /* needed for closure */\n .attachInternals();\n\n @query('#date-input') dateInput!: HTMLInputElement;\n\n @query('vaadin-date-picker') datePicker!: any;\n\n @property({ type: Boolean, reflect: true }) disabled = false;\n\n /**\n * Gets or sets whether or not the text field is in a visually invalid state.\n *\n * This error state overrides the error state controlled by\n * `reportValidity()`.\n */\n get error() {\n return !!this.errorText;\n }\n\n @property({ type: String, attribute: 'error-text' }) errorText = '';\n\n @property({ type: Boolean, reflect: true }) required = false;\n\n @property({ type: Boolean, reflect: true }) hideError = false;\n\n @property({ type: Boolean, attribute: 'clear-button-visible' })\n clearButtonVisible = true;\n\n /**\n * The associated form element with which this element's value will submit.\n */\n get form() {\n return this.internals.form;\n }\n\n /**\n * The labels this element is associated with.\n */\n get labels() {\n return this.internals.labels;\n }\n\n /**\n * The HTML name to use in form submission.\n */\n get name() {\n return this.getAttribute('name') ?? '';\n }\n\n set name(name: string) {\n this.setAttribute('name', name);\n }\n\n /**\n * Returns the text field's validation error message.\n *\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation\n */\n get validationMessage() {\n return this.internals.validationMessage;\n }\n\n /**\n * Returns a `ValidityState` object that represents the validity states of the\n * text field.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ValidityState\n */\n get validity() {\n return this.internals.validity;\n }\n\n /**\n * Returns whether an element will successfully validate based on forms\n * validation rules and constraints.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/willValidate\n */\n get willValidate() {\n return this.internals.willValidate;\n }\n\n checkValidity() {\n return this.internals.checkValidity();\n }\n\n reportValidity() {\n return this.internals.reportValidity();\n }\n\n /** @private */\n formResetCallback() {\n this.reset();\n }\n\n /**\n * Reset the text field to its default value.\n */\n reset() {\n this.clear();\n this.value = this.getAttribute('value') ?? '';\n }\n\n protected override updated(\n changedProperties: Map<string | number | symbol, unknown>\n ) {\n if (changedProperties.has('value')) {\n const inputVal = this.dateInput ? this.dateInput : this.datePicker;\n if (inputVal) {\n this.internals.setValidity(\n {\n badInput: this.error,\n },\n this.error ? this.errorText : '',\n inputVal\n );\n }\n }\n\n this.internals.setFormValue(this.value);\n }\n\n override focus() {\n this.dateInput.focus();\n }\n\n // eslint-disable-next-line class-methods-use-this\n @property({ type: Function }) onChanged: any = () => {};\n\n @state() private focused = false;\n\n connectedCallback(): void {\n super.connectedCallback();\n document.addEventListener(\n 'dateFormatChanged',\n this.handleDateFormatChanged\n );\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n document.removeEventListener(\n 'dateFormatChanged',\n this.handleDateFormatChanged\n );\n }\n\n handleDateFormatChanged = async () => {\n await dateFormatState.hydrateStore();\n\n this.format = dateFormatState.preferredDateFormat;\n this.timeFormat = dateFormatState.preferredTimeFormat;\n };\n\n firstUpdated() {\n const minDate = new Date(this.min);\n const maxDate = new Date(this.max);\n\n if (minDate && !Number.isNaN(minDate.valueOf())) {\n const [min] = minDate.toISOString().split('T');\n this.min = min;\n }\n\n if (maxDate && !Number.isNaN(maxDate.valueOf())) {\n const [max] = maxDate.toISOString().split('T');\n this.max = max;\n }\n\n this.validateDate();\n\n this.format = dateFormatState.preferredDateFormat;\n\n this.timeFormat = dateFormatState.preferredTimeFormat;\n\n if (this.datePicker) {\n const formatDateIso8601 = (dateParts: any): string => {\n const { year, month, day } = dateParts;\n const date = new Date(year, month, day);\n\n return format(date, this.format);\n };\n\n const parseDateIso8601 = (inputValue: string) => {\n const date = parse(inputValue, this.format, new Date());\n\n return {\n year: date.getFullYear(),\n month: date.getMonth(),\n day: date.getDate(),\n };\n };\n\n this.datePicker.i18n = {\n ...this.datePicker.i18n,\n formatDate: formatDateIso8601,\n parseDate: parseDateIso8601,\n };\n }\n }\n\n handleMouseDown = (e: Event) => {\n if (this.showCalendarOnMouseDown) {\n const inputElement = e.target as HTMLInputElement;\n\n if ('showPicker' in inputElement) {\n inputElement.showPicker();\n }\n }\n };\n\n focusin = () => {\n this.focused = true;\n };\n\n clear = () => {\n this.value = '';\n };\n\n handleChange = (e: InputEvent) => {\n const { value } = e.target as HTMLInputElement;\n this.value = value;\n this.validateDate();\n this.onChanged(value);\n };\n\n validateDate = () => {\n if (this.value) {\n const date = new Date(this.value);\n\n if (!date || Number.isNaN(date.valueOf())) {\n this.errorText = 'Invalid date format.';\n }\n }\n };\n\n focusOut = () => {\n this.focused = false;\n };\n\n formatDate = (date: string | Date) => {\n const parsedDate = typeof date === 'string' ? parseISO(date) : date;\n return isValid(parsedDate)\n ? format(parsedDate, this.format || 'dd/MM/yyyy')\n : '';\n };\n\n formatTime = (date: string | Date) => {\n const parsedDate = typeof date === 'string' ? parseISO(date) : date;\n return isValid(parsedDate)\n ? format(parsedDate, this.timeFormat || 'HH:mm')\n : '';\n };\n\n get nativeInputValue() {\n try {\n return new Date(this.value).toISOString().split('T')[0];\n } catch (error) {\n return this.value;\n }\n }\n\n render() {\n const classes = {\n disabled: this.disabled,\n error: !this.disabled && this.error,\n };\n\n return this.type === 'static'\n ? html`\n <span\n >${this.formatDate(this.value)}${this.variant === 'date-time'\n ? `${\n this.dateTimeText ? ` ${this.dateTimeText} ` : ' '\n }${this.formatTime(this.value)}`\n : ''}</span\n >\n `\n : html`<ix-field\n class=\"${classMap(classes)}\"\n ?focused=${this.focused}\n ?populated=${this.value}\n ?disabled=${this.disabled}\n ?required=${this.required}\n ?error=${this.error && !this.hideError}\n error-text=${this.errorText}\n label=${this.label}\n @focusin=${this.focusin}\n @focusout=${this.focusOut}\n >\n ${html`<input\n id=\"date-input\"\n @change=${this.handleChange}\n @mousedown=${this.handleMouseDown}\n .value=${this.nativeInputValue}\n class=\"flex-fill\"\n type=\"date\"\n min=${this.min}\n max=${this.max}\n ?disabled=${this.disabled}\n />`}\n </ix-field> `;\n }\n}\n"]}
1
+ {"version":3,"file":"IxDate.js","sourceRoot":"","sources":["../src/IxDate.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,sCAAsC,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAElD,MAAM,OAAO,MAAO,SAAQ,cAAc;IAA1C;;QAS8B,SAAI,GAAyB,SAAS,CAAC;QAEvC,YAAO,GAAkC,MAAM,CAAC;QAEhD,WAAM,GAAG,iBAAiB,CAAC;QAE3B,eAAU,GAAG,iBAAiB,CAAC;QAE/B,aAAQ,GAAG,KAAK,CAAC;QAEjB,UAAK,GAAG,EAAE,CAAC;QAEX,iBAAY,GAAG,EAAE,CAAC;QAE9C;;;;;;;aAOK;QACuB,UAAK,GAAG,EAAE,CAAC;QAEV,4BAAuB,GAAG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;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,CAAC;kDACrC;AAqGI;IAA7B,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;yCAA2B;AAE/C;IAAR,KAAK,EAAE;uCAAyB","sourcesContent":["import { html, LitElement } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport '@digital-realty/ix-field/ix-field.js';\nimport { requestUpdateOnAriaChange } from '@material/web/internal/aria/delegate.js';\nimport { format } from 'date-fns/format.js';\nimport { isValid } from 'date-fns/isValid.js';\nimport { parse } from 'date-fns/parse.js';\nimport { parseISO } from 'date-fns/parseISO.js';\nimport { MobxLitElement } from '@adobe/lit-mobx';\nimport {\n dateFormatState,\n defaultDateFormat,\n defaultTimeFormat,\n} from './state/date-format-state.js';\nimport { IxDateStyles } from './ix-date-styles.js';\n\nexport const NativeInputDateFormat = 'yyyy-MM-dd';\n\nexport class IxDate extends MobxLitElement {\n static {\n requestUpdateOnAriaChange(IxDate);\n }\n\n static get styles() {\n return [IxDateStyles];\n }\n\n @property({ type: String }) type: 'default' | 'static' = 'default';\n\n @property({ type: String }) variant: 'date' | 'time' | 'date-time' = 'date';\n\n @property({ type: String }) format = defaultDateFormat;\n\n @property({ type: String }) timeFormat = defaultTimeFormat;\n\n @property({ type: String }) timezone = 'UTC';\n\n @property({ type: String }) label = '';\n\n @property({ type: String }) dateTimeText = '';\n\n /**\n * For `type='default'`, should be any value that is accepted by [new Date()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date).\n *\n * For `type='static'`, should be a date string that can be parsed by [parseISO](https://date-fns.org/v2.0.0/docs/parseISO), e.g.\n * - `2025-01-01`\n * - `2025-01-01 12:30Z`\n * - `2025-01-01T12:30:00.000+02:00`\n * */\n @property({ type: String }) value = '';\n\n @property({ type: Boolean }) showCalendarOnMouseDown = false;\n\n @property({ type: String }) min = '';\n\n @property({ type: String }) max = '9999-12-31';\n\n /**\n * Applies when type=static. Defaults to `false`.\n *\n * If `true`, the value is formatted but no time zone conversions are applied.\n *\n * If `false`, values that do not specify a time zone are interpreted as being in the\n * user's local time zone and all values are displayed in the user's local time zone.\n */\n @property({ type: Boolean, attribute: 'no-time-zone-conversion' })\n noTimeZoneConversion = false;\n\n // Form association\n\n /** @nocollapse */\n static override shadowRootOptions = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n /** @nocollapse */\n static readonly formAssociated = true;\n\n private readonly internals = (this as HTMLElement) /* needed for closure */\n .attachInternals();\n\n @query('#date-input') dateInput!: HTMLInputElement;\n\n @query('vaadin-date-picker') datePicker!: any;\n\n @property({ type: Boolean, reflect: true }) disabled = false;\n\n /**\n * Gets or sets whether or not the text field is in a visually invalid state.\n *\n * This error state overrides the error state controlled by\n * `reportValidity()`.\n */\n get error() {\n return !!this.errorText;\n }\n\n @property({ type: String, attribute: 'error-text' }) errorText = '';\n\n @property({ type: Boolean, reflect: true }) required = false;\n\n @property({ type: Boolean, reflect: true }) hideError = false;\n\n @property({ type: Boolean, attribute: 'clear-button-visible' })\n clearButtonVisible = true;\n\n /**\n * The associated form element with which this element's value will submit.\n */\n get form() {\n return this.internals.form;\n }\n\n /**\n * The labels this element is associated with.\n */\n get labels() {\n return this.internals.labels;\n }\n\n /**\n * The HTML name to use in form submission.\n */\n get name() {\n return this.getAttribute('name') ?? '';\n }\n\n set name(name: string) {\n this.setAttribute('name', name);\n }\n\n /**\n * Returns the text field's validation error message.\n *\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation\n */\n get validationMessage() {\n return this.internals.validationMessage;\n }\n\n /**\n * Returns a `ValidityState` object that represents the validity states of the\n * text field.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ValidityState\n */\n get validity() {\n return this.internals.validity;\n }\n\n /**\n * Returns whether an element will successfully validate based on forms\n * validation rules and constraints.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/willValidate\n */\n get willValidate() {\n return this.internals.willValidate;\n }\n\n checkValidity() {\n return this.internals.checkValidity();\n }\n\n reportValidity() {\n return this.internals.reportValidity();\n }\n\n /** @private */\n formResetCallback() {\n this.reset();\n }\n\n /**\n * Reset the text field to its default value.\n */\n reset() {\n this.clear();\n this.value = this.getAttribute('value') ?? '';\n }\n\n protected override updated(\n changedProperties: Map<string | number | symbol, unknown>\n ) {\n if (changedProperties.has('value')) {\n const inputVal = this.dateInput ? this.dateInput : this.datePicker;\n if (inputVal) {\n this.internals.setValidity(\n {\n badInput: this.error,\n },\n this.error ? this.errorText : '',\n inputVal\n );\n }\n }\n\n this.internals.setFormValue(this.value);\n }\n\n override focus() {\n this.dateInput.focus();\n }\n\n // eslint-disable-next-line class-methods-use-this\n @property({ type: Function }) onChanged: any = () => {};\n\n @state() private focused = false;\n\n connectedCallback(): void {\n super.connectedCallback();\n document.addEventListener(\n 'dateFormatChanged',\n this.handleDateFormatChanged\n );\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n document.removeEventListener(\n 'dateFormatChanged',\n this.handleDateFormatChanged\n );\n }\n\n handleDateFormatChanged = async () => {\n await dateFormatState.hydrateStore();\n\n this.format = dateFormatState.preferredDateFormat;\n this.timeFormat = dateFormatState.preferredTimeFormat;\n this.timezone = dateFormatState.preferredTimezone;\n };\n\n firstUpdated() {\n const minDate = new Date(this.min);\n const maxDate = new Date(this.max);\n\n if (minDate && !Number.isNaN(minDate.valueOf())) {\n const [min] = minDate.toISOString().split('T');\n this.min = min;\n }\n\n if (maxDate && !Number.isNaN(maxDate.valueOf())) {\n const [max] = maxDate.toISOString().split('T');\n this.max = max;\n }\n\n this.validateDate();\n\n this.format = dateFormatState.preferredDateFormat;\n\n this.timeFormat = dateFormatState.preferredTimeFormat;\n\n this.timezone = dateFormatState.preferredTimezone;\n\n if (this.datePicker) {\n const formatDateIso8601 = (dateParts: any): string => {\n const { year, month, day } = dateParts;\n const date = new Date(year, month, day);\n\n return format(date, this.format);\n };\n\n const parseDateIso8601 = (inputValue: string) => {\n const date = parse(inputValue, this.format, new Date());\n\n return {\n year: date.getFullYear(),\n month: date.getMonth(),\n day: date.getDate(),\n };\n };\n\n this.datePicker.i18n = {\n ...this.datePicker.i18n,\n formatDate: formatDateIso8601,\n parseDate: parseDateIso8601,\n };\n }\n }\n\n handleMouseDown = (e: Event) => {\n if (this.showCalendarOnMouseDown) {\n const inputElement = e.target as HTMLInputElement;\n\n if ('showPicker' in inputElement) {\n inputElement.showPicker();\n }\n }\n };\n\n focusin = () => {\n this.focused = true;\n };\n\n clear = () => {\n this.value = '';\n };\n\n handleChange = (e: InputEvent) => {\n const { value } = e.target as HTMLInputElement;\n this.value = value;\n this.validateDate();\n this.onChanged(value);\n };\n\n validateDate = () => {\n if (this.value) {\n const date = new Date(this.value);\n\n if (!date || Number.isNaN(date.valueOf())) {\n this.errorText = 'Invalid date format.';\n }\n }\n };\n\n focusOut = () => {\n this.focused = false;\n };\n\n parseValue = () => {\n if (typeof this.value !== 'string') {\n return this.value;\n }\n\n if (this.noTimeZoneConversion) {\n // Matches the time zone designator, e.g. `Z` or `-02:00`.\n // Note: does not match `-02` and `-0200`, which are valid ISO 8601 but rarely used.\n const timeZoneRegex = /Z|([+-]\\d\\d:\\d\\d)/;\n const valueWithoutTimeZone = this.value.split(timeZoneRegex)[0];\n return parseISO(valueWithoutTimeZone);\n }\n\n return parseISO(this.value);\n };\n\n getTimezoneDateTime = (date: Date) => {\n const parts = new Intl.DateTimeFormat('en-GB', {\n timeZone: this.timezone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: false,\n }).formatToParts(new Date(date));\n\n const get = (type: string) => parts.find(p => p.type === type)?.value;\n\n const year = get('year');\n const month = get('month');\n const day = get('day');\n const hour = get('hour');\n const minute = get('minute');\n const second = get('second');\n\n return new Date(`${year}-${month}-${day}T${hour}:${minute}:${second}`);\n };\n\n formatValueAsDate = (date: Date) => {\n if (new Date(date).toISOString().includes('T')) {\n return format(\n this.getTimezoneDateTime(date),\n this.format || defaultDateFormat\n );\n }\n return format(date, this.format || defaultDateFormat);\n };\n\n formatValueAsTime = (date: Date) =>\n format(\n this.getTimezoneDateTime(date),\n this.timeFormat || defaultTimeFormat\n );\n\n formatValueAsDateTime = (date: Date) =>\n `${this.formatValueAsDate(date)}${\n this.dateTimeText ? ` ${this.dateTimeText} ` : ' '\n }${this.formatValueAsTime(date)}`;\n\n formatValue = () => {\n const parsedDate = this.parseValue();\n if (!isValid(parsedDate)) return '';\n switch (this.variant) {\n case 'date':\n return this.formatValueAsDate(parsedDate);\n case 'time':\n return this.formatValueAsTime(parsedDate);\n case 'date-time':\n return this.formatValueAsDateTime(parsedDate);\n default:\n return '';\n }\n };\n\n get nativeInputValue() {\n try {\n return new Date(this.value).toISOString().split('T')[0];\n } catch (error) {\n return this.value;\n }\n }\n\n renderStaticDate() {\n return html`<span>${this.formatValue()}</span>`;\n }\n\n renderDateInput() {\n const classes = {\n disabled: this.disabled,\n error: !this.disabled && this.error,\n };\n\n return html` <ix-field\n class=\"${classMap(classes)}\"\n ?focused=${this.focused}\n ?populated=${this.value}\n ?disabled=${this.disabled}\n ?required=${this.required}\n ?error=${this.error && !this.hideError}\n error-text=${this.errorText}\n label=${this.label}\n @focusin=${this.focusin}\n @focusout=${this.focusOut}\n >\n ${html`<input\n id=\"date-input\"\n @change=${this.handleChange}\n @mousedown=${this.handleMouseDown}\n .value=${this.nativeInputValue}\n class=\"flex-fill\"\n type=\"date\"\n min=${this.min}\n max=${this.max}\n ?disabled=${this.disabled}\n />`}\n </ix-field>`;\n }\n\n render() {\n return this.type === 'static'\n ? this.renderStaticDate()\n : this.renderDateInput();\n }\n}\n"]}
@@ -1 +1 @@
1
- import{__decorate}from"tslib";import{css,LitElement,html}from"lit";import{property,query,state}from"lit/decorators.js";import{classMap}from"lit/directives/class-map.js";import"@digital-realty/ix-field/ix-field.js";import{requestUpdateOnAriaChange}from"@material/web/internal/aria/delegate.js";import{format}from"date-fns/format.js";import{isValid}from"date-fns/isValid.js";import{parse}from"date-fns/parse.js";import{parseISO}from"date-fns/parseISO.js";import{MobxLitElement}from"@adobe/lit-mobx";import{makeAutoObservable}from"mobx";import{makePersistable,isHydrated,hydrateStore,clearPersistedStore,getPersistedStore}from"mobx-persist-store";class DateFormatState{constructor(){this.preferredDateFormat="dd/MM/yyyy",this.preferredTimeFormat="HH:mm",makeAutoObservable(this),makePersistable(this,{name:"date-format",properties:["preferredDateFormat","preferredTimeFormat"],storage:window.localStorage})}get isHydrated(){return isHydrated(this)}async hydrateStore(){await hydrateStore(this)}async clearStoredDate(){await clearPersistedStore(this)}async getStoredData(){return getPersistedStore(this)}}let dateFormatState=new DateFormatState,IxDateStyles=css`:host{display:block}::part(input-field){background:0 0;padding:0;height:26px}#search-input-vaadin-date-picker-3{padding:0!important;--_hover-highlight:transparent}ix-field{display:block;position:relative;--vaadin-field-default-width:auto;height:var(--ix-line-height);cursor:pointer}input::-webkit-calendar-picker-indicator{cursor:pointer}vaadin-date-picker::before{display:none}`;class IxDate extends MobxLitElement{constructor(){super(...arguments),this.type="default",this.format="dd/MM/yyyy",this.timeFormat="HH:mm",this.variant="date",this.label="",this.dateTimeText="",this.value="",this.showCalendarOnMouseDown=!1,this.min="",this.max="9999-12-31",this.internals=this.attachInternals(),this.disabled=!1,this.errorText="",this.required=!1,this.hideError=!1,this.clearButtonVisible=!0,this.onChanged=()=>{},this.focused=!1,this.handleDateFormatChanged=async()=>{await dateFormatState.hydrateStore(),this.format=dateFormatState.preferredDateFormat,this.timeFormat=dateFormatState.preferredTimeFormat},this.handleMouseDown=t=>{this.showCalendarOnMouseDown&&"showPicker"in(t=t.target)&&t.showPicker()},this.focusin=()=>{this.focused=!0},this.clear=()=>{this.value=""},this.handleChange=t=>{t=t.target.value;this.value=t,this.validateDate(),this.onChanged(t)},this.validateDate=()=>{var t;!this.value||(t=new Date(this.value))&&!Number.isNaN(t.valueOf())||(this.errorText="Invalid date format.")},this.focusOut=()=>{this.focused=!1},this.formatDate=t=>{t="string"==typeof t?parseISO(t):t;return isValid(t)?format(t,this.format||"dd/MM/yyyy"):""},this.formatTime=t=>{t="string"==typeof t?parseISO(t):t;return isValid(t)?format(t,this.timeFormat||"HH:mm"):""}}static get styles(){return[IxDateStyles]}get error(){return!!this.errorText}get form(){return this.internals.form}get labels(){return this.internals.labels}get name(){var t;return null!=(t=this.getAttribute("name"))?t:""}set name(t){this.setAttribute("name",t)}get validationMessage(){return this.internals.validationMessage}get validity(){return this.internals.validity}get willValidate(){return this.internals.willValidate}checkValidity(){return this.internals.checkValidity()}reportValidity(){return this.internals.reportValidity()}formResetCallback(){this.reset()}reset(){var t;this.clear(),this.value=null!=(t=this.getAttribute("value"))?t:""}updated(t){t.has("value")&&(t=this.dateInput||this.datePicker)&&this.internals.setValidity({badInput:this.error},this.error?this.errorText:"",t),this.internals.setFormValue(this.value)}focus(){this.dateInput.focus()}connectedCallback(){super.connectedCallback(),document.addEventListener("dateFormatChanged",this.handleDateFormatChanged)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("dateFormatChanged",this.handleDateFormatChanged)}firstUpdated(){var t=new Date(this.min),e=new Date(this.max);t&&!Number.isNaN(t.valueOf())&&([t]=t.toISOString().split("T"),this.min=t),e&&!Number.isNaN(e.valueOf())&&([t]=e.toISOString().split("T"),this.max=t),this.validateDate(),this.format=dateFormatState.preferredDateFormat,this.timeFormat=dateFormatState.preferredTimeFormat,this.datePicker&&(this.datePicker.i18n={...this.datePicker.i18n,formatDate:t=>{var{year:t,month:e,day:r}=t,t=new Date(t,e,r);return format(t,this.format)},parseDate:t=>{t=parse(t,this.format,new Date);return{year:t.getFullYear(),month:t.getMonth(),day:t.getDate()}}})}get nativeInputValue(){try{return new Date(this.value).toISOString().split("T")[0]}catch(t){return this.value}}render(){var t={disabled:this.disabled,error:!this.disabled&&this.error};return"static"===this.type?html`<span>${this.formatDate(this.value)}${"date-time"===this.variant?(this.dateTimeText?` ${this.dateTimeText} `:" ")+this.formatTime(this.value):""}</span>`:html`<ix-field class="${classMap(t)}" ?focused="${this.focused}" ?populated="${this.value}" ?disabled="${this.disabled}" ?required="${this.required}" ?error="${this.error&&!this.hideError}" error-text="${this.errorText}" label="${this.label}" @focusin="${this.focusin}" @focusout="${this.focusOut}">${html`<input id="date-input" @change="${this.handleChange}" @mousedown="${this.handleMouseDown}" .value="${this.nativeInputValue}" class="flex-fill" type="date" min="${this.min}" max="${this.max}" ?disabled="${this.disabled}">`}</ix-field>`}}requestUpdateOnAriaChange(IxDate),IxDate.shadowRootOptions={...LitElement.shadowRootOptions,delegatesFocus:!0},IxDate.formAssociated=!0,__decorate([property({type:String})],IxDate.prototype,"type",void 0),__decorate([property({type:String})],IxDate.prototype,"format",void 0),__decorate([property({type:String})],IxDate.prototype,"timeFormat",void 0),__decorate([property({type:String})],IxDate.prototype,"variant",void 0),__decorate([property({type:String})],IxDate.prototype,"label",void 0),__decorate([property({type:String})],IxDate.prototype,"dateTimeText",void 0),__decorate([property({type:String})],IxDate.prototype,"value",void 0),__decorate([property({type:Boolean})],IxDate.prototype,"showCalendarOnMouseDown",void 0),__decorate([property({type:String})],IxDate.prototype,"min",void 0),__decorate([property({type:String})],IxDate.prototype,"max",void 0),__decorate([query("#date-input")],IxDate.prototype,"dateInput",void 0),__decorate([query("vaadin-date-picker")],IxDate.prototype,"datePicker",void 0),__decorate([property({type:Boolean,reflect:!0})],IxDate.prototype,"disabled",void 0),__decorate([property({type:String,attribute:"error-text"})],IxDate.prototype,"errorText",void 0),__decorate([property({type:Boolean,reflect:!0})],IxDate.prototype,"required",void 0),__decorate([property({type:Boolean,reflect:!0})],IxDate.prototype,"hideError",void 0),__decorate([property({type:Boolean,attribute:"clear-button-visible"})],IxDate.prototype,"clearButtonVisible",void 0),__decorate([property({type:Function})],IxDate.prototype,"onChanged",void 0),__decorate([state()],IxDate.prototype,"focused",void 0),window.customElements.define("ix-date",IxDate);
1
+ import{__decorate}from"tslib";import{css,LitElement,html}from"lit";import{property,query,state}from"lit/decorators.js";import{classMap}from"lit/directives/class-map.js";import"@digital-realty/ix-field/ix-field.js";import{requestUpdateOnAriaChange}from"@material/web/internal/aria/delegate.js";import{format}from"date-fns/format.js";import{isValid}from"date-fns/isValid.js";import{parse}from"date-fns/parse.js";import{parseISO}from"date-fns/parseISO.js";import{MobxLitElement}from"@adobe/lit-mobx";import{makeAutoObservable}from"mobx";import{makePersistable,isHydrated,hydrateStore,clearPersistedStore,getPersistedStore}from"mobx-persist-store";let defaultDateFormat="dd/MM/yyyy",defaultTimeFormat="HH:mm",defaultTimezone="UTC";class DateFormatState{constructor(){this.preferredDateFormat=defaultDateFormat,this.preferredTimeFormat=defaultTimeFormat,this.preferredTimezone=defaultTimezone,makeAutoObservable(this),makePersistable(this,{name:"date-format",properties:["preferredDateFormat","preferredTimeFormat","preferredTimezone"],storage:window.localStorage})}get isHydrated(){return isHydrated(this)}async hydrateStore(){await hydrateStore(this)}async clearStoredDate(){await clearPersistedStore(this)}async getStoredData(){return getPersistedStore(this)}}let dateFormatState=new DateFormatState,IxDateStyles=css`:host{display:block}::part(input-field){background:0 0;padding:0;height:26px}#search-input-vaadin-date-picker-3{padding:0!important;--_hover-highlight:transparent}ix-field{display:block;position:relative;--vaadin-field-default-width:auto;height:var(--ix-line-height);cursor:pointer}input::-webkit-calendar-picker-indicator{cursor:pointer}vaadin-date-picker::before{display:none}`;class IxDate extends MobxLitElement{constructor(){super(...arguments),this.type="default",this.variant="date",this.format=defaultDateFormat,this.timeFormat=defaultTimeFormat,this.timezone="UTC",this.label="",this.dateTimeText="",this.value="",this.showCalendarOnMouseDown=!1,this.min="",this.max="9999-12-31",this.noTimeZoneConversion=!1,this.internals=this.attachInternals(),this.disabled=!1,this.errorText="",this.required=!1,this.hideError=!1,this.clearButtonVisible=!0,this.onChanged=()=>{},this.focused=!1,this.handleDateFormatChanged=async()=>{await dateFormatState.hydrateStore(),this.format=dateFormatState.preferredDateFormat,this.timeFormat=dateFormatState.preferredTimeFormat,this.timezone=dateFormatState.preferredTimezone},this.handleMouseDown=t=>{this.showCalendarOnMouseDown&&"showPicker"in(t=t.target)&&t.showPicker()},this.focusin=()=>{this.focused=!0},this.clear=()=>{this.value=""},this.handleChange=t=>{t=t.target.value;this.value=t,this.validateDate(),this.onChanged(t)},this.validateDate=()=>{var t;!this.value||(t=new Date(this.value))&&!Number.isNaN(t.valueOf())||(this.errorText="Invalid date format.")},this.focusOut=()=>{this.focused=!1},this.parseValue=()=>{var t;return"string"!=typeof this.value?this.value:this.noTimeZoneConversion?(t=this.value.split(/Z|([+-]\d\d:\d\d)/)[0],parseISO(t)):parseISO(this.value)},this.getTimezoneDateTime=t=>{let a=new Intl.DateTimeFormat("en-GB",{timeZone:this.timezone,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(t));var t=e=>{var t;return null==(t=a.find(t=>t.type===e))?void 0:t.value},e=t("year"),r=t("month"),i=t("day"),o=t("hour"),s=t("minute"),t=t("second");return new Date(e+`-${r}-${i}T${o}:${s}:`+t)},this.formatValueAsDate=t=>new Date(t).toISOString().includes("T")?format(this.getTimezoneDateTime(t),this.format||defaultDateFormat):format(t,this.format||defaultDateFormat),this.formatValueAsTime=t=>format(this.getTimezoneDateTime(t),this.timeFormat||defaultTimeFormat),this.formatValueAsDateTime=t=>""+this.formatValueAsDate(t)+(this.dateTimeText?` ${this.dateTimeText} `:" ")+this.formatValueAsTime(t),this.formatValue=()=>{var t=this.parseValue();if(!isValid(t))return"";switch(this.variant){case"date":return this.formatValueAsDate(t);case"time":return this.formatValueAsTime(t);case"date-time":return this.formatValueAsDateTime(t);default:return""}}}static get styles(){return[IxDateStyles]}get error(){return!!this.errorText}get form(){return this.internals.form}get labels(){return this.internals.labels}get name(){var t;return null!=(t=this.getAttribute("name"))?t:""}set name(t){this.setAttribute("name",t)}get validationMessage(){return this.internals.validationMessage}get validity(){return this.internals.validity}get willValidate(){return this.internals.willValidate}checkValidity(){return this.internals.checkValidity()}reportValidity(){return this.internals.reportValidity()}formResetCallback(){this.reset()}reset(){var t;this.clear(),this.value=null!=(t=this.getAttribute("value"))?t:""}updated(t){t.has("value")&&(t=this.dateInput||this.datePicker)&&this.internals.setValidity({badInput:this.error},this.error?this.errorText:"",t),this.internals.setFormValue(this.value)}focus(){this.dateInput.focus()}connectedCallback(){super.connectedCallback(),document.addEventListener("dateFormatChanged",this.handleDateFormatChanged)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("dateFormatChanged",this.handleDateFormatChanged)}firstUpdated(){var t=new Date(this.min),e=new Date(this.max);t&&!Number.isNaN(t.valueOf())&&([t]=t.toISOString().split("T"),this.min=t),e&&!Number.isNaN(e.valueOf())&&([t]=e.toISOString().split("T"),this.max=t),this.validateDate(),this.format=dateFormatState.preferredDateFormat,this.timeFormat=dateFormatState.preferredTimeFormat,this.timezone=dateFormatState.preferredTimezone,this.datePicker&&(this.datePicker.i18n={...this.datePicker.i18n,formatDate:t=>{var{year:t,month:e,day:a}=t,t=new Date(t,e,a);return format(t,this.format)},parseDate:t=>{t=parse(t,this.format,new Date);return{year:t.getFullYear(),month:t.getMonth(),day:t.getDate()}}})}get nativeInputValue(){try{return new Date(this.value).toISOString().split("T")[0]}catch(t){return this.value}}renderStaticDate(){return html`<span>${this.formatValue()}</span>`}renderDateInput(){var t={disabled:this.disabled,error:!this.disabled&&this.error};return html`<ix-field class="${classMap(t)}" ?focused="${this.focused}" ?populated="${this.value}" ?disabled="${this.disabled}" ?required="${this.required}" ?error="${this.error&&!this.hideError}" error-text="${this.errorText}" label="${this.label}" @focusin="${this.focusin}" @focusout="${this.focusOut}">${html`<input id="date-input" @change="${this.handleChange}" @mousedown="${this.handleMouseDown}" .value="${this.nativeInputValue}" class="flex-fill" type="date" min="${this.min}" max="${this.max}" ?disabled="${this.disabled}">`}</ix-field>`}render(){return"static"===this.type?this.renderStaticDate():this.renderDateInput()}}requestUpdateOnAriaChange(IxDate),IxDate.shadowRootOptions={...LitElement.shadowRootOptions,delegatesFocus:!0},IxDate.formAssociated=!0,__decorate([property({type:String})],IxDate.prototype,"type",void 0),__decorate([property({type:String})],IxDate.prototype,"variant",void 0),__decorate([property({type:String})],IxDate.prototype,"format",void 0),__decorate([property({type:String})],IxDate.prototype,"timeFormat",void 0),__decorate([property({type:String})],IxDate.prototype,"timezone",void 0),__decorate([property({type:String})],IxDate.prototype,"label",void 0),__decorate([property({type:String})],IxDate.prototype,"dateTimeText",void 0),__decorate([property({type:String})],IxDate.prototype,"value",void 0),__decorate([property({type:Boolean})],IxDate.prototype,"showCalendarOnMouseDown",void 0),__decorate([property({type:String})],IxDate.prototype,"min",void 0),__decorate([property({type:String})],IxDate.prototype,"max",void 0),__decorate([property({type:Boolean,attribute:"no-time-zone-conversion"})],IxDate.prototype,"noTimeZoneConversion",void 0),__decorate([query("#date-input")],IxDate.prototype,"dateInput",void 0),__decorate([query("vaadin-date-picker")],IxDate.prototype,"datePicker",void 0),__decorate([property({type:Boolean,reflect:!0})],IxDate.prototype,"disabled",void 0),__decorate([property({type:String,attribute:"error-text"})],IxDate.prototype,"errorText",void 0),__decorate([property({type:Boolean,reflect:!0})],IxDate.prototype,"required",void 0),__decorate([property({type:Boolean,reflect:!0})],IxDate.prototype,"hideError",void 0),__decorate([property({type:Boolean,attribute:"clear-button-visible"})],IxDate.prototype,"clearButtonVisible",void 0),__decorate([property({type:Function})],IxDate.prototype,"onChanged",void 0),__decorate([state()],IxDate.prototype,"focused",void 0),window.customElements.define("ix-date",IxDate);
@@ -1,7 +1,11 @@
1
+ export declare const defaultDateFormat = "dd/MM/yyyy";
2
+ export declare const defaultTimeFormat = "HH:mm";
3
+ export declare const defaultTimezone = "UTC";
1
4
  declare class DateFormatState {
2
5
  constructor();
3
6
  preferredDateFormat: string;
4
7
  preferredTimeFormat: string;
8
+ preferredTimezone: string;
5
9
  get isHydrated(): boolean;
6
10
  hydrateStore(): Promise<void>;
7
11
  clearStoredDate(): Promise<void>;
@@ -1,13 +1,21 @@
1
1
  import { makeAutoObservable } from 'mobx';
2
2
  import { makePersistable, isHydrated, hydrateStore, clearPersistedStore, getPersistedStore, } from 'mobx-persist-store';
3
+ export const defaultDateFormat = 'dd/MM/yyyy';
4
+ export const defaultTimeFormat = 'HH:mm';
5
+ export const defaultTimezone = 'UTC';
3
6
  class DateFormatState {
4
7
  constructor() {
5
- this.preferredDateFormat = 'dd/MM/yyyy';
6
- this.preferredTimeFormat = 'HH:mm';
8
+ this.preferredDateFormat = defaultDateFormat;
9
+ this.preferredTimeFormat = defaultTimeFormat;
10
+ this.preferredTimezone = defaultTimezone;
7
11
  makeAutoObservable(this);
8
12
  makePersistable(this, {
9
13
  name: 'date-format',
10
- properties: ['preferredDateFormat', 'preferredTimeFormat'],
14
+ properties: [
15
+ 'preferredDateFormat',
16
+ 'preferredTimeFormat',
17
+ 'preferredTimezone',
18
+ ],
11
19
  storage: window.localStorage,
12
20
  });
13
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"date-format-state.js","sourceRoot":"","sources":["../../src/state/date-format-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EACL,eAAe,EACf,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,eAAe;IACnB;QASO,wBAAmB,GAAW,YAAY,CAAC;QAE3C,wBAAmB,GAAW,OAAO,CAAC;QAV3C,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACzB,eAAe,CAAC,IAAI,EAAE;YACpB,IAAI,EAAE,aAAa;YACnB,UAAU,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;YAC1D,OAAO,EAAE,MAAM,CAAC,YAAY;SAC7B,CAAC,CAAC;IACL,CAAC;IAMD,IAAI,UAAU;QACZ,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC","sourcesContent":["import { makeAutoObservable } from 'mobx';\nimport {\n makePersistable,\n isHydrated,\n hydrateStore,\n clearPersistedStore,\n getPersistedStore,\n} from 'mobx-persist-store';\n\nclass DateFormatState {\n constructor() {\n makeAutoObservable(this);\n makePersistable(this, {\n name: 'date-format',\n properties: ['preferredDateFormat', 'preferredTimeFormat'],\n storage: window.localStorage,\n });\n }\n\n public preferredDateFormat: string = 'dd/MM/yyyy';\n\n public preferredTimeFormat: string = 'HH:mm';\n\n get isHydrated() {\n return isHydrated(this);\n }\n\n async hydrateStore() {\n await hydrateStore(this);\n }\n\n async clearStoredDate() {\n await clearPersistedStore(this);\n }\n\n async getStoredData() {\n return getPersistedStore(this);\n }\n}\n\nexport const dateFormatState = new DateFormatState();\n"]}
1
+ {"version":3,"file":"date-format-state.js","sourceRoot":"","sources":["../../src/state/date-format-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EACL,eAAe,EACf,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAC9C,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAEzC,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAErC,MAAM,eAAe;IACnB;QAaO,wBAAmB,GAAW,iBAAiB,CAAC;QAEhD,wBAAmB,GAAW,iBAAiB,CAAC;QAEhD,sBAAiB,GAAW,eAAe,CAAC;QAhBjD,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACzB,eAAe,CAAC,IAAI,EAAE;YACpB,IAAI,EAAE,aAAa;YACnB,UAAU,EAAE;gBACV,qBAAqB;gBACrB,qBAAqB;gBACrB,mBAAmB;aACpB;YACD,OAAO,EAAE,MAAM,CAAC,YAAY;SAC7B,CAAC,CAAC;IACL,CAAC;IAQD,IAAI,UAAU;QACZ,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC","sourcesContent":["import { makeAutoObservable } from 'mobx';\nimport {\n makePersistable,\n isHydrated,\n hydrateStore,\n clearPersistedStore,\n getPersistedStore,\n} from 'mobx-persist-store';\n\nexport const defaultDateFormat = 'dd/MM/yyyy';\nexport const defaultTimeFormat = 'HH:mm';\n\nexport const defaultTimezone = 'UTC';\n\nclass DateFormatState {\n constructor() {\n makeAutoObservable(this);\n makePersistable(this, {\n name: 'date-format',\n properties: [\n 'preferredDateFormat',\n 'preferredTimeFormat',\n 'preferredTimezone',\n ],\n storage: window.localStorage,\n });\n }\n\n public preferredDateFormat: string = defaultDateFormat;\n\n public preferredTimeFormat: string = defaultTimeFormat;\n\n public preferredTimezone: string = defaultTimezone;\n\n get isHydrated() {\n return isHydrated(this);\n }\n\n async hydrateStore() {\n await hydrateStore(this);\n }\n\n async clearStoredDate() {\n await clearPersistedStore(this);\n }\n\n async getStoredData() {\n return getPersistedStore(this);\n }\n}\n\nexport const dateFormatState = new DateFormatState();\n"]}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent ix-date following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "Digital Realty",
6
- "version": "1.1.22",
6
+ "version": "1.1.24",
7
7
  "type": "module",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.js",
@@ -40,7 +40,9 @@
40
40
  "@custom-elements-manifest/analyzer": "^0.4.17",
41
41
  "@open-wc/eslint-config": "^9.2.1",
42
42
  "@open-wc/testing": "^3.1.6",
43
+ "@rollup/plugin-commonjs": "^25.0.4",
43
44
  "@types/glob": "^8.1.0",
45
+ "@types/timezoned-date": "^3.0.2",
44
46
  "@typescript-eslint/eslint-plugin": "^5.48.0",
45
47
  "@typescript-eslint/parser": "^5.48.0",
46
48
  "@web/dev-server": "^0.1.34",
@@ -52,12 +54,14 @@
52
54
  "eslint-config-prettier": "^8.3.0",
53
55
  "husky": "^4.3.8",
54
56
  "lint-staged": "^10.5.4",
57
+ "mockdate": "^3.0.5",
55
58
  "prettier": "^2.4.1",
56
59
  "rollup": "^4.29.1",
57
60
  "rollup-plugin-minify-html-literals": "^1.2.6",
58
61
  "rollup-plugin-replace": "^2.2.0",
59
62
  "rollup-plugin-summary": "^2.0.0",
60
63
  "rollup-plugin-uglify": "^6.0.4",
64
+ "timezoned-date": "^3.0.2",
61
65
  "tslib": "^2.3.1",
62
66
  "typescript": "^4.5.2"
63
67
  },
@@ -108,5 +112,5 @@
108
112
  "README.md",
109
113
  "LICENSE"
110
114
  ],
111
- "gitHead": "15f4dd5cd6ac90da99b1aafb7f7729941df4c0f2"
115
+ "gitHead": "2af1c127e13d502807e04fd16849459bb70a5c13"
112
116
  }