tyrell-components 1.0.0-RC16 → 1.0.0-RC18

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.
Files changed (240) hide show
  1. package/README.md +1 -1
  2. package/css/tyrell-colors-static.css +1 -316
  3. package/css/tyrell-theme.css +1 -1471
  4. package/css/tyrell.css +1 -1385
  5. package/dist/tyrell-colors-static.css +1 -1
  6. package/dist/tyrell-theme.css +1 -1
  7. package/dist/tyrell.js +1 -1
  8. package/lib/base/ty-component.d.ts +28 -15
  9. package/lib/base/ty-component.js +81 -38
  10. package/lib/components/button.d.ts +14 -0
  11. package/lib/components/button.js +55 -7
  12. package/lib/components/calendar-month.d.ts +7 -1
  13. package/lib/components/calendar-month.js +35 -28
  14. package/lib/components/calendar-navigation.js +19 -6
  15. package/lib/components/calendar.d.ts +27 -3
  16. package/lib/components/calendar.js +107 -63
  17. package/lib/components/checkbox.d.ts +8 -1
  18. package/lib/components/checkbox.js +27 -6
  19. package/lib/components/copy.d.ts +2 -0
  20. package/lib/components/copy.js +15 -31
  21. package/lib/components/date-picker.d.ts +53 -18
  22. package/lib/components/date-picker.js +217 -146
  23. package/lib/components/file-upload.d.ts +4 -1
  24. package/lib/components/file-upload.js +23 -5
  25. package/lib/components/input.d.ts +73 -3
  26. package/lib/components/input.js +158 -22
  27. package/lib/components/modal.d.ts +2 -0
  28. package/lib/components/modal.js +97 -17
  29. package/lib/components/option.d.ts +19 -0
  30. package/lib/components/option.js +45 -31
  31. package/lib/components/popup.js +115 -15
  32. package/lib/components/radio.d.ts +10 -1
  33. package/lib/components/radio.js +22 -29
  34. package/lib/components/resize-observer.js +2 -0
  35. package/lib/components/scroll-container.js +2 -0
  36. package/lib/components/select.d.ts +150 -190
  37. package/lib/components/select.js +501 -796
  38. package/lib/components/selected-tags.d.ts +14 -4
  39. package/lib/components/selected-tags.js +35 -8
  40. package/lib/components/switch.d.ts +9 -1
  41. package/lib/components/switch.js +27 -6
  42. package/lib/components/tabs.js +1 -1
  43. package/lib/components/tag.d.ts +0 -9
  44. package/lib/components/tag.js +0 -11
  45. package/lib/components/textarea.d.ts +47 -2
  46. package/lib/components/textarea.js +81 -17
  47. package/lib/index.d.ts +1 -0
  48. package/lib/index.js +1 -0
  49. package/lib/styles/button.js +21 -19
  50. package/lib/styles/calendar-month.js +1 -1
  51. package/lib/styles/calendar.js +3 -0
  52. package/lib/styles/checkbox.js +11 -5
  53. package/lib/styles/date-picker.js +16 -4
  54. package/lib/styles/file-upload.d.ts +1 -1
  55. package/lib/styles/file-upload.js +3 -3
  56. package/lib/styles/icon.d.ts +1 -1
  57. package/lib/styles/icon.js +2 -2
  58. package/lib/styles/input.js +6 -10
  59. package/lib/styles/option.d.ts +1 -1
  60. package/lib/styles/option.js +6 -7
  61. package/lib/styles/popup.d.ts +1 -1
  62. package/lib/styles/popup.js +2 -0
  63. package/lib/styles/radio.js +12 -6
  64. package/lib/styles/select-base.js +22 -60
  65. package/lib/styles/select.d.ts +1 -1
  66. package/lib/styles/select.js +13 -2
  67. package/lib/styles/switch.js +10 -5
  68. package/lib/styles/tag.js +3 -5
  69. package/lib/styles/textarea.d.ts +1 -1
  70. package/lib/styles/textarea.js +7 -0
  71. package/lib/types/common.d.ts +3 -3
  72. package/lib/utils/calendar-utils.d.ts +49 -0
  73. package/lib/utils/calendar-utils.js +63 -6
  74. package/lib/utils/property-manager.d.ts +6 -5
  75. package/lib/utils/property-manager.js +14 -15
  76. package/lib/utils/scroll-lock.d.ts +10 -4
  77. package/lib/utils/scroll-lock.js +102 -2
  78. package/lib/utils/upgrade-properties.d.ts +21 -0
  79. package/lib/utils/upgrade-properties.js +47 -0
  80. package/lib/utils/validity.d.ts +98 -2
  81. package/lib/utils/validity.js +244 -8
  82. package/lib/version.d.ts +1 -1
  83. package/lib/version.js +1 -1
  84. package/package.json +8 -6
  85. package/lib/base/ty-component.d.ts.map +0 -1
  86. package/lib/base/ty-component.js.map +0 -1
  87. package/lib/components/button.d.ts.map +0 -1
  88. package/lib/components/button.js.map +0 -1
  89. package/lib/components/calendar-month.d.ts.map +0 -1
  90. package/lib/components/calendar-month.js.map +0 -1
  91. package/lib/components/calendar-navigation.d.ts.map +0 -1
  92. package/lib/components/calendar-navigation.js.map +0 -1
  93. package/lib/components/calendar.d.ts.map +0 -1
  94. package/lib/components/calendar.js.map +0 -1
  95. package/lib/components/checkbox.d.ts.map +0 -1
  96. package/lib/components/checkbox.js.map +0 -1
  97. package/lib/components/copy.d.ts.map +0 -1
  98. package/lib/components/copy.js.map +0 -1
  99. package/lib/components/date-picker.d.ts.map +0 -1
  100. package/lib/components/date-picker.js.map +0 -1
  101. package/lib/components/dropdown.d.ts +0 -403
  102. package/lib/components/dropdown.d.ts.map +0 -1
  103. package/lib/components/dropdown.js +0 -1315
  104. package/lib/components/dropdown.js.map +0 -1
  105. package/lib/components/icon.d.ts.map +0 -1
  106. package/lib/components/icon.js.map +0 -1
  107. package/lib/components/input.d.ts.map +0 -1
  108. package/lib/components/input.js.map +0 -1
  109. package/lib/components/modal.d.ts.map +0 -1
  110. package/lib/components/modal.js.map +0 -1
  111. package/lib/components/multiselect.d.ts +0 -389
  112. package/lib/components/multiselect.d.ts.map +0 -1
  113. package/lib/components/multiselect.js +0 -1301
  114. package/lib/components/multiselect.js.map +0 -1
  115. package/lib/components/option.d.ts.map +0 -1
  116. package/lib/components/option.js.map +0 -1
  117. package/lib/components/popup.d.ts.map +0 -1
  118. package/lib/components/popup.js.map +0 -1
  119. package/lib/components/resize-observer.d.ts.map +0 -1
  120. package/lib/components/resize-observer.js.map +0 -1
  121. package/lib/components/scroll-container.d.ts.map +0 -1
  122. package/lib/components/scroll-container.js.map +0 -1
  123. package/lib/components/step.d.ts.map +0 -1
  124. package/lib/components/step.js.map +0 -1
  125. package/lib/components/tab.d.ts.map +0 -1
  126. package/lib/components/tab.js.map +0 -1
  127. package/lib/components/tabs.d.ts.map +0 -1
  128. package/lib/components/tabs.js.map +0 -1
  129. package/lib/components/tag.d.ts.map +0 -1
  130. package/lib/components/tag.js.map +0 -1
  131. package/lib/components/textarea.d.ts.map +0 -1
  132. package/lib/components/textarea.js.map +0 -1
  133. package/lib/components/tooltip.d.ts.map +0 -1
  134. package/lib/components/tooltip.js.map +0 -1
  135. package/lib/components/wizard.d.ts.map +0 -1
  136. package/lib/components/wizard.js.map +0 -1
  137. package/lib/icons/fontawesome/brands.d.ts.map +0 -1
  138. package/lib/icons/fontawesome/brands.js.map +0 -1
  139. package/lib/icons/fontawesome/regular.d.ts.map +0 -1
  140. package/lib/icons/fontawesome/regular.js.map +0 -1
  141. package/lib/icons/fontawesome/solid.d.ts.map +0 -1
  142. package/lib/icons/fontawesome/solid.js.map +0 -1
  143. package/lib/icons/heroicons/micro.d.ts.map +0 -1
  144. package/lib/icons/heroicons/micro.js.map +0 -1
  145. package/lib/icons/heroicons/mini.d.ts.map +0 -1
  146. package/lib/icons/heroicons/mini.js.map +0 -1
  147. package/lib/icons/heroicons/outline.d.ts.map +0 -1
  148. package/lib/icons/heroicons/outline.js.map +0 -1
  149. package/lib/icons/heroicons/solid.d.ts.map +0 -1
  150. package/lib/icons/heroicons/solid.js.map +0 -1
  151. package/lib/icons/lucide.d.ts.map +0 -1
  152. package/lib/icons/lucide.js.map +0 -1
  153. package/lib/icons/material/filled.d.ts.map +0 -1
  154. package/lib/icons/material/filled.js.map +0 -1
  155. package/lib/icons/material/outlined.d.ts.map +0 -1
  156. package/lib/icons/material/outlined.js.map +0 -1
  157. package/lib/icons/material/round.d.ts.map +0 -1
  158. package/lib/icons/material/round.js.map +0 -1
  159. package/lib/icons/material/sharp.d.ts.map +0 -1
  160. package/lib/icons/material/sharp.js.map +0 -1
  161. package/lib/icons/material/two-tone.d.ts.map +0 -1
  162. package/lib/icons/material/two-tone.js.map +0 -1
  163. package/lib/index.d.ts.map +0 -1
  164. package/lib/index.js.map +0 -1
  165. package/lib/styles/button.d.ts.map +0 -1
  166. package/lib/styles/button.js.map +0 -1
  167. package/lib/styles/calendar-month.d.ts.map +0 -1
  168. package/lib/styles/calendar-month.js.map +0 -1
  169. package/lib/styles/calendar-navigation.d.ts.map +0 -1
  170. package/lib/styles/calendar-navigation.js.map +0 -1
  171. package/lib/styles/calendar.d.ts.map +0 -1
  172. package/lib/styles/calendar.js.map +0 -1
  173. package/lib/styles/copy.d.ts.map +0 -1
  174. package/lib/styles/copy.js.map +0 -1
  175. package/lib/styles/date-picker.d.ts.map +0 -1
  176. package/lib/styles/date-picker.js.map +0 -1
  177. package/lib/styles/dropdown.d.ts +0 -12
  178. package/lib/styles/dropdown.d.ts.map +0 -1
  179. package/lib/styles/dropdown.js +0 -725
  180. package/lib/styles/dropdown.js.map +0 -1
  181. package/lib/styles/icon.d.ts.map +0 -1
  182. package/lib/styles/icon.js.map +0 -1
  183. package/lib/styles/input.d.ts.map +0 -1
  184. package/lib/styles/input.js.map +0 -1
  185. package/lib/styles/modal.d.ts.map +0 -1
  186. package/lib/styles/modal.js.map +0 -1
  187. package/lib/styles/multiselect.d.ts +0 -6
  188. package/lib/styles/multiselect.d.ts.map +0 -1
  189. package/lib/styles/multiselect.js +0 -568
  190. package/lib/styles/multiselect.js.map +0 -1
  191. package/lib/styles/option.d.ts.map +0 -1
  192. package/lib/styles/option.js.map +0 -1
  193. package/lib/styles/popup.d.ts.map +0 -1
  194. package/lib/styles/popup.js.map +0 -1
  195. package/lib/styles/resize-observer.d.ts.map +0 -1
  196. package/lib/styles/resize-observer.js.map +0 -1
  197. package/lib/styles/scroll-container.d.ts.map +0 -1
  198. package/lib/styles/scroll-container.js.map +0 -1
  199. package/lib/styles/step.d.ts.map +0 -1
  200. package/lib/styles/step.js.map +0 -1
  201. package/lib/styles/tab.d.ts.map +0 -1
  202. package/lib/styles/tab.js.map +0 -1
  203. package/lib/styles/tabs.d.ts.map +0 -1
  204. package/lib/styles/tabs.js.map +0 -1
  205. package/lib/styles/tag.d.ts.map +0 -1
  206. package/lib/styles/tag.js.map +0 -1
  207. package/lib/styles/textarea.d.ts.map +0 -1
  208. package/lib/styles/textarea.js.map +0 -1
  209. package/lib/styles/tooltip.d.ts.map +0 -1
  210. package/lib/styles/tooltip.js.map +0 -1
  211. package/lib/styles/wizard.d.ts.map +0 -1
  212. package/lib/styles/wizard.js.map +0 -1
  213. package/lib/types/common.d.ts.map +0 -1
  214. package/lib/types/common.js.map +0 -1
  215. package/lib/utils/calendar-utils.d.ts.map +0 -1
  216. package/lib/utils/calendar-utils.js.map +0 -1
  217. package/lib/utils/icon-registry.d.ts.map +0 -1
  218. package/lib/utils/icon-registry.js.map +0 -1
  219. package/lib/utils/locale.d.ts.map +0 -1
  220. package/lib/utils/locale.js.map +0 -1
  221. package/lib/utils/number-format.d.ts.map +0 -1
  222. package/lib/utils/number-format.js.map +0 -1
  223. package/lib/utils/parse-boolean.d.ts +0 -39
  224. package/lib/utils/parse-boolean.d.ts.map +0 -1
  225. package/lib/utils/parse-boolean.js +0 -23
  226. package/lib/utils/parse-boolean.js.map +0 -1
  227. package/lib/utils/positioning.d.ts.map +0 -1
  228. package/lib/utils/positioning.js.map +0 -1
  229. package/lib/utils/property-capture.d.ts.map +0 -1
  230. package/lib/utils/property-capture.js.map +0 -1
  231. package/lib/utils/property-manager.d.ts.map +0 -1
  232. package/lib/utils/property-manager.js.map +0 -1
  233. package/lib/utils/resize-observer.d.ts.map +0 -1
  234. package/lib/utils/resize-observer.js.map +0 -1
  235. package/lib/utils/scroll-lock.d.ts.map +0 -1
  236. package/lib/utils/scroll-lock.js.map +0 -1
  237. package/lib/utils/styles.d.ts.map +0 -1
  238. package/lib/utils/styles.js.map +0 -1
  239. package/lib/version.d.ts.map +0 -1
  240. package/lib/version.js.map +0 -1
@@ -7,6 +7,8 @@ import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
7
7
  import { isMobileTouch } from '../utils/mobile.js';
8
8
  import { TyComponent } from '../base/ty-component.js';
9
9
  import { DEFAULT_SIZE } from '../types/common.js';
10
+ import { nativeMessage } from '../utils/validity.js';
11
+ import { parseDateTime, toISODay, wallClockDate } from '../utils/calendar-utils.js';
10
12
  const CALENDAR_ICON_SVG = `<svg stroke='currentColor' fill='none' stroke-width='2' viewBox='0 0 24 24' width='16' height='16' xmlns='http://www.w3.org/2000/svg'><rect x='3' y='4' width='18' height='18' rx='2' ry='2'></rect><line x1='16' y1='2' x2='16' y2='6'></line><line x1='8' y1='2' x2='8' y2='6'></line><line x1='3' y1='10' x2='21' y2='10'></line></svg>`;
11
13
  const CLEAR_ICON_SVG = `<svg stroke='currentColor' fill='none' stroke-width='2' viewBox='0 0 24 24' width='14' height='14' xmlns='http://www.w3.org/2000/svg'><line x1='18' y1='6' x2='6' y2='18'></line><line x1='6' y1='6' x2='18' y2='18'></line></svg>`;
12
14
  const SCHEDULE_ICON_SVG = `<svg stroke='currentColor' fill='none' stroke-width='2' viewBox='0 0 24 24' width='16' height='16' xmlns='http://www.w3.org/2000/svg'><circle cx='12' cy='12' r='10'></circle><polyline points='12,6 12,12 16,14'></polyline></svg>`;
@@ -20,48 +22,28 @@ elementIds.set(element, id);
20
22
  }
21
23
  return id;
22
24
  }
23
- function parseValue(value, withTime) {
24
- if (!value)
25
- return null;
26
- let dateObj = null;
27
- if (typeof value === 'string') {
28
- if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
29
- const [yearStr, monthStr, dayStr] = value.split('-');
30
- const year = parseInt(yearStr, 10);
31
- const month = parseInt(monthStr, 10) - 1;
32
- const day = parseInt(dayStr, 10);
33
- dateObj = new Date(year, month, day, 0, 0, 0, 0);
34
- }
35
- else {
36
- dateObj = new Date(value);
37
- }
38
- }
39
- else if (typeof value === 'number') {
40
- dateObj = new Date(value);
41
- }
42
- if (!dateObj || isNaN(dateObj.getTime())) {
43
- return null;
44
- }
45
- const components = {
46
- year: dateObj.getFullYear(),
47
- month: dateObj.getMonth() + 1,
48
- day: dateObj.getDate(),
49
- hour: withTime ? dateObj.getHours() : 0,
50
- minute: withTime ? dateObj.getMinutes() : 0,
51
- };
52
- return components;
53
- }
54
25
  function componentsToDateObject(components) {
55
- const { year, month, day, hour, minute } = components;
26
+ const { year, month, day, hour, minute, second } = components;
56
27
  if (!year || !month || !day)
57
28
  return null;
58
- return new Date(year, month - 1, day, hour || 0, minute || 0, 0, 0);
29
+ const date = new Date(2000, 0, 1, 12);
30
+ date.setFullYear(year, month - 1, day);
31
+ date.setHours(hour || 0, minute || 0, second || 0, 0);
32
+ return date;
33
+ }
34
+ function effectiveComponents(components, withTime) {
35
+ return withTime ? components : { ...components, hour: 0, minute: 0, second: 0, epoch: undefined };
59
36
  }
60
- function componentsToOutputValue(components) {
37
+ function componentsToOutputValue(components, withTime, native) {
61
38
  if (!components.year || !components.month || !components.day) {
62
39
  return null;
63
40
  }
64
- const dateObj = componentsToDateObject(components);
41
+ const c = effectiveComponents(components, withTime);
42
+ if (native)
43
+ return componentsToLocalValue(c, withTime);
44
+ if (c.epoch !== undefined)
45
+ return new Date(c.epoch).toISOString();
46
+ const dateObj = componentsToDateObject(c);
65
47
  return dateObj ? dateObj.toISOString() : null;
66
48
  }
67
49
  function componentsToLocalValue(components, withTime) {
@@ -74,27 +56,34 @@ const day = components.day.toString().padStart(2, '0');
74
56
  if (withTime) {
75
57
  const hour = (components.hour || 0).toString().padStart(2, '0');
76
58
  const minute = (components.minute || 0).toString().padStart(2, '0');
77
- return `${year}-${month}-${day}T${hour}:${minute}`;
59
+ const second = components.second ? `:${components.second.toString().padStart(2, '0')}` : '';
60
+ return `${year}-${month}-${day}T${hour}:${minute}${second}`;
78
61
  }
79
62
  else {
80
63
  return `${year}-${month}-${day}`;
81
64
  }
82
65
  }
83
- function formatDisplayValue(components, formatType, locale, withTime) {
66
+ function displayDate(components, native) {
67
+ return native
68
+ ? { date: wallClockDate(components), timeZone: 'UTC' }
69
+ : { date: componentsToDateObject(components) };
70
+ }
71
+ function formatDisplayValue(components, formatType, locale, withTime, native) {
84
72
  if (!components.year || !components.month || !components.day) {
85
73
  return null;
86
74
  }
87
- const dateObj = componentsToDateObject(components);
88
- if (!dateObj)
75
+ const { date, timeZone } = displayDate(components, native);
76
+ if (!date)
89
77
  return null;
90
78
  const options = {
91
79
  dateStyle: formatType || 'long',
80
+ timeZone,
92
81
  };
93
82
  if (withTime) {
94
83
  options.timeStyle = 'short';
95
84
  }
96
85
  const formatter = new Intl.DateTimeFormat(locale, options);
97
- return formatter.format(dateObj);
86
+ return formatter.format(date);
98
87
  }
99
88
  class TimeFields {
100
89
  constructor(hourEl, minuteEl, onChange, hour = 0, minute = 0) {
@@ -213,14 +202,19 @@ withTime: false,
213
202
  open: false,
214
203
  };
215
204
  this._closeTimestamp = 0;
205
+ this._initialized = false;
206
+ this._syncing = false;
216
207
  this._customFlavorSheet = null;
217
208
  const shadow = this.shadowRoot;
218
209
  ensureStyles(shadow, { css: datePickerStyles, id: 'ty-date-picker' });
219
210
  }
220
211
  onConnect() {
212
+ if (this._initialized)
213
+ this._state.open = false;
214
+ else
221
215
  this.initializeState();
222
216
  this.render();
223
- this.updateValidity();
217
+ this.updateFormValue();
224
218
  this._localeObserver = observeLocaleChanges(this, () => {
225
219
  this.render();
226
220
  });
@@ -253,74 +247,68 @@ break;
253
247
  case 'noClear':
254
248
  case 'format':
255
249
  case 'locale':
250
+ case 'error':
256
251
  break;
257
252
  case 'value': {
258
- const newComponents = parseValue(newValue, this._state.withTime);
259
- if (newComponents === null) {
260
- const hasDate = this._state.year !== undefined ||
261
- this._state.month !== undefined ||
262
- this._state.day !== undefined;
263
- if (hasDate) {
253
+ if (!this._initialized || this._syncing)
254
+ break;
264
255
  this._state = {
265
256
  withTime: this._state.withTime,
266
257
  open: this._state.open,
258
+ ...parseDateTime(newValue),
267
259
  };
268
- }
269
260
  this.syncFormValue();
270
261
  break;
271
262
  }
272
- const currentComponents = {
273
- year: this._state.year,
274
- month: this._state.month,
275
- day: this._state.day,
276
- hour: this._state.hour,
277
- minute: this._state.minute,
278
- };
279
- const changed = newComponents?.year !== currentComponents.year ||
280
- newComponents?.month !== currentComponents.month ||
281
- newComponents?.day !== currentComponents.day ||
282
- newComponents?.hour !== currentComponents.hour ||
283
- newComponents?.minute !== currentComponents.minute;
284
- if (changed) {
285
- this._state = {
286
- ...this._state,
287
- ...newComponents,
288
- };
289
- this.syncFormValue();
290
- }
291
- break;
292
- }
293
263
  case 'with-time': {
264
+ if (!this._initialized)
265
+ break;
294
266
  const newWithTime = newValue;
295
- const oldWithTime = this._state.withTime;
296
- if (newWithTime !== oldWithTime) {
267
+ if (newWithTime !== this._state.withTime) {
297
268
  this._state.withTime = newWithTime;
298
- const hasDate = this._state.year !== undefined &&
299
- this._state.month !== undefined &&
300
- this._state.day !== undefined;
301
- if (hasDate) {
302
269
  this.syncFormValue();
303
- }
270
+ this.updateValidity();
304
271
  }
305
272
  break;
306
273
  }
274
+ case 'native':
275
+ if (this._initialized)
276
+ this.syncFormValue();
277
+ break;
307
278
  }
308
279
  }
309
280
  }
310
281
  getFormValue() {
311
- return componentsToOutputValue(this.getComponents());
282
+ return this.outputValue(this.getComponents());
283
+ }
284
+ outputValue(components) {
285
+ return componentsToOutputValue(components, this._state.withTime, !!this.getProperty('native'));
312
286
  }
313
287
  updateFormValue() {
314
- super.updateFormValue();
288
+ this._internals.setFormValue(this.getFormValue() ?? '');
315
289
  this.updateValidity();
316
290
  }
291
+ focusTarget() {
292
+ return this.shadowRoot?.querySelector('.native-date-input')
293
+ ?? this.shadowRoot?.querySelector('.date-picker-stub')
294
+ ?? null;
295
+ }
296
+ focus(options) {
297
+ if (this.getProperty('disabled'))
298
+ return;
299
+ const target = this.focusTarget();
300
+ if (target)
301
+ target.focus(options);
302
+ else
303
+ super.focus(options);
304
+ }
317
305
  updateValidity() {
318
306
  if (this.getProperty('disabled') || !this.getProperty('required') || this.getFormValue()) {
319
307
  this.applyValidity({});
320
308
  return;
321
309
  }
322
- const anchor = this.shadowRoot?.querySelector('.date-picker-stub, .native-date-input');
323
- this.applyValidity({ valueMissing: true }, 'Please select a date', anchor ?? undefined);
310
+ const type = this._state.withTime ? 'datetime-local' : 'date';
311
+ this.applyValidity({ valueMissing: true }, nativeMessage('input', { type, required: true }), this.focusTarget() ?? undefined);
324
312
  }
325
313
  getComponents() {
326
314
  return {
@@ -329,6 +317,8 @@ month: this._state.month,
329
317
  day: this._state.day,
330
318
  hour: this._state.hour,
331
319
  minute: this._state.minute,
320
+ second: this._state.second,
321
+ epoch: this._state.epoch,
332
322
  };
333
323
  }
334
324
  hasDate() {
@@ -338,25 +328,15 @@ getFormattedValue(components) {
338
328
  const c = components || this.getComponents();
339
329
  if (!c.year || !c.month || !c.day)
340
330
  return null;
341
- return formatDisplayValue(c, this.getProperty('format') || 'long', getEffectiveLocale(this, this.getProperty('locale')), this._state.withTime);
331
+ return formatDisplayValue(c, this.getProperty('format') || 'long', getEffectiveLocale(this, this.getProperty('locale')), this._state.withTime, !!this.getProperty('native'));
342
332
  }
343
333
  initializeState() {
344
- const valueAttr = this.getProperty('value');
345
- const withTime = this.getProperty('with-time');
346
- const components = parseValue(valueAttr, withTime);
347
- if (components === null) {
348
334
  this._state = {
349
- withTime,
335
+ ...parseDateTime(this.getProperty('value')),
336
+ withTime: this.getProperty('with-time'),
350
337
  open: false,
351
338
  };
352
- }
353
- else {
354
- this._state = {
355
- ...components,
356
- withTime,
357
- open: false,
358
- };
359
- }
339
+ this._initialized = true;
360
340
  this.syncFormValue();
361
341
  }
362
342
  updateState(updates, forceSync = false) {
@@ -367,24 +347,26 @@ this.syncFormValue();
367
347
  }
368
348
  }
369
349
  syncFormValue() {
370
- const utcValue = this.getFormValue();
350
+ const formValue = this.getFormValue();
371
351
  const currentValue = this.getProperty('value');
372
- if (utcValue !== currentValue) {
373
- if (utcValue) {
374
- this.setProperty('value', utcValue);
352
+ if (formValue !== currentValue) {
353
+ this._syncing = true;
354
+ try {
355
+ this.setProperty('value', formValue || null);
375
356
  }
376
- else {
377
- this.setProperty('value', null);
357
+ finally {
358
+ this._syncing = false;
378
359
  }
379
360
  }
380
361
  }
381
362
  handleTimeInputChange(hour, minute) {
382
363
  if (!this.hasDate())
383
364
  return;
384
- const components = { ...this.getComponents(), hour, minute };
365
+ const components = { ...this.getComponents(), hour, minute, second: 0, epoch: undefined };
385
366
  this.updateState(components, true);
386
367
  this.emitChangeEvent(components, 'time-change');
387
368
  this.updateTimeSummary();
369
+ this.revealValidity();
388
370
  }
389
371
  updateTimeSummary(summary = this.shadowRoot?.querySelector('.time-summary')) {
390
372
  if (!summary)
@@ -398,19 +380,22 @@ iso.textContent = '';
398
380
  return;
399
381
  }
400
382
  const locale = getEffectiveLocale(this, this.getProperty('locale')) || undefined;
401
- const date = new Date(c.year, c.month - 1, c.day, c.hour ?? 0, c.minute ?? 0);
402
- const day = new Intl.DateTimeFormat(locale, { weekday: 'short', month: 'short', day: 'numeric' }).format(date);
403
- const time = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }).format(date);
383
+ const { date, timeZone } = displayDate(c, !!this.getProperty('native'));
384
+ const day = new Intl.DateTimeFormat(locale, { weekday: 'short', month: 'short', day: 'numeric', timeZone }).format(date);
385
+ const time = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', hourCycle: 'h23', timeZone }).format(date);
404
386
  text.textContent = `${day} · ${time}`;
405
387
  iso.textContent = componentsToLocalValue(c, true) ?? '';
406
388
  }
407
389
  emitChangeEvent(components, source) {
408
- const utcValue = components ? componentsToOutputValue(components) : null;
390
+ const value = components ? this.outputValue(components) : null;
409
391
  const localValue = components ? componentsToLocalValue(components, this._state.withTime) : null;
410
- const milliseconds = components ? componentsToDateObject(components)?.getTime() ?? null : null;
392
+ const effective = components && effectiveComponents(components, this._state.withTime);
393
+ const milliseconds = effective
394
+ ? effective.epoch ?? componentsToDateObject(effective)?.getTime() ?? null
395
+ : null;
411
396
  const formatted = components ? this.getFormattedValue(components) : null;
412
397
  const detail = {
413
- value: utcValue,
398
+ value,
414
399
  localValue,
415
400
  milliseconds,
416
401
  formatted,
@@ -451,16 +436,26 @@ get max() { return this.getProperty('max'); }
451
436
  set max(v) { this.setProperty('max', v ?? ''); }
452
437
  get withTime() { return this.getProperty('with-time'); }
453
438
  set withTime(v) { this.setProperty('with-time', v); }
439
+ get native() { return this.getProperty('native'); }
440
+ set native(v) { this.setProperty('native', v); }
441
+ get error() { return this.getProperty('error'); }
442
+ set error(v) { this.setProperty('error', v); }
454
443
  get value() {
444
+ if (this._initialized)
455
445
  return this.getProperty('value') || null;
446
+ const parsed = parseDateTime(this.getProperty('value'));
447
+ return parsed && componentsToOutputValue(parsed, !!this.getProperty('with-time'), !!this.getProperty('native'));
456
448
  }
457
449
  set value(val) {
458
450
  if (val === null || val === undefined || val === '') {
459
451
  this.setProperty('value', null);
460
452
  }
453
+ else if (typeof val === 'string') {
454
+ this.setProperty('value', val);
455
+ }
461
456
  else {
462
- const strValue = val instanceof Date ? val.toISOString() : val;
463
- this.setProperty('value', strValue);
457
+ const date = new Date(val);
458
+ this.setProperty('value', isNaN(date.getTime()) ? null : date.toISOString());
464
459
  }
465
460
  }
466
461
  clear() {
@@ -472,6 +467,8 @@ if (this.getProperty('disabled'))
472
467
  classes.push('disabled');
473
468
  if (this.getProperty('required'))
474
469
  classes.push('required');
470
+ if (this.getProperty('error'))
471
+ classes.push('error');
475
472
  if (this._state.open)
476
473
  classes.push('open');
477
474
  return classes.join(' ');
@@ -494,7 +491,7 @@ stub.setAttribute('aria-labelledby', `date-picker-label-${getElementHash(this)}`
494
491
  }
495
492
  stub.addEventListener('keydown', (e) => {
496
493
  const ke = e;
497
- if (this._state.open)
494
+ if (this._state.open || e.target !== stub)
498
495
  return;
499
496
  if (ke.key === 'Enter' || ke.key === ' ') {
500
497
  ke.preventDefault();
@@ -590,7 +587,7 @@ const contentWrapper = document.createElement('div');
590
587
  contentWrapper.className = 'calendar-content';
591
588
  const calendar = document.createElement('ty-calendar');
592
589
  if (this._state.year && this._state.month && this._state.day) {
593
- calendar.setAttribute('year', this._state.year.toString());
590
+ calendar.setAttribute('year', String(this._state.year).padStart(4, '0'));
594
591
  calendar.setAttribute('month', this._state.month.toString());
595
592
  calendar.setAttribute('day', this._state.day.toString());
596
593
  }
@@ -604,8 +601,8 @@ if (min)
604
601
  calendar.setAttribute('min', min);
605
602
  if (max)
606
603
  calendar.setAttribute('max', max);
607
- const flavor = this.getProperty('flavor');
608
- if (flavor && flavor !== 'default')
604
+ const flavor = this.calendarFlavor();
605
+ if (flavor)
609
606
  calendar.setAttribute('flavor', flavor);
610
607
  calendar.addEventListener('change', (e) => this.handleCalendarChange(e));
611
608
  contentWrapper.appendChild(calendar);
@@ -613,11 +610,18 @@ if (this._state.withTime) {
613
610
  contentWrapper.appendChild(this.renderTimeSection());
614
611
  }
615
612
  dialog.appendChild(contentWrapper);
616
- dialog.addEventListener('close', () => {
617
- this.updateState({ open: false });
618
- });
613
+ new MutationObserver(() => {
614
+ if (this._state.open && !dialog.open && dialog.isConnected && this.isConnected)
615
+ this.closeDropdown();
616
+ }).observe(dialog, { attributes: true, attributeFilter: ['open'] });
619
617
  return dialog;
620
618
  }
619
+ calendarFlavor() {
620
+ if (this.getProperty('error'))
621
+ return 'danger';
622
+ const flavor = this.getProperty('flavor');
623
+ return flavor && flavor !== 'default' ? flavor : null;
624
+ }
621
625
  renderNativeInput() {
622
626
  const wrapper = document.createElement('div');
623
627
  wrapper.className = 'dropdown-wrapper';
@@ -629,21 +633,8 @@ stub.setAttribute('disabled', 'true');
629
633
  }
630
634
  const input = document.createElement('input');
631
635
  input.className = 'native-date-input';
632
- input.type = this._state.withTime ? 'datetime-local' : 'date';
633
- if (isDisabled)
634
- input.disabled = true;
635
- if (this.getProperty('required'))
636
- input.required = true;
637
- const minBound = this.getProperty('min');
638
- const maxBound = this.getProperty('max');
639
- if (minBound)
640
- input.min = this._state.withTime ? `${minBound}T00:00` : minBound;
641
- if (maxBound)
642
- input.max = this._state.withTime ? `${maxBound}T23:59` : maxBound;
643
- const localValue = componentsToLocalValue(this.getComponents(), this._state.withTime);
644
- if (localValue) {
645
- input.value = localValue;
646
- }
636
+ this.syncNativeInput(input);
637
+ const localValue = input.value;
647
638
  const placeholder = this.getProperty('placeholder') || 'Select date...';
648
639
  const formattedValue = this.getFormattedValue();
649
640
  const placeholderEl = document.createElement('span');
@@ -652,13 +643,17 @@ placeholderEl.textContent = formattedValue || placeholder;
652
643
  input.addEventListener('change', () => {
653
644
  if (!input.value) {
654
645
  this.clearValue();
655
- return;
656
646
  }
657
- const parsed = parseValue(input.value, this._state.withTime);
647
+ else {
648
+ const parsed = parseDateTime(input.value);
658
649
  if (parsed) {
659
- this.updateState(parsed, true);
660
- this.emitChangeEvent(parsed, 'selection');
650
+ const { hour, minute, second } = this._state.withTime ? parsed : this._state;
651
+ const components = { ...parsed, hour, minute, second, epoch: undefined };
652
+ this.updateState(components, true);
653
+ this.emitChangeEvent(components, 'selection');
661
654
  }
655
+ }
656
+ this.revealValidity();
662
657
  });
663
658
  const startSlot = document.createElement('slot');
664
659
  startSlot.name = 'start';
@@ -684,6 +679,23 @@ stub.appendChild(iconContainer);
684
679
  wrapper.appendChild(stub);
685
680
  return wrapper;
686
681
  }
682
+ syncNativeInput(input) {
683
+ const withTime = this._state.withTime;
684
+ input.type = withTime ? 'datetime-local' : 'date';
685
+ input.disabled = !!this.getProperty('disabled');
686
+ input.required = !!this.getProperty('required');
687
+ const min = toISODay(this.getProperty('min'));
688
+ const max = toISODay(this.getProperty('max'));
689
+ if (min)
690
+ input.min = withTime ? `${min}T00:00` : min;
691
+ else
692
+ input.removeAttribute('min');
693
+ if (max)
694
+ input.max = withTime ? `${max}T23:59` : max;
695
+ else
696
+ input.removeAttribute('max');
697
+ input.value = componentsToLocalValue(this.getComponents(), withTime) ?? '';
698
+ }
687
699
  calculateCalendarPosition() {
688
700
  if (!this.shadowRoot)
689
701
  return;
@@ -750,6 +762,8 @@ this.shadowRoot.innerHTML = '';
750
762
  const container = this.renderContainer();
751
763
  container.appendChild(this.renderNativeInput());
752
764
  this.shadowRoot.appendChild(container);
765
+ this.syncErrorLine();
766
+ this.updateValidity();
753
767
  return;
754
768
  }
755
769
  const existingDialog = this.shadowRoot.querySelector('.calendar-dialog');
@@ -759,6 +773,7 @@ this.updateDisplay();
759
773
  this.calculateCalendarPosition();
760
774
  return;
761
775
  }
776
+ const hadFocus = !!this.shadowRoot.activeElement;
762
777
  this.shadowRoot.innerHTML = '';
763
778
  const container = this.renderContainer();
764
779
  const wrapper = document.createElement('div');
@@ -767,7 +782,33 @@ wrapper.appendChild(this.renderStub());
767
782
  wrapper.appendChild(this.renderCalendarDropdown());
768
783
  container.appendChild(wrapper);
769
784
  this.shadowRoot.appendChild(container);
785
+ this.syncErrorLine();
770
786
  this.setupEventListeners();
787
+ this.updateValidity();
788
+ if (hadFocus)
789
+ this.focus({ preventScroll: true });
790
+ }
791
+ syncErrorLine() {
792
+ const container = this.shadowRoot?.querySelector('.dropdown-container');
793
+ if (!container)
794
+ return;
795
+ const error = this.getProperty('error');
796
+ const errorId = `date-picker-error-${getElementHash(this)}`;
797
+ let line = container.querySelector(':scope > .error-message');
798
+ if (error) {
799
+ if (!line) {
800
+ line = document.createElement('div');
801
+ line.className = 'error-message';
802
+ line.id = errorId;
803
+ container.appendChild(line);
804
+ }
805
+ line.textContent = error;
806
+ this.focusTarget()?.setAttribute('aria-describedby', errorId);
807
+ }
808
+ else {
809
+ line?.remove();
810
+ this.focusTarget()?.removeAttribute('aria-describedby');
811
+ }
771
812
  }
772
813
  updateDisplay() {
773
814
  if (!this.shadowRoot)
@@ -786,23 +827,26 @@ const clearButton = this.shadowRoot.querySelector('.stub-clear');
786
827
  if (clearButton) {
787
828
  clearButton.style.display = (clearable && hasValue && !isDisabled) ? '' : 'none';
788
829
  }
830
+ const stub = this.shadowRoot.querySelector('.date-picker-stub');
831
+ if (stub)
832
+ stub.className = this.buildStubClasses();
833
+ this.syncErrorLine();
789
834
  if (isMobileTouch()) {
790
835
  const nativeInput = this.shadowRoot.querySelector('.native-date-input');
791
- if (nativeInput) {
792
- const localValue = componentsToLocalValue(this.getComponents(), this._state.withTime);
793
- nativeInput.value = localValue || '';
794
- }
836
+ if (nativeInput)
837
+ this.syncNativeInput(nativeInput);
838
+ stub?.toggleAttribute('disabled', !!isDisabled);
795
839
  return;
796
840
  }
797
841
  const calendar = this.shadowRoot.querySelector('ty-calendar');
798
842
  if (calendar && hasValue) {
799
- calendar.setAttribute('year', this._state.year.toString());
843
+ calendar.setAttribute('year', String(this._state.year).padStart(4, '0'));
800
844
  calendar.setAttribute('month', this._state.month.toString());
801
845
  calendar.setAttribute('day', this._state.day.toString());
802
846
  }
803
847
  if (calendar) {
804
- const flavor = this.getProperty('flavor');
805
- if (flavor && flavor !== 'default')
848
+ const flavor = this.calendarFlavor();
849
+ if (flavor)
806
850
  calendar.setAttribute('flavor', flavor);
807
851
  else
808
852
  calendar.removeAttribute('flavor');
@@ -844,7 +888,7 @@ event.preventDefault();
844
888
  const dialog = this.shadowRoot?.querySelector('.calendar-dialog');
845
889
  if (this._state.open && (!dialog || !dialog.open)) {
846
890
  this.updateState({ open: false }, true);
847
- unlockScroll(`date-picker-${this.id || this.toString()}`);
891
+ unlockScroll(`date-picker-${getElementHash(this)}`);
848
892
  }
849
893
  const disabled = this.getProperty('disabled');
850
894
  if (!disabled && Date.now() - this._closeTimestamp > 300) {
@@ -858,6 +902,8 @@ month: undefined,
858
902
  day: undefined,
859
903
  hour: undefined,
860
904
  minute: undefined,
905
+ second: undefined,
906
+ epoch: undefined,
861
907
  }, true);
862
908
  this.value = null;
863
909
  this.emitChangeEvent(null, 'clear');
@@ -867,6 +913,11 @@ handleClearClick(event) {
867
913
  event.preventDefault();
868
914
  event.stopPropagation();
869
915
  this.clearValue();
916
+ const active = document.activeElement;
917
+ if (this.matches(':focus-within') || !active || active === document.body) {
918
+ this.shadowRoot?.querySelector('.native-date-input')?.focus({ preventScroll: true });
919
+ }
920
+ this.revealValidity();
870
921
  }
871
922
  handleCalendarChange(event) {
872
923
  event.preventDefault();
@@ -882,9 +933,12 @@ month: dayContext.month,
882
933
  day: dayContext.dayInMonth,
883
934
  hour: this._state.hour,
884
935
  minute: this._state.minute,
936
+ second: this._state.second,
937
+ epoch: undefined,
885
938
  };
886
939
  this.updateState(newComponents, true);
887
940
  this.emitChangeEvent(newComponents, 'selection');
941
+ this.revealValidity();
888
942
  if (!this._state.withTime) {
889
943
  this.closeDropdown();
890
944
  }
@@ -938,9 +992,15 @@ this.render();
938
992
  requestAnimationFrame(() => {
939
993
  if (!this.shadowRoot)
940
994
  return;
995
+ if (!this._state.open || !this.isConnected)
996
+ return;
997
+ if (this.shadowRoot.querySelector('.date-picker-stub')?.checkVisibility() === false) {
998
+ this.closeDropdown();
999
+ return;
1000
+ }
941
1001
  const dialog = this.shadowRoot.querySelector('.calendar-dialog');
942
1002
  if (dialog) {
943
- const pickerId = `date-picker-${this.id || this.toString()}`;
1003
+ const pickerId = `date-picker-${getElementHash(this)}`;
944
1004
  lockScroll(pickerId);
945
1005
  dialog.showModal();
946
1006
  this.calculateCalendarPosition();
@@ -959,7 +1019,7 @@ closeDropdown() {
959
1019
  if (!this._state.open)
960
1020
  return;
961
1021
  this._closeTimestamp = Date.now();
962
- const pickerId = `date-picker-${this.id || this.toString()}`;
1022
+ const pickerId = `date-picker-${getElementHash(this)}`;
963
1023
  this.updateState({ open: false }, true);
964
1024
  unlockScroll(pickerId);
965
1025
  if (this.shadowRoot) {
@@ -974,6 +1034,7 @@ stubEl.setAttribute('aria-expanded', 'false');
974
1034
  }
975
1035
  this.dispatchEvent(new CustomEvent('close'));
976
1036
  this.render();
1037
+ this.focus();
977
1038
  }
978
1039
  cleanup() {
979
1040
  if (this._clickListener) {
@@ -989,7 +1050,7 @@ dialog.removeEventListener('click', this._dialogClickListener);
989
1050
  }
990
1051
  }
991
1052
  if (this._state.open) {
992
- const pickerId = `date-picker-${this.id || this.toString()}`;
1053
+ const pickerId = `date-picker-${getElementHash(this)}`;
993
1054
  unlockScroll(pickerId);
994
1055
  }
995
1056
  this._clickListener = undefined;
@@ -1062,6 +1123,11 @@ type: 'boolean',
1062
1123
  visual: true,
1063
1124
  default: false
1064
1125
  },
1126
+ error: {
1127
+ type: 'string',
1128
+ visual: true,
1129
+ default: ''
1130
+ },
1065
1131
  format: {
1066
1132
  type: 'string',
1067
1133
  visual: true,
@@ -1092,6 +1158,11 @@ default: null
1092
1158
  type: 'boolean',
1093
1159
  visual: true,
1094
1160
  default: false
1161
+ },
1162
+ native: {
1163
+ type: 'boolean',
1164
+ visual: true,
1165
+ default: false
1095
1166
  }
1096
1167
  };
1097
1168
  TyDatePicker.formAssociated = true;