sheer-ui 0.0.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.
- package/LICENSE +21 -0
- package/README.md +42 -0
- package/package.json +369 -0
- package/src/lib/VENDORED.md +109 -0
- package/src/lib/assets/ui.css +733 -0
- package/src/lib/blocks/Appearance.svelte +104 -0
- package/src/lib/blocks/BoundaryFailed.svelte +33 -0
- package/src/lib/blocks/ErrorPage.svelte +65 -0
- package/src/lib/blocks/Footer.svelte +71 -0
- package/src/lib/blocks/Header.svelte +67 -0
- package/src/lib/blocks/Heading.svelte +86 -0
- package/src/lib/blocks/MobileNav.svelte +169 -0
- package/src/lib/blocks/PhoneInput.svelte +68 -0
- package/src/lib/blocks/Section.svelte +34 -0
- package/src/lib/blocks/alert-modal/AlertModal.svelte +83 -0
- package/src/lib/blocks/alert-modal/alert-modal.svelte.ts +81 -0
- package/src/lib/blocks/alert-modal/index.ts +2 -0
- package/src/lib/blocks/calendar.svelte +155 -0
- package/src/lib/blocks/copy-button/copy-button.svelte +43 -0
- package/src/lib/blocks/copy-button/copy.svelte.ts +52 -0
- package/src/lib/blocks/copy-button/index.ts +2 -0
- package/src/lib/blocks/date-picker/date-picker-with-presets.svelte +109 -0
- package/src/lib/blocks/date-picker/date-picker.svelte +91 -0
- package/src/lib/blocks/date-picker/index.ts +13 -0
- package/src/lib/blocks/date-picker/range-date-picker.svelte +128 -0
- package/src/lib/blocks/index.ts +12 -0
- package/src/lib/blocks/mockups/Browser.svelte +22 -0
- package/src/lib/blocks/mockups/Phone.svelte +44 -0
- package/src/lib/blocks/mockups/index.ts +2 -0
- package/src/lib/blocks/tab-nav/index.ts +1 -0
- package/src/lib/blocks/tab-nav/tab-nav.svelte +46 -0
- package/src/lib/blocks/time-picker/index.ts +16 -0
- package/src/lib/blocks/time-picker/time-input.svelte +118 -0
- package/src/lib/blocks/time-picker/time-picker.svelte +93 -0
- package/src/lib/blocks/time-picker/time-range-input.svelte +34 -0
- package/src/lib/blocks/time-picker/time-range-picker.svelte +180 -0
- package/src/lib/blocks/time-picker/time-slots.ts +61 -0
- package/src/lib/blocks/user-avatar/UserAvatar.svelte +36 -0
- package/src/lib/blocks/user-avatar/index.ts +1 -0
- package/src/lib/blocks/verification-code-field/VerificationCodeField.svelte +57 -0
- package/src/lib/blocks/verification-code-field/index.ts +1 -0
- package/src/lib/components/accordion/accordion.svelte.ts +43 -0
- package/src/lib/components/accordion/components/accordion-content.svelte +17 -0
- package/src/lib/components/accordion/components/accordion-item.svelte +58 -0
- package/src/lib/components/accordion/components/accordion-trigger.svelte +38 -0
- package/src/lib/components/accordion/components/accordion.svelte +24 -0
- package/src/lib/components/accordion/index.ts +11 -0
- package/src/lib/components/accordion/types.ts +19 -0
- package/src/lib/components/alert/alert-action.svelte +11 -0
- package/src/lib/components/alert/alert-description.svelte +18 -0
- package/src/lib/components/alert/alert-title.svelte +18 -0
- package/src/lib/components/alert/alert.svelte +37 -0
- package/src/lib/components/alert/index.ts +17 -0
- package/src/lib/components/avatar/avatar.svelte.ts +154 -0
- package/src/lib/components/avatar/components/avatar-fallback.svelte +38 -0
- package/src/lib/components/avatar/components/avatar-image.svelte +47 -0
- package/src/lib/components/avatar/components/avatar.svelte +57 -0
- package/src/lib/components/avatar/index.ts +9 -0
- package/src/lib/components/avatar/types.ts +46 -0
- package/src/lib/components/badge/badge.svelte +49 -0
- package/src/lib/components/badge/index.ts +1 -0
- package/src/lib/components/breadcrumb/breadcrumb-ellipsis.svelte +23 -0
- package/src/lib/components/breadcrumb/breadcrumb-item.svelte +11 -0
- package/src/lib/components/breadcrumb/breadcrumb-link.svelte +32 -0
- package/src/lib/components/breadcrumb/breadcrumb-list.svelte +15 -0
- package/src/lib/components/breadcrumb/breadcrumb-page.svelte +18 -0
- package/src/lib/components/breadcrumb/breadcrumb-separator.svelte +22 -0
- package/src/lib/components/breadcrumb/breadcrumb.svelte +10 -0
- package/src/lib/components/breadcrumb/index.ts +25 -0
- package/src/lib/components/button/button.svelte +55 -0
- package/src/lib/components/button/index.ts +12 -0
- package/src/lib/components/button/variants.ts +51 -0
- package/src/lib/components/calendar/calendar.svelte.ts +1081 -0
- package/src/lib/components/calendar/components/calendar-cell.svelte +34 -0
- package/src/lib/components/calendar/components/calendar-day.svelte +36 -0
- package/src/lib/components/calendar/components/calendar-grid-body.svelte +29 -0
- package/src/lib/components/calendar/components/calendar-grid-head.svelte +29 -0
- package/src/lib/components/calendar/components/calendar-grid-row.svelte +29 -0
- package/src/lib/components/calendar/components/calendar-grid.svelte +29 -0
- package/src/lib/components/calendar/components/calendar-head-cell.svelte +29 -0
- package/src/lib/components/calendar/components/calendar-header.svelte +29 -0
- package/src/lib/components/calendar/components/calendar-heading.svelte +33 -0
- package/src/lib/components/calendar/components/calendar-month-select.svelte +50 -0
- package/src/lib/components/calendar/components/calendar-next-button.svelte +37 -0
- package/src/lib/components/calendar/components/calendar-prev-button.svelte +37 -0
- package/src/lib/components/calendar/components/calendar-year-select.svelte +50 -0
- package/src/lib/components/calendar/components/calendar.svelte +123 -0
- package/src/lib/components/calendar/exports.ts +31 -0
- package/src/lib/components/calendar/index.ts +2 -0
- package/src/lib/components/calendar/types.ts +417 -0
- package/src/lib/components/card/card-action.svelte +15 -0
- package/src/lib/components/card/card-content.svelte +11 -0
- package/src/lib/components/card/card-description.svelte +11 -0
- package/src/lib/components/card/card-footer.svelte +11 -0
- package/src/lib/components/card/card-header.svelte +18 -0
- package/src/lib/components/card/card-title.svelte +11 -0
- package/src/lib/components/card/card.svelte +15 -0
- package/src/lib/components/card/index.ts +25 -0
- package/src/lib/components/carousel/carousel-arrow.svelte +42 -0
- package/src/lib/components/carousel/carousel-content.svelte +25 -0
- package/src/lib/components/carousel/carousel-dots.svelte +21 -0
- package/src/lib/components/carousel/carousel-item.svelte +21 -0
- package/src/lib/components/carousel/carousel-next.svelte +9 -0
- package/src/lib/components/carousel/carousel-previous.svelte +9 -0
- package/src/lib/components/carousel/carousel.svelte +245 -0
- package/src/lib/components/carousel/carouselState.svelte.ts +30 -0
- package/src/lib/components/carousel/index.ts +24 -0
- package/src/lib/components/chart/chart-container.svelte +52 -0
- package/src/lib/components/chart/chart-style.svelte +29 -0
- package/src/lib/components/chart/chart-tooltip.svelte +163 -0
- package/src/lib/components/chart/chart-utils.ts +50 -0
- package/src/lib/components/chart/index.ts +6 -0
- package/src/lib/components/checkbox/checkbox.svelte.ts +199 -0
- package/src/lib/components/checkbox/components/checkbox-group-label.svelte +29 -0
- package/src/lib/components/checkbox/components/checkbox-group.svelte +48 -0
- package/src/lib/components/checkbox/components/checkbox.svelte +85 -0
- package/src/lib/components/checkbox/index.ts +9 -0
- package/src/lib/components/checkbox/types.ts +131 -0
- package/src/lib/components/checkbox-native/checkbox.svelte +96 -0
- package/src/lib/components/checkbox-native/index.ts +8 -0
- package/src/lib/components/collapsible/components/collapsible-content.svelte +16 -0
- package/src/lib/components/collapsible/components/collapsible-trigger.svelte +14 -0
- package/src/lib/components/collapsible/components/collapsible.svelte +68 -0
- package/src/lib/components/collapsible/index.ts +9 -0
- package/src/lib/components/collapsible/types.ts +25 -0
- package/src/lib/components/combobox/components/combobox-arrow.svelte +8 -0
- package/src/lib/components/combobox/components/combobox-input.svelte +46 -0
- package/src/lib/components/combobox/components/combobox-trigger.svelte +44 -0
- package/src/lib/components/combobox/components/combobox.svelte +83 -0
- package/src/lib/components/combobox/index.ts +30 -0
- package/src/lib/components/combobox/select/components/select-content-static.svelte +56 -0
- package/src/lib/components/combobox/select/components/select-content.svelte +95 -0
- package/src/lib/components/combobox/select/components/select-group-heading.svelte +51 -0
- package/src/lib/components/combobox/select/components/select-group.svelte +51 -0
- package/src/lib/components/combobox/select/components/select-hidden-input.svelte +16 -0
- package/src/lib/components/combobox/select/components/select-item.svelte +86 -0
- package/src/lib/components/combobox/select/components/select-scroll-down-button.svelte +41 -0
- package/src/lib/components/combobox/select/components/select-scroll-up-button.svelte +34 -0
- package/src/lib/components/combobox/select/components/select-trigger.svelte +32 -0
- package/src/lib/components/combobox/select/components/select-value.svelte +40 -0
- package/src/lib/components/combobox/select/components/select-viewport.svelte +29 -0
- package/src/lib/components/combobox/select/components/select.svelte +92 -0
- package/src/lib/components/combobox/select/select.svelte.ts +1596 -0
- package/src/lib/components/combobox/select/types.ts +291 -0
- package/src/lib/components/combobox/types.ts +77 -0
- package/src/lib/components/command/command-dialog.svelte +42 -0
- package/src/lib/components/command/command.svelte.ts +1506 -0
- package/src/lib/components/command/components/_command-label.svelte +31 -0
- package/src/lib/components/command/components/command-empty.svelte +34 -0
- package/src/lib/components/command/components/command-group-heading.svelte +29 -0
- package/src/lib/components/command/components/command-group-items.svelte +31 -0
- package/src/lib/components/command/components/command-group.svelte +76 -0
- package/src/lib/components/command/components/command-input.svelte +55 -0
- package/src/lib/components/command/components/command-item.svelte +61 -0
- package/src/lib/components/command/components/command-link-item.svelte +61 -0
- package/src/lib/components/command/components/command-list.svelte +41 -0
- package/src/lib/components/command/components/command-loading.svelte +30 -0
- package/src/lib/components/command/components/command-separator.svelte +34 -0
- package/src/lib/components/command/components/command-viewport.svelte +29 -0
- package/src/lib/components/command/components/command.svelte +143 -0
- package/src/lib/components/command/compute-command-score.ts +207 -0
- package/src/lib/components/command/index.ts +29 -0
- package/src/lib/components/command/types.ts +222 -0
- package/src/lib/components/command/utils.ts +30 -0
- package/src/lib/components/context-menu/components/context-menu-content-static.svelte +22 -0
- package/src/lib/components/context-menu/components/context-menu-content.svelte +22 -0
- package/src/lib/components/context-menu/components/context-menu-trigger.svelte +46 -0
- package/src/lib/components/context-menu/components/context-menu.svelte +8 -0
- package/src/lib/components/context-menu/index.ts +39 -0
- package/src/lib/components/context-menu/types.ts +56 -0
- package/src/lib/components/data-table/column-helpers.ts +97 -0
- package/src/lib/components/data-table/data-table-checkbox.svelte +25 -0
- package/src/lib/components/data-table/data-table-sort-button.svelte +16 -0
- package/src/lib/components/data-table/flex-render.svelte +42 -0
- package/src/lib/components/data-table/index.ts +29 -0
- package/src/lib/components/data-table/render-helpers.ts +105 -0
- package/src/lib/components/data-table/table-cell.svelte +9 -0
- package/src/lib/components/data-table/table-column-header.svelte +51 -0
- package/src/lib/components/data-table/table-faceted-filter.svelte +109 -0
- package/src/lib/components/data-table/table-pagination.svelte +54 -0
- package/src/lib/components/data-table/table-priority-cell.svelte +22 -0
- package/src/lib/components/data-table/table-row-actions.svelte +29 -0
- package/src/lib/components/data-table/table-status-cell.svelte +34 -0
- package/src/lib/components/data-table/table-title-cell.svelte +24 -0
- package/src/lib/components/data-table/table-toolbar.svelte +55 -0
- package/src/lib/components/data-table/table-view-options.svelte +25 -0
- package/src/lib/components/date-field/components/date-field-hidden-input.svelte +9 -0
- package/src/lib/components/date-field/components/date-field-input.svelte +33 -0
- package/src/lib/components/date-field/components/date-field-label.svelte +29 -0
- package/src/lib/components/date-field/components/date-field-segment.svelte +29 -0
- package/src/lib/components/date-field/components/date-field.svelte +106 -0
- package/src/lib/components/date-field/date-field.svelte.ts +1474 -0
- package/src/lib/components/date-field/index.ts +11 -0
- package/src/lib/components/date-field/types.ts +165 -0
- package/src/lib/components/date-range-field/components/date-range-field-input.svelte +36 -0
- package/src/lib/components/date-range-field/components/date-range-field-label.svelte +29 -0
- package/src/lib/components/date-range-field/components/date-range-field.svelte +106 -0
- package/src/lib/components/date-range-field/date-range-field.svelte.ts +212 -0
- package/src/lib/components/date-range-field/index.ts +11 -0
- package/src/lib/components/date-range-field/types.ts +171 -0
- package/src/lib/components/dialog/components/dialog-close.svelte +31 -0
- package/src/lib/components/dialog/components/dialog-content-headless.svelte +104 -0
- package/src/lib/components/dialog/components/dialog-content.svelte +69 -0
- package/src/lib/components/dialog/components/dialog-description.svelte +29 -0
- package/src/lib/components/dialog/components/dialog-overlay.svelte +31 -0
- package/src/lib/components/dialog/components/dialog-title.svelte +30 -0
- package/src/lib/components/dialog/components/dialog-trigger.svelte +30 -0
- package/src/lib/components/dialog/components/dialog.svelte +21 -0
- package/src/lib/components/dialog/components/modal-surface.svelte +131 -0
- package/src/lib/components/dialog/dialog.svelte.ts +371 -0
- package/src/lib/components/dialog/index.ts +19 -0
- package/src/lib/components/dialog/types.ts +105 -0
- package/src/lib/components/drawer/drawer-close.svelte +7 -0
- package/src/lib/components/drawer/drawer-content.svelte +91 -0
- package/src/lib/components/drawer/drawer-description.svelte +8 -0
- package/src/lib/components/drawer/drawer-footer.svelte +11 -0
- package/src/lib/components/drawer/drawer-header.svelte +11 -0
- package/src/lib/components/drawer/drawer-nested.svelte +44 -0
- package/src/lib/components/drawer/drawer-overlay.svelte +60 -0
- package/src/lib/components/drawer/drawer-portal.svelte +10 -0
- package/src/lib/components/drawer/drawer-title.svelte +8 -0
- package/src/lib/components/drawer/drawer-trigger.svelte +7 -0
- package/src/lib/components/drawer/drawer.svelte +290 -0
- package/src/lib/components/drawer/index.ts +37 -0
- package/src/lib/components/dropdown-menu/components/dropdown-menu-content-static.svelte +22 -0
- package/src/lib/components/dropdown-menu/components/dropdown-menu-content.svelte +22 -0
- package/src/lib/components/dropdown-menu/index.ts +39 -0
- package/src/lib/components/dropdown-menu/types.ts +41 -0
- package/src/lib/components/empty/empty-content.svelte +15 -0
- package/src/lib/components/empty/empty-description.svelte +15 -0
- package/src/lib/components/empty/empty-header.svelte +15 -0
- package/src/lib/components/empty/empty-media.svelte +21 -0
- package/src/lib/components/empty/empty-title.svelte +11 -0
- package/src/lib/components/empty/empty.svelte +18 -0
- package/src/lib/components/empty/index.ts +22 -0
- package/src/lib/components/empty/variants.ts +16 -0
- package/src/lib/components/field/field-content.svelte +14 -0
- package/src/lib/components/field/field-description.svelte +19 -0
- package/src/lib/components/field/field-error.svelte +47 -0
- package/src/lib/components/field/field-group.svelte +17 -0
- package/src/lib/components/field/field-label.svelte +18 -0
- package/src/lib/components/field/field-legend.svelte +23 -0
- package/src/lib/components/field/field-separator.svelte +32 -0
- package/src/lib/components/field/field-set.svelte +14 -0
- package/src/lib/components/field/field-title.svelte +14 -0
- package/src/lib/components/field/field.svelte +36 -0
- package/src/lib/components/field/index.ts +32 -0
- package/src/lib/components/field/variants.ts +19 -0
- package/src/lib/components/input/file-input.svelte +26 -0
- package/src/lib/components/input/index.ts +12 -0
- package/src/lib/components/input/input.svelte +24 -0
- package/src/lib/components/input/variants.ts +28 -0
- package/src/lib/components/item/index.ts +34 -0
- package/src/lib/components/item/item-actions.svelte +11 -0
- package/src/lib/components/item/item-content.svelte +15 -0
- package/src/lib/components/item/item-description.svelte +18 -0
- package/src/lib/components/item/item-footer.svelte +11 -0
- package/src/lib/components/item/item-group.svelte +16 -0
- package/src/lib/components/item/item-header.svelte +11 -0
- package/src/lib/components/item/item-media.svelte +37 -0
- package/src/lib/components/item/item-separator.svelte +9 -0
- package/src/lib/components/item/item-title.svelte +15 -0
- package/src/lib/components/item/item.svelte +61 -0
- package/src/lib/components/kbd/index.ts +10 -0
- package/src/lib/components/kbd/kbd-group.svelte +11 -0
- package/src/lib/components/kbd/kbd.svelte +18 -0
- package/src/lib/components/label/exports.ts +2 -0
- package/src/lib/components/label/index.ts +2 -0
- package/src/lib/components/label/label.svelte +39 -0
- package/src/lib/components/label/label.svelte.ts +39 -0
- package/src/lib/components/label/types.ts +7 -0
- package/src/lib/components/link-preview/components/link-preview-content.svelte +60 -0
- package/src/lib/components/link-preview/components/link-preview-trigger.svelte +29 -0
- package/src/lib/components/link-preview/components/link-preview.svelte +34 -0
- package/src/lib/components/link-preview/exports.ts +11 -0
- package/src/lib/components/link-preview/index.ts +2 -0
- package/src/lib/components/link-preview/link-preview.svelte.ts +270 -0
- package/src/lib/components/link-preview/types.ts +102 -0
- package/src/lib/components/menu/components/menu-arrow.svelte +14 -0
- package/src/lib/components/menu/components/menu-checkbox-group.svelte +42 -0
- package/src/lib/components/menu/components/menu-checkbox-item.svelte +85 -0
- package/src/lib/components/menu/components/menu-content.svelte +98 -0
- package/src/lib/components/menu/components/menu-group-heading.svelte +47 -0
- package/src/lib/components/menu/components/menu-group.svelte +36 -0
- package/src/lib/components/menu/components/menu-item.svelte +58 -0
- package/src/lib/components/menu/components/menu-radio-group.svelte +44 -0
- package/src/lib/components/menu/components/menu-radio-item.svelte +65 -0
- package/src/lib/components/menu/components/menu-separator.svelte +38 -0
- package/src/lib/components/menu/components/menu-sub-content-static.svelte +8 -0
- package/src/lib/components/menu/components/menu-sub-content.svelte +133 -0
- package/src/lib/components/menu/components/menu-sub-trigger.svelte +60 -0
- package/src/lib/components/menu/components/menu-sub.svelte +23 -0
- package/src/lib/components/menu/components/menu-trigger.svelte +50 -0
- package/src/lib/components/menu/components/menu.svelte +58 -0
- package/src/lib/components/menu/exports.ts +38 -0
- package/src/lib/components/menu/menu.svelte.ts +1599 -0
- package/src/lib/components/menu/types.ts +285 -0
- package/src/lib/components/menu/utils.ts +68 -0
- package/src/lib/components/menubar/components/menubar-content-static.svelte +50 -0
- package/src/lib/components/menubar/components/menubar-content.svelte +54 -0
- package/src/lib/components/menubar/components/menubar-menu.svelte +34 -0
- package/src/lib/components/menubar/components/menubar-trigger.svelte +50 -0
- package/src/lib/components/menubar/components/menubar.svelte +57 -0
- package/src/lib/components/menubar/exports.ts +44 -0
- package/src/lib/components/menubar/index.ts +2 -0
- package/src/lib/components/menubar/menubar.svelte.ts +394 -0
- package/src/lib/components/menubar/types.ts +97 -0
- package/src/lib/components/meter/components/meter.svelte +41 -0
- package/src/lib/components/meter/exports.ts +2 -0
- package/src/lib/components/meter/index.ts +2 -0
- package/src/lib/components/meter/meter.svelte.ts +47 -0
- package/src/lib/components/meter/types.ts +28 -0
- package/src/lib/components/navigation-menu/components/navigation-menu-content-impl.svelte +85 -0
- package/src/lib/components/navigation-menu/components/navigation-menu-content.svelte +58 -0
- package/src/lib/components/navigation-menu/components/navigation-menu-indicator-impl.svelte +29 -0
- package/src/lib/components/navigation-menu/components/navigation-menu-indicator.svelte +56 -0
- package/src/lib/components/navigation-menu/components/navigation-menu-item.svelte +56 -0
- package/src/lib/components/navigation-menu/components/navigation-menu-link.svelte +64 -0
- package/src/lib/components/navigation-menu/components/navigation-menu-list.svelte +59 -0
- package/src/lib/components/navigation-menu/components/navigation-menu-sub.svelte +46 -0
- package/src/lib/components/navigation-menu/components/navigation-menu-trigger.svelte +80 -0
- package/src/lib/components/navigation-menu/components/navigation-menu-viewport.svelte +63 -0
- package/src/lib/components/navigation-menu/components/navigation-menu.svelte +80 -0
- package/src/lib/components/navigation-menu/index.ts +28 -0
- package/src/lib/components/navigation-menu/navigation-menu.svelte.ts +1092 -0
- package/src/lib/components/navigation-menu/types.ts +189 -0
- package/src/lib/components/pagination/components/pagination-next-button.svelte +60 -0
- package/src/lib/components/pagination/components/pagination-page.svelte +65 -0
- package/src/lib/components/pagination/components/pagination-prev-button.svelte +60 -0
- package/src/lib/components/pagination/components/pagination.svelte +65 -0
- package/src/lib/components/pagination/index.ts +11 -0
- package/src/lib/components/pagination/pagination.svelte.ts +275 -0
- package/src/lib/components/pagination/types.ts +100 -0
- package/src/lib/components/pin-input/components/pin-input-cell.svelte +49 -0
- package/src/lib/components/pin-input/components/pin-input.svelte +76 -0
- package/src/lib/components/pin-input/exports.ts +4 -0
- package/src/lib/components/pin-input/index.ts +2 -0
- package/src/lib/components/pin-input/pin-input.svelte.ts +541 -0
- package/src/lib/components/pin-input/types.ts +118 -0
- package/src/lib/components/pin-input/usePasswordManager.svelte.ts +122 -0
- package/src/lib/components/popover/components/popover-close.svelte +38 -0
- package/src/lib/components/popover/components/popover-content.svelte +70 -0
- package/src/lib/components/popover/components/popover-header.svelte +11 -0
- package/src/lib/components/popover/components/popover-title.svelte +11 -0
- package/src/lib/components/popover/components/popover-trigger.svelte +44 -0
- package/src/lib/components/popover/components/popover.svelte +26 -0
- package/src/lib/components/popover/exports.ts +13 -0
- package/src/lib/components/popover/index.ts +2 -0
- package/src/lib/components/popover/popover.svelte.ts +392 -0
- package/src/lib/components/popover/types.ts +92 -0
- package/src/lib/components/progress/components/progress.svelte +56 -0
- package/src/lib/components/progress/exports.ts +3 -0
- package/src/lib/components/progress/index.ts +2 -0
- package/src/lib/components/progress/progress.svelte.ts +58 -0
- package/src/lib/components/progress/types.ts +28 -0
- package/src/lib/components/radio-group/context.ts +13 -0
- package/src/lib/components/radio-group/index.ts +10 -0
- package/src/lib/components/radio-group/radio-group-item.svelte +67 -0
- package/src/lib/components/radio-group/radio-group.svelte +87 -0
- package/src/lib/components/range-calendar/components/range-calendar-cell.svelte +31 -0
- package/src/lib/components/range-calendar/components/range-calendar-day.svelte +33 -0
- package/src/lib/components/range-calendar/components/range-calendar.svelte +120 -0
- package/src/lib/components/range-calendar/exports.ts +31 -0
- package/src/lib/components/range-calendar/index.ts +2 -0
- package/src/lib/components/range-calendar/range-calendar.svelte.ts +739 -0
- package/src/lib/components/range-calendar/types.ts +258 -0
- package/src/lib/components/resizable/index.ts +15 -0
- package/src/lib/components/resizable/resizable-handle.svelte +30 -0
- package/src/lib/components/resizable/resizable-pane-group.svelte +19 -0
- package/src/lib/components/scroll-area/components/scroll-area-corner-impl.svelte +34 -0
- package/src/lib/components/scroll-area/components/scroll-area-corner.svelte +18 -0
- package/src/lib/components/scroll-area/components/scroll-area-scrollbar-auto.svelte +15 -0
- package/src/lib/components/scroll-area/components/scroll-area-scrollbar-hover.svelte +22 -0
- package/src/lib/components/scroll-area/components/scroll-area-scrollbar-scroll.svelte +16 -0
- package/src/lib/components/scroll-area/components/scroll-area-scrollbar-shared.svelte +19 -0
- package/src/lib/components/scroll-area/components/scroll-area-scrollbar-visible.svelte +16 -0
- package/src/lib/components/scroll-area/components/scroll-area-scrollbar-x.svelte +23 -0
- package/src/lib/components/scroll-area/components/scroll-area-scrollbar-y.svelte +24 -0
- package/src/lib/components/scroll-area/components/scroll-area-scrollbar.svelte +56 -0
- package/src/lib/components/scroll-area/components/scroll-area-thumb-impl.svelte +49 -0
- package/src/lib/components/scroll-area/components/scroll-area-thumb.svelte +21 -0
- package/src/lib/components/scroll-area/components/scroll-area-viewport.svelte +39 -0
- package/src/lib/components/scroll-area/components/scroll-area.svelte +82 -0
- package/src/lib/components/scroll-area/exports.ts +13 -0
- package/src/lib/components/scroll-area/index.ts +2 -0
- package/src/lib/components/scroll-area/scroll-area.svelte.ts +946 -0
- package/src/lib/components/scroll-area/types.ts +67 -0
- package/src/lib/components/select/index.ts +5 -0
- package/src/lib/components/select/select-opt-group.svelte +10 -0
- package/src/lib/components/select/select-option.svelte +15 -0
- package/src/lib/components/select/select.svelte +281 -0
- package/src/lib/components/separator/components/separator.svelte +49 -0
- package/src/lib/components/separator/index.ts +3 -0
- package/src/lib/components/separator/separator.svelte.ts +43 -0
- package/src/lib/components/separator/types.ts +22 -0
- package/src/lib/components/sheet/components/sheet-close.svelte +8 -0
- package/src/lib/components/sheet/components/sheet-content.svelte +108 -0
- package/src/lib/components/sheet/components/sheet-description.svelte +9 -0
- package/src/lib/components/sheet/components/sheet-footer.svelte +11 -0
- package/src/lib/components/sheet/components/sheet-header.svelte +11 -0
- package/src/lib/components/sheet/components/sheet-overlay.svelte +13 -0
- package/src/lib/components/sheet/components/sheet-title.svelte +9 -0
- package/src/lib/components/sheet/components/sheet-trigger.svelte +8 -0
- package/src/lib/components/sheet/index.ts +47 -0
- package/src/lib/components/sheet/variants.ts +20 -0
- package/src/lib/components/sidebar/constants.ts +6 -0
- package/src/lib/components/sidebar/context.svelte.ts +54 -0
- package/src/lib/components/sidebar/index.ts +77 -0
- package/src/lib/components/sidebar/sidebar-content.svelte +16 -0
- package/src/lib/components/sidebar/sidebar-desktop-surface.svelte +60 -0
- package/src/lib/components/sidebar/sidebar-footer.svelte +11 -0
- package/src/lib/components/sidebar/sidebar-group-action.svelte +34 -0
- package/src/lib/components/sidebar/sidebar-group-content.svelte +16 -0
- package/src/lib/components/sidebar/sidebar-group-label.svelte +34 -0
- package/src/lib/components/sidebar/sidebar-group.svelte +16 -0
- package/src/lib/components/sidebar/sidebar-header.svelte +11 -0
- package/src/lib/components/sidebar/sidebar-input.svelte +14 -0
- package/src/lib/components/sidebar/sidebar-inset.svelte +18 -0
- package/src/lib/components/sidebar/sidebar-menu-action.svelte +38 -0
- package/src/lib/components/sidebar/sidebar-menu-badge.svelte +19 -0
- package/src/lib/components/sidebar/sidebar-menu-button.svelte +99 -0
- package/src/lib/components/sidebar/sidebar-menu-item.svelte +21 -0
- package/src/lib/components/sidebar/sidebar-menu-skeleton.svelte +34 -0
- package/src/lib/components/sidebar/sidebar-menu-sub-button.svelte +40 -0
- package/src/lib/components/sidebar/sidebar-menu-sub-item.svelte +16 -0
- package/src/lib/components/sidebar/sidebar-menu-sub.svelte +19 -0
- package/src/lib/components/sidebar/sidebar-menu.svelte +21 -0
- package/src/lib/components/sidebar/sidebar-mobile-surface.svelte +48 -0
- package/src/lib/components/sidebar/sidebar-provider.svelte +60 -0
- package/src/lib/components/sidebar/sidebar-rail.svelte +36 -0
- package/src/lib/components/sidebar/sidebar-separator.svelte +9 -0
- package/src/lib/components/sidebar/sidebar-trigger.svelte +35 -0
- package/src/lib/components/sidebar/sidebar.svelte +30 -0
- package/src/lib/components/sidebar/types.ts +14 -0
- package/src/lib/components/skeleton/index.ts +7 -0
- package/src/lib/components/skeleton/skeleton.svelte +9 -0
- package/src/lib/components/slider/components/slider-range.svelte +37 -0
- package/src/lib/components/slider/components/slider-thumb-label.svelte +42 -0
- package/src/lib/components/slider/components/slider-thumb.svelte +46 -0
- package/src/lib/components/slider/components/slider-tick-label.svelte +42 -0
- package/src/lib/components/slider/components/slider-tick.svelte +28 -0
- package/src/lib/components/slider/components/slider.svelte +136 -0
- package/src/lib/components/slider/helpers.ts +249 -0
- package/src/lib/components/slider/index.ts +15 -0
- package/src/lib/components/slider/slider.svelte.ts +979 -0
- package/src/lib/components/slider/types.ts +294 -0
- package/src/lib/components/sonner/Toast.svelte +558 -0
- package/src/lib/components/sonner/Toaster.svelte +603 -0
- package/src/lib/components/sonner/index.ts +15 -0
- package/src/lib/components/sonner/toast-state.svelte.ts +217 -0
- package/src/lib/components/sonner/types.ts +384 -0
- package/src/lib/components/switch/index.ts +8 -0
- package/src/lib/components/switch/switch.svelte +78 -0
- package/src/lib/components/table/index.ts +28 -0
- package/src/lib/components/table/table-body.svelte +15 -0
- package/src/lib/components/table/table-caption.svelte +10 -0
- package/src/lib/components/table/table-cell.svelte +14 -0
- package/src/lib/components/table/table-footer.svelte +19 -0
- package/src/lib/components/table/table-head.svelte +17 -0
- package/src/lib/components/table/table-header.svelte +15 -0
- package/src/lib/components/table/table-row.svelte +14 -0
- package/src/lib/components/table/table.svelte +12 -0
- package/src/lib/components/tabs/components/tabs-content.svelte +30 -0
- package/src/lib/components/tabs/components/tabs-list.svelte +38 -0
- package/src/lib/components/tabs/components/tabs-trigger.svelte +51 -0
- package/src/lib/components/tabs/components/tabs.svelte +52 -0
- package/src/lib/components/tabs/index.ts +11 -0
- package/src/lib/components/tabs/tabs.svelte.ts +253 -0
- package/src/lib/components/tabs/types.ts +86 -0
- package/src/lib/components/textarea/index.ts +7 -0
- package/src/lib/components/textarea/textarea.svelte +23 -0
- package/src/lib/components/theme-toggle/index.ts +5 -0
- package/src/lib/components/theme-toggle/theme-toggle.svelte +49 -0
- package/src/lib/components/theme-toggle/theme.svelte.ts +81 -0
- package/src/lib/components/time-field/components/time-field-hidden-input.svelte +9 -0
- package/src/lib/components/time-field/components/time-field-input.svelte +33 -0
- package/src/lib/components/time-field/components/time-field-label.svelte +29 -0
- package/src/lib/components/time-field/components/time-field-segment.svelte +29 -0
- package/src/lib/components/time-field/components/time-field.svelte +99 -0
- package/src/lib/components/time-field/index.ts +11 -0
- package/src/lib/components/time-field/time-field.svelte.ts +1198 -0
- package/src/lib/components/time-field/types.ts +174 -0
- package/src/lib/components/time-range-field/components/time-range-field-input.svelte +36 -0
- package/src/lib/components/time-range-field/components/time-range-field-label.svelte +29 -0
- package/src/lib/components/time-range-field/components/time-range-field.svelte +104 -0
- package/src/lib/components/time-range-field/index.ts +11 -0
- package/src/lib/components/time-range-field/time-range-field.svelte.ts +235 -0
- package/src/lib/components/time-range-field/types.ts +181 -0
- package/src/lib/components/toggle/components/toggle.svelte +55 -0
- package/src/lib/components/toggle/index.ts +3 -0
- package/src/lib/components/toggle/toggle.svelte.ts +57 -0
- package/src/lib/components/toggle/types.ts +33 -0
- package/src/lib/components/toggle/variants.ts +25 -0
- package/src/lib/components/toggle-group/components/toggle-group-item.svelte +67 -0
- package/src/lib/components/toggle-group/components/toggle-group.svelte +109 -0
- package/src/lib/components/toggle-group/index.ts +7 -0
- package/src/lib/components/toggle-group/toggle-group.svelte.ts +235 -0
- package/src/lib/components/toggle-group/types.ts +89 -0
- package/src/lib/components/toolbar/components/toolbar-button.svelte +46 -0
- package/src/lib/components/toolbar/components/toolbar-group-item.svelte +56 -0
- package/src/lib/components/toolbar/components/toolbar-group.svelte +69 -0
- package/src/lib/components/toolbar/components/toolbar-link.svelte +39 -0
- package/src/lib/components/toolbar/components/toolbar.svelte +39 -0
- package/src/lib/components/toolbar/index.ts +13 -0
- package/src/lib/components/toolbar/toolbar.svelte.ts +373 -0
- package/src/lib/components/toolbar/types.ts +60 -0
- package/src/lib/components/tooltip/components/tooltip-content.svelte +81 -0
- package/src/lib/components/tooltip/components/tooltip-provider.svelte +26 -0
- package/src/lib/components/tooltip/components/tooltip-trigger.svelte +48 -0
- package/src/lib/components/tooltip/components/tooltip.svelte +55 -0
- package/src/lib/components/tooltip/index.ts +17 -0
- package/src/lib/components/tooltip/tooltip.svelte.ts +796 -0
- package/src/lib/components/tooltip/types.ts +175 -0
- package/src/lib/components/tooltip/utils.ts +1 -0
- package/src/lib/icons/google-icon.svelte +10 -0
- package/src/lib/icons/google-workspace.svelte +18 -0
- package/src/lib/icons/icon.d.ts +19 -0
- package/src/lib/icons/instagram.svelte +9 -0
- package/src/lib/icons/instantly.svelte +10 -0
- package/src/lib/icons/linkedin.svelte +9 -0
- package/src/lib/icons/mailshake.svelte +10 -0
- package/src/lib/icons/microsoft-365.svelte +7 -0
- package/src/lib/icons/passcode.svelte +12 -0
- package/src/lib/icons/replyio.svelte +10 -0
- package/src/lib/icons/smartlead.svelte +19 -0
- package/src/lib/icons/smtp.svelte +10 -0
- package/src/lib/icons/x-logo.svelte +9 -0
- package/src/lib/internal/animations-settled.svelte.ts +119 -0
- package/src/lib/internal/arrays.ts +253 -0
- package/src/lib/internal/attribute-types.ts +53 -0
- package/src/lib/internal/attrs.ts +64 -0
- package/src/lib/internal/body-scroll-lock.svelte.ts +330 -0
- package/src/lib/internal/create-id.ts +12 -0
- package/src/lib/internal/date-time/announcer.ts +74 -0
- package/src/lib/internal/date-time/calendar-helpers.svelte.ts +399 -0
- package/src/lib/internal/date-time/field/helpers.ts +431 -0
- package/src/lib/internal/date-time/field/parts.ts +15 -0
- package/src/lib/internal/date-time/field/range-field.svelte.ts +45 -0
- package/src/lib/internal/date-time/field/segments.ts +89 -0
- package/src/lib/internal/date-time/field/time-helpers.ts +311 -0
- package/src/lib/internal/date-time/formatter.ts +86 -0
- package/src/lib/internal/date-time/placeholders.ts +131 -0
- package/src/lib/internal/date-time/types.ts +121 -0
- package/src/lib/internal/date-time/utils.ts +243 -0
- package/src/lib/internal/dismissible-layer/index.ts +3 -0
- package/src/lib/internal/dismissible-layer/scheduler.ts +48 -0
- package/src/lib/internal/dismissible-layer/types.ts +57 -0
- package/src/lib/internal/dismissible-layer/use-dismissable-layer.svelte.ts +291 -0
- package/src/lib/internal/escape-layer/index.ts +3 -0
- package/src/lib/internal/escape-layer/types.ts +34 -0
- package/src/lib/internal/escape-layer/use-escape-layer.svelte.ts +91 -0
- package/src/lib/internal/floating-layer/components/floating-layer-arrow.svelte +35 -0
- package/src/lib/internal/floating-layer/components/floating-layer-content-static.svelte +19 -0
- package/src/lib/internal/floating-layer/components/floating-layer-content.svelte +52 -0
- package/src/lib/internal/floating-layer/components/floating-layer.svelte +12 -0
- package/src/lib/internal/floating-layer/components/index.ts +6 -0
- package/src/lib/internal/floating-layer/index.ts +2 -0
- package/src/lib/internal/floating-layer/types.ts +126 -0
- package/src/lib/internal/floating-layer/use-floating-layer.svelte.ts +471 -0
- package/src/lib/internal/focus-scope/focus-scope.svelte.ts +310 -0
- package/src/lib/internal/focus-scope/index.ts +4 -0
- package/src/lib/internal/focus-scope/types.ts +45 -0
- package/src/lib/internal/focus.ts +14 -0
- package/src/lib/internal/global-singleton.ts +10 -0
- package/src/lib/internal/group-value.svelte.ts +36 -0
- package/src/lib/internal/hover-intent-geometry.ts +96 -0
- package/src/lib/internal/index.ts +44 -0
- package/src/lib/internal/kbd.ts +60 -0
- package/src/lib/internal/layer-stack.ts +37 -0
- package/src/lib/internal/math.ts +11 -0
- package/src/lib/internal/merge-props.ts +7 -0
- package/src/lib/internal/native-dialog-controller.svelte.ts +102 -0
- package/src/lib/internal/native-popover.svelte.ts +173 -0
- package/src/lib/internal/open-cell.svelte.ts +41 -0
- package/src/lib/internal/paneforge/index.ts +5 -0
- package/src/lib/internal/paneforge/internal/constants.ts +2 -0
- package/src/lib/internal/paneforge/internal/helpers.ts +354 -0
- package/src/lib/internal/paneforge/internal/types.ts +33 -0
- package/src/lib/internal/paneforge/internal/utils/adjust-layout.ts +122 -0
- package/src/lib/internal/paneforge/internal/utils/aria.ts +36 -0
- package/src/lib/internal/paneforge/internal/utils/compare.ts +15 -0
- package/src/lib/internal/paneforge/internal/utils/is.ts +13 -0
- package/src/lib/internal/paneforge/internal/utils/resize.ts +31 -0
- package/src/lib/internal/paneforge/internal/utils/storage.ts +116 -0
- package/src/lib/internal/paneforge/internal/utils/style.ts +104 -0
- package/src/lib/internal/paneforge/pane-group.svelte +48 -0
- package/src/lib/internal/paneforge/pane-resizer.svelte +40 -0
- package/src/lib/internal/paneforge/pane.svelte +60 -0
- package/src/lib/internal/paneforge/paneforge.svelte.ts +821 -0
- package/src/lib/internal/paneforge/types.ts +179 -0
- package/src/lib/internal/popper-layer/index.ts +2 -0
- package/src/lib/internal/popper-layer/popper-content.svelte +19 -0
- package/src/lib/internal/popper-layer/popper-layer-inner.svelte +122 -0
- package/src/lib/internal/popper-layer/popper-layer.svelte +71 -0
- package/src/lib/internal/popper-layer/types.ts +65 -0
- package/src/lib/internal/portal/index.ts +2 -0
- package/src/lib/internal/portal/portal.svelte +61 -0
- package/src/lib/internal/prop-resolvers.ts +14 -0
- package/src/lib/internal/roving-focus-group.ts +147 -0
- package/src/lib/internal/roving-focus-item.svelte.ts +51 -0
- package/src/lib/internal/safe-polygon.svelte.ts +239 -0
- package/src/lib/internal/shared-state.svelte.ts +39 -0
- package/src/lib/internal/state-machine.ts +32 -0
- package/src/lib/internal/svelte-resize-observer.svelte.ts +37 -0
- package/src/lib/internal/tabbable.ts +398 -0
- package/src/lib/internal/table/core.ts +53 -0
- package/src/lib/internal/table/filter-fns.ts +10 -0
- package/src/lib/internal/table/index.ts +2 -0
- package/src/lib/internal/table/sorting-fns.ts +84 -0
- package/src/lib/internal/table/table.svelte.ts +330 -0
- package/src/lib/internal/table/types.ts +33 -0
- package/src/lib/internal/timeout-fn.svelte.ts +36 -0
- package/src/lib/internal/tools/box.svelte.ts +153 -0
- package/src/lib/internal/tools/index.ts +22 -0
- package/src/lib/internal/tools/types.ts +44 -0
- package/src/lib/internal/tools/utils/attach-ref.ts +74 -0
- package/src/lib/internal/tools/utils/compose-handlers.ts +36 -0
- package/src/lib/internal/tools/utils/dom-context.svelte.ts +63 -0
- package/src/lib/internal/tools/utils/dom.ts +62 -0
- package/src/lib/internal/tools/utils/events.ts +1 -0
- package/src/lib/internal/tools/utils/index.ts +5 -0
- package/src/lib/internal/tools/utils/strings.ts +28 -0
- package/src/lib/internal/typeahead.svelte.ts +48 -0
- package/src/lib/internal/types.ts +119 -0
- package/src/lib/internal/utils.ts +10 -0
- package/src/lib/internal/vaul/browser.ts +8 -0
- package/src/lib/internal/vaul/constants.ts +19 -0
- package/src/lib/internal/vaul/helpers.ts +39 -0
- package/src/lib/internal/vaul/types.ts +142 -0
- package/src/lib/internal/vaul/use-drawer-content.svelte.ts +219 -0
- package/src/lib/internal/vaul/use-drawer-root.svelte.ts +682 -0
- package/src/lib/internal/vaul/use-position-fixed.svelte.ts +142 -0
- package/src/lib/internal/vaul/use-prevent-scroll.svelte.ts +267 -0
- package/src/lib/internal/vaul/use-snap-points.svelte.ts +246 -0
- package/src/lib/time.ts +73 -0
|
@@ -0,0 +1,1198 @@
|
|
|
1
|
+
import type { Updater } from 'svelte/store';
|
|
2
|
+
import { CalendarDateTime, Time, ZonedDateTime } from '@internationalized/date';
|
|
3
|
+
import {
|
|
4
|
+
attachRef,
|
|
5
|
+
type WritableBox,
|
|
6
|
+
DOMContext,
|
|
7
|
+
type ReadableBoxedValues,
|
|
8
|
+
type WritableBoxedValues,
|
|
9
|
+
simpleBox,
|
|
10
|
+
} from '../../internal/tools/index.js';
|
|
11
|
+
import { createContext, onMount, untrack } from 'svelte';
|
|
12
|
+
import type { BitsFocusEvent, BitsInputEvent, BitsKeyboardEvent, BitsMouseEvent, RefAttachment, WithRefOpts } from '../../internal/types.js';
|
|
13
|
+
import { createBitsAttrs, boolToStr, boolToStrTrueOrUndef, boolToEmptyStrOrUndef } from '../../internal/attrs.js';
|
|
14
|
+
import { BROWSER } from 'esm-env';
|
|
15
|
+
import { kbd } from '../../internal/kbd.js';
|
|
16
|
+
import type {
|
|
17
|
+
TimeSegmentObj,
|
|
18
|
+
SegmentPart,
|
|
19
|
+
HourCycle,
|
|
20
|
+
TimeSegmentValueObj,
|
|
21
|
+
TimeValidator,
|
|
22
|
+
TimeOnInvalid,
|
|
23
|
+
EditableTimeSegmentPart,
|
|
24
|
+
} from '../../internal/date-time/types.js';
|
|
25
|
+
import { type TimeFormatter, createTimeFormatter } from '../../internal/date-time/formatter.js';
|
|
26
|
+
import { type Announcer, getAnnouncer } from '../../internal/date-time/announcer.js';
|
|
27
|
+
import { EDITABLE_TIME_SEGMENT_PARTS } from '../../internal/date-time/field/parts.js';
|
|
28
|
+
import { toDate } from '../../internal/date-time/utils.js';
|
|
29
|
+
|
|
30
|
+
import type { TimeValue } from '../../internal/date-time/types.js';
|
|
31
|
+
import {
|
|
32
|
+
areAllTimeSegmentsFilled,
|
|
33
|
+
convertTimeValueToTime,
|
|
34
|
+
createTimeContent,
|
|
35
|
+
getISOTimeValue,
|
|
36
|
+
getTimeValueFromSegments,
|
|
37
|
+
initTimeSegmentStates,
|
|
38
|
+
isFirstTimeSegment,
|
|
39
|
+
isTimeBefore,
|
|
40
|
+
removeTimeDescriptionElement,
|
|
41
|
+
setTimeDescription,
|
|
42
|
+
} from '../../internal/date-time/field/time-helpers.js';
|
|
43
|
+
import {
|
|
44
|
+
getFirstTimeSegment,
|
|
45
|
+
handleTimeSegmentNavigation,
|
|
46
|
+
isSegmentNavigationKey,
|
|
47
|
+
moveToNextSegment,
|
|
48
|
+
moveToPrevSegment,
|
|
49
|
+
} from '../../internal/date-time/field/segments.js';
|
|
50
|
+
import {
|
|
51
|
+
getDefaultHourCycle,
|
|
52
|
+
isAcceptableDayPeriodKey,
|
|
53
|
+
isAcceptableSegmentKey,
|
|
54
|
+
isArrowDown,
|
|
55
|
+
isArrowUp,
|
|
56
|
+
isBackspace,
|
|
57
|
+
} from '../../internal/date-time/field/helpers.js';
|
|
58
|
+
import type { TimeRangeFieldRootState } from '../time-range-field/time-range-field.svelte.js';
|
|
59
|
+
|
|
60
|
+
export const timeFieldAttrs = createBitsAttrs({
|
|
61
|
+
component: 'time-field',
|
|
62
|
+
parts: ['input', 'label'],
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const [getTimeFieldRoot, setTimeFieldRoot] = createContext<TimeFieldRootState>();
|
|
66
|
+
|
|
67
|
+
interface SegmentConfig {
|
|
68
|
+
min: number | ((root: TimeFieldRootState) => number);
|
|
69
|
+
max: number | ((root: TimeFieldRootState) => number);
|
|
70
|
+
cycle: number;
|
|
71
|
+
canBeZero?: boolean;
|
|
72
|
+
padZero?: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const SEGMENT_CONFIGS: Record<'hour' | 'minute' | 'second', SegmentConfig> = {
|
|
76
|
+
hour: {
|
|
77
|
+
min: (root) => (root.hourCycle === 12 ? 1 : 0),
|
|
78
|
+
max: (root) => {
|
|
79
|
+
if (root.hourCycle === 24) return 23;
|
|
80
|
+
if ('dayPeriod' in root.segmentValues && root.segmentValues.dayPeriod !== null) return 12;
|
|
81
|
+
return 23;
|
|
82
|
+
},
|
|
83
|
+
cycle: 1,
|
|
84
|
+
canBeZero: true,
|
|
85
|
+
padZero: true,
|
|
86
|
+
},
|
|
87
|
+
minute: {
|
|
88
|
+
min: 0,
|
|
89
|
+
max: 59,
|
|
90
|
+
cycle: 1,
|
|
91
|
+
canBeZero: true,
|
|
92
|
+
padZero: true,
|
|
93
|
+
},
|
|
94
|
+
second: {
|
|
95
|
+
min: 0,
|
|
96
|
+
max: 59,
|
|
97
|
+
cycle: 1,
|
|
98
|
+
canBeZero: true,
|
|
99
|
+
padZero: true,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
function get24HourValueFromTypedHour(hour: string, dayPeriod: Exclude<TimeSegmentObj['dayPeriod'], null>): string {
|
|
104
|
+
const parsedHour = Number.parseInt(hour);
|
|
105
|
+
if (Number.isNaN(parsedHour)) return hour;
|
|
106
|
+
if (dayPeriod === 'AM') {
|
|
107
|
+
return parsedHour === 12 ? '0' : `${parsedHour}`;
|
|
108
|
+
}
|
|
109
|
+
return parsedHour < 12 ? `${parsedHour + 12}` : `${parsedHour}`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface TimeFieldRootStateOpts<T extends TimeValue = Time>
|
|
113
|
+
extends
|
|
114
|
+
WritableBoxedValues<{
|
|
115
|
+
value: T | undefined;
|
|
116
|
+
placeholder: TimeValue;
|
|
117
|
+
}>,
|
|
118
|
+
ReadableBoxedValues<{
|
|
119
|
+
readonlySegments: SegmentPart[];
|
|
120
|
+
validate: TimeValidator<T> | undefined;
|
|
121
|
+
onInvalid: TimeOnInvalid | undefined;
|
|
122
|
+
minValue: TimeValue | undefined;
|
|
123
|
+
maxValue: TimeValue | undefined;
|
|
124
|
+
disabled: boolean;
|
|
125
|
+
readonly: boolean;
|
|
126
|
+
granularity: 'hour' | 'minute' | 'second' | undefined;
|
|
127
|
+
hourCycle: HourCycle | undefined;
|
|
128
|
+
locale: string;
|
|
129
|
+
hideTimeZone: boolean;
|
|
130
|
+
required: boolean;
|
|
131
|
+
errorMessageId: string | undefined;
|
|
132
|
+
isInvalidProp: boolean | undefined;
|
|
133
|
+
}> {
|
|
134
|
+
descriptionId: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export class TimeFieldRootState<T extends TimeValue = Time> {
|
|
138
|
+
static create<T extends TimeValue = Time>(opts: TimeFieldRootStateOpts<T>, rangeRoot?: TimeRangeFieldRootState<T>) {
|
|
139
|
+
return setTimeFieldRoot(new TimeFieldRootState(opts, rangeRoot) as unknown as TimeFieldRootState);
|
|
140
|
+
}
|
|
141
|
+
value: TimeFieldRootStateOpts<T>['value'];
|
|
142
|
+
placeholder: WritableBox<TimeValue>;
|
|
143
|
+
validate: TimeFieldRootStateOpts<T>['validate'];
|
|
144
|
+
minValue: TimeFieldRootStateOpts<T>['minValue'];
|
|
145
|
+
maxValue: TimeFieldRootStateOpts<T>['maxValue'];
|
|
146
|
+
disabled: TimeFieldRootStateOpts<T>['disabled'];
|
|
147
|
+
readonly: TimeFieldRootStateOpts<T>['readonly'];
|
|
148
|
+
granularity: TimeFieldRootStateOpts<T>['granularity'];
|
|
149
|
+
readonlySegments: TimeFieldRootStateOpts<T>['readonlySegments'];
|
|
150
|
+
hourCycleProp: TimeFieldRootStateOpts<T>['hourCycle'];
|
|
151
|
+
locale: TimeFieldRootStateOpts<T>['locale'];
|
|
152
|
+
hideTimeZone: TimeFieldRootStateOpts<T>['hideTimeZone'];
|
|
153
|
+
required: TimeFieldRootStateOpts<T>['required'];
|
|
154
|
+
onInvalid: TimeFieldRootStateOpts<T>['onInvalid'];
|
|
155
|
+
errorMessageId: TimeFieldRootStateOpts<T>['errorMessageId'];
|
|
156
|
+
isInvalidProp: TimeFieldRootStateOpts<T>['isInvalidProp'];
|
|
157
|
+
readonly descriptionId: string;
|
|
158
|
+
formatter: TimeFormatter;
|
|
159
|
+
segmentValues = $state() as TimeSegmentObj;
|
|
160
|
+
announcer: Announcer;
|
|
161
|
+
readonly readonlySegmentsSet = $derived.by(() => new Set(this.readonlySegments.current));
|
|
162
|
+
#fieldNode = $state<HTMLElement | null>(null);
|
|
163
|
+
#labelNode = $state<HTMLElement | null>(null);
|
|
164
|
+
descriptionNode = $state<HTMLElement | null>(null);
|
|
165
|
+
validationNode = $state<HTMLElement | null>(null);
|
|
166
|
+
states = initTimeSegmentStates();
|
|
167
|
+
hourInputDayPeriodHint: TimeSegmentObj['dayPeriod'] = null;
|
|
168
|
+
dayPeriodNode = $state<HTMLElement | null>(null);
|
|
169
|
+
name = $state('');
|
|
170
|
+
readonly maxValueTime = $derived.by(() => {
|
|
171
|
+
if (!this.maxValue.current) return undefined;
|
|
172
|
+
return convertTimeValueToTime(this.maxValue.current);
|
|
173
|
+
});
|
|
174
|
+
readonly minValueTime = $derived.by(() => {
|
|
175
|
+
if (!this.minValue.current) return undefined;
|
|
176
|
+
return convertTimeValueToTime(this.minValue.current);
|
|
177
|
+
});
|
|
178
|
+
readonly valueTime = $derived.by(() => {
|
|
179
|
+
if (!this.value.current) return undefined;
|
|
180
|
+
return convertTimeValueToTime(this.value.current);
|
|
181
|
+
});
|
|
182
|
+
readonly hourCycle = $derived.by(() => {
|
|
183
|
+
if (this.hourCycleProp.current) return this.hourCycleProp.current;
|
|
184
|
+
return getDefaultHourCycle(this.locale.current);
|
|
185
|
+
});
|
|
186
|
+
readonly rangeRoot: TimeRangeFieldRootState<T> | undefined = undefined;
|
|
187
|
+
domContext = new DOMContext(() => null);
|
|
188
|
+
|
|
189
|
+
constructor(props: TimeFieldRootStateOpts<T>, rangeRoot?: TimeRangeFieldRootState<T>) {
|
|
190
|
+
this.rangeRoot = rangeRoot;
|
|
191
|
+
this.descriptionId = props.descriptionId;
|
|
192
|
+
/**
|
|
193
|
+
* Since the `TimeFieldRootState` can be used in two contexts, as a standalone
|
|
194
|
+
* field or as a field within a `TimeRangeField` component, we handle assigning
|
|
195
|
+
* the props based on that context.
|
|
196
|
+
*/
|
|
197
|
+
this.value = props.value;
|
|
198
|
+
this.placeholder = rangeRoot ? rangeRoot.opts.placeholder : props.placeholder;
|
|
199
|
+
this.validate = rangeRoot ? simpleBox(undefined) : props.validate;
|
|
200
|
+
this.minValue = rangeRoot ? rangeRoot.opts.minValue : props.minValue;
|
|
201
|
+
this.maxValue = rangeRoot ? rangeRoot.opts.maxValue : props.maxValue;
|
|
202
|
+
this.disabled = rangeRoot ? rangeRoot.opts.disabled : props.disabled;
|
|
203
|
+
this.readonly = rangeRoot ? rangeRoot.opts.readonly : props.readonly;
|
|
204
|
+
this.granularity = rangeRoot ? rangeRoot.opts.granularity : props.granularity;
|
|
205
|
+
this.readonlySegments = rangeRoot ? rangeRoot.opts.readonlySegments : props.readonlySegments;
|
|
206
|
+
this.hourCycleProp = rangeRoot ? rangeRoot.opts.hourCycle : props.hourCycle;
|
|
207
|
+
this.locale = rangeRoot ? rangeRoot.opts.locale : props.locale;
|
|
208
|
+
this.hideTimeZone = rangeRoot ? rangeRoot.opts.hideTimeZone : props.hideTimeZone;
|
|
209
|
+
this.required = rangeRoot ? rangeRoot.opts.required : props.required;
|
|
210
|
+
this.onInvalid = rangeRoot ? rangeRoot.opts.onInvalid : props.onInvalid;
|
|
211
|
+
this.errorMessageId = rangeRoot ? rangeRoot.opts.errorMessageId : props.errorMessageId;
|
|
212
|
+
this.isInvalidProp = props.isInvalidProp;
|
|
213
|
+
this.formatter = createTimeFormatter(this.locale.current);
|
|
214
|
+
this.segmentValues = this.#initializeTimeSegmentValues();
|
|
215
|
+
this.announcer = getAnnouncer(null);
|
|
216
|
+
|
|
217
|
+
this.getFieldNode = this.getFieldNode.bind(this);
|
|
218
|
+
this.updateSegment = this.updateSegment.bind(this);
|
|
219
|
+
this.handleSegmentClick = this.handleSegmentClick.bind(this);
|
|
220
|
+
this.getBaseSegmentAttrs = this.getBaseSegmentAttrs.bind(this);
|
|
221
|
+
|
|
222
|
+
onMount(() => {
|
|
223
|
+
this.announcer = getAnnouncer(this.domContext.getDocument());
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
onMount(() => () => {
|
|
227
|
+
removeTimeDescriptionElement(this.descriptionId, this.domContext.getDocument());
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
$effect(() => {
|
|
231
|
+
if (this.formatter.getLocale() === this.locale.current) return;
|
|
232
|
+
this.formatter.setLocale(this.locale.current);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
$effect(() => {
|
|
236
|
+
if (this.value.current) {
|
|
237
|
+
const descriptionId = untrack(() => this.descriptionId);
|
|
238
|
+
setTimeDescription({
|
|
239
|
+
id: descriptionId,
|
|
240
|
+
formatter: this.formatter,
|
|
241
|
+
value: this.#toDateValue(this.value.current),
|
|
242
|
+
doc: this.domContext.getDocument(),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
const placeholder = untrack(() => this.placeholder.current);
|
|
246
|
+
if (this.value.current && placeholder !== this.value.current) {
|
|
247
|
+
untrack(() => {
|
|
248
|
+
if (this.value.current) {
|
|
249
|
+
this.placeholder.current = this.value.current;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
if (this.value.current) {
|
|
256
|
+
this.syncSegmentValues(this.value.current);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
$effect(() => {
|
|
260
|
+
this.locale.current;
|
|
261
|
+
if (this.value.current) {
|
|
262
|
+
this.syncSegmentValues(this.value.current);
|
|
263
|
+
}
|
|
264
|
+
this.#clearUpdating();
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
$effect(() => {
|
|
268
|
+
if (this.value.current === undefined) {
|
|
269
|
+
this.segmentValues = this.#initializeTimeSegmentValues();
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
$effect(() => {
|
|
274
|
+
this.validationStatus;
|
|
275
|
+
untrack(() => {
|
|
276
|
+
if (this.validationStatus !== false) {
|
|
277
|
+
this.onInvalid.current?.(this.validationStatus.reason, this.validationStatus.message);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
#initializeTimeSegmentValues(): TimeSegmentObj {
|
|
284
|
+
const granularity = this.inferredGranularity;
|
|
285
|
+
const segments: TimeSegmentObj = {
|
|
286
|
+
hour: null,
|
|
287
|
+
minute: null,
|
|
288
|
+
second: null,
|
|
289
|
+
dayPeriod: 'AM',
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
if (granularity === 'second') {
|
|
293
|
+
segments.second = null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (this.hourCycle === 24) {
|
|
297
|
+
segments.dayPeriod = null;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return segments;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
#toDateValue(timeValue: TimeValue): CalendarDateTime | ZonedDateTime {
|
|
304
|
+
return 'calendar' in timeValue
|
|
305
|
+
? timeValue
|
|
306
|
+
: new CalendarDateTime(2000, 1, 1, timeValue.hour, timeValue.minute, timeValue.second, timeValue.millisecond);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
#clearUpdating() {
|
|
310
|
+
this.states.hour.updating = null;
|
|
311
|
+
this.states.minute.updating = null;
|
|
312
|
+
this.states.second.updating = null;
|
|
313
|
+
this.states.dayPeriod.updating = null;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
setName(name: string) {
|
|
317
|
+
this.name = name;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
setFieldNode(node: HTMLElement | null) {
|
|
321
|
+
this.#fieldNode = node;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Gets the correct field node for the time field regardless of whether it's being
|
|
326
|
+
* used in a standalone context or within a `TimeRangeField` component.
|
|
327
|
+
*/
|
|
328
|
+
getFieldNode() {
|
|
329
|
+
return this.rangeRoot ? this.rangeRoot.fieldNode : this.#fieldNode;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
setLabelNode(node: HTMLElement | null) {
|
|
333
|
+
this.#labelNode = node;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
getLabelNode() {
|
|
337
|
+
return this.#labelNode;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
setValue(value: T | undefined) {
|
|
341
|
+
this.value.current = value;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
syncSegmentValues(value: TimeValue) {
|
|
345
|
+
const timeValues = EDITABLE_TIME_SEGMENT_PARTS.map((part) => {
|
|
346
|
+
if (part === 'dayPeriod') {
|
|
347
|
+
if (this.states.dayPeriod.updating) {
|
|
348
|
+
return [part, this.states.dayPeriod.updating];
|
|
349
|
+
} else {
|
|
350
|
+
return [part, this.formatter.dayPeriod(toDate(this.#toDateValue(value)))];
|
|
351
|
+
}
|
|
352
|
+
} else if (part === 'hour') {
|
|
353
|
+
if (this.states.hour.updating) {
|
|
354
|
+
return [part, this.states.hour.updating];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (value[part] !== undefined && value[part] < 10) {
|
|
358
|
+
return [part, `0${value[part]}`];
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (value[part] === 0 && this.dayPeriodNode) {
|
|
362
|
+
return [part, '12'];
|
|
363
|
+
}
|
|
364
|
+
} else if (part === 'minute') {
|
|
365
|
+
if (this.states.minute.updating) {
|
|
366
|
+
return [part, this.states.minute.updating];
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (value[part] !== undefined && value[part] < 10) {
|
|
370
|
+
return [part, `0${value[part]}`];
|
|
371
|
+
}
|
|
372
|
+
} else if (part === 'second') {
|
|
373
|
+
if (this.states.second.updating) {
|
|
374
|
+
return [part, this.states.second.updating];
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (value[part] !== undefined && value[part] < 10) {
|
|
378
|
+
return [part, `0${value[part]}`];
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return [part, `${value[part]}`];
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
this.segmentValues = Object.fromEntries(timeValues);
|
|
385
|
+
this.#clearUpdating();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
validationStatus = $derived.by(() => {
|
|
389
|
+
const value = this.value.current;
|
|
390
|
+
if (!value) return false as const;
|
|
391
|
+
|
|
392
|
+
const msg = this.validate.current?.(value);
|
|
393
|
+
if (msg) {
|
|
394
|
+
return {
|
|
395
|
+
reason: 'custom',
|
|
396
|
+
message: msg,
|
|
397
|
+
} as const;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (!this.valueTime) return false as const;
|
|
401
|
+
|
|
402
|
+
if (this.minValueTime && isTimeBefore(this.valueTime, this.minValueTime)) {
|
|
403
|
+
return {
|
|
404
|
+
reason: 'min',
|
|
405
|
+
} as const;
|
|
406
|
+
}
|
|
407
|
+
if (this.maxValueTime && isTimeBefore(this.maxValueTime, this.valueTime)) {
|
|
408
|
+
return {
|
|
409
|
+
reason: 'max',
|
|
410
|
+
} as const;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return false;
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
isInvalid = $derived.by(() => {
|
|
417
|
+
if (this.isInvalidProp.current) return true;
|
|
418
|
+
return this.validationStatus !== false;
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
inferredGranularity = $derived.by(() => {
|
|
422
|
+
return this.granularity.current ?? 'minute';
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
timeRef = $derived.by(() => this.value.current ?? this.placeholder.current) as T;
|
|
426
|
+
|
|
427
|
+
allSegmentContent = $derived.by(() =>
|
|
428
|
+
createTimeContent({
|
|
429
|
+
segmentValues: this.segmentValues,
|
|
430
|
+
formatter: this.formatter,
|
|
431
|
+
locale: this.locale.current,
|
|
432
|
+
granularity: this.inferredGranularity,
|
|
433
|
+
timeRef: this.timeRef,
|
|
434
|
+
hideTimeZone: this.hideTimeZone.current,
|
|
435
|
+
hourCycle: this.hourCycle,
|
|
436
|
+
}),
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
segmentContents = $derived.by(() => this.allSegmentContent.arr);
|
|
440
|
+
|
|
441
|
+
sharedSegmentAttrs = {
|
|
442
|
+
role: 'spinbutton',
|
|
443
|
+
contenteditable: 'true',
|
|
444
|
+
tabindex: 0,
|
|
445
|
+
spellcheck: false,
|
|
446
|
+
inputmode: 'numeric',
|
|
447
|
+
autocorrect: 'off',
|
|
448
|
+
enterkeyhint: 'next',
|
|
449
|
+
style: {
|
|
450
|
+
caretColor: 'transparent',
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
#getLabelledBy(segmentId: string) {
|
|
455
|
+
return `${segmentId} ${this.getLabelNode()?.id ?? ''}`;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
updateSegment<T extends EditableTimeSegmentPart>(part: T, cb: Updater<TimeSegmentObj[T]>) {
|
|
459
|
+
const disabled = this.disabled.current;
|
|
460
|
+
const readonly = this.readonly.current;
|
|
461
|
+
const readonlySegmentsSet = this.readonlySegmentsSet;
|
|
462
|
+
if (disabled || readonly || readonlySegmentsSet.has(part)) return;
|
|
463
|
+
|
|
464
|
+
const prev = this.segmentValues;
|
|
465
|
+
let newSegmentValues: TimeSegmentObj = prev;
|
|
466
|
+
|
|
467
|
+
if (part === 'dayPeriod') {
|
|
468
|
+
const next = cb(prev[part]) as TimeSegmentObj['dayPeriod'];
|
|
469
|
+
this.states.dayPeriod.updating = next;
|
|
470
|
+
const value = this.value.current;
|
|
471
|
+
if (value && 'hour' in value) {
|
|
472
|
+
const trueHour = value.hour;
|
|
473
|
+
if (next === 'AM') {
|
|
474
|
+
if (trueHour >= 12) {
|
|
475
|
+
prev.hour = `${trueHour - 12}`;
|
|
476
|
+
}
|
|
477
|
+
} else if (next === 'PM') {
|
|
478
|
+
if (trueHour < 12) {
|
|
479
|
+
prev.hour = `${trueHour + 12}`;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
newSegmentValues = { ...prev, [part]: next };
|
|
484
|
+
} else if (part === 'hour') {
|
|
485
|
+
const next = cb(prev[part]) as TimeSegmentObj['hour'];
|
|
486
|
+
this.states.hour.updating = next;
|
|
487
|
+
if (next !== null && prev.dayPeriod !== null) {
|
|
488
|
+
if (this.hourCycle !== 24 && this.hourInputDayPeriodHint !== null) {
|
|
489
|
+
prev.dayPeriod = this.hourInputDayPeriodHint;
|
|
490
|
+
} else {
|
|
491
|
+
const dayPeriod = this.formatter.dayPeriod(
|
|
492
|
+
toDate(this.#toDateValue(this.timeRef.set({ hour: Number.parseInt(next) }))),
|
|
493
|
+
this.hourCycle,
|
|
494
|
+
);
|
|
495
|
+
if (dayPeriod === 'AM' || dayPeriod === 'PM') {
|
|
496
|
+
prev.dayPeriod = dayPeriod;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
newSegmentValues = { ...prev, [part]: next };
|
|
501
|
+
} else if (part === 'minute') {
|
|
502
|
+
const next = cb(prev[part]) as TimeSegmentObj['minute'];
|
|
503
|
+
this.states.minute.updating = next;
|
|
504
|
+
newSegmentValues = { ...prev, [part]: next };
|
|
505
|
+
} else if (part === 'second') {
|
|
506
|
+
const next = cb(prev[part]) as TimeSegmentObj['second'];
|
|
507
|
+
this.states.second.updating = next;
|
|
508
|
+
newSegmentValues = { ...prev, [part]: next };
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
this.segmentValues = newSegmentValues;
|
|
512
|
+
|
|
513
|
+
const segmentObjForValue: TimeSegmentObj =
|
|
514
|
+
part === 'hour' && this.hourCycle !== 24 && this.hourInputDayPeriodHint !== null && newSegmentValues.hour !== null
|
|
515
|
+
? {
|
|
516
|
+
...newSegmentValues,
|
|
517
|
+
hour: get24HourValueFromTypedHour(newSegmentValues.hour, this.hourInputDayPeriodHint),
|
|
518
|
+
}
|
|
519
|
+
: newSegmentValues;
|
|
520
|
+
|
|
521
|
+
if (areAllTimeSegmentsFilled(newSegmentValues, this.#fieldNode)) {
|
|
522
|
+
this.setValue(
|
|
523
|
+
getTimeValueFromSegments({
|
|
524
|
+
segmentObj: segmentObjForValue,
|
|
525
|
+
fieldNode: this.#fieldNode,
|
|
526
|
+
timeRef: this.timeRef,
|
|
527
|
+
}),
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
handleSegmentClick(e: BitsMouseEvent) {
|
|
533
|
+
if (this.disabled.current) {
|
|
534
|
+
e.preventDefault();
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
getBaseSegmentAttrs(part: SegmentPart, segmentId: string) {
|
|
539
|
+
const inReadonlySegments = this.readonlySegmentsSet.has(part);
|
|
540
|
+
const defaultAttrs = {
|
|
541
|
+
'aria-invalid': boolToStrTrueOrUndef(this.isInvalid),
|
|
542
|
+
'aria-disabled': boolToStr(this.disabled.current),
|
|
543
|
+
'aria-readonly': boolToStr(this.readonly.current || inReadonlySegments),
|
|
544
|
+
'data-invalid': boolToEmptyStrOrUndef(this.isInvalid),
|
|
545
|
+
'data-disabled': boolToEmptyStrOrUndef(this.disabled.current),
|
|
546
|
+
'data-readonly': boolToEmptyStrOrUndef(this.readonly.current || inReadonlySegments),
|
|
547
|
+
'data-segment': `${part}`,
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
if (part === 'literal') return defaultAttrs;
|
|
551
|
+
|
|
552
|
+
const descriptionId = this.descriptionNode?.id;
|
|
553
|
+
const hasDescription = isFirstTimeSegment(segmentId, this.#fieldNode) && descriptionId;
|
|
554
|
+
const errorMsgId = this.errorMessageId?.current;
|
|
555
|
+
|
|
556
|
+
const describedBy = hasDescription ? `${descriptionId} ${this.isInvalid && errorMsgId ? errorMsgId : ''}` : undefined;
|
|
557
|
+
|
|
558
|
+
const contenteditable = !(this.readonly.current || inReadonlySegments || this.disabled.current);
|
|
559
|
+
|
|
560
|
+
return {
|
|
561
|
+
...defaultAttrs,
|
|
562
|
+
'aria-labelledby': this.#getLabelledBy(segmentId),
|
|
563
|
+
contenteditable: contenteditable ? 'true' : undefined,
|
|
564
|
+
'aria-describedby': describedBy,
|
|
565
|
+
tabindex: this.disabled.current ? undefined : 0,
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
interface TimeFieldInputStateOpts
|
|
571
|
+
extends
|
|
572
|
+
WithRefOpts,
|
|
573
|
+
ReadableBoxedValues<{
|
|
574
|
+
name: string;
|
|
575
|
+
}> {}
|
|
576
|
+
|
|
577
|
+
export class TimeFieldInputState {
|
|
578
|
+
static create(opts: TimeFieldInputStateOpts) {
|
|
579
|
+
return new TimeFieldInputState(opts, getTimeFieldRoot());
|
|
580
|
+
}
|
|
581
|
+
readonly opts: TimeFieldInputStateOpts;
|
|
582
|
+
readonly root: TimeFieldRootState;
|
|
583
|
+
readonly attachment: RefAttachment;
|
|
584
|
+
domContext: DOMContext;
|
|
585
|
+
|
|
586
|
+
constructor(opts: TimeFieldInputStateOpts, root: TimeFieldRootState) {
|
|
587
|
+
this.opts = opts;
|
|
588
|
+
this.root = root;
|
|
589
|
+
this.attachment = attachRef(opts.ref, (v) => this.root.setFieldNode(v));
|
|
590
|
+
this.domContext = new DOMContext(opts.ref);
|
|
591
|
+
this.root.setName(this.opts.name.current);
|
|
592
|
+
|
|
593
|
+
$effect(() => {
|
|
594
|
+
this.root.setName(this.opts.name.current);
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
readonly #ariaDescribedBy = $derived.by(() => {
|
|
599
|
+
if (!BROWSER) return undefined;
|
|
600
|
+
const doesDescriptionExist = this.domContext.getElementById(this.root.descriptionId);
|
|
601
|
+
if (!doesDescriptionExist) return undefined;
|
|
602
|
+
return this.root.descriptionId;
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
readonly props = $derived.by(
|
|
606
|
+
() =>
|
|
607
|
+
({
|
|
608
|
+
id: this.opts.id.current,
|
|
609
|
+
role: 'group',
|
|
610
|
+
'aria-labelledby': this.root.getLabelNode()?.id ?? undefined,
|
|
611
|
+
'aria-describedby': this.#ariaDescribedBy,
|
|
612
|
+
'aria-disabled': boolToStr(this.root.disabled.current),
|
|
613
|
+
'data-invalid': this.root.isInvalid ? '' : undefined,
|
|
614
|
+
'data-disabled': boolToEmptyStrOrUndef(this.root.disabled.current),
|
|
615
|
+
[timeFieldAttrs.input]: '',
|
|
616
|
+
...this.attachment,
|
|
617
|
+
}) as const,
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
export class TimeFieldHiddenInputState {
|
|
622
|
+
static create() {
|
|
623
|
+
return new TimeFieldHiddenInputState(getTimeFieldRoot());
|
|
624
|
+
}
|
|
625
|
+
readonly root: TimeFieldRootState;
|
|
626
|
+
readonly shouldRender = $derived.by(() => this.root.name !== '');
|
|
627
|
+
readonly isoValue = $derived.by(() => (this.root.value.current ? getISOTimeValue(this.root.value.current) : undefined));
|
|
628
|
+
|
|
629
|
+
constructor(root: TimeFieldRootState) {
|
|
630
|
+
this.root = root;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
readonly props = $derived.by(
|
|
634
|
+
() =>
|
|
635
|
+
({
|
|
636
|
+
name: this.root.name,
|
|
637
|
+
value: this.isoValue,
|
|
638
|
+
required: this.root.required.current,
|
|
639
|
+
}) as const,
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
interface TimeFieldLabelStateOpts extends WithRefOpts {}
|
|
644
|
+
|
|
645
|
+
export class TimeFieldLabelState {
|
|
646
|
+
static create(opts: TimeFieldLabelStateOpts) {
|
|
647
|
+
return new TimeFieldLabelState(opts, getTimeFieldRoot());
|
|
648
|
+
}
|
|
649
|
+
readonly opts: TimeFieldLabelStateOpts;
|
|
650
|
+
readonly root: TimeFieldRootState;
|
|
651
|
+
readonly attachment: RefAttachment;
|
|
652
|
+
|
|
653
|
+
constructor(opts: TimeFieldLabelStateOpts, root: TimeFieldRootState) {
|
|
654
|
+
this.opts = opts;
|
|
655
|
+
this.root = root;
|
|
656
|
+
this.attachment = attachRef(opts.ref, (v) => this.root.setLabelNode(v));
|
|
657
|
+
this.onclick = this.onclick.bind(this);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
onclick(_: BitsMouseEvent) {
|
|
661
|
+
if (this.root.disabled.current) return;
|
|
662
|
+
const firstSegment = getFirstTimeSegment(this.root.getFieldNode());
|
|
663
|
+
if (!firstSegment) return;
|
|
664
|
+
firstSegment.focus();
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
readonly props = $derived.by(
|
|
668
|
+
() =>
|
|
669
|
+
({
|
|
670
|
+
id: this.opts.id.current,
|
|
671
|
+
'data-invalid': boolToEmptyStrOrUndef(this.root.isInvalid),
|
|
672
|
+
'data-disabled': boolToEmptyStrOrUndef(this.root.disabled.current),
|
|
673
|
+
[timeFieldAttrs.label]: '',
|
|
674
|
+
onclick: this.onclick,
|
|
675
|
+
...this.attachment,
|
|
676
|
+
}) as const,
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// Base class for time segments - simplified from date-field version
|
|
681
|
+
abstract class BaseTimeSegmentState {
|
|
682
|
+
readonly opts: WithRefOpts;
|
|
683
|
+
readonly root: TimeFieldRootState;
|
|
684
|
+
readonly announcer: Announcer;
|
|
685
|
+
readonly part: string;
|
|
686
|
+
readonly config: SegmentConfig;
|
|
687
|
+
readonly attachment: RefAttachment;
|
|
688
|
+
|
|
689
|
+
constructor(opts: WithRefOpts, root: TimeFieldRootState, part: string, config: SegmentConfig) {
|
|
690
|
+
this.opts = opts;
|
|
691
|
+
this.root = root;
|
|
692
|
+
this.part = part;
|
|
693
|
+
this.config = config;
|
|
694
|
+
this.announcer = root.announcer;
|
|
695
|
+
this.attachment = attachRef(opts.ref);
|
|
696
|
+
this.onkeydown = this.onkeydown.bind(this);
|
|
697
|
+
this.onfocusout = this.onfocusout.bind(this);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
#getMax(): number {
|
|
701
|
+
return typeof this.config.max === 'function' ? this.config.max(this.root) : this.config.max;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
#getMin(): number {
|
|
705
|
+
return typeof this.config.min === 'function' ? this.config.min(this.root) : this.config.min;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
#formatValue(value: number, forDisplay = true): string {
|
|
709
|
+
const str = String(value);
|
|
710
|
+
if (forDisplay && this.config.padZero && str.length === 1) {
|
|
711
|
+
return `0${value}`;
|
|
712
|
+
}
|
|
713
|
+
return str;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
onkeydown(e: BitsKeyboardEvent) {
|
|
717
|
+
const placeholder = this.root.value.current ?? this.root.placeholder.current;
|
|
718
|
+
if (e.ctrlKey || e.metaKey || this.root.disabled.current) return;
|
|
719
|
+
|
|
720
|
+
if (e.key !== kbd.TAB) e.preventDefault();
|
|
721
|
+
if (!isAcceptableSegmentKey(e.key)) return;
|
|
722
|
+
|
|
723
|
+
if (isArrowUp(e.key)) {
|
|
724
|
+
this.#handleArrowUp(placeholder);
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
if (isArrowDown(e.key)) {
|
|
729
|
+
this.#handleArrowDown(placeholder);
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if (e.key.length === 1 && e.key >= '0' && e.key <= '9') {
|
|
734
|
+
this.#handleNumberKey(e);
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
if (isBackspace(e.key)) {
|
|
739
|
+
this.#handleBackspace(e);
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
if (isSegmentNavigationKey(e.key)) {
|
|
744
|
+
handleTimeSegmentNavigation(e, this.root.getFieldNode());
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
#handleArrowUp(placeholder: TimeValue) {
|
|
749
|
+
const stateKey = this.part as EditableTimeSegmentPart;
|
|
750
|
+
if (stateKey in this.root.states) {
|
|
751
|
+
this.root.states[stateKey].hasLeftFocus = false;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// @ts-expect-error shhh
|
|
755
|
+
this.root.updateSegment(this.part, (prev: string | null) => {
|
|
756
|
+
if (prev === null) {
|
|
757
|
+
const next = placeholder[this.part as keyof TimeValue];
|
|
758
|
+
this.announcer.announce(String(next));
|
|
759
|
+
return this.#formatValue(next as number);
|
|
760
|
+
}
|
|
761
|
+
const current = placeholder.set({
|
|
762
|
+
[this.part]: Number.parseInt(prev),
|
|
763
|
+
});
|
|
764
|
+
// @ts-expect-error shhh
|
|
765
|
+
const next = current.cycle(this.part, this.config.cycle)[this.part as keyof TimeValue];
|
|
766
|
+
this.announcer.announce(String(next));
|
|
767
|
+
return this.#formatValue(next as number);
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
#handleArrowDown(placeholder: TimeValue) {
|
|
772
|
+
const stateKey = this.part as keyof typeof this.root.states;
|
|
773
|
+
if (stateKey in this.root.states) {
|
|
774
|
+
this.root.states[stateKey].hasLeftFocus = false;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// @ts-expect-error - this is a part
|
|
778
|
+
this.root.updateSegment(this.part, (prev: string | null) => {
|
|
779
|
+
if (prev === null) {
|
|
780
|
+
const next = placeholder[this.part as keyof TimeValue];
|
|
781
|
+
this.announcer.announce(String(next));
|
|
782
|
+
return this.#formatValue(next as number);
|
|
783
|
+
}
|
|
784
|
+
const current = placeholder.set({
|
|
785
|
+
[this.part]: Number.parseInt(prev),
|
|
786
|
+
});
|
|
787
|
+
// @ts-expect-error shhh
|
|
788
|
+
const next = current.cycle(this.part, -this.config.cycle)[this.part as keyof TimeValue];
|
|
789
|
+
this.announcer.announce(String(next));
|
|
790
|
+
return this.#formatValue(next as number);
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
#handleNumberKey(e: BitsKeyboardEvent) {
|
|
795
|
+
const num = Number.parseInt(e.key);
|
|
796
|
+
let moveToNext = false;
|
|
797
|
+
const max = this.#getMax();
|
|
798
|
+
const maxStart = Math.floor(max / 10);
|
|
799
|
+
const numIsZero = num === 0;
|
|
800
|
+
const stateKey = this.part as keyof typeof this.root.states;
|
|
801
|
+
|
|
802
|
+
// @ts-expect-error this is a part
|
|
803
|
+
this.root.updateSegment(this.part, (prev: string | null) => {
|
|
804
|
+
if (stateKey in this.root.states && this.root.states[stateKey].hasLeftFocus) {
|
|
805
|
+
prev = null;
|
|
806
|
+
this.root.states[stateKey].hasLeftFocus = false;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
if (prev === null) {
|
|
810
|
+
if (numIsZero) {
|
|
811
|
+
if (stateKey in this.root.states) {
|
|
812
|
+
this.root.states[stateKey].lastKeyZero = true;
|
|
813
|
+
}
|
|
814
|
+
this.announcer.announce('0');
|
|
815
|
+
return '0';
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
if (stateKey in this.root.states && (this.root.states[stateKey].lastKeyZero || num > maxStart)) {
|
|
819
|
+
moveToNext = true;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
if (stateKey in this.root.states) {
|
|
823
|
+
this.root.states[stateKey].lastKeyZero = false;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
if (moveToNext && String(num).length === 1) {
|
|
827
|
+
this.announcer.announce(num);
|
|
828
|
+
return `0${num}`;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
return `${num}`;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
if (stateKey in this.root.states && this.root.states[stateKey].lastKeyZero) {
|
|
835
|
+
if (num !== 0) {
|
|
836
|
+
moveToNext = true;
|
|
837
|
+
this.root.states[stateKey].lastKeyZero = false;
|
|
838
|
+
return `0${num}`;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
if (this.part === 'hour' && num === 0 && this.root.hourCycle === 24) {
|
|
842
|
+
moveToNext = true;
|
|
843
|
+
this.root.states[stateKey].lastKeyZero = false;
|
|
844
|
+
return `00`;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
if ((this.part === 'minute' || this.part === 'second') && num === 0) {
|
|
848
|
+
moveToNext = true;
|
|
849
|
+
this.root.states[stateKey].lastKeyZero = false;
|
|
850
|
+
return '00';
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
return prev;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
const total = Number.parseInt(prev + num.toString());
|
|
857
|
+
|
|
858
|
+
if (total > max) {
|
|
859
|
+
moveToNext = true;
|
|
860
|
+
return `0${num}`;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
moveToNext = true;
|
|
864
|
+
return `${total}`;
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
if (moveToNext) {
|
|
868
|
+
moveToNextSegment(e, this.root.getFieldNode());
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
#handleBackspace(e: BitsKeyboardEvent) {
|
|
873
|
+
const stateKey = this.part as keyof typeof this.root.states;
|
|
874
|
+
if (stateKey in this.root.states) {
|
|
875
|
+
this.root.states[stateKey].hasLeftFocus = false;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
let moveToPrev = false;
|
|
879
|
+
// @ts-expect-error this is a part
|
|
880
|
+
this.root.updateSegment(this.part, (prev: string | null) => {
|
|
881
|
+
if (prev === null) {
|
|
882
|
+
moveToPrev = true;
|
|
883
|
+
this.announcer.announce(null);
|
|
884
|
+
return null;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
if (prev.length === 2 && prev.startsWith('0')) {
|
|
888
|
+
this.announcer.announce(null);
|
|
889
|
+
return null;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
const str = prev.toString();
|
|
893
|
+
if (str.length === 1) {
|
|
894
|
+
this.announcer.announce(null);
|
|
895
|
+
return null;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
const next = Number.parseInt(str.slice(0, -1));
|
|
899
|
+
this.announcer.announce(String(next));
|
|
900
|
+
return `${next}`;
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
if (moveToPrev) {
|
|
904
|
+
moveToPrevSegment(e, this.root.getFieldNode());
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
onfocusout(_: BitsFocusEvent) {
|
|
909
|
+
const stateKey = this.part as keyof typeof this.root.states;
|
|
910
|
+
if (stateKey in this.root.states) {
|
|
911
|
+
this.root.states[stateKey].hasLeftFocus = true;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// Pad with zero if needed
|
|
915
|
+
if (this.config.padZero) {
|
|
916
|
+
// @ts-expect-error this is a part
|
|
917
|
+
this.root.updateSegment(this.part, (prev: string | null) => {
|
|
918
|
+
if (prev && prev.length === 1) {
|
|
919
|
+
return `0${prev}`;
|
|
920
|
+
}
|
|
921
|
+
return prev;
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
getSegmentProps() {
|
|
927
|
+
const segmentValues = this.root.segmentValues;
|
|
928
|
+
const placeholder = this.root.placeholder.current;
|
|
929
|
+
const isEmpty = segmentValues[this.part as keyof TimeSegmentValueObj] === null;
|
|
930
|
+
|
|
931
|
+
let value = placeholder;
|
|
932
|
+
if (segmentValues[this.part as keyof TimeSegmentValueObj]) {
|
|
933
|
+
value = placeholder.set({
|
|
934
|
+
[this.part]: Number.parseInt(segmentValues[this.part as keyof TimeSegmentValueObj] as string),
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
const valueNow = value[this.part as keyof TimeValue] as number;
|
|
939
|
+
const valueMin = this.#getMin();
|
|
940
|
+
const valueMax = this.#getMax();
|
|
941
|
+
let valueText = isEmpty ? 'Empty' : `${valueNow}`;
|
|
942
|
+
|
|
943
|
+
// special handling for hour segment with dayPeriod
|
|
944
|
+
if (this.part === 'hour' && 'dayPeriod' in segmentValues && segmentValues.dayPeriod) {
|
|
945
|
+
valueText = isEmpty ? 'Empty' : `${valueNow} ${segmentValues.dayPeriod}`;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
return {
|
|
949
|
+
'aria-label': `${this.part}, `,
|
|
950
|
+
'aria-valuemin': valueMin,
|
|
951
|
+
'aria-valuemax': valueMax,
|
|
952
|
+
'aria-valuenow': valueNow,
|
|
953
|
+
'aria-valuetext': valueText,
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
props = $derived.by(() => {
|
|
958
|
+
return {
|
|
959
|
+
...this.root.sharedSegmentAttrs,
|
|
960
|
+
id: this.opts.id.current,
|
|
961
|
+
...this.getSegmentProps(),
|
|
962
|
+
onkeydown: this.onkeydown,
|
|
963
|
+
onfocusout: this.onfocusout,
|
|
964
|
+
onclick: this.root.handleSegmentClick,
|
|
965
|
+
...this.root.getBaseSegmentAttrs(this.part as SegmentPart, this.opts.id.current),
|
|
966
|
+
...this.attachment,
|
|
967
|
+
};
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
class TimeFieldHourSegmentState extends BaseTimeSegmentState {
|
|
972
|
+
constructor(opts: WithRefOpts, root: TimeFieldRootState) {
|
|
973
|
+
super(opts, root, 'hour', SEGMENT_CONFIGS.hour);
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
override onkeydown(e: BitsKeyboardEvent) {
|
|
977
|
+
const oldUpdateSegment = this.root.updateSegment.bind(this.root);
|
|
978
|
+
|
|
979
|
+
if (e.key.length === 1 && e.key >= '0' && e.key <= '9') {
|
|
980
|
+
this.root.hourInputDayPeriodHint = this.root.hourCycle === 24 ? null : this.root.segmentValues.dayPeriod;
|
|
981
|
+
this.root.updateSegment = <T extends EditableTimeSegmentPart>(part: T, cb: Updater<TimeSegmentObj[T]>): void => {
|
|
982
|
+
oldUpdateSegment(part, cb);
|
|
983
|
+
|
|
984
|
+
// after updating hour, check if we need to display "12" instead of "0"
|
|
985
|
+
if (part === 'hour' && 'hour' in this.root.segmentValues) {
|
|
986
|
+
const hourValue = this.root.segmentValues.hour;
|
|
987
|
+
if (hourValue === '0' && this.root.dayPeriodNode && this.root.hourCycle !== 24) {
|
|
988
|
+
this.root.segmentValues.hour = '12';
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
super.onkeydown(e);
|
|
995
|
+
|
|
996
|
+
this.root.updateSegment = oldUpdateSegment;
|
|
997
|
+
this.root.hourInputDayPeriodHint = null;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
class TimeFieldMinuteSegmentState extends BaseTimeSegmentState {
|
|
1002
|
+
constructor(opts: WithRefOpts, root: TimeFieldRootState) {
|
|
1003
|
+
super(opts, root, 'minute', SEGMENT_CONFIGS.minute);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
class TimeFieldSecondSegmentState extends BaseTimeSegmentState {
|
|
1008
|
+
constructor(opts: WithRefOpts, root: TimeFieldRootState) {
|
|
1009
|
+
super(opts, root, 'second', SEGMENT_CONFIGS.second);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
interface TimeFieldDayPeriodSegmentStateOpts extends WithRefOpts {}
|
|
1014
|
+
|
|
1015
|
+
class TimeFieldDayPeriodSegmentState {
|
|
1016
|
+
readonly opts: TimeFieldDayPeriodSegmentStateOpts;
|
|
1017
|
+
readonly root: TimeFieldRootState;
|
|
1018
|
+
readonly attachment: RefAttachment;
|
|
1019
|
+
#announcer: Announcer;
|
|
1020
|
+
|
|
1021
|
+
constructor(opts: TimeFieldDayPeriodSegmentStateOpts, root: TimeFieldRootState) {
|
|
1022
|
+
this.opts = opts;
|
|
1023
|
+
this.root = root;
|
|
1024
|
+
this.#announcer = this.root.announcer;
|
|
1025
|
+
this.attachment = attachRef(opts.ref, (v) => (this.root.dayPeriodNode = v));
|
|
1026
|
+
this.onkeydown = this.onkeydown.bind(this);
|
|
1027
|
+
this.onbeforeinput = this.onbeforeinput.bind(this);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
onbeforeinput(e: BitsInputEvent) {
|
|
1031
|
+
if (this.root.disabled.current) return;
|
|
1032
|
+
|
|
1033
|
+
const data = typeof e.data === 'string' ? e.data.trim().toLowerCase() : '';
|
|
1034
|
+
if (!data) return;
|
|
1035
|
+
|
|
1036
|
+
e.preventDefault();
|
|
1037
|
+
|
|
1038
|
+
if (data === 'a' || data === 'p') {
|
|
1039
|
+
this.root.updateSegment('dayPeriod', () => {
|
|
1040
|
+
const next = data === 'a' ? 'AM' : 'PM';
|
|
1041
|
+
this.#announcer.announce(next);
|
|
1042
|
+
return next;
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
onkeydown(e: BitsKeyboardEvent) {
|
|
1048
|
+
if (e.ctrlKey || e.metaKey || this.root.disabled.current) return;
|
|
1049
|
+
|
|
1050
|
+
if (e.key !== kbd.TAB) e.preventDefault();
|
|
1051
|
+
if (!isAcceptableDayPeriodKey(e.key)) return;
|
|
1052
|
+
|
|
1053
|
+
if (isArrowUp(e.key) || isArrowDown(e.key)) {
|
|
1054
|
+
this.root.updateSegment('dayPeriod', (prev) => {
|
|
1055
|
+
if (prev === 'AM') {
|
|
1056
|
+
const next = 'PM';
|
|
1057
|
+
this.#announcer.announce(next);
|
|
1058
|
+
return next;
|
|
1059
|
+
}
|
|
1060
|
+
const next = 'AM';
|
|
1061
|
+
this.#announcer.announce(next);
|
|
1062
|
+
return next;
|
|
1063
|
+
});
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
if (isBackspace(e.key)) {
|
|
1068
|
+
this.root.states.dayPeriod.hasLeftFocus = false;
|
|
1069
|
+
this.root.updateSegment('dayPeriod', () => {
|
|
1070
|
+
const next = 'AM';
|
|
1071
|
+
this.#announcer.announce(next);
|
|
1072
|
+
return next;
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
if (e.key === kbd.A || e.key === kbd.P || e.key === kbd.a || e.key === kbd.p) {
|
|
1077
|
+
this.root.updateSegment('dayPeriod', () => {
|
|
1078
|
+
const next = e.key === kbd.A || e.key === kbd.a ? 'AM' : 'PM';
|
|
1079
|
+
this.#announcer.announce(next);
|
|
1080
|
+
return next;
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
if (isSegmentNavigationKey(e.key)) {
|
|
1085
|
+
handleTimeSegmentNavigation(e, this.root.getFieldNode());
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
readonly props = $derived.by(() => {
|
|
1090
|
+
const segmentValues = this.root.segmentValues;
|
|
1091
|
+
if (!('dayPeriod' in segmentValues)) return;
|
|
1092
|
+
|
|
1093
|
+
const valueMin = 0;
|
|
1094
|
+
const valueMax = 12;
|
|
1095
|
+
const valueNow = segmentValues.dayPeriod === 'AM' ? 0 : 12;
|
|
1096
|
+
const valueText = segmentValues.dayPeriod === 'AM' ? 'AM' : 'PM';
|
|
1097
|
+
|
|
1098
|
+
return {
|
|
1099
|
+
...this.root.sharedSegmentAttrs,
|
|
1100
|
+
id: this.opts.id.current,
|
|
1101
|
+
inputmode: 'text',
|
|
1102
|
+
'aria-label': 'AM/PM',
|
|
1103
|
+
'aria-valuemin': valueMin,
|
|
1104
|
+
'aria-valuemax': valueMax,
|
|
1105
|
+
'aria-valuenow': valueNow,
|
|
1106
|
+
'aria-valuetext': valueText,
|
|
1107
|
+
onkeydown: this.onkeydown,
|
|
1108
|
+
onbeforeinput: this.onbeforeinput,
|
|
1109
|
+
onclick: this.root.handleSegmentClick,
|
|
1110
|
+
...this.root.getBaseSegmentAttrs('dayPeriod', this.opts.id.current),
|
|
1111
|
+
...this.attachment,
|
|
1112
|
+
};
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
interface TimeFieldLiteralSegmentStateOpts extends WithRefOpts {}
|
|
1117
|
+
|
|
1118
|
+
class TimeFieldLiteralSegmentState {
|
|
1119
|
+
readonly opts: TimeFieldLiteralSegmentStateOpts;
|
|
1120
|
+
readonly root: TimeFieldRootState;
|
|
1121
|
+
readonly attachment: RefAttachment;
|
|
1122
|
+
|
|
1123
|
+
constructor(opts: TimeFieldLiteralSegmentStateOpts, root: TimeFieldRootState) {
|
|
1124
|
+
this.opts = opts;
|
|
1125
|
+
this.root = root;
|
|
1126
|
+
this.attachment = attachRef(opts.ref);
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
readonly props = $derived.by(
|
|
1130
|
+
() =>
|
|
1131
|
+
({
|
|
1132
|
+
id: this.opts.id.current,
|
|
1133
|
+
'aria-hidden': boolToStrTrueOrUndef(true),
|
|
1134
|
+
...this.root.getBaseSegmentAttrs('literal', this.opts.id.current),
|
|
1135
|
+
...this.attachment,
|
|
1136
|
+
}) as const,
|
|
1137
|
+
);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
class TimeFieldTimeZoneSegmentState {
|
|
1141
|
+
readonly opts: TimeFieldLiteralSegmentStateOpts;
|
|
1142
|
+
readonly root: TimeFieldRootState;
|
|
1143
|
+
readonly attachment: RefAttachment;
|
|
1144
|
+
|
|
1145
|
+
constructor(opts: TimeFieldLiteralSegmentStateOpts, root: TimeFieldRootState) {
|
|
1146
|
+
this.opts = opts;
|
|
1147
|
+
this.root = root;
|
|
1148
|
+
this.attachment = attachRef(opts.ref);
|
|
1149
|
+
this.onkeydown = this.onkeydown.bind(this);
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
onkeydown(e: BitsKeyboardEvent) {
|
|
1153
|
+
if (e.key !== kbd.TAB) e.preventDefault();
|
|
1154
|
+
if (this.root.disabled.current) return;
|
|
1155
|
+
if (isSegmentNavigationKey(e.key)) {
|
|
1156
|
+
handleTimeSegmentNavigation(e, this.root.getFieldNode());
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
readonly props = $derived.by(
|
|
1161
|
+
() =>
|
|
1162
|
+
({
|
|
1163
|
+
role: 'textbox',
|
|
1164
|
+
id: this.opts.id.current,
|
|
1165
|
+
'aria-label': 'timezone, ',
|
|
1166
|
+
style: {
|
|
1167
|
+
caretColor: 'transparent',
|
|
1168
|
+
},
|
|
1169
|
+
onkeydown: this.onkeydown,
|
|
1170
|
+
tabindex: 0,
|
|
1171
|
+
...this.root.getBaseSegmentAttrs('timeZoneName', this.opts.id.current),
|
|
1172
|
+
'data-readonly': boolToEmptyStrOrUndef(true),
|
|
1173
|
+
...this.attachment,
|
|
1174
|
+
}) as const,
|
|
1175
|
+
);
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
export class TimeFieldSegmentState {
|
|
1179
|
+
static create(part: SegmentPart, opts: WithRefOpts) {
|
|
1180
|
+
const root = getTimeFieldRoot();
|
|
1181
|
+
switch (part) {
|
|
1182
|
+
case 'hour':
|
|
1183
|
+
return new TimeFieldHourSegmentState(opts, root);
|
|
1184
|
+
case 'minute':
|
|
1185
|
+
return new TimeFieldMinuteSegmentState(opts, root);
|
|
1186
|
+
case 'second':
|
|
1187
|
+
return new TimeFieldSecondSegmentState(opts, root);
|
|
1188
|
+
case 'dayPeriod':
|
|
1189
|
+
return new TimeFieldDayPeriodSegmentState(opts, root);
|
|
1190
|
+
case 'literal':
|
|
1191
|
+
return new TimeFieldLiteralSegmentState(opts, root);
|
|
1192
|
+
case 'timeZoneName':
|
|
1193
|
+
return new TimeFieldTimeZoneSegmentState(opts, root);
|
|
1194
|
+
default:
|
|
1195
|
+
throw new Error(`Invalid part: ${part}`);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|