@threadlabs/looma 0.50.2 → 0.51.1

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 (373) hide show
  1. package/components/shared/binding-inputs.js +5 -0
  2. package/components/shared/calendar-model.js +84 -0
  3. package/components/shared/date-input-segments.js +25 -0
  4. package/components/shared/date-navigation.js +35 -0
  5. package/components/shared/date-picker.js +38 -0
  6. package/components/shared/date-range.js +61 -0
  7. package/components/shared/date-time.js +273 -0
  8. package/components/shared/external-value.js +12 -0
  9. package/components/shared/form-reset.js +1 -1
  10. package/components/shared/icons.js +2 -0
  11. package/components/shared/initial-field-value.js +14 -0
  12. package/components/shared/input-segments.js +190 -0
  13. package/components/shared/prepared-module.js +19 -0
  14. package/components/ui-button/ui-button.html +31 -10
  15. package/components/ui-calendar/calendar-source.js +34 -0
  16. package/components/ui-calendar/ui-calendar.html +221 -0
  17. package/components/ui-calendar/ui-calendar.js +185 -0
  18. package/components/ui-cluster/ui-cluster.html +5 -2
  19. package/components/ui-date-field/ui-date-field.html +143 -0
  20. package/components/ui-date-field/ui-date-field.js +258 -0
  21. package/components/ui-date-picker/ui-date-picker.html +213 -0
  22. package/components/ui-date-picker/ui-date-picker.js +153 -0
  23. package/components/ui-date-range-picker/ui-date-range-picker.html +202 -0
  24. package/components/ui-date-range-picker/ui-date-range-picker.js +224 -0
  25. package/components/ui-file-input/files.js +15 -0
  26. package/components/ui-file-input/ui-file-input.html +79 -0
  27. package/components/ui-file-input/ui-file-input.js +108 -0
  28. package/components/ui-form-field/ui-form-field.js +2 -2
  29. package/components/ui-grid/ui-grid.html +74 -5
  30. package/components/ui-icon/ui-icon.html +8 -0
  31. package/components/ui-icon-button/ui-icon-button.html +22 -7
  32. package/components/ui-input/ui-input.html +10 -1
  33. package/components/ui-input/ui-input.js +11 -5
  34. package/components/ui-input-group/ui-input-group.html +2 -2
  35. package/components/ui-input-group/ui-input-group.js +6 -5
  36. package/components/ui-popover/ui-popover.html +2 -0
  37. package/components/ui-popover/ui-popover.js +5 -1
  38. package/components/ui-select/ui-select.html +8 -3
  39. package/components/ui-time-field/ui-time-field.html +62 -0
  40. package/components/ui-time-field/ui-time-field.js +21 -0
  41. package/components/ui-time-picker/time-options.js +25 -0
  42. package/components/ui-time-picker/ui-time-picker.html +160 -0
  43. package/components/ui-time-picker/ui-time-picker.js +132 -0
  44. package/dist/index.js +68 -61
  45. package/docs/README.md +2 -2
  46. package/docs/catalog.json +14346 -6343
  47. package/docs/documentation.css +1 -1
  48. package/docs/framework-examples.mjs +13 -2
  49. package/docs/site.mjs +1 -1
  50. package/editor/components.css +62 -29
  51. package/editor/icons.d.ts +2 -0
  52. package/editor/index.js +602 -141
  53. package/package.json +6 -4
  54. package/styles/ui-action-bar.css +1 -1
  55. package/styles/ui-affordance-scope.css +1 -1
  56. package/styles/ui-avatar-group.css +1 -1
  57. package/styles/ui-avatar.css +1 -1
  58. package/styles/ui-badge.css +1 -1
  59. package/styles/ui-breadcrumb-item.css +1 -1
  60. package/styles/ui-breadcrumbs.css +1 -1
  61. package/styles/ui-button.css +19 -7
  62. package/styles/ui-calendar.css +1 -0
  63. package/styles/ui-callout.css +1 -1
  64. package/styles/ui-card-group.css +1 -1
  65. package/styles/ui-card.css +1 -1
  66. package/styles/ui-checkbox.css +1 -1
  67. package/styles/ui-cluster.css +4 -1
  68. package/styles/ui-color-picker.css +1 -1
  69. package/styles/ui-combobox.css +1 -1
  70. package/styles/ui-compact-content.css +1 -1
  71. package/styles/ui-compact-editor.css +1 -1
  72. package/styles/ui-compact-mark.css +1 -1
  73. package/styles/ui-compact-node.css +1 -1
  74. package/styles/ui-container.css +1 -1
  75. package/styles/ui-context-menu.css +1 -1
  76. package/styles/ui-cover.css +1 -1
  77. package/styles/ui-curve-editor.css +1 -1
  78. package/styles/ui-cycle-button.css +1 -1
  79. package/styles/ui-date-field.css +1 -0
  80. package/styles/ui-date-picker.css +1 -0
  81. package/styles/ui-date-range-picker.css +1 -0
  82. package/styles/ui-description-item.css +1 -1
  83. package/styles/ui-description-list.css +1 -1
  84. package/styles/ui-dialog.css +1 -1
  85. package/styles/ui-disclosure.css +1 -1
  86. package/styles/ui-editable.css +1 -1
  87. package/styles/ui-editor-block-actions.css +1 -1
  88. package/styles/ui-editor-chip-editor.css +1 -1
  89. package/styles/ui-editor-code-language.css +1 -1
  90. package/styles/ui-editor-footnote-editor.css +1 -1
  91. package/styles/ui-editor-formatting-tools.css +1 -1
  92. package/styles/ui-editor-image-toolbar.css +1 -1
  93. package/styles/ui-editor-insert-table-grid.css +1 -1
  94. package/styles/ui-editor-link-card.css +1 -1
  95. package/styles/ui-editor-link-form.css +1 -1
  96. package/styles/ui-editor-mention-menu-item.css +1 -1
  97. package/styles/ui-editor-mention-menu.css +1 -1
  98. package/styles/ui-editor-slash-menu-group.css +1 -1
  99. package/styles/ui-editor-slash-menu-item.css +1 -1
  100. package/styles/ui-editor-slash-menu.css +1 -1
  101. package/styles/ui-editor-surface.css +1 -1
  102. package/styles/ui-editor-table-context-menu.css +1 -1
  103. package/styles/ui-editor-table-overlay.css +1 -1
  104. package/styles/ui-editor-table-toolbar.css +1 -1
  105. package/styles/ui-editor-toolbar.css +1 -1
  106. package/styles/ui-editor.css +1 -1
  107. package/styles/ui-file-input.css +1 -0
  108. package/styles/ui-floating-action-button.css +1 -1
  109. package/styles/ui-form-field.css +1 -1
  110. package/styles/ui-grid.css +44 -1
  111. package/styles/ui-icon-button.css +19 -5
  112. package/styles/ui-icon.css +5 -1
  113. package/styles/ui-image.css +1 -1
  114. package/styles/ui-input-group.css +3 -3
  115. package/styles/ui-input.css +1 -1
  116. package/styles/ui-light-editor.css +1 -1
  117. package/styles/ui-list-item.css +1 -1
  118. package/styles/ui-list.css +1 -1
  119. package/styles/ui-listbox.css +1 -1
  120. package/styles/ui-menu-group.css +1 -1
  121. package/styles/ui-menu-item.css +1 -1
  122. package/styles/ui-menu.css +1 -1
  123. package/styles/ui-meter.css +1 -1
  124. package/styles/ui-nav-item.css +1 -1
  125. package/styles/ui-number-input.css +1 -1
  126. package/styles/ui-page-header.css +1 -1
  127. package/styles/ui-pagination.css +1 -1
  128. package/styles/ui-popover.css +1 -1
  129. package/styles/ui-radio-group.css +1 -1
  130. package/styles/ui-radio.css +1 -1
  131. package/styles/ui-reel.css +1 -1
  132. package/styles/ui-scroll-area.css +1 -1
  133. package/styles/ui-search-result-row.css +1 -1
  134. package/styles/ui-search-shell.css +1 -1
  135. package/styles/ui-section.css +1 -1
  136. package/styles/ui-select.css +9 -4
  137. package/styles/ui-separator.css +1 -1
  138. package/styles/ui-sidebar.css +1 -1
  139. package/styles/ui-site-header.css +19 -19
  140. package/styles/ui-skeleton.css +1 -1
  141. package/styles/ui-slider.css +1 -1
  142. package/styles/ui-spinner.css +1 -1
  143. package/styles/ui-stack.css +1 -1
  144. package/styles/ui-status-message.css +1 -1
  145. package/styles/ui-swatch.css +1 -1
  146. package/styles/ui-switch.css +1 -1
  147. package/styles/ui-switcher.css +1 -1
  148. package/styles/ui-table.css +1 -1
  149. package/styles/ui-tabs.css +1 -1
  150. package/styles/ui-text.css +1 -1
  151. package/styles/ui-textarea.css +1 -1
  152. package/styles/ui-time-field.css +1 -0
  153. package/styles/ui-time-picker.css +1 -0
  154. package/styles/ui-toast-region.css +1 -1
  155. package/styles/ui-toast.css +1 -1
  156. package/styles/ui-tooltip.css +1 -1
  157. package/styles/ui-top-bar.css +1 -1
  158. package/styles/ui-tree-item.css +1 -1
  159. package/styles/ui-tree.css +1 -1
  160. package/tokens.css +4 -0
  161. package/vanilla/UiActionBar.d.ts +1 -1
  162. package/vanilla/UiActionBar.js +1 -1
  163. package/vanilla/UiAffordanceScope.d.ts +1 -1
  164. package/vanilla/UiAffordanceScope.js +1 -1
  165. package/vanilla/UiAvatar.d.ts +1 -1
  166. package/vanilla/UiAvatar.js +1 -1
  167. package/vanilla/UiAvatarGroup.d.ts +1 -1
  168. package/vanilla/UiAvatarGroup.js +1 -1
  169. package/vanilla/UiBadge.d.ts +1 -1
  170. package/vanilla/UiBadge.js +1 -1
  171. package/vanilla/UiBreadcrumbItem.d.ts +1 -1
  172. package/vanilla/UiBreadcrumbItem.js +1 -1
  173. package/vanilla/UiBreadcrumbs.d.ts +1 -1
  174. package/vanilla/UiBreadcrumbs.js +1 -1
  175. package/vanilla/UiButton.d.ts +2 -1
  176. package/vanilla/UiButton.js +128 -108
  177. package/vanilla/UiCalendar.d.ts +50 -0
  178. package/vanilla/UiCalendar.js +477 -0
  179. package/vanilla/UiCallout.d.ts +1 -1
  180. package/vanilla/UiCallout.js +1 -1
  181. package/vanilla/UiCard.d.ts +1 -1
  182. package/vanilla/UiCard.js +1 -1
  183. package/vanilla/UiCardGroup.d.ts +1 -1
  184. package/vanilla/UiCardGroup.js +1 -1
  185. package/vanilla/UiCheckbox.d.ts +1 -1
  186. package/vanilla/UiCheckbox.js +1 -1
  187. package/vanilla/UiCluster.d.ts +2 -2
  188. package/vanilla/UiCluster.js +2 -2
  189. package/vanilla/UiColorPicker.d.ts +1 -1
  190. package/vanilla/UiColorPicker.js +1 -1
  191. package/vanilla/UiCombobox.d.ts +1 -1
  192. package/vanilla/UiCombobox.js +1 -1
  193. package/vanilla/UiCompactContent.d.ts +1 -1
  194. package/vanilla/UiCompactContent.js +1 -1
  195. package/vanilla/UiCompactEditor.d.ts +1 -1
  196. package/vanilla/UiCompactEditor.js +1 -1
  197. package/vanilla/UiCompactMark.d.ts +1 -1
  198. package/vanilla/UiCompactMark.js +1 -1
  199. package/vanilla/UiCompactNode.d.ts +1 -1
  200. package/vanilla/UiCompactNode.js +1 -1
  201. package/vanilla/UiContainer.d.ts +1 -1
  202. package/vanilla/UiContainer.js +1 -1
  203. package/vanilla/UiContextMenu.d.ts +1 -1
  204. package/vanilla/UiContextMenu.js +1 -1
  205. package/vanilla/UiCover.d.ts +1 -1
  206. package/vanilla/UiCover.js +1 -1
  207. package/vanilla/UiCurveEditor.d.ts +1 -1
  208. package/vanilla/UiCurveEditor.js +1 -1
  209. package/vanilla/UiCycleButton.d.ts +1 -1
  210. package/vanilla/UiCycleButton.js +1 -1
  211. package/vanilla/UiDateField.d.ts +52 -0
  212. package/vanilla/UiDateField.js +208 -0
  213. package/vanilla/UiDatePicker.d.ts +63 -0
  214. package/vanilla/UiDatePicker.js +360 -0
  215. package/vanilla/UiDateRangePicker.d.ts +60 -0
  216. package/vanilla/UiDateRangePicker.js +418 -0
  217. package/vanilla/UiDescriptionItem.d.ts +1 -1
  218. package/vanilla/UiDescriptionItem.js +1 -1
  219. package/vanilla/UiDescriptionList.d.ts +1 -1
  220. package/vanilla/UiDescriptionList.js +1 -1
  221. package/vanilla/UiDialog.d.ts +1 -1
  222. package/vanilla/UiDialog.js +1 -1
  223. package/vanilla/UiDisclosure.d.ts +1 -1
  224. package/vanilla/UiDisclosure.js +1 -1
  225. package/vanilla/UiEditable.d.ts +1 -1
  226. package/vanilla/UiEditable.js +1 -1
  227. package/vanilla/UiEditor.d.ts +1 -1
  228. package/vanilla/UiEditor.js +1 -1
  229. package/vanilla/UiEditorBlockActions.d.ts +1 -1
  230. package/vanilla/UiEditorBlockActions.js +1 -1
  231. package/vanilla/UiEditorChipEditor.d.ts +1 -1
  232. package/vanilla/UiEditorChipEditor.js +1 -1
  233. package/vanilla/UiEditorCodeLanguage.d.ts +1 -1
  234. package/vanilla/UiEditorCodeLanguage.js +1 -1
  235. package/vanilla/UiEditorFootnoteEditor.d.ts +1 -1
  236. package/vanilla/UiEditorFootnoteEditor.js +1 -1
  237. package/vanilla/UiEditorFormattingTools.d.ts +1 -1
  238. package/vanilla/UiEditorFormattingTools.js +1 -1
  239. package/vanilla/UiEditorImageToolbar.d.ts +1 -1
  240. package/vanilla/UiEditorImageToolbar.js +1 -1
  241. package/vanilla/UiEditorInsertTableGrid.d.ts +1 -1
  242. package/vanilla/UiEditorInsertTableGrid.js +1 -1
  243. package/vanilla/UiEditorLinkCard.d.ts +1 -1
  244. package/vanilla/UiEditorLinkCard.js +1 -1
  245. package/vanilla/UiEditorLinkForm.d.ts +1 -1
  246. package/vanilla/UiEditorLinkForm.js +1 -1
  247. package/vanilla/UiEditorMentionMenu.d.ts +1 -1
  248. package/vanilla/UiEditorMentionMenu.js +1 -1
  249. package/vanilla/UiEditorMentionMenuItem.d.ts +1 -1
  250. package/vanilla/UiEditorMentionMenuItem.js +1 -1
  251. package/vanilla/UiEditorSlashMenu.d.ts +1 -1
  252. package/vanilla/UiEditorSlashMenu.js +1 -1
  253. package/vanilla/UiEditorSlashMenuGroup.d.ts +1 -1
  254. package/vanilla/UiEditorSlashMenuGroup.js +1 -1
  255. package/vanilla/UiEditorSlashMenuItem.d.ts +1 -1
  256. package/vanilla/UiEditorSlashMenuItem.js +1 -1
  257. package/vanilla/UiEditorSurface.d.ts +1 -1
  258. package/vanilla/UiEditorSurface.js +1 -1
  259. package/vanilla/UiEditorTableContextMenu.d.ts +1 -1
  260. package/vanilla/UiEditorTableContextMenu.js +1 -1
  261. package/vanilla/UiEditorTableOverlay.d.ts +1 -1
  262. package/vanilla/UiEditorTableOverlay.js +1 -1
  263. package/vanilla/UiEditorTableToolbar.d.ts +1 -1
  264. package/vanilla/UiEditorTableToolbar.js +1 -1
  265. package/vanilla/UiEditorToolbar.d.ts +1 -1
  266. package/vanilla/UiEditorToolbar.js +1 -1
  267. package/vanilla/UiFileInput.d.ts +36 -0
  268. package/vanilla/UiFileInput.js +209 -0
  269. package/vanilla/UiFloatingActionButton.d.ts +1 -1
  270. package/vanilla/UiFloatingActionButton.js +1 -1
  271. package/vanilla/UiFormField.d.ts +1 -1
  272. package/vanilla/UiFormField.js +1 -1
  273. package/vanilla/UiGrid.d.ts +7 -2
  274. package/vanilla/UiGrid.js +85 -19
  275. package/vanilla/UiIcon.d.ts +2 -1
  276. package/vanilla/UiIcon.js +10 -10
  277. package/vanilla/UiIconButton.d.ts +2 -2
  278. package/vanilla/UiIconButton.js +2 -2
  279. package/vanilla/UiImage.d.ts +1 -1
  280. package/vanilla/UiImage.js +1 -1
  281. package/vanilla/UiInput.d.ts +2 -1
  282. package/vanilla/UiInput.js +11 -11
  283. package/vanilla/UiInputGroup.d.ts +1 -1
  284. package/vanilla/UiInputGroup.js +1 -1
  285. package/vanilla/UiLightEditor.d.ts +1 -1
  286. package/vanilla/UiLightEditor.js +1 -1
  287. package/vanilla/UiList.d.ts +1 -1
  288. package/vanilla/UiList.js +1 -1
  289. package/vanilla/UiListItem.d.ts +1 -1
  290. package/vanilla/UiListItem.js +1 -1
  291. package/vanilla/UiListbox.d.ts +1 -1
  292. package/vanilla/UiListbox.js +1 -1
  293. package/vanilla/UiMenu.d.ts +1 -1
  294. package/vanilla/UiMenu.js +1 -1
  295. package/vanilla/UiMenuGroup.d.ts +1 -1
  296. package/vanilla/UiMenuGroup.js +1 -1
  297. package/vanilla/UiMenuItem.d.ts +1 -1
  298. package/vanilla/UiMenuItem.js +1 -1
  299. package/vanilla/UiMeter.d.ts +1 -1
  300. package/vanilla/UiMeter.js +1 -1
  301. package/vanilla/UiNavItem.d.ts +1 -1
  302. package/vanilla/UiNavItem.js +1 -1
  303. package/vanilla/UiNumberInput.d.ts +1 -1
  304. package/vanilla/UiNumberInput.js +1 -1
  305. package/vanilla/UiPageHeader.d.ts +1 -1
  306. package/vanilla/UiPageHeader.js +1 -1
  307. package/vanilla/UiPagination.d.ts +1 -1
  308. package/vanilla/UiPagination.js +1 -1
  309. package/vanilla/UiPopover.d.ts +2 -1
  310. package/vanilla/UiPopover.js +4 -4
  311. package/vanilla/UiRadio.d.ts +1 -1
  312. package/vanilla/UiRadio.js +1 -1
  313. package/vanilla/UiRadioGroup.d.ts +1 -1
  314. package/vanilla/UiRadioGroup.js +1 -1
  315. package/vanilla/UiReel.d.ts +1 -1
  316. package/vanilla/UiReel.js +1 -1
  317. package/vanilla/UiScrollArea.d.ts +1 -1
  318. package/vanilla/UiScrollArea.js +1 -1
  319. package/vanilla/UiSearchResultRow.d.ts +1 -1
  320. package/vanilla/UiSearchResultRow.js +1 -1
  321. package/vanilla/UiSearchShell.d.ts +1 -1
  322. package/vanilla/UiSearchShell.js +1 -1
  323. package/vanilla/UiSection.d.ts +1 -1
  324. package/vanilla/UiSection.js +1 -1
  325. package/vanilla/UiSelect.d.ts +1 -1
  326. package/vanilla/UiSelect.js +1 -1
  327. package/vanilla/UiSeparator.d.ts +1 -1
  328. package/vanilla/UiSeparator.js +1 -1
  329. package/vanilla/UiSidebar.d.ts +1 -1
  330. package/vanilla/UiSidebar.js +1 -1
  331. package/vanilla/UiSiteHeader.d.ts +1 -1
  332. package/vanilla/UiSiteHeader.js +1 -1
  333. package/vanilla/UiSkeleton.d.ts +1 -1
  334. package/vanilla/UiSkeleton.js +1 -1
  335. package/vanilla/UiSlider.d.ts +1 -1
  336. package/vanilla/UiSlider.js +1 -1
  337. package/vanilla/UiSpinner.d.ts +1 -1
  338. package/vanilla/UiSpinner.js +1 -1
  339. package/vanilla/UiStack.d.ts +1 -1
  340. package/vanilla/UiStack.js +1 -1
  341. package/vanilla/UiStatusMessage.d.ts +1 -1
  342. package/vanilla/UiStatusMessage.js +1 -1
  343. package/vanilla/UiSwatch.d.ts +1 -1
  344. package/vanilla/UiSwatch.js +1 -1
  345. package/vanilla/UiSwitch.d.ts +1 -1
  346. package/vanilla/UiSwitch.js +1 -1
  347. package/vanilla/UiSwitcher.d.ts +1 -1
  348. package/vanilla/UiSwitcher.js +1 -1
  349. package/vanilla/UiTable.d.ts +1 -1
  350. package/vanilla/UiTable.js +1 -1
  351. package/vanilla/UiTabs.d.ts +1 -1
  352. package/vanilla/UiTabs.js +1 -1
  353. package/vanilla/UiText.d.ts +1 -1
  354. package/vanilla/UiText.js +1 -1
  355. package/vanilla/UiTextarea.d.ts +1 -1
  356. package/vanilla/UiTextarea.js +1 -1
  357. package/vanilla/UiTimeField.d.ts +42 -0
  358. package/vanilla/UiTimeField.js +112 -0
  359. package/vanilla/UiTimePicker.d.ts +48 -0
  360. package/vanilla/UiTimePicker.js +372 -0
  361. package/vanilla/UiToast.d.ts +1 -1
  362. package/vanilla/UiToast.js +1 -1
  363. package/vanilla/UiToastRegion.d.ts +1 -1
  364. package/vanilla/UiToastRegion.js +1 -1
  365. package/vanilla/UiTooltip.d.ts +1 -1
  366. package/vanilla/UiTooltip.js +1 -1
  367. package/vanilla/UiTopBar.d.ts +1 -1
  368. package/vanilla/UiTopBar.js +1 -1
  369. package/vanilla/UiTree.d.ts +1 -1
  370. package/vanilla/UiTree.js +1 -1
  371. package/vanilla/UiTreeItem.d.ts +1 -1
  372. package/vanilla/UiTreeItem.js +1 -1
  373. package/vanilla/index.js +7 -0
@@ -0,0 +1,185 @@
1
+ import { preparedModule } from "../shared/prepared-module.js";
2
+ import { componentInputs } from "@nextwebwg/html-next/inputs";
3
+ import { Temporal, asciiDigits, canonicalValue, compileDateRules, isDateAllowed } from "../shared/date-time.js";
4
+ import { availableDate } from "../shared/date-navigation.js";
5
+ import { createCalendarBindings } from "./calendar-source.js";
6
+
7
+ const constraintNames = ["min", "max", "allowedDates", "allowedRanges", "disabledDates", "disabledRanges", "disabledWeekdays"];
8
+
9
+ /** Navigate civil dates independently of typed entry, using the same Temporal availability rules. */
10
+ function interactions(host) {
11
+ const element = host.element;
12
+ const inputs = componentInputs(host);
13
+ let frame;
14
+ let connected = true;
15
+ const model = () => host.props.model.value;
16
+ const blocked = () => host.props.disabled.value;
17
+ const settings = () => Object.fromEntries(constraintNames.map(key => [key, host.props[key].value]));
18
+ const focus = selector => {
19
+ cancelAnimationFrame(frame);
20
+ frame = requestAnimationFrame(() => {
21
+ if (!connected) return;
22
+ const target = element.querySelector(selector) ?? element.querySelector(host.state.mode === "days" ? '[data-calendar-days][tabindex="0"]' : "[data-calendar-year-toggle]");
23
+ if (target && !target.closest("[hidden]")) target.focus();
24
+ });
25
+ };
26
+ const focusView = () => focus(host.state.mode === "days" ? '[data-calendar-day][tabindex="0"]' : `[data-calendar-${host.state.mode === "months" ? "month" : "year"}][tabindex="0"]`);
27
+ const showMonth = (month, trigger = "programmatic") => {
28
+ const previous = model()?.month;
29
+ host.state.visibleMonth = month;
30
+ if (month !== previous) host.dispatch("month-change", { month, trigger });
31
+ };
32
+ const showMode = mode => {
33
+ if (host.state.mode === "days") {
34
+ // Popup entry transforms affect client rectangles, but not the computed layout height.
35
+ const height = parseFloat(getComputedStyle(element.querySelector("[data-calendar-viewport]")).height);
36
+ if (height > 0) host.state.viewHeight = height;
37
+ }
38
+ host.state.mode = mode;
39
+ host.state.yearError = "";
40
+ if (mode === "years") {
41
+ host.state.yearPageStart = Math.floor((Number(model().month.slice(0, 4)) - 1) / 12) * 12 + 1;
42
+ element.querySelector("[data-calendar-year-input]").value = model().yearLabel;
43
+ }
44
+ focusView();
45
+ };
46
+ const select = (value, trigger) => {
47
+ const status = inputs.status("model");
48
+ const ready = constraintNames.every(name => {
49
+ const input = inputs.status(name);
50
+ return !input.pending && !input.error && !input.stale && (input.ready || !inputs.supplied(name));
51
+ });
52
+ if (blocked() || host.props.readonly.value || !ready || !status.ready || status.stale || !isDateAllowed(value, compileDateRules(settings()))) return;
53
+ const changed = value !== host.state.current;
54
+ host.state.current = value; host.state.focusedDate = value;
55
+ showMonth(value.slice(0, 7), trigger);
56
+ if (changed) {
57
+ host.dispatch("input", { value, trigger });
58
+ host.dispatch("change", { value, trigger });
59
+ }
60
+ host.dispatch("select", { value, trigger });
61
+ focus(`[data-calendar-day="${value}"]`);
62
+ };
63
+ const moveDay = (value, direction) => {
64
+ const date = availableDate(value, direction, compileDateRules(settings()));
65
+ if (!date) return;
66
+ host.state.focusedDate = date;
67
+ showMonth(date.slice(0, 7), "keyboard");
68
+ focus(`[data-calendar-day="${date}"]`);
69
+ };
70
+ const navigate = (direction, trigger) => {
71
+ const current = model(); if (!current) return;
72
+ if (host.state.mode === "years") host.state.yearPageStart = Math.max(1, Math.min(9997, current.yearPageStart + direction * 12));
73
+ else {
74
+ const date = Temporal.PlainYearMonth.from(current.month).add(host.state.mode === "days" ? { months: direction } : { years: direction });
75
+ if (date.year < 1 || date.year > 9999) return;
76
+ showMonth(date.toString(), trigger);
77
+ }
78
+ };
79
+ const chooseYear = (year, trigger) => {
80
+ showMonth(`${String(year).padStart(4, "0")}-${model().month.slice(5)}`, trigger);
81
+ showMode("months");
82
+ };
83
+ const goToYear = trigger => {
84
+ const input = element.querySelector("[data-calendar-year-input]");
85
+ const text = asciiDigits(input.value, host.props.locale.value);
86
+ const year = Number(text);
87
+ if (!/^\d{1,4}$/.test(text) || year < 1 || year > 9999) {
88
+ host.state.yearError = host.props.yearErrorLabel.value; input.focus(); return;
89
+ }
90
+ chooseYear(year, trigger);
91
+ };
92
+ const click = event => {
93
+ const button = event.target.closest?.("button");
94
+ if (blocked() || !button || button.disabled || !element.contains(button)) return;
95
+ const trigger = event.detail === 0 ? "keyboard" : "pointer";
96
+ if (button.hasAttribute("data-calendar-day")) select(button.dataset.calendarDay, trigger);
97
+ else if (button.hasAttribute("data-calendar-month-toggle")) showMode(host.state.mode === "months" ? "days" : "months");
98
+ else if (button.hasAttribute("data-calendar-year-toggle")) showMode(host.state.mode === "years" ? "days" : "years");
99
+ else if (button.hasAttribute("data-calendar-previous")) navigate(-1, trigger);
100
+ else if (button.hasAttribute("data-calendar-next")) navigate(1, trigger);
101
+ else if (button.hasAttribute("data-calendar-month")) { showMonth(button.dataset.calendarMonth, trigger); showMode("days"); }
102
+ else if (button.hasAttribute("data-calendar-year")) chooseYear(Number(button.dataset.calendarYear), trigger);
103
+
104
+ };
105
+ const keydown = event => {
106
+ if (blocked() || event.altKey || event.ctrlKey || event.metaKey) return;
107
+ if (event.key === "Escape" && host.state.mode !== "days") { event.preventDefault(); event.stopPropagation(); showMode("days"); return; }
108
+ if (event.target.matches("[data-calendar-year-input]")) {
109
+ if (event.key === "Enter") { event.preventDefault(); goToYear("keyboard"); }
110
+ return;
111
+ }
112
+ const button = event.target.closest?.("button"); if (!button) return;
113
+ const horizontal = getComputedStyle(element).direction === "rtl" ? -1 : 1;
114
+ if (button.hasAttribute("data-calendar-day")) {
115
+ const date = Temporal.PlainDate.from(button.dataset.calendarDay);
116
+ let target; let direction;
117
+ if (event.key === "ArrowLeft" || event.key === "ArrowRight") { direction = (event.key === "ArrowRight" ? 1 : -1) * horizontal; target = date.add({ days: direction }); }
118
+ else if (event.key === "ArrowUp" || event.key === "ArrowDown") { direction = event.key === "ArrowDown" ? 1 : -1; target = date.add({ days: direction * 7 }); }
119
+ else if (event.key === "PageUp" || event.key === "PageDown") { direction = event.key === "PageDown" ? 1 : -1; target = date.add(event.shiftKey ? { years: direction } : { months: direction }); }
120
+ else if (event.key === "Home" || event.key === "End") {
121
+ const offset = (date.dayOfWeek - model().weekStartsOn + 7) % 7;
122
+ direction = event.key === "Home" ? 1 : -1;
123
+ target = date.add({ days: event.key === "Home" ? -offset : 6 - offset });
124
+ const found = availableDate(target.toString(), direction, compileDateRules(settings()));
125
+ if (!found || Math.abs(Temporal.PlainDate.from(found).since(target, { largestUnit: "days" }).days) > 6) { event.preventDefault(); return; }
126
+ } else return;
127
+ event.preventDefault(); moveDay(target.toString(), direction);
128
+ } else if (button.matches("[data-calendar-month], [data-calendar-year]")) {
129
+ const name = host.state.mode === "months" ? "month" : "year";
130
+ const buttons = [...element.querySelectorAll(`[data-calendar-${name}]`)];
131
+ let index = buttons.indexOf(button); let step;
132
+ if (event.key === "ArrowLeft" || event.key === "ArrowRight") step = (event.key === "ArrowRight" ? 1 : -1) * horizontal;
133
+ else if (event.key === "ArrowUp" || event.key === "ArrowDown") step = event.key === "ArrowDown" ? 3 : -3;
134
+ else if (event.key === "Home" || event.key === "End") { index = event.key === "Home" ? -1 : buttons.length; step = event.key === "Home" ? 1 : -1; }
135
+ else return;
136
+ event.preventDefault();
137
+ for (index += step; index >= 0 && index < buttons.length; index += step) {
138
+ if (buttons[index].disabled) continue;
139
+ for (const item of buttons) item.tabIndex = -1;
140
+ buttons[index].tabIndex = 0; buttons[index].focus(); break;
141
+ }
142
+ }
143
+ };
144
+ const focusin = event => {
145
+ const button = event.target.closest?.("[data-calendar-day]");
146
+ if (button) for (const day of element.querySelectorAll("[data-calendar-day]")) day.tabIndex = day === button ? 0 : -1;
147
+ };
148
+ const request = event => {
149
+ if (event.target !== element || !(event instanceof CustomEvent)) return;
150
+ if (blocked()) { if (event.cancelable) event.preventDefault(); return; }
151
+ try {
152
+ const value = canonicalValue(event.detail?.value);
153
+ if (!value) throw new RangeError("A focus request requires a complete date.");
154
+ host.state.focusedDate = value; showMonth(value.slice(0, 7)); host.state.mode = "days"; focusView();
155
+ } catch { if (event.cancelable) event.preventDefault(); }
156
+ };
157
+ element.addEventListener("click", click);
158
+ element.addEventListener("keydown", keydown);
159
+ element.addEventListener("focusin", focusin);
160
+ element.addEventListener("focus-date", request);
161
+ let externalValue = host.props.value.value;
162
+ let externalMonth = host.props.month.value;
163
+ const stop = host.effect(() => {
164
+ const value = host.props.value.value;
165
+ const month = host.props.month.value;
166
+ if (value !== externalValue) {
167
+ externalValue = value;
168
+ if (host.state.current !== value) {
169
+ host.state.current = value;
170
+ if (!month && value) host.state.visibleMonth = value.slice(0, 7);
171
+ }
172
+ }
173
+ if (month !== externalMonth) { externalMonth = month; host.state.visibleMonth = month; }
174
+ });
175
+ return () => {
176
+ connected = false; cancelAnimationFrame(frame); stop();
177
+ element.removeEventListener("click", click); element.removeEventListener("keydown", keydown);
178
+ element.removeEventListener("focusin", focusin); element.removeEventListener("focus-date", request);
179
+ };
180
+ }
181
+
182
+ /** Share server preparation, producer adoption and browser behavior through one binding instance. */
183
+ export const { connect, prepare, adopt } = preparedModule(host => ({
184
+ props: createCalendarBindings(componentInputs(host)), connect: interactions,
185
+ }));
@@ -1,7 +1,7 @@
1
1
  <template component="ui-cluster" module="./ui-cluster.js">
2
2
  <defs>
3
- <prop name="padding" type="keyword" values="none, s, m, l" default="none"
4
- >Optional internal space for an action group, using the shared spacing scale.</prop>
3
+ <prop name="padding" type="keyword" values="none, xs, s, m, l" default="none"
4
+ >Optional internal space for an action group, using the shared spacing scale. xs is 0.25rem, s is 0.5rem, m is 0.75rem, and l is 1rem.</prop>
5
5
  <prop name="paddingEnd" type="keyword" values="none, s, m, l, xl" default="none"
6
6
  >Optional extra space at the inline end, such as clearance beside another control. xl is 4rem.</prop>
7
7
  <prop name="fixed" type="boolean" default="false">Keeps this group at its content size inside a flex layout.</prop>
@@ -63,6 +63,9 @@
63
63
  :host([fixed]) {
64
64
  flex: none;
65
65
  }
66
+ :host([padding="xs"]) {
67
+ padding: var(--ui-space-1) !important;
68
+ }
66
69
  :host([padding="s"]) {
67
70
  padding: var(--ui-space-2) !important;
68
71
  }
@@ -0,0 +1,143 @@
1
+ <link rel="component" href="../ui-input/ui-input.html">
2
+ <template component="ui-date-field" module="./ui-date-field.js">
3
+ <defs>
4
+ <prop name="value" type="string" default=""
5
+ >Initial canonical value, and a replacement when changed externally. Valid edits update live state and emit input/change; a form reset returns to the last
6
+ external value.</prop>
7
+ <prop name="type" type="keyword" values="date, time, datetime-local, instant, zoned" default="date"
8
+ >The value's meaning and export format. Date is the default and exports only YYYY-MM-DD, without a time or timezone. Time and local date-time remain
9
+ wall-clock values; instant uses a UTC timestamp; zoned retains a named zone. Display options alone never change this type.</prop>
10
+ <prop name="valueFormat" type="keyword" values="iso, space" default="iso"
11
+ >Local date-time bindings use T by default; space emits YYYY-MM-DD HH:mm[:ss]. Other types retain their ISO form.</prop>
12
+ <prop name="locale" type="string" default="en-US">Explicit Intl locale for numeric editing order, digits and display. ISO input is always accepted.</prop>
13
+ <prop name="timeZone" type="string" default=""
14
+ >Display/editing zone for instant values, required for localized instant editing. Zoned values otherwise use their saved zone; local typing through an
15
+ override preserves that saved zone. Required for a new zoned value. Date, time and local date-time bindings remain without a zone.</prop>
16
+ <prop name="disambiguation" type="keyword" values="reject, earlier, later, compatible" default="reject"
17
+ >How zoned edits resolve a skipped or repeated wall-clock time. Reject leaves the draft visible with a validation error.</prop>
18
+ <prop name="hourCycle" type="keyword" values="h11, h12, h23, h24">Intl hour cycle. Omit to follow locale conventions.</prop>
19
+ <prop name="granularity" type="keyword" values="minute, second" default="minute"
20
+ >Smallest displayed time unit. Existing nonzero seconds and fractions remain editable without precision loss.</prop>
21
+ <prop name="displayOptions" type="object">Intl display options while unfocused. Focusing uses the numeric editing grammar; formatting does not change the
22
+ binding. Calendar identity and editing timezone stay with the field.
23
+ <prop name="dateStyle" type="keyword" values="full, long, medium, short"></prop>
24
+ <prop name="timeStyle" type="keyword" values="full, long, medium, short"></prop>
25
+ <prop name="weekday" type="keyword" values="long, short, narrow"></prop>
26
+ <prop name="era" type="keyword" values="long, short, narrow"></prop>
27
+ <prop name="year" type="keyword" values="numeric, 2-digit"></prop>
28
+ <prop name="month" type="keyword" values="numeric, 2-digit, long, short, narrow"></prop>
29
+ <prop name="day" type="keyword" values="numeric, 2-digit"></prop>
30
+ <prop name="hour" type="keyword" values="numeric, 2-digit"></prop>
31
+ <prop name="minute" type="keyword" values="numeric, 2-digit"></prop>
32
+ <prop name="second" type="keyword" values="numeric, 2-digit"></prop>
33
+ <prop name="timeZoneName" type="keyword" values="long, short, shortOffset, longOffset, shortGeneric, longGeneric"></prop>
34
+ <prop name="dayPeriod" type="keyword" values="long, short, narrow"></prop>
35
+ <prop name="hourCycle" type="keyword" values="h11, h12, h23, h24"></prop>
36
+ <prop name="localeMatcher" type="string" values="lookup, best fit"></prop>
37
+ <prop name="formatMatcher" type="string" values="basic, best fit"></prop>
38
+ <prop name="fractionalSecondDigits" type="integer" min="1" max="3"></prop>
39
+ <prop name="hour12" type="boolean"></prop>
40
+ <prop name="numberingSystem" type="string"></prop>
41
+ </prop>
42
+ <prop name="min" type="string" default="">Inclusive minimum in the bound value's format.</prop>
43
+ <prop name="max" type="string" default="">Inclusive maximum in the bound value's format.</prop>
44
+ <prop name="disabledDates" type="list(string)" default="[]">Unavailable ISO dates, applied in the editing zone for exact values.</prop>
45
+ <prop name="disabledRanges" type="list" default="[]">Unavailable inclusive ISO-date intervals.<prop type="object"><prop
46
+ name="start"
47
+ type="string"
48
+ required
49
+ ></prop><prop name="end" type="string" required></prop></prop></prop>
50
+ <prop name="disabledWeekdays" type="list(integer)" default="[]">Unavailable ISO weekdays, from 1 (Monday) to 7 (Sunday).</prop>
51
+ <prop name="allowedDates" type="list(string)"
52
+ >Allowed ISO dates, unioned with allowedRanges. Omission imposes no allow restriction; an explicitly empty allow set permits nothing.</prop>
53
+ <prop name="allowedRanges" type="list">Allowed inclusive ISO-date intervals, unioned with allowedDates.<prop type="object"><prop
54
+ name="start"
55
+ type="string"
56
+ required
57
+ ></prop><prop name="end" type="string" required></prop></prop></prop>
58
+ <prop name="name" type="string" default="">Native form field name. The enhanced field submits its canonical value.</prop>
59
+ <prop name="form" type="string" default="">Optional ID of a form outside this component’s ancestor tree.</prop>
60
+ <prop name="inputId" type="string" default="">ID of the active native input for an authored label's for attribute, preserved across upgrade.</prop>
61
+ <prop name="label" type="string" default=""
62
+ >Optional accessible name. Prefer an authored visible label associated with input-id; a supplied label overrides that name.</prop>
63
+ <prop name="size" type="keyword" values="sm, md, lg" default="md">Input's shared size scale.</prop>
64
+ <prop name="placeholder" type="string" default="">Optional editing hint. A placeholder never replaces the label.</prop>
65
+ <prop name="disabled" type="boolean" default="false">Prevents editing and omits the value from submission.</prop>
66
+ <prop name="readonly" type="boolean" default="false">Retains selection and submission while preventing edits.</prop>
67
+ <prop name="required" type="boolean" default="false">Requires a complete value.</prop>
68
+ <prop name="invalid" type="boolean" default="false">External invalid state, independent of parsing and availability.</prop>
69
+ <state name="enhanced" type="boolean" value="false"></state>
70
+ <state name="current" type="string" from="$value"></state>
71
+ <state name="editingPlaceholder" type="string" value=""></state>
72
+ <state name="segments" type="list(object({ placeholder?: string, pattern?: string, literal?: string }))" value="[]"></state>
73
+ <state name="localInvalid" type="boolean" value="false"></state>
74
+ <computed
75
+ name="nativeType"
76
+ from="{ date: 'date', time: { true: 'text', false: 'time' }[concat($current.length > 12)], 'datetime-local': { true: 'text', false: 'datetime-local' }[concat($valueFormat = 'space' or $current.length > 23)], instant: 'text', zoned: 'text' }[$type]"
77
+ ></computed>
78
+ <event name="input" type="object"><prop name="value" type="string" required></prop><prop
79
+ name="trigger"
80
+ type="keyword"
81
+ values="keyboard, pointer, programmatic"
82
+ required
83
+ ></prop></event>
84
+ <event name="change" type="object"><prop name="value" type="string" required></prop><prop
85
+ name="trigger"
86
+ type="keyword"
87
+ values="keyboard, pointer, programmatic"
88
+ required
89
+ ></prop></event>
90
+ <event name="query-change" type="object"><prop name="query" type="string" required></prop></event>
91
+ <event name="validation-change" type="object"><prop name="invalid" type="boolean" required></prop><prop
92
+ name="message"
93
+ type="string"
94
+ required
95
+ ></prop></event>
96
+ </defs>
97
+ <span>
98
+ <ui-input
99
+ data-date-fallback
100
+ from:id="{ true: $inputId, false: null }[concat(not $enhanced and $inputId != '')]"
101
+ from:type="$nativeType"
102
+ from:value="$current"
103
+ from:name="$name"
104
+ from:form="{ true: $form, false: null }[concat($form != '')]"
105
+ from:aria-label="$label"
106
+ from:size="$size"
107
+ from:hidden="$enhanced"
108
+ from:disabled="$disabled or $enhanced"
109
+ from:readonly="$readonly"
110
+ from:required="$required"
111
+ from:min="$min"
112
+ from:max="$max"
113
+ step="any"
114
+ ></ui-input>
115
+ <!-- Input owns its styling; this uncontrolled input leaves draft text and selection with the field controller. -->
116
+ <ui-input
117
+ data-date-editor
118
+ from:segments="$segments"
119
+ data-ui-field-control
120
+ from:form="{ true: $form, false: null }[concat($form != '')]"
121
+ from:id="{ true: $inputId, false: null }[concat($enhanced and $inputId != '')]"
122
+ from:aria-label="$label"
123
+ from:size="$size"
124
+ from:placeholder="{ true: $placeholder, false: $editingPlaceholder }[concat($placeholder != '')]"
125
+ from:hidden="not $enhanced"
126
+ from:disabled="$disabled or not $enhanced"
127
+ from:readonly="$readonly"
128
+ from:required="$required"
129
+ from:invalid="$invalid or $localInvalid"
130
+ spellcheck="false"
131
+ autocomplete="off"
132
+ ></ui-input>
133
+ <input
134
+ data-date-value
135
+ data-ui-field-value
136
+ type="hidden"
137
+ from:name="$name"
138
+ from:form="{ true: $form, false: null }[concat($form != '')]"
139
+ from:value="$current"
140
+ from:disabled="$disabled or not $enhanced"
141
+ >
142
+ </span>
143
+ </template>
@@ -0,0 +1,258 @@
1
+ import { dateInputSegments } from "../shared/date-input-segments.js";
2
+ import { canonicalValue, parseInput, formatInput, formatDisplay, isValueAllowed, Temporal } from "../shared/date-time.js";
3
+ import { afterFormReset } from "../shared/form-reset.js";
4
+ import { externalValueTracker } from "../shared/external-value.js";
5
+
6
+ const optionNames = ["type", "valueFormat", "locale", "timeZone", "disambiguation", "hourCycle", "granularity", "displayOptions", "min", "max", "disabledDates", "disabledRanges", "disabledWeekdays", "allowedDates", "allowedRanges", "required"];
7
+
8
+ /** Keep the editable draft separate from the canonical form value, following Input's native-like value ownership. */
9
+ export function connect(host) {
10
+ const editor = host.element.querySelector("[data-date-editor]");
11
+ const fallback = host.element.querySelector("[data-date-fallback]");
12
+ const field = host.element.querySelector("[data-date-value]");
13
+ let options;
14
+ let current = host.state.current ?? "";
15
+ const initialValue = current;
16
+ const initialExternal = host.props.value.value;
17
+ const nativeValue = fallback.value;
18
+ const nativePartial = fallback.validity.badInput;
19
+ let focusValue = current;
20
+ let focused = false;
21
+ let dirty = false;
22
+ let signature;
23
+ const externalChanged = externalValueTracker(host.element);
24
+ let lastValidation;
25
+ let validityMessage = "";
26
+ let trigger = "programmatic";
27
+ const blocked = () => editor.matches(":disabled") || editor.readOnly;
28
+ const write = text => { if (editor.value !== text) editor.value = text; };
29
+ const accept = value => { current = value; host.state.current = value; field.value = value; };
30
+ const show = () => {
31
+ try {
32
+ host.state.segments = dateInputSegments(current, options);
33
+ host.state.editingPlaceholder = host.state.segments.map(part => part.literal ?? part.placeholder).join("");
34
+ write(focused ? formatInput(current, options) : formatDisplay(current, options));
35
+ }
36
+ catch { write(current); }
37
+ };
38
+ // Input's generated prop checks refresh native validity during rendering. Reapply
39
+ // the domain error after that flush as well as immediately for synchronous submit.
40
+ const setValidity = message => {
41
+ validityMessage = message;
42
+ editor.setCustomValidity(message);
43
+ queueMicrotask(() => { if (connected) editor.setCustomValidity(validityMessage); });
44
+ };
45
+ const validate = (value, announce = false) => {
46
+ let message = "";
47
+ try {
48
+ if (!value && editor.required) message = "Enter a complete value.";
49
+ else if (!isValueAllowed(value, options)) message = "Choose an available value within the permitted range.";
50
+ } catch (error) { message = error.message; }
51
+ if (announce || !message) host.state.localInvalid = Boolean(message);
52
+ if (announce && message !== lastValidation) {
53
+ lastValidation = message;
54
+ host.dispatch("validation-change", { invalid: Boolean(message), message });
55
+ }
56
+ setValidity(message);
57
+ return !message;
58
+ };
59
+ const parse = (announce = false) => {
60
+ try {
61
+ let settings = options;
62
+ if (options.type === "zoned" && current) {
63
+ // Invalid external text must still be replaceable by a complete ISO paste.
64
+ let boundTimeZone;
65
+ try { boundTimeZone = Temporal.ZonedDateTime.from(current).timeZoneId; } catch { /* No saved zone to preserve. */ }
66
+ settings = { ...options, boundTimeZone, timeZone: options.timeZone || boundTimeZone };
67
+ }
68
+ const value = parseInput(editor.value, settings);
69
+ return validate(value, announce) ? value : null;
70
+ } catch (error) {
71
+ if (announce) {
72
+ host.state.localInvalid = true;
73
+ if (lastValidation !== error.message) host.dispatch("validation-change", { invalid: true, message: error.message });
74
+ lastValidation = error.message;
75
+ }
76
+ setValidity(error.message);
77
+ return null;
78
+ }
79
+ };
80
+ const input = event => {
81
+ event.stopPropagation();
82
+ if (blocked()) return;
83
+ dirty = true;
84
+ host.dispatch("query-change", { query: editor.value });
85
+ const value = parse();
86
+ if (value === null) return;
87
+ accept(value);
88
+ host.dispatch("input", { value, trigger: event.isTrusted ? "keyboard" : trigger });
89
+ };
90
+ const commit = () => {
91
+ if (blocked()) return;
92
+ const value = parse(true);
93
+ if (value === null) return;
94
+ accept(value);
95
+ if (value !== focusValue) host.dispatch("change", { value, trigger });
96
+ focusValue = value;
97
+ dirty = false;
98
+ // Let child bindings flush before displaying the localized committed value.
99
+ queueMicrotask(() => { if (connected && !focused) show(); });
100
+ };
101
+ const focus = () => {
102
+ const displayed = editor.value;
103
+ const selectedAll = editor.selectionStart === 0 && editor.selectionEnd === editor.value.length;
104
+ focused = true; focusValue = current;
105
+ if (!dirty) {
106
+ show();
107
+ // Changing representation invalidates the old caret/selection. Select the
108
+ // numeric value so typing or paste replaces it instead of appending to it.
109
+ if (host.state.segments.length && !selectedAll) editor.dispatchEvent(new Event("select-first-segment"));
110
+ else if (selectedAll || editor.value !== displayed) editor.select();
111
+ }
112
+ };
113
+ const blur = () => { focused = false; commit(); };
114
+ const paste = event => {
115
+ if (blocked()) return;
116
+ const text = event.clipboardData?.getData("text");
117
+ if (!text) return;
118
+ try {
119
+ parseInput(text, { ...options, timeZone: options.timeZone || (options.type === "zoned" && current ? Temporal.ZonedDateTime.from(current).timeZoneId : undefined) });
120
+ } catch { return; }
121
+ event.preventDefault(); write(text);
122
+ editor.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertFromPaste", data: text }));
123
+ };
124
+ const change = event => { event.stopPropagation(); };
125
+ const key = event => {
126
+ trigger = "keyboard";
127
+ if (event.key === "Enter" && !event.isComposing) { event.preventDefault(); commit(); }
128
+ else if (event.key === "Escape") { event.preventDefault(); dirty = false; show(); validate(current, true); }
129
+ };
130
+ const pointer = () => { trigger = "pointer"; };
131
+ const explicitValidation = () => { if (dirty) parse(true); else validate(current, true); };
132
+ const setValue = event => {
133
+ if (event.target !== host.element) return;
134
+ if (!event.detail || blocked()) { event.preventDefault(); return; }
135
+ event.stopPropagation();
136
+ try {
137
+ const value = canonicalValue(event.detail.value, options);
138
+ if (!value && editor.required) throw new RangeError("Enter a complete value.");
139
+ if (!isValueAllowed(value, options)) throw new RangeError("Choose an available value within the permitted range.");
140
+ validate(value, true);
141
+ const previous = current;
142
+ stopNative(); accept(value); dirty = false; focusValue = current; show(); reveal(true);
143
+ if (value !== previous) {
144
+ const detail = { value, trigger: ["keyboard", "pointer"].includes(event.detail.trigger) ? event.detail.trigger : "programmatic" };
145
+ host.dispatch("input", detail); host.dispatch("change", detail);
146
+ }
147
+ } catch { event.preventDefault(); }
148
+ };
149
+ let connected = true;
150
+ let focusFrame;
151
+ let nativeFrame;
152
+ let nativeCommit = false;
153
+ const stopNative = () => {
154
+ cancelAnimationFrame(nativeFrame); nativeFrame = undefined;
155
+ fallback.removeEventListener("input", nativeInput); fallback.removeEventListener("change", nativeChange);
156
+ };
157
+ const reveal = (force = false) => {
158
+ if (host.state.enhanced || fallback.validity.badInput && !force) return;
159
+ const focusedFallback = fallback.ownerDocument.activeElement === fallback;
160
+ if (fallback.id && !host.props.inputId.value) { editor.id = fallback.id; fallback.removeAttribute("id"); }
161
+ for (const name of ["aria-describedby", "aria-labelledby"]) if (fallback.hasAttribute(name)) editor.setAttribute(name, fallback.getAttribute(name));
162
+ host.state.enhanced = true;
163
+ if (focusedFallback) focusFrame = requestAnimationFrame(() => {
164
+ const active = editor.ownerDocument.activeElement;
165
+ if (connected && (active === fallback || active === editor.ownerDocument.body)) { editor.focus(); editor.select(); }
166
+ });
167
+ };
168
+ const nativeInput = event => {
169
+ event.stopPropagation();
170
+ if (host.state.enhanced || fallback.validity.badInput || nativeFrame !== undefined) return;
171
+ const query = fallback.value;
172
+ const previous = current;
173
+ write(query);
174
+ const value = parse();
175
+ if (value !== null) { accept(value); focusValue = value; show(); }
176
+ else dirty = true;
177
+ reveal();
178
+ nativeFrame = requestAnimationFrame(() => {
179
+ nativeFrame = undefined;
180
+ if (!connected) return;
181
+ host.dispatch("query-change", { query });
182
+ if (value !== null) {
183
+ const detail = { value, trigger: event.isTrusted ? "keyboard" : "programmatic" };
184
+ host.dispatch("input", detail);
185
+ if (nativeCommit && value !== previous && current === value) host.dispatch("change", detail);
186
+ }
187
+ stopNative();
188
+ });
189
+ };
190
+ const nativeChange = event => {
191
+ event.stopPropagation();
192
+ if (fallback.validity.badInput) return;
193
+ nativeCommit = true;
194
+ if (!host.state.enhanced) nativeInput(event);
195
+ };
196
+ if (nativePartial) { fallback.addEventListener("input", nativeInput); fallback.addEventListener("change", nativeChange); }
197
+ editor.addEventListener("input", input);
198
+ editor.addEventListener("paste", paste);
199
+ editor.addEventListener("change", change);
200
+ editor.addEventListener("focus", focus);
201
+ editor.addEventListener("blur", blur);
202
+ editor.addEventListener("keydown", key);
203
+ editor.addEventListener("pointerdown", pointer);
204
+ editor.addEventListener("invalid", explicitValidation);
205
+ host.element.addEventListener("validate", explicitValidation);
206
+ host.element.addEventListener("set-value", setValue);
207
+ const stop = host.effect(() => {
208
+ const next = Object.fromEntries(optionNames.map(name => [name, host.props[name].value]));
209
+ const value = host.props.value.value;
210
+ const nextSignature = JSON.stringify([next, value]);
211
+ if (signature === nextSignature) return;
212
+ const first = signature === undefined;
213
+ signature = nextSignature;
214
+ options = next;
215
+ if (externalChanged(value)) {
216
+ const raw = value;
217
+ let accepted;
218
+ try { accepted = canonicalValue(raw ?? "", options); }
219
+ catch { accepted = raw ?? ""; }
220
+ const replace = first || accepted !== current;
221
+ accept(accepted);
222
+ // A model echo of an accepted edit updates the reset seed without disturbing typing.
223
+ if (replace) { dirty = false; focusValue = current; show(); }
224
+ if (!first && replace) { stopNative(); reveal(true); }
225
+ } else if (!dirty) show();
226
+ if (first && !nativePartial && value === initialExternal && (value ?? "") === initialValue && nativeValue !== initialValue) {
227
+ let usableSeed = true;
228
+ try { canonicalValue(initialValue, options); } catch { usableSeed = false; }
229
+ if (usableSeed || nativeValue !== "") {
230
+ write(nativeValue);
231
+ const adopted = parse();
232
+ if (adopted !== null) { accept(adopted); focusValue = adopted; show(); }
233
+ else dirty = true;
234
+ }
235
+ }
236
+ // Required and other native constraints reach the child during the same render turn.
237
+ queueMicrotask(() => { if (connected) { if (dirty) parse(); else validate(current); } });
238
+ });
239
+ // Partial native date/time segments are opaque; retain that control until they are usable.
240
+ reveal();
241
+ const reset = afterFormReset(editor, () => {
242
+ stopNative();
243
+ try { accept(canonicalValue(host.props.value.value ?? "", options)); }
244
+ catch { accept(host.props.value.value ?? ""); }
245
+ dirty = false; focusValue = current; show(); validate(current, true);
246
+ reveal(true);
247
+ });
248
+ return () => {
249
+ connected = false; cancelAnimationFrame(focusFrame); stopNative(); stop(); reset(); host.state.enhanced = false;
250
+ editor.setCustomValidity("");
251
+ editor.removeEventListener("paste", paste);
252
+ editor.removeEventListener("input", input); editor.removeEventListener("change", change);
253
+ editor.removeEventListener("focus", focus); editor.removeEventListener("blur", blur);
254
+ editor.removeEventListener("keydown", key); editor.removeEventListener("pointerdown", pointer);
255
+ editor.removeEventListener("invalid", explicitValidation); host.element.removeEventListener("validate", explicitValidation);
256
+ host.element.removeEventListener("set-value", setValue);
257
+ };
258
+ }