@chromvoid/uikit 0.1.0

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 (246) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +96 -0
  3. package/dist/components/cv-accordion-item.d.ts +69 -0
  4. package/dist/components/cv-accordion-item.js +176 -0
  5. package/dist/components/cv-accordion.d.ts +79 -0
  6. package/dist/components/cv-accordion.js +310 -0
  7. package/dist/components/cv-alert-dialog.d.ts +86 -0
  8. package/dist/components/cv-alert-dialog.js +393 -0
  9. package/dist/components/cv-alert.d.ts +48 -0
  10. package/dist/components/cv-alert.js +156 -0
  11. package/dist/components/cv-badge.d.ts +56 -0
  12. package/dist/components/cv-badge.js +280 -0
  13. package/dist/components/cv-breadcrumb-item.d.ts +35 -0
  14. package/dist/components/cv-breadcrumb-item.js +64 -0
  15. package/dist/components/cv-breadcrumb.d.ts +39 -0
  16. package/dist/components/cv-breadcrumb.js +160 -0
  17. package/dist/components/cv-button.d.ts +83 -0
  18. package/dist/components/cv-button.js +541 -0
  19. package/dist/components/cv-callout.d.ts +32 -0
  20. package/dist/components/cv-callout.js +221 -0
  21. package/dist/components/cv-card.d.ts +48 -0
  22. package/dist/components/cv-card.js +269 -0
  23. package/dist/components/cv-carousel-slide.d.ts +25 -0
  24. package/dist/components/cv-carousel-slide.js +51 -0
  25. package/dist/components/cv-carousel.d.ts +96 -0
  26. package/dist/components/cv-carousel.js +457 -0
  27. package/dist/components/cv-checkbox.d.ts +84 -0
  28. package/dist/components/cv-checkbox.js +274 -0
  29. package/dist/components/cv-combobox-group.d.ts +15 -0
  30. package/dist/components/cv-combobox-group.js +34 -0
  31. package/dist/components/cv-combobox-option.d.ts +30 -0
  32. package/dist/components/cv-combobox-option.js +66 -0
  33. package/dist/components/cv-combobox.d.ts +135 -0
  34. package/dist/components/cv-combobox.js +834 -0
  35. package/dist/components/cv-command-item.d.ts +30 -0
  36. package/dist/components/cv-command-item.js +68 -0
  37. package/dist/components/cv-command-palette.d.ts +105 -0
  38. package/dist/components/cv-command-palette.js +578 -0
  39. package/dist/components/cv-context-menu.d.ts +98 -0
  40. package/dist/components/cv-context-menu.js +515 -0
  41. package/dist/components/cv-copy-button.d.ts +61 -0
  42. package/dist/components/cv-copy-button.js +318 -0
  43. package/dist/components/cv-date-picker.d.ts +161 -0
  44. package/dist/components/cv-date-picker.js +803 -0
  45. package/dist/components/cv-dialog.d.ts +89 -0
  46. package/dist/components/cv-dialog.js +459 -0
  47. package/dist/components/cv-disclosure.d.ts +57 -0
  48. package/dist/components/cv-disclosure.js +241 -0
  49. package/dist/components/cv-drawer.d.ts +102 -0
  50. package/dist/components/cv-drawer.js +595 -0
  51. package/dist/components/cv-feed-article.d.ts +26 -0
  52. package/dist/components/cv-feed-article.js +52 -0
  53. package/dist/components/cv-feed.d.ts +62 -0
  54. package/dist/components/cv-feed.js +310 -0
  55. package/dist/components/cv-grid-cell.d.ts +30 -0
  56. package/dist/components/cv-grid-cell.js +57 -0
  57. package/dist/components/cv-grid-column.d.ts +30 -0
  58. package/dist/components/cv-grid-column.js +43 -0
  59. package/dist/components/cv-grid-row.d.ts +30 -0
  60. package/dist/components/cv-grid-row.js +42 -0
  61. package/dist/components/cv-grid.d.ts +119 -0
  62. package/dist/components/cv-grid.js +567 -0
  63. package/dist/components/cv-icon.d.ts +57 -0
  64. package/dist/components/cv-icon.js +352 -0
  65. package/dist/components/cv-input.d.ts +127 -0
  66. package/dist/components/cv-input.js +482 -0
  67. package/dist/components/cv-landmark.d.ts +32 -0
  68. package/dist/components/cv-landmark.js +62 -0
  69. package/dist/components/cv-link.d.ts +22 -0
  70. package/dist/components/cv-link.js +99 -0
  71. package/dist/components/cv-listbox-group.d.ts +15 -0
  72. package/dist/components/cv-listbox-group.js +42 -0
  73. package/dist/components/cv-listbox.d.ts +81 -0
  74. package/dist/components/cv-listbox.js +388 -0
  75. package/dist/components/cv-menu-button.d.ts +118 -0
  76. package/dist/components/cv-menu-button.js +822 -0
  77. package/dist/components/cv-menu-group.d.ts +20 -0
  78. package/dist/components/cv-menu-group.js +48 -0
  79. package/dist/components/cv-menu-item.d.ts +52 -0
  80. package/dist/components/cv-menu-item.js +105 -0
  81. package/dist/components/cv-menu.d.ts +62 -0
  82. package/dist/components/cv-menu.js +414 -0
  83. package/dist/components/cv-meter.d.ts +66 -0
  84. package/dist/components/cv-meter.js +154 -0
  85. package/dist/components/cv-number.d.ts +139 -0
  86. package/dist/components/cv-number.js +553 -0
  87. package/dist/components/cv-option.d.ts +30 -0
  88. package/dist/components/cv-option.js +84 -0
  89. package/dist/components/cv-popover.d.ts +87 -0
  90. package/dist/components/cv-popover.js +373 -0
  91. package/dist/components/cv-progress-ring.d.ts +45 -0
  92. package/dist/components/cv-progress-ring.js +169 -0
  93. package/dist/components/cv-progress.d.ts +45 -0
  94. package/dist/components/cv-progress.js +148 -0
  95. package/dist/components/cv-radio-group.d.ts +79 -0
  96. package/dist/components/cv-radio-group.js +398 -0
  97. package/dist/components/cv-radio.d.ts +36 -0
  98. package/dist/components/cv-radio.js +123 -0
  99. package/dist/components/cv-select-group.d.ts +15 -0
  100. package/dist/components/cv-select-group.js +44 -0
  101. package/dist/components/cv-select-option.d.ts +30 -0
  102. package/dist/components/cv-select-option.js +66 -0
  103. package/dist/components/cv-select.d.ts +128 -0
  104. package/dist/components/cv-select.js +666 -0
  105. package/dist/components/cv-sidebar-item.d.ts +26 -0
  106. package/dist/components/cv-sidebar-item.js +142 -0
  107. package/dist/components/cv-sidebar.d.ts +171 -0
  108. package/dist/components/cv-sidebar.js +767 -0
  109. package/dist/components/cv-slider-multi-thumb.d.ts +73 -0
  110. package/dist/components/cv-slider-multi-thumb.js +374 -0
  111. package/dist/components/cv-slider.d.ts +84 -0
  112. package/dist/components/cv-slider.js +328 -0
  113. package/dist/components/cv-spinbutton.d.ts +121 -0
  114. package/dist/components/cv-spinbutton.js +486 -0
  115. package/dist/components/cv-spinner.d.ts +18 -0
  116. package/dist/components/cv-spinner.js +95 -0
  117. package/dist/components/cv-switch.d.ts +81 -0
  118. package/dist/components/cv-switch.js +285 -0
  119. package/dist/components/cv-tab-panel.d.ts +20 -0
  120. package/dist/components/cv-tab-panel.js +37 -0
  121. package/dist/components/cv-tab.d.ts +40 -0
  122. package/dist/components/cv-tab.js +132 -0
  123. package/dist/components/cv-table-cell.d.ts +31 -0
  124. package/dist/components/cv-table-cell.js +49 -0
  125. package/dist/components/cv-table-column.d.ts +37 -0
  126. package/dist/components/cv-table-column.js +63 -0
  127. package/dist/components/cv-table-row.d.ts +30 -0
  128. package/dist/components/cv-table-row.js +45 -0
  129. package/dist/components/cv-table.d.ts +147 -0
  130. package/dist/components/cv-table.js +607 -0
  131. package/dist/components/cv-tabs.d.ts +70 -0
  132. package/dist/components/cv-tabs.js +524 -0
  133. package/dist/components/cv-textarea.d.ts +108 -0
  134. package/dist/components/cv-textarea.js +328 -0
  135. package/dist/components/cv-toast-region.d.ts +39 -0
  136. package/dist/components/cv-toast-region.js +162 -0
  137. package/dist/components/cv-toast.d.ts +67 -0
  138. package/dist/components/cv-toast.js +315 -0
  139. package/dist/components/cv-toolbar-item.d.ts +25 -0
  140. package/dist/components/cv-toolbar-item.js +72 -0
  141. package/dist/components/cv-toolbar-separator.d.ts +25 -0
  142. package/dist/components/cv-toolbar-separator.js +45 -0
  143. package/dist/components/cv-toolbar.d.ts +63 -0
  144. package/dist/components/cv-toolbar.js +295 -0
  145. package/dist/components/cv-tooltip.d.ts +83 -0
  146. package/dist/components/cv-tooltip.js +455 -0
  147. package/dist/components/cv-treegrid-cell.d.ts +30 -0
  148. package/dist/components/cv-treegrid-cell.js +57 -0
  149. package/dist/components/cv-treegrid-column.d.ts +37 -0
  150. package/dist/components/cv-treegrid-column.js +53 -0
  151. package/dist/components/cv-treegrid-row.d.ts +55 -0
  152. package/dist/components/cv-treegrid-row.js +90 -0
  153. package/dist/components/cv-treegrid.d.ts +96 -0
  154. package/dist/components/cv-treegrid.js +632 -0
  155. package/dist/components/cv-treeitem.d.ts +58 -0
  156. package/dist/components/cv-treeitem.js +144 -0
  157. package/dist/components/cv-treeview.d.ts +70 -0
  158. package/dist/components/cv-treeview.js +396 -0
  159. package/dist/components/cv-window-splitter.d.ts +79 -0
  160. package/dist/components/cv-window-splitter.js +316 -0
  161. package/dist/components/index.d.ts +94 -0
  162. package/dist/components/index.js +79 -0
  163. package/dist/dialog/create-dialog-controller.d.ts +31 -0
  164. package/dist/dialog/create-dialog-controller.js +320 -0
  165. package/dist/dialog/index.d.ts +2 -0
  166. package/dist/dialog/index.js +1 -0
  167. package/dist/form-associated/FormAssociatedReatomElement.d.ts +25 -0
  168. package/dist/form-associated/FormAssociatedReatomElement.js +70 -0
  169. package/dist/form-associated/withFormAssociated.d.ts +5 -0
  170. package/dist/form-associated/withFormAssociated.js +1 -0
  171. package/dist/index.d.ts +10 -0
  172. package/dist/index.js +9 -0
  173. package/dist/reatom-lit/ReatomLitElement.d.ts +27 -0
  174. package/dist/reatom-lit/ReatomLitElement.js +118 -0
  175. package/dist/reatom-lit/html.d.ts +4 -0
  176. package/dist/reatom-lit/html.js +10 -0
  177. package/dist/reatom-lit/index.d.ts +4 -0
  178. package/dist/reatom-lit/index.js +4 -0
  179. package/dist/reatom-lit/watch.d.ts +15 -0
  180. package/dist/reatom-lit/watch.js +40 -0
  181. package/dist/reatom-lit/withReatomElement.d.ts +4 -0
  182. package/dist/reatom-lit/withReatomElement.js +57 -0
  183. package/dist/register.d.ts +1 -0
  184. package/dist/register.js +84 -0
  185. package/dist/styles/component-styles.d.ts +4 -0
  186. package/dist/styles/component-styles.js +78 -0
  187. package/dist/theme/cv-theme-provider.d.ts +32 -0
  188. package/dist/theme/cv-theme-provider.js +110 -0
  189. package/dist/theme/index.d.ts +4 -0
  190. package/dist/theme/index.js +2 -0
  191. package/dist/theme/theme-engine.d.ts +4 -0
  192. package/dist/theme/theme-engine.js +67 -0
  193. package/dist/theme/tokens.css +265 -0
  194. package/dist/theme/types.d.ts +7 -0
  195. package/dist/theme/types.js +1 -0
  196. package/dist/toast/create-toast-controller.d.ts +12 -0
  197. package/dist/toast/create-toast-controller.js +12 -0
  198. package/dist/toast/index.d.ts +2 -0
  199. package/dist/toast/index.js +1 -0
  200. package/package.json +146 -0
  201. package/specs/_template.md +110 -0
  202. package/specs/components/accordion.md +207 -0
  203. package/specs/components/alert.md +83 -0
  204. package/specs/components/badge.md +183 -0
  205. package/specs/components/breadcrumb.md +152 -0
  206. package/specs/components/button.md +227 -0
  207. package/specs/components/callout.md +153 -0
  208. package/specs/components/card.md +192 -0
  209. package/specs/components/carousel.md +232 -0
  210. package/specs/components/checkbox.md +141 -0
  211. package/specs/components/combobox.md +427 -0
  212. package/specs/components/context-menu.md +375 -0
  213. package/specs/components/copy-button.md +236 -0
  214. package/specs/components/date-picker.md +290 -0
  215. package/specs/components/dialog.md +184 -0
  216. package/specs/components/disclosure.md +151 -0
  217. package/specs/components/drawer.md +216 -0
  218. package/specs/components/feed.md +266 -0
  219. package/specs/components/grid.md +423 -0
  220. package/specs/components/input.md +237 -0
  221. package/specs/components/landmark.md +92 -0
  222. package/specs/components/link.md +117 -0
  223. package/specs/components/listbox.md +327 -0
  224. package/specs/components/menu.md +508 -0
  225. package/specs/components/meter.md +148 -0
  226. package/specs/components/number.md +268 -0
  227. package/specs/components/option.md +167 -0
  228. package/specs/components/popover.md +207 -0
  229. package/specs/components/progress-ring.md +134 -0
  230. package/specs/components/progress.md +110 -0
  231. package/specs/components/radio.md +208 -0
  232. package/specs/components/select.md +305 -0
  233. package/specs/components/sidebar.md +204 -0
  234. package/specs/components/spinbutton.md +157 -0
  235. package/specs/components/spinner.md +83 -0
  236. package/specs/components/switch.md +145 -0
  237. package/specs/components/table.md +372 -0
  238. package/specs/components/tabs.md +242 -0
  239. package/specs/components/textarea.md +166 -0
  240. package/specs/components/theme.md +364 -0
  241. package/specs/components/toast.md +198 -0
  242. package/specs/components/toolbar.md +258 -0
  243. package/specs/components/tooltip.md +152 -0
  244. package/specs/components/treegrid.md +363 -0
  245. package/specs/components/treeview.md +263 -0
  246. package/specs/components/window-splitter.md +225 -0
@@ -0,0 +1,803 @@
1
+ import { createDatePicker, } from '@chromvoid/headless-ui/date-picker';
2
+ import { css, html, nothing } from 'lit';
3
+ import { FormAssociatedReatomElement } from '../form-associated/FormAssociatedReatomElement.js';
4
+ let cvDatePickerNonce = 0;
5
+ export class CVDatePicker extends FormAssociatedReatomElement {
6
+ static elementName = 'cv-date-picker';
7
+ static get properties() {
8
+ return {
9
+ name: { type: String },
10
+ value: { type: String, reflect: true },
11
+ open: { type: Boolean, reflect: true },
12
+ disabled: { type: Boolean, reflect: true },
13
+ readonly: { type: Boolean, reflect: true },
14
+ required: { type: Boolean, reflect: true },
15
+ placeholder: { type: String },
16
+ size: { type: String, reflect: true },
17
+ locale: { type: String },
18
+ timeZone: { type: String, attribute: 'time-zone', reflect: true },
19
+ min: { type: String },
20
+ max: { type: String },
21
+ minuteStep: { type: Number, attribute: 'minute-step' },
22
+ hourCycle: { type: Number, attribute: 'hour-cycle' },
23
+ closeOnEscape: { type: Boolean, attribute: 'close-on-escape', reflect: true },
24
+ ariaLabel: { type: String, attribute: 'aria-label' },
25
+ inputInvalid: { type: Boolean, attribute: 'input-invalid', reflect: true },
26
+ hasValue: { type: Boolean, attribute: 'has-value', reflect: true },
27
+ };
28
+ }
29
+ idBase = `cv-date-picker-${++cvDatePickerNonce}`;
30
+ model;
31
+ pendingCommitSource = 'input';
32
+ documentPointerDownListener;
33
+ defaultValue = '';
34
+ didCaptureDefaultValue = false;
35
+ constructor() {
36
+ super();
37
+ this.name = '';
38
+ this.value = '';
39
+ this.open = false;
40
+ this.disabled = false;
41
+ this.readonly = false;
42
+ this.required = false;
43
+ this.placeholder = 'Select date and time';
44
+ this.size = 'medium';
45
+ this.locale = 'en-US';
46
+ this.timeZone = 'local';
47
+ this.min = '';
48
+ this.max = '';
49
+ this.minuteStep = 1;
50
+ this.hourCycle = 24;
51
+ this.closeOnEscape = true;
52
+ this.ariaLabel = '';
53
+ this.inputInvalid = false;
54
+ this.hasValue = false;
55
+ this.model = this.createModel();
56
+ this.documentPointerDownListener = this.handleDocumentPointerDown.bind(this);
57
+ this.syncHostStateFromModel();
58
+ }
59
+ static styles = [
60
+ css `
61
+ :host {
62
+ display: inline-block;
63
+ inline-size: var(--cv-date-picker-min-width, 260px);
64
+ }
65
+
66
+ [part='base'] {
67
+ display: grid;
68
+ gap: var(--cv-space-2, 8px);
69
+ }
70
+
71
+ [part='input-wrap'] {
72
+ display: flex;
73
+ align-items: center;
74
+ gap: var(--cv-space-2, 8px);
75
+ min-block-size: var(--cv-date-picker-input-min-height, 36px);
76
+ padding: var(--cv-date-picker-input-padding-block, var(--cv-space-2, 8px))
77
+ var(--cv-date-picker-input-padding-inline, var(--cv-space-3, 12px));
78
+ border: 1px solid var(--cv-color-border, #2a3245);
79
+ border-radius: var(--cv-date-picker-border-radius, var(--cv-radius-md, 10px));
80
+ background: var(--cv-color-surface, #141923);
81
+ }
82
+
83
+ [part='prefix'],
84
+ [part='suffix'] {
85
+ display: inline-flex;
86
+ align-items: center;
87
+ }
88
+
89
+ [part='label'] {
90
+ flex: 1;
91
+ min-inline-size: 0;
92
+ display: inline-flex;
93
+ }
94
+
95
+ [part='input'] {
96
+ inline-size: 100%;
97
+ border: none;
98
+ outline: none;
99
+ background: transparent;
100
+ color: var(--cv-color-text, #e8ecf6);
101
+ font: inherit;
102
+ }
103
+
104
+ [part='clear-button'] {
105
+ display: inline-flex;
106
+ align-items: center;
107
+ justify-content: center;
108
+ border: none;
109
+ background: transparent;
110
+ color: var(--cv-color-text-muted, #9aa6bf);
111
+ cursor: pointer;
112
+ padding: 0;
113
+ }
114
+
115
+ [part='dialog'] {
116
+ inline-size: var(--cv-date-picker-dialog-width, min(560px, calc(100vw - 32px)));
117
+ display: grid;
118
+ gap: var(--cv-space-2, 8px);
119
+ padding: var(--cv-space-3, 12px);
120
+ border-radius: var(--cv-date-picker-border-radius, var(--cv-radius-md, 10px));
121
+ border: 1px solid var(--cv-color-border, #2a3245);
122
+ background: var(--cv-color-surface-elevated, #1d2432);
123
+ }
124
+
125
+ [part='dialog'][hidden] {
126
+ display: none;
127
+ }
128
+
129
+ [part='calendar-shell'] {
130
+ display: grid;
131
+ grid-template-columns: auto auto 1fr auto auto;
132
+ align-items: center;
133
+ gap: var(--cv-space-2, 8px);
134
+ }
135
+
136
+ [part='month-label'] {
137
+ justify-self: center;
138
+ }
139
+
140
+ [part='month-nav-button'],
141
+ [part='year-nav-button'],
142
+ [part='apply-button'],
143
+ [part='cancel-button'] {
144
+ border: 1px solid var(--cv-color-border, #2a3245);
145
+ background: var(--cv-color-surface, #141923);
146
+ color: var(--cv-color-text, #e8ecf6);
147
+ border-radius: var(--cv-radius-sm, 6px);
148
+ cursor: pointer;
149
+ }
150
+
151
+ [part='calendar-grid'] {
152
+ display: grid;
153
+ grid-template-columns: repeat(7, minmax(0, 1fr));
154
+ gap: var(--cv-date-picker-day-gap, var(--cv-space-1, 4px));
155
+ }
156
+
157
+ [part='calendar-day'] {
158
+ min-block-size: var(--cv-date-picker-day-size, 34px);
159
+ border: 1px solid var(--cv-color-border, #2a3245);
160
+ background: transparent;
161
+ color: var(--cv-color-text, #e8ecf6);
162
+ border-radius: var(--cv-radius-sm, 6px);
163
+ cursor: pointer;
164
+ }
165
+
166
+ [part='calendar-day'][data-month='prev'],
167
+ [part='calendar-day'][data-month='next'] {
168
+ color: var(--cv-color-text-muted, #9aa6bf);
169
+ }
170
+
171
+ [part='calendar-day'][aria-selected='true'] {
172
+ background: color-mix(in oklab, var(--cv-color-primary, #65d7ff) 22%, transparent);
173
+ }
174
+
175
+ [part='time-row'] {
176
+ display: inline-flex;
177
+ align-items: center;
178
+ gap: var(--cv-space-2, 8px);
179
+ }
180
+
181
+ [part='hour-input'],
182
+ [part='minute-input'] {
183
+ inline-size: 3.5ch;
184
+ text-align: center;
185
+ }
186
+
187
+ [part='actions'] {
188
+ display: inline-flex;
189
+ justify-content: flex-end;
190
+ gap: var(--cv-date-picker-button-gap, var(--cv-space-2, 8px));
191
+ }
192
+
193
+ [part='dialog-caption'] {
194
+ color: var(--cv-color-text-muted, #9aa6bf);
195
+ font-size: 0.85em;
196
+ }
197
+
198
+ :host([size='small']) {
199
+ --cv-date-picker-input-min-height: 30px;
200
+ --cv-date-picker-input-padding-inline: var(--cv-space-2, 8px);
201
+ --cv-date-picker-input-padding-block: var(--cv-space-1, 4px);
202
+ }
203
+
204
+ :host([size='large']) {
205
+ --cv-date-picker-input-min-height: 42px;
206
+ --cv-date-picker-input-padding-inline: var(--cv-space-4, 16px);
207
+ --cv-date-picker-input-padding-block: var(--cv-space-2, 8px);
208
+ }
209
+
210
+ :host([disabled]) {
211
+ opacity: 0.55;
212
+ }
213
+
214
+ :host([disabled]) [part='input-wrap'],
215
+ :host([disabled]) [part='dialog'] {
216
+ pointer-events: none;
217
+ }
218
+
219
+ :host([input-invalid]) [part='input-wrap'] {
220
+ border-color: var(--cv-color-danger, #ff6b6b);
221
+ }
222
+ `,
223
+ ];
224
+ static define() {
225
+ if (!customElements.get(this.elementName)) {
226
+ customElements.define(this.elementName, this);
227
+ }
228
+ }
229
+ connectedCallback() {
230
+ super.connectedCallback();
231
+ this.syncOutsidePointerListener();
232
+ if (!this.didCaptureDefaultValue) {
233
+ this.defaultValue = this.value;
234
+ this.didCaptureDefaultValue = true;
235
+ }
236
+ }
237
+ disconnectedCallback() {
238
+ super.disconnectedCallback();
239
+ this.syncOutsidePointerListener(true);
240
+ }
241
+ willUpdate(changedProperties) {
242
+ super.willUpdate(changedProperties);
243
+ if (changedProperties.has('ariaLabel') || changedProperties.has('closeOnEscape')) {
244
+ this.rebuildModel();
245
+ return;
246
+ }
247
+ if (changedProperties.has('disabled') && this.model.state.disabled() !== this.disabled) {
248
+ this.model.actions.setDisabled(this.isEffectivelyDisabled());
249
+ }
250
+ if (changedProperties.has('readonly') && this.model.state.readonly() !== this.readonly) {
251
+ this.model.actions.setReadonly(this.readonly);
252
+ }
253
+ if (changedProperties.has('required') && this.model.state.required() !== this.required) {
254
+ this.model.actions.setRequired(this.required);
255
+ }
256
+ if (changedProperties.has('placeholder') && this.model.state.placeholder() !== this.placeholder) {
257
+ this.model.actions.setPlaceholder(this.placeholder);
258
+ }
259
+ if (changedProperties.has('locale') && this.model.state.locale() !== this.locale) {
260
+ this.model.actions.setLocale(this.locale);
261
+ }
262
+ if (changedProperties.has('timeZone')) {
263
+ const normalizedTimeZone = this.timeZone === 'utc' ? 'utc' : 'local';
264
+ if (this.model.state.timeZone() !== normalizedTimeZone) {
265
+ this.model.actions.setTimeZone(normalizedTimeZone);
266
+ }
267
+ }
268
+ if (changedProperties.has('min') && this.model.state.min() !== this.toNullable(this.min)) {
269
+ this.model.actions.setMin(this.toNullable(this.min));
270
+ }
271
+ if (changedProperties.has('max') && this.model.state.max() !== this.toNullable(this.max)) {
272
+ this.model.actions.setMax(this.toNullable(this.max));
273
+ }
274
+ if (changedProperties.has('minuteStep') && this.model.state.minuteStep() !== this.minuteStep) {
275
+ this.model.actions.setMinuteStep(this.minuteStep);
276
+ }
277
+ if (changedProperties.has('hourCycle') && this.model.state.hourCycle() !== this.hourCycle) {
278
+ this.model.actions.setHourCycle(this.hourCycle);
279
+ }
280
+ if (changedProperties.has('value')) {
281
+ this.syncModelFromExternalValue();
282
+ }
283
+ if (changedProperties.has('open') && this.model.state.isOpen() !== this.open) {
284
+ if (this.open) {
285
+ this.model.actions.open();
286
+ }
287
+ else {
288
+ this.model.actions.close();
289
+ }
290
+ }
291
+ this.syncHostStateFromModel();
292
+ this.syncFormAssociatedState();
293
+ }
294
+ updated(changedProperties) {
295
+ super.updated(changedProperties);
296
+ this.syncOutsidePointerListener();
297
+ if (changedProperties.has('size')) {
298
+ this.requestUpdate();
299
+ }
300
+ }
301
+ createModel(initialValue = this.value) {
302
+ return createDatePicker({
303
+ idBase: this.idBase,
304
+ value: this.toNullable(initialValue),
305
+ required: this.required,
306
+ disabled: this.isEffectivelyDisabled(),
307
+ readonly: this.readonly,
308
+ placeholder: this.placeholder,
309
+ locale: this.locale,
310
+ timeZone: this.timeZone === 'utc' ? 'utc' : 'local',
311
+ min: this.toNullable(this.min),
312
+ max: this.toNullable(this.max),
313
+ minuteStep: this.minuteStep,
314
+ hourCycle: this.hourCycle,
315
+ closeOnEscape: this.closeOnEscape,
316
+ ariaLabel: this.ariaLabel || undefined,
317
+ onInput: (inputValue) => {
318
+ this.handleHeadlessInput(inputValue);
319
+ },
320
+ onCommit: (nextValue) => {
321
+ this.handleHeadlessCommit(nextValue);
322
+ },
323
+ onClear: () => {
324
+ this.syncHostStateFromModel();
325
+ },
326
+ });
327
+ }
328
+ rebuildModel() {
329
+ const currentValue = this.model.state.committedValue() ?? this.value;
330
+ const isOpen = this.model.state.isOpen();
331
+ this.model = this.createModel(currentValue);
332
+ if (isOpen) {
333
+ this.model.actions.open();
334
+ }
335
+ this.syncHostStateFromModel();
336
+ }
337
+ toNullable(value) {
338
+ const trimmed = value.trim();
339
+ return trimmed.length > 0 ? trimmed : null;
340
+ }
341
+ syncModelFromExternalValue() {
342
+ const nextValue = this.value.trim();
343
+ const committedValue = this.model.state.committedValue() ?? '';
344
+ if (nextValue === committedValue)
345
+ return;
346
+ if (nextValue.length === 0) {
347
+ this.pendingCommitSource = 'input';
348
+ this.model.actions.clear();
349
+ return;
350
+ }
351
+ this.model.actions.setInputValue(nextValue);
352
+ this.pendingCommitSource = 'input';
353
+ this.model.actions.commitInput();
354
+ }
355
+ syncHostStateFromModel() {
356
+ const committedValue = this.model.state.committedValue() ?? '';
357
+ const isOpen = this.model.state.isOpen();
358
+ const inputInvalid = this.model.state.inputInvalid();
359
+ const hasValue = this.model.state.hasCommittedSelection();
360
+ if (this.value !== committedValue) {
361
+ this.value = committedValue;
362
+ }
363
+ if (this.open !== isOpen) {
364
+ this.open = isOpen;
365
+ }
366
+ if (this.inputInvalid !== inputInvalid) {
367
+ this.inputInvalid = inputInvalid;
368
+ }
369
+ if (this.hasValue !== hasValue) {
370
+ this.hasValue = hasValue;
371
+ }
372
+ this.syncFormAssociatedState();
373
+ }
374
+ dispatchInput(detail) {
375
+ this.dispatchEvent(new CustomEvent('cv-input', {
376
+ detail,
377
+ bubbles: true,
378
+ composed: true,
379
+ }));
380
+ }
381
+ dispatchChange(detail) {
382
+ this.dispatchEvent(new CustomEvent('cv-change', {
383
+ detail,
384
+ bubbles: true,
385
+ composed: true,
386
+ }));
387
+ }
388
+ handleHeadlessInput(inputValue) {
389
+ this.dispatchInput({
390
+ value: this.model.state.committedValue() ?? '',
391
+ inputValue,
392
+ open: this.model.state.isOpen(),
393
+ invalid: this.model.state.inputInvalid(),
394
+ });
395
+ this.syncHostStateFromModel();
396
+ }
397
+ handleHeadlessCommit(nextValue) {
398
+ const previousValue = this.value;
399
+ const normalizedValue = nextValue ?? '';
400
+ const source = this.pendingCommitSource;
401
+ this.pendingCommitSource = 'input';
402
+ this.syncHostStateFromModel();
403
+ if (previousValue !== normalizedValue) {
404
+ this.dispatchChange({
405
+ value: normalizedValue,
406
+ previousValue,
407
+ source,
408
+ });
409
+ }
410
+ }
411
+ syncOutsidePointerListener(forceOff = false) {
412
+ const shouldListen = !forceOff && this.model.state.isOpen();
413
+ if (shouldListen) {
414
+ document.addEventListener('pointerdown', this.documentPointerDownListener);
415
+ }
416
+ else {
417
+ document.removeEventListener('pointerdown', this.documentPointerDownListener);
418
+ }
419
+ }
420
+ handleDocumentPointerDown(event) {
421
+ if (!this.model.state.isOpen())
422
+ return;
423
+ const path = event.composedPath();
424
+ if (path.includes(this))
425
+ return;
426
+ this.model.contracts.getDialogProps().onPointerDownOutside();
427
+ this.syncHostStateFromModel();
428
+ }
429
+ handleInputEvent(event) {
430
+ const value = event.currentTarget.value;
431
+ this.model.contracts.getInputProps().onInput(value);
432
+ this.syncHostStateFromModel();
433
+ }
434
+ handleInputKeyDown(event) {
435
+ if (event.key === 'Enter') {
436
+ this.pendingCommitSource = 'input';
437
+ }
438
+ this.model.contracts.getInputProps().onKeyDown(event);
439
+ this.syncHostStateFromModel();
440
+ }
441
+ handleInputFocus() {
442
+ this.model.contracts.getInputProps().onFocus();
443
+ this.syncHostStateFromModel();
444
+ }
445
+ handleInputBlur() {
446
+ this.model.contracts.getInputProps().onBlur();
447
+ this.syncHostStateFromModel();
448
+ }
449
+ handleDialogKeyDown(event) {
450
+ this.model.contracts.getDialogProps().onKeyDown(event);
451
+ this.syncHostStateFromModel();
452
+ }
453
+ handleGridKeyDown(event) {
454
+ if (event.key === 'Enter' && event.ctrlKey) {
455
+ this.pendingCommitSource = 'dialog';
456
+ }
457
+ this.model.contracts.getCalendarGridProps().onKeyDown(event);
458
+ this.syncHostStateFromModel();
459
+ }
460
+ handleDayClick(event) {
461
+ const target = event.currentTarget;
462
+ const date = target.getAttribute('data-date');
463
+ if (!date)
464
+ return;
465
+ this.model.contracts.getCalendarDayProps(date).onClick();
466
+ this.syncHostStateFromModel();
467
+ }
468
+ handleDayMouseEnter(event) {
469
+ const target = event.currentTarget;
470
+ const date = target.getAttribute('data-date');
471
+ if (!date)
472
+ return;
473
+ this.model.contracts.getCalendarDayProps(date).onMouseEnter();
474
+ this.syncHostStateFromModel();
475
+ }
476
+ handleMonthPrevClick() {
477
+ this.model.contracts.getMonthNavButtonProps('prev').onClick();
478
+ this.syncHostStateFromModel();
479
+ }
480
+ handleMonthNextClick() {
481
+ this.model.contracts.getMonthNavButtonProps('next').onClick();
482
+ this.syncHostStateFromModel();
483
+ }
484
+ handleYearPrevClick() {
485
+ this.model.contracts.getYearNavButtonProps('prev').onClick();
486
+ this.syncHostStateFromModel();
487
+ }
488
+ handleYearNextClick() {
489
+ this.model.contracts.getYearNavButtonProps('next').onClick();
490
+ this.syncHostStateFromModel();
491
+ }
492
+ handleTimeInput(event) {
493
+ const target = event.currentTarget;
494
+ const segment = target.getAttribute('data-segment');
495
+ if (segment === 'hour') {
496
+ this.model.contracts.getHourInputProps().onInput(target.value);
497
+ }
498
+ else {
499
+ this.model.contracts.getMinuteInputProps().onInput(target.value);
500
+ }
501
+ this.syncHostStateFromModel();
502
+ }
503
+ handleTimeKeyDown(event) {
504
+ if (event.key === 'Enter') {
505
+ this.pendingCommitSource = 'dialog';
506
+ }
507
+ const target = event.currentTarget;
508
+ const segment = target.getAttribute('data-segment');
509
+ if (segment === 'hour') {
510
+ this.model.contracts.getHourInputProps().onKeyDown(event);
511
+ }
512
+ else {
513
+ this.model.contracts.getMinuteInputProps().onKeyDown(event);
514
+ }
515
+ this.syncHostStateFromModel();
516
+ }
517
+ handleApplyClick() {
518
+ this.pendingCommitSource = 'dialog';
519
+ this.model.contracts.getApplyButtonProps().onClick();
520
+ this.syncHostStateFromModel();
521
+ }
522
+ handleCancelClick() {
523
+ this.model.contracts.getCancelButtonProps().onClick();
524
+ this.syncHostStateFromModel();
525
+ }
526
+ handleClearClick() {
527
+ this.pendingCommitSource = 'input';
528
+ this.model.contracts.getClearButtonProps().onClick();
529
+ this.syncHostStateFromModel();
530
+ }
531
+ onFormDisabledChanged(_disabled) {
532
+ this.model.actions.setDisabled(this.isEffectivelyDisabled());
533
+ }
534
+ onFormReset() {
535
+ this.pendingCommitSource = 'input';
536
+ this.value = this.defaultValue;
537
+ this.syncModelFromExternalValue();
538
+ this.syncHostStateFromModel();
539
+ }
540
+ onFormStateRestore(state) {
541
+ if (typeof state !== 'string')
542
+ return;
543
+ this.pendingCommitSource = 'input';
544
+ this.value = state;
545
+ this.syncModelFromExternalValue();
546
+ this.syncHostStateFromModel();
547
+ }
548
+ isFormAssociatedDisabled() {
549
+ return this.isEffectivelyDisabled();
550
+ }
551
+ getFormAssociatedValue() {
552
+ return this.value || null;
553
+ }
554
+ getFormAssociatedValidity() {
555
+ if (this.inputInvalid) {
556
+ return {
557
+ flags: { badInput: true },
558
+ message: 'Please enter a valid date and time.',
559
+ };
560
+ }
561
+ if (this.required && this.value.length === 0) {
562
+ return {
563
+ flags: { valueMissing: true },
564
+ message: 'Please fill out this field.',
565
+ };
566
+ }
567
+ return { flags: {} };
568
+ }
569
+ isEffectivelyDisabled() {
570
+ return this.disabled || this.formDisabled;
571
+ }
572
+ formatMonthLabel(year, month) {
573
+ const date = new Date(Date.UTC(year, month - 1, 1, 12, 0, 0, 0));
574
+ try {
575
+ return new Intl.DateTimeFormat(this.locale, {
576
+ month: 'long',
577
+ year: 'numeric',
578
+ timeZone: 'UTC',
579
+ }).format(date);
580
+ }
581
+ catch {
582
+ return `${year}-${String(month).padStart(2, '0')}`;
583
+ }
584
+ }
585
+ render() {
586
+ const inputProps = this.model.contracts.getInputProps();
587
+ const dialogProps = this.model.contracts.getDialogProps();
588
+ const gridProps = this.model.contracts.getCalendarGridProps();
589
+ const monthPrevProps = this.model.contracts.getMonthNavButtonProps('prev');
590
+ const monthNextProps = this.model.contracts.getMonthNavButtonProps('next');
591
+ const yearPrevProps = this.model.contracts.getYearNavButtonProps('prev');
592
+ const yearNextProps = this.model.contracts.getYearNavButtonProps('next');
593
+ const hourInputProps = this.model.contracts.getHourInputProps();
594
+ const minuteInputProps = this.model.contracts.getMinuteInputProps();
595
+ const applyButtonProps = this.model.contracts.getApplyButtonProps();
596
+ const cancelButtonProps = this.model.contracts.getCancelButtonProps();
597
+ const clearButtonProps = this.model.contracts.getClearButtonProps();
598
+ const displayedYear = this.model.state.displayedYear();
599
+ const displayedMonth = this.model.state.displayedMonth();
600
+ const monthLabel = this.formatMonthLabel(displayedYear, displayedMonth);
601
+ const visibleDays = this.model.contracts.getVisibleDays();
602
+ return html `
603
+ <div part="base">
604
+ <div part="input-wrap">
605
+ <span part="prefix"><slot name="prefix"></slot></span>
606
+ <span part="label">
607
+ <input
608
+ part="input"
609
+ id=${inputProps.id}
610
+ role=${inputProps.role}
611
+ tabindex=${inputProps.tabindex}
612
+ autocomplete=${inputProps.autocomplete}
613
+ .value=${inputProps.value}
614
+ ?disabled=${inputProps.disabled}
615
+ ?readonly=${Boolean(inputProps.readonly)}
616
+ ?required=${Boolean(inputProps.required)}
617
+ name=${this.name || nothing}
618
+ placeholder=${inputProps.placeholder}
619
+ aria-haspopup=${inputProps['aria-haspopup']}
620
+ aria-expanded=${inputProps['aria-expanded']}
621
+ aria-controls=${inputProps['aria-controls']}
622
+ aria-activedescendant=${inputProps['aria-activedescendant'] ?? nothing}
623
+ aria-invalid=${inputProps['aria-invalid'] ?? nothing}
624
+ aria-required=${inputProps.required ? 'true' : nothing}
625
+ aria-label=${inputProps['aria-label'] ?? nothing}
626
+ @input=${this.handleInputEvent}
627
+ @keydown=${this.handleInputKeyDown}
628
+ @focus=${this.handleInputFocus}
629
+ @blur=${this.handleInputBlur}
630
+ />
631
+ </span>
632
+ <span part="suffix"><slot name="suffix"></slot></span>
633
+ <button
634
+ part="clear-button"
635
+ id=${clearButtonProps.id}
636
+ role=${clearButtonProps.role}
637
+ tabindex=${clearButtonProps.tabindex}
638
+ aria-label=${clearButtonProps['aria-label']}
639
+ ?disabled=${clearButtonProps.disabled}
640
+ ?hidden=${!this.hasValue}
641
+ @click=${this.handleClearClick}
642
+ >
643
+ <slot name="clear-icon">&times;</slot>
644
+ </button>
645
+ </div>
646
+
647
+ <div
648
+ part="dialog"
649
+ id=${dialogProps.id}
650
+ role=${dialogProps.role}
651
+ tabindex=${dialogProps.tabindex}
652
+ ?hidden=${dialogProps.hidden}
653
+ aria-modal=${dialogProps['aria-modal']}
654
+ aria-label=${dialogProps['aria-label']}
655
+ @keydown=${this.handleDialogKeyDown}
656
+ >
657
+ <div part="calendar-shell">
658
+ <button
659
+ part="year-nav-button"
660
+ id=${yearPrevProps.id}
661
+ role=${yearPrevProps.role}
662
+ tabindex=${yearPrevProps.tabindex}
663
+ aria-label=${yearPrevProps['aria-label']}
664
+ data-dir="prev"
665
+ @click=${this.handleYearPrevClick}
666
+ >
667
+ <slot name="year-prev">&laquo;</slot>
668
+ </button>
669
+ <button
670
+ part="month-nav-button"
671
+ id=${monthPrevProps.id}
672
+ role=${monthPrevProps.role}
673
+ tabindex=${monthPrevProps.tabindex}
674
+ aria-label=${monthPrevProps['aria-label']}
675
+ data-dir="prev"
676
+ @click=${this.handleMonthPrevClick}
677
+ >
678
+ <slot name="month-prev">&lsaquo;</slot>
679
+ </button>
680
+ <span part="month-label">${monthLabel}</span>
681
+ <button
682
+ part="month-nav-button"
683
+ id=${monthNextProps.id}
684
+ role=${monthNextProps.role}
685
+ tabindex=${monthNextProps.tabindex}
686
+ aria-label=${monthNextProps['aria-label']}
687
+ data-dir="next"
688
+ @click=${this.handleMonthNextClick}
689
+ >
690
+ <slot name="month-next">&rsaquo;</slot>
691
+ </button>
692
+ <button
693
+ part="year-nav-button"
694
+ id=${yearNextProps.id}
695
+ role=${yearNextProps.role}
696
+ tabindex=${yearNextProps.tabindex}
697
+ aria-label=${yearNextProps['aria-label']}
698
+ data-dir="next"
699
+ @click=${this.handleYearNextClick}
700
+ >
701
+ <slot name="year-next">&raquo;</slot>
702
+ </button>
703
+ </div>
704
+
705
+ <div
706
+ part="calendar-grid"
707
+ id=${gridProps.id}
708
+ role=${gridProps.role}
709
+ tabindex=${gridProps.tabindex}
710
+ aria-label=${gridProps['aria-label']}
711
+ @keydown=${this.handleGridKeyDown}
712
+ >
713
+ ${visibleDays.map((day) => {
714
+ const dayProps = this.model.contracts.getCalendarDayProps(day.date);
715
+ const dayText = Number(day.date.slice(8, 10));
716
+ return html `
717
+ <button
718
+ part="calendar-day"
719
+ id=${dayProps.id}
720
+ role=${dayProps.role}
721
+ tabindex=${dayProps.tabindex}
722
+ aria-selected=${dayProps['aria-selected']}
723
+ aria-disabled=${dayProps['aria-disabled'] ?? nothing}
724
+ aria-current=${dayProps['aria-current'] ?? nothing}
725
+ data-date=${dayProps['data-date']}
726
+ data-month=${day.month}
727
+ ?disabled=${day.disabled}
728
+ @click=${this.handleDayClick}
729
+ @mouseenter=${this.handleDayMouseEnter}
730
+ >
731
+ ${dayText}
732
+ </button>
733
+ `;
734
+ })}
735
+ </div>
736
+
737
+ <div part="time-row">
738
+ <input
739
+ part="hour-input"
740
+ id=${hourInputProps.id}
741
+ type=${hourInputProps.type}
742
+ inputmode=${hourInputProps.inputmode}
743
+ aria-label=${hourInputProps['aria-label']}
744
+ .value=${hourInputProps.value}
745
+ minlength=${hourInputProps.minlength}
746
+ maxlength=${hourInputProps.maxlength}
747
+ ?disabled=${hourInputProps.disabled}
748
+ ?readonly=${hourInputProps.readonly}
749
+ data-segment="hour"
750
+ @input=${this.handleTimeInput}
751
+ @keydown=${this.handleTimeKeyDown}
752
+ />
753
+ <span part="time-separator">:</span>
754
+ <input
755
+ part="minute-input"
756
+ id=${minuteInputProps.id}
757
+ type=${minuteInputProps.type}
758
+ inputmode=${minuteInputProps.inputmode}
759
+ aria-label=${minuteInputProps['aria-label']}
760
+ .value=${minuteInputProps.value}
761
+ minlength=${minuteInputProps.minlength}
762
+ maxlength=${minuteInputProps.maxlength}
763
+ ?disabled=${minuteInputProps.disabled}
764
+ ?readonly=${minuteInputProps.readonly}
765
+ data-segment="minute"
766
+ @input=${this.handleTimeInput}
767
+ @keydown=${this.handleTimeKeyDown}
768
+ />
769
+ </div>
770
+
771
+ <div part="actions">
772
+ <button
773
+ part="apply-button"
774
+ id=${applyButtonProps.id}
775
+ role=${applyButtonProps.role}
776
+ tabindex=${applyButtonProps.tabindex}
777
+ aria-label=${applyButtonProps['aria-label']}
778
+ ?disabled=${applyButtonProps.disabled}
779
+ @click=${this.handleApplyClick}
780
+ >
781
+ <slot name="apply-label">Apply</slot>
782
+ </button>
783
+ <button
784
+ part="cancel-button"
785
+ id=${cancelButtonProps.id}
786
+ role=${cancelButtonProps.role}
787
+ tabindex=${cancelButtonProps.tabindex}
788
+ aria-label=${cancelButtonProps['aria-label']}
789
+ ?disabled=${cancelButtonProps.disabled}
790
+ @click=${this.handleCancelClick}
791
+ >
792
+ <slot name="cancel-label">Cancel</slot>
793
+ </button>
794
+ </div>
795
+
796
+ <span part="dialog-caption">
797
+ <slot name="dialog-caption">Use calendar keys and Enter to apply.</slot>
798
+ </span>
799
+ </div>
800
+ </div>
801
+ `;
802
+ }
803
+ }