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,1081 @@
|
|
|
1
|
+
import { type DateValue, getLocalTimeZone, isSameDay, isSameMonth, isToday } from '@internationalized/date';
|
|
2
|
+
import { DEV } from 'esm-env';
|
|
3
|
+
import { createContext, onMount, untrack } from 'svelte';
|
|
4
|
+
import { attachRef, DOMContext, type ReadableBoxedValues, type WritableBoxedValues } from '../../internal/tools/index.js';
|
|
5
|
+
import type { RangeCalendarRootState } from '../range-calendar/range-calendar.svelte.js';
|
|
6
|
+
import { boolToStr, boolToStrTrueOrUndef, boolToEmptyStrOrUndef } from '../../internal/attrs.js';
|
|
7
|
+
import type { BitsKeyboardEvent, BitsMouseEvent, RefAttachment, WithRefOpts } from '../../internal/types.js';
|
|
8
|
+
import { createId } from '../../internal/create-id.js';
|
|
9
|
+
import type { DateMatcher, Month } from '../../internal/index.js';
|
|
10
|
+
import { type Announcer, getAnnouncer } from '../../internal/date-time/announcer.js';
|
|
11
|
+
import { type Formatter, createFormatter } from '../../internal/date-time/formatter.js';
|
|
12
|
+
import {
|
|
13
|
+
calendarAttrs,
|
|
14
|
+
createAccessibleHeading,
|
|
15
|
+
createMonths,
|
|
16
|
+
getCalendarElementProps,
|
|
17
|
+
getCalendarHeadingValue,
|
|
18
|
+
getDateWithPreviousTime,
|
|
19
|
+
getDefaultYears,
|
|
20
|
+
getIsNextButtonDisabled,
|
|
21
|
+
getIsPrevButtonDisabled,
|
|
22
|
+
getWeekdays,
|
|
23
|
+
handleCalendarKeydown,
|
|
24
|
+
shiftCalendarFocus,
|
|
25
|
+
shiftCalendarPage,
|
|
26
|
+
shiftCalendarYear,
|
|
27
|
+
setCalendarMonth,
|
|
28
|
+
setCalendarYear,
|
|
29
|
+
isOutsideCalendarView,
|
|
30
|
+
useEnsureNonDisabledPlaceholder,
|
|
31
|
+
} from '../../internal/date-time/calendar-helpers.svelte.js';
|
|
32
|
+
import { getDateValueType, isBefore, toDate } from '../../internal/date-time/utils.js';
|
|
33
|
+
import type { WeekStartsOn } from '../../internal/date-time/types.js';
|
|
34
|
+
|
|
35
|
+
interface CalendarRootStateOpts
|
|
36
|
+
extends
|
|
37
|
+
WithRefOpts,
|
|
38
|
+
WritableBoxedValues<{
|
|
39
|
+
value: DateValue | undefined | DateValue[];
|
|
40
|
+
placeholder: DateValue;
|
|
41
|
+
}>,
|
|
42
|
+
ReadableBoxedValues<{
|
|
43
|
+
preventDeselect: boolean;
|
|
44
|
+
minValue: DateValue | undefined;
|
|
45
|
+
maxValue: DateValue | undefined;
|
|
46
|
+
disabled: boolean;
|
|
47
|
+
pagedNavigation: boolean;
|
|
48
|
+
weekStartsOn: WeekStartsOn | undefined;
|
|
49
|
+
weekdayFormat: Intl.DateTimeFormatOptions['weekday'];
|
|
50
|
+
isDateDisabled: DateMatcher;
|
|
51
|
+
isDateUnavailable: DateMatcher;
|
|
52
|
+
fixedWeeks: boolean;
|
|
53
|
+
numberOfMonths: number;
|
|
54
|
+
locale: string;
|
|
55
|
+
calendarLabel: string;
|
|
56
|
+
type: 'single' | 'multiple';
|
|
57
|
+
readonly: boolean;
|
|
58
|
+
disableDaysOutsideMonth: boolean;
|
|
59
|
+
initialFocus: boolean;
|
|
60
|
+
maxDays: number | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* This is strictly used by the `DatePicker` component to close the popover when a date
|
|
63
|
+
* is selected. It is not intended to be used by the user.
|
|
64
|
+
*/
|
|
65
|
+
onDateSelect?: () => void;
|
|
66
|
+
monthFormat: Intl.DateTimeFormatOptions['month'] | ((month: number) => string);
|
|
67
|
+
yearFormat: Intl.DateTimeFormatOptions['year'] | ((year: number) => string);
|
|
68
|
+
}> {
|
|
69
|
+
defaultPlaceholder: DateValue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const [getCalendarRoot, setCalendarRoot] = createContext<CalendarRootState | RangeCalendarRootState>();
|
|
73
|
+
|
|
74
|
+
export class CalendarRootState {
|
|
75
|
+
static create(opts: CalendarRootStateOpts) {
|
|
76
|
+
return setCalendarRoot(new CalendarRootState(opts));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
readonly opts: CalendarRootStateOpts;
|
|
80
|
+
readonly visibleMonths = $derived.by(() => this.months.map((month) => month.value));
|
|
81
|
+
readonly formatter: Formatter;
|
|
82
|
+
readonly accessibleHeadingId: string;
|
|
83
|
+
readonly domContext: DOMContext;
|
|
84
|
+
readonly attachment: RefAttachment;
|
|
85
|
+
/** The month anchoring the view. Owned by navigation; the placeholder follow effect snaps it. */
|
|
86
|
+
#anchor = $state.raw<DateValue | undefined>(undefined);
|
|
87
|
+
readonly months = $derived.by((): Month<DateValue>[] => {
|
|
88
|
+
const anchor = this.#anchor;
|
|
89
|
+
if (!anchor) return [];
|
|
90
|
+
return createMonths({
|
|
91
|
+
dateObj: anchor,
|
|
92
|
+
weekStartsOn: this.opts.weekStartsOn.current,
|
|
93
|
+
locale: this.opts.locale.current,
|
|
94
|
+
fixedWeeks: this.opts.fixedWeeks.current,
|
|
95
|
+
numberOfMonths: this.opts.numberOfMonths.current,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
announcer: Announcer;
|
|
99
|
+
|
|
100
|
+
constructor(opts: CalendarRootStateOpts) {
|
|
101
|
+
this.opts = opts;
|
|
102
|
+
this.accessibleHeadingId = createId('heading', opts.id.current);
|
|
103
|
+
this.attachment = attachRef(this.opts.ref);
|
|
104
|
+
this.domContext = new DOMContext(opts.ref);
|
|
105
|
+
this.announcer = getAnnouncer(null);
|
|
106
|
+
this.formatter = createFormatter({
|
|
107
|
+
locale: this.opts.locale,
|
|
108
|
+
monthFormat: this.opts.monthFormat,
|
|
109
|
+
yearFormat: this.opts.yearFormat,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
this.nextPage = this.nextPage.bind(this);
|
|
113
|
+
this.prevPage = this.prevPage.bind(this);
|
|
114
|
+
this.prevYear = this.prevYear.bind(this);
|
|
115
|
+
this.nextYear = this.nextYear.bind(this);
|
|
116
|
+
this.setYear = this.setYear.bind(this);
|
|
117
|
+
this.setMonth = this.setMonth.bind(this);
|
|
118
|
+
this.isOutsideVisibleMonths = this.isOutsideVisibleMonths.bind(this);
|
|
119
|
+
this.isDateDisabled = this.isDateDisabled.bind(this);
|
|
120
|
+
this.isDateSelected = this.isDateSelected.bind(this);
|
|
121
|
+
this.shiftFocus = this.shiftFocus.bind(this);
|
|
122
|
+
this.handleCellClick = this.handleCellClick.bind(this);
|
|
123
|
+
this.handleMultipleUpdate = this.handleMultipleUpdate.bind(this);
|
|
124
|
+
this.handleSingleUpdate = this.handleSingleUpdate.bind(this);
|
|
125
|
+
this.onkeydown = this.onkeydown.bind(this);
|
|
126
|
+
this.getBitsAttr = this.getBitsAttr.bind(this);
|
|
127
|
+
|
|
128
|
+
onMount(() => {
|
|
129
|
+
this.announcer = getAnnouncer(this.domContext.getDocument());
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
this.#anchor = this.opts.placeholder.current;
|
|
133
|
+
|
|
134
|
+
this.#setupInitialFocusEffect();
|
|
135
|
+
this.#setupAccessibleHeadingEffect();
|
|
136
|
+
|
|
137
|
+
// Snap the view when the placeholder moves outside it (keyboard nav, dropdowns, external binds).
|
|
138
|
+
$effect(() => {
|
|
139
|
+
const placeholder = this.opts.placeholder.current;
|
|
140
|
+
untrack(() => {
|
|
141
|
+
if (!this.visibleMonths.some((month) => isSameMonth(month, placeholder))) {
|
|
142
|
+
this.#anchor = placeholder;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Update the accessible heading's text content when the `fullCalendarLabel`
|
|
149
|
+
* changes.
|
|
150
|
+
*/
|
|
151
|
+
$effect(() => {
|
|
152
|
+
const label = this.fullCalendarLabel;
|
|
153
|
+
untrack(() => {
|
|
154
|
+
const node = this.domContext.getElementById(this.accessibleHeadingId);
|
|
155
|
+
if (!node) return;
|
|
156
|
+
node.textContent = label;
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The selected value controls the calendar's placeholder/view month, and
|
|
162
|
+
* parents using bind:placeholder should observe that navigation-state update.
|
|
163
|
+
*/
|
|
164
|
+
$effect(() => {
|
|
165
|
+
this.opts.value.current;
|
|
166
|
+
untrack(() => {
|
|
167
|
+
const value = this.opts.value.current;
|
|
168
|
+
if (Array.isArray(value) && value.length) {
|
|
169
|
+
const lastValue = value[value.length - 1];
|
|
170
|
+
if (lastValue && this.opts.placeholder.current !== lastValue) {
|
|
171
|
+
this.opts.placeholder.current = lastValue;
|
|
172
|
+
}
|
|
173
|
+
} else if (!Array.isArray(value) && value && this.opts.placeholder.current !== value) {
|
|
174
|
+
this.opts.placeholder.current = value;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
useEnsureNonDisabledPlaceholder({
|
|
180
|
+
placeholder: opts.placeholder,
|
|
181
|
+
defaultPlaceholder: opts.defaultPlaceholder,
|
|
182
|
+
isDateDisabled: opts.isDateDisabled,
|
|
183
|
+
maxValue: opts.maxValue,
|
|
184
|
+
minValue: opts.minValue,
|
|
185
|
+
ref: opts.ref,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* This derived state holds an array of localized day names for the current
|
|
191
|
+
* locale and calendar view. It dynamically syncs with the 'weekStartsOn' option,
|
|
192
|
+
* updating its content when the option changes. Using this state to render the
|
|
193
|
+
* calendar's days of the week is strongly recommended, as it guarantees that
|
|
194
|
+
* the days are correctly formatted for the current locale and calendar view.
|
|
195
|
+
*/
|
|
196
|
+
readonly weekdays = $derived.by(() => {
|
|
197
|
+
return getWeekdays({
|
|
198
|
+
months: this.months,
|
|
199
|
+
formatter: this.formatter,
|
|
200
|
+
weekdayFormat: this.opts.weekdayFormat.current,
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
readonly initialPlaceholderYear = $derived.by(() => untrack(() => this.opts.placeholder.current.year));
|
|
205
|
+
|
|
206
|
+
readonly defaultYears = $derived.by(() => {
|
|
207
|
+
return getDefaultYears({
|
|
208
|
+
minValue: this.opts.minValue.current,
|
|
209
|
+
maxValue: this.opts.maxValue.current,
|
|
210
|
+
placeholderYear: this.initialPlaceholderYear,
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
#setupInitialFocusEffect() {
|
|
215
|
+
$effect(() => {
|
|
216
|
+
const initialFocus = untrack(() => this.opts.initialFocus.current);
|
|
217
|
+
if (initialFocus) {
|
|
218
|
+
// focus the first `data-focused` day node
|
|
219
|
+
const firstFocusedDay = this.opts.ref.current?.querySelector<HTMLElement>(`[data-focused]`);
|
|
220
|
+
if (firstFocusedDay) {
|
|
221
|
+
firstFocusedDay.focus();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
#setupAccessibleHeadingEffect() {
|
|
228
|
+
$effect(() => {
|
|
229
|
+
if (!this.opts.ref.current) return;
|
|
230
|
+
const removeHeading = createAccessibleHeading({
|
|
231
|
+
calendarNode: this.opts.ref.current,
|
|
232
|
+
label: untrack(() => this.fullCalendarLabel),
|
|
233
|
+
accessibleHeadingId: this.accessibleHeadingId,
|
|
234
|
+
});
|
|
235
|
+
return removeHeading;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Navigates to the next page of the calendar.
|
|
241
|
+
*/
|
|
242
|
+
nextPage() {
|
|
243
|
+
this.#shiftView(1);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Navigates to the previous page of the calendar.
|
|
248
|
+
*/
|
|
249
|
+
prevPage() {
|
|
250
|
+
this.#shiftView(-1);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** Moves the anchor a page (or single month) and keeps the placeholder in the new view. */
|
|
254
|
+
#shiftView(direction: 1 | -1) {
|
|
255
|
+
shiftCalendarPage({
|
|
256
|
+
months: this.months,
|
|
257
|
+
placeholder: this.opts.placeholder,
|
|
258
|
+
pagedNavigation: this.opts.pagedNavigation.current,
|
|
259
|
+
numberOfMonths: this.opts.numberOfMonths.current,
|
|
260
|
+
direction,
|
|
261
|
+
setAnchor: (value) => (this.#anchor = value),
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
nextYear() {
|
|
266
|
+
shiftCalendarYear(this.opts.placeholder, 1);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
prevYear() {
|
|
270
|
+
shiftCalendarYear(this.opts.placeholder, -1);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
setYear(year: number) {
|
|
274
|
+
setCalendarYear(this.opts.placeholder, year);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
setMonth(month: number) {
|
|
278
|
+
setCalendarMonth(this.opts.placeholder, month);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
isNextButtonDisabled = $derived.by(() => {
|
|
282
|
+
return getIsNextButtonDisabled({
|
|
283
|
+
maxValue: this.opts.maxValue.current,
|
|
284
|
+
months: this.months,
|
|
285
|
+
disabled: this.opts.disabled.current,
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
isPrevButtonDisabled = $derived.by(() => {
|
|
290
|
+
return getIsPrevButtonDisabled({
|
|
291
|
+
minValue: this.opts.minValue.current,
|
|
292
|
+
months: this.months,
|
|
293
|
+
disabled: this.opts.disabled.current,
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
isInvalid = $derived.by(() => {
|
|
298
|
+
const value = this.opts.value.current;
|
|
299
|
+
const isDateDisabled = this.opts.isDateDisabled.current;
|
|
300
|
+
const isDateUnavailable = this.opts.isDateUnavailable.current;
|
|
301
|
+
if (Array.isArray(value)) {
|
|
302
|
+
if (!value.length) return false;
|
|
303
|
+
for (const date of value) {
|
|
304
|
+
if (isDateDisabled(date)) return true;
|
|
305
|
+
if (isDateUnavailable(date)) return true;
|
|
306
|
+
}
|
|
307
|
+
} else {
|
|
308
|
+
if (!value) return false;
|
|
309
|
+
if (isDateDisabled(value)) return true;
|
|
310
|
+
if (isDateUnavailable(value)) return true;
|
|
311
|
+
}
|
|
312
|
+
return false;
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
readonly headingValue = $derived.by(() => {
|
|
316
|
+
this.opts.monthFormat.current;
|
|
317
|
+
this.opts.yearFormat.current;
|
|
318
|
+
return getCalendarHeadingValue({
|
|
319
|
+
months: this.months,
|
|
320
|
+
formatter: this.formatter,
|
|
321
|
+
locale: this.opts.locale.current,
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
readonly fullCalendarLabel = $derived.by(() => {
|
|
326
|
+
return `${this.opts.calendarLabel.current} ${this.headingValue}`;
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
isOutsideVisibleMonths(date: DateValue) {
|
|
330
|
+
return isOutsideCalendarView(this.visibleMonths, date);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
isDateDisabled(date: DateValue) {
|
|
334
|
+
if (this.opts.isDateDisabled.current(date) || this.opts.disabled.current) return true;
|
|
335
|
+
const minValue = this.opts.minValue.current;
|
|
336
|
+
const maxValue = this.opts.maxValue.current;
|
|
337
|
+
if (minValue && isBefore(date, minValue)) return true;
|
|
338
|
+
if (maxValue && isBefore(maxValue, date)) return true;
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
isDateSelected(date: DateValue) {
|
|
343
|
+
const value = this.opts.value.current;
|
|
344
|
+
if (Array.isArray(value)) {
|
|
345
|
+
return value.some((d) => isSameDay(d, date));
|
|
346
|
+
} else if (!value) {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
return isSameDay(value, date);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
shiftFocus(node: HTMLElement, add: number) {
|
|
353
|
+
return shiftCalendarFocus({
|
|
354
|
+
node,
|
|
355
|
+
add,
|
|
356
|
+
placeholder: this.opts.placeholder,
|
|
357
|
+
calendarNode: this.opts.ref.current,
|
|
358
|
+
isPrevButtonDisabled: this.isPrevButtonDisabled,
|
|
359
|
+
isNextButtonDisabled: this.isNextButtonDisabled,
|
|
360
|
+
months: this.months,
|
|
361
|
+
numberOfMonths: this.opts.numberOfMonths.current,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
#isMultipleSelectionValid(selectedDates: DateValue[]): boolean {
|
|
366
|
+
// only validate for multiple type and when maxDays is set
|
|
367
|
+
if (this.opts.type.current !== 'multiple') return true;
|
|
368
|
+
if (!this.opts.maxDays.current) return true;
|
|
369
|
+
const selectedCount = selectedDates.length;
|
|
370
|
+
if (this.opts.maxDays.current && selectedCount > this.opts.maxDays.current) return false;
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
handleCellClick(_: Event, date: DateValue) {
|
|
375
|
+
if (this.opts.readonly.current || this.opts.isDateDisabled.current?.(date) || this.opts.isDateUnavailable.current?.(date)) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const prev = this.opts.value.current;
|
|
380
|
+
const multiple = this.opts.type.current === 'multiple';
|
|
381
|
+
if (multiple) {
|
|
382
|
+
if (Array.isArray(prev) || prev === undefined) {
|
|
383
|
+
this.opts.value.current = this.handleMultipleUpdate(prev, date);
|
|
384
|
+
}
|
|
385
|
+
} else if (!Array.isArray(prev)) {
|
|
386
|
+
const next = this.handleSingleUpdate(prev, date);
|
|
387
|
+
if (!next) {
|
|
388
|
+
this.announcer.announce('Selected date is now empty.', 'polite', 5000);
|
|
389
|
+
} else {
|
|
390
|
+
this.announcer.announce(`Selected Date: ${this.formatter.selectedDate(next, false)}`, 'polite');
|
|
391
|
+
}
|
|
392
|
+
this.opts.value.current = getDateWithPreviousTime(next, prev);
|
|
393
|
+
if (next !== undefined) {
|
|
394
|
+
this.opts.onDateSelect?.current?.();
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
handleMultipleUpdate(prev: DateValue[] | undefined, date: DateValue) {
|
|
400
|
+
if (!prev) {
|
|
401
|
+
const newSelection = [date];
|
|
402
|
+
return this.#isMultipleSelectionValid(newSelection) ? newSelection : [date];
|
|
403
|
+
}
|
|
404
|
+
if (!Array.isArray(prev)) {
|
|
405
|
+
if (DEV) throw new Error('Invalid value for multiple prop.');
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const index = prev.findIndex((d) => isSameDay(d, date));
|
|
409
|
+
const preventDeselect = this.opts.preventDeselect.current;
|
|
410
|
+
if (index === -1) {
|
|
411
|
+
// adding a new date - check if it would be valid
|
|
412
|
+
const newSelection = [...prev, date];
|
|
413
|
+
if (this.#isMultipleSelectionValid(newSelection)) {
|
|
414
|
+
return newSelection;
|
|
415
|
+
} else {
|
|
416
|
+
// reset to just the newly selected date when constraints are violated
|
|
417
|
+
return [date];
|
|
418
|
+
}
|
|
419
|
+
} else if (preventDeselect) {
|
|
420
|
+
return prev;
|
|
421
|
+
} else {
|
|
422
|
+
const next = prev.filter((d) => !isSameDay(d, date));
|
|
423
|
+
if (!next.length) {
|
|
424
|
+
this.opts.placeholder.current = date;
|
|
425
|
+
return undefined;
|
|
426
|
+
}
|
|
427
|
+
return next;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
handleSingleUpdate(prev: DateValue | undefined, date: DateValue) {
|
|
432
|
+
if (Array.isArray(prev)) {
|
|
433
|
+
if (DEV) throw new Error('Invalid value for single prop.');
|
|
434
|
+
}
|
|
435
|
+
if (!prev) return date;
|
|
436
|
+
const preventDeselect = this.opts.preventDeselect.current;
|
|
437
|
+
if (!preventDeselect && isSameDay(prev, date)) {
|
|
438
|
+
this.opts.placeholder.current = date;
|
|
439
|
+
return undefined;
|
|
440
|
+
}
|
|
441
|
+
return date;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
onkeydown(event: BitsKeyboardEvent) {
|
|
445
|
+
handleCalendarKeydown({
|
|
446
|
+
event,
|
|
447
|
+
handleCellClick: this.handleCellClick,
|
|
448
|
+
shiftFocus: this.shiftFocus,
|
|
449
|
+
placeholderValue: this.opts.placeholder.current,
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
readonly snippetProps = $derived.by(() => ({
|
|
454
|
+
months: this.months,
|
|
455
|
+
weekdays: this.weekdays,
|
|
456
|
+
}));
|
|
457
|
+
|
|
458
|
+
getBitsAttr: (typeof calendarAttrs)['getAttr'] = (part) => {
|
|
459
|
+
return calendarAttrs.getAttr(part);
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
readonly props = $derived.by(
|
|
463
|
+
() =>
|
|
464
|
+
({
|
|
465
|
+
...getCalendarElementProps({
|
|
466
|
+
fullCalendarLabel: this.fullCalendarLabel,
|
|
467
|
+
id: this.opts.id.current,
|
|
468
|
+
isInvalid: this.isInvalid,
|
|
469
|
+
disabled: this.opts.disabled.current,
|
|
470
|
+
readonly: this.opts.readonly.current,
|
|
471
|
+
}),
|
|
472
|
+
[this.getBitsAttr('root')]: '',
|
|
473
|
+
//
|
|
474
|
+
onkeydown: this.onkeydown,
|
|
475
|
+
...this.attachment,
|
|
476
|
+
}) as const,
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
interface CalendarHeadingStateOpts extends WithRefOpts {}
|
|
481
|
+
|
|
482
|
+
export class CalendarHeadingState {
|
|
483
|
+
static create(opts: CalendarHeadingStateOpts) {
|
|
484
|
+
return new CalendarHeadingState(opts, getCalendarRoot());
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
readonly opts: CalendarHeadingStateOpts;
|
|
488
|
+
readonly root: CalendarRootState | RangeCalendarRootState;
|
|
489
|
+
readonly attachment: RefAttachment;
|
|
490
|
+
|
|
491
|
+
constructor(opts: CalendarHeadingStateOpts, root: CalendarRootState | RangeCalendarRootState) {
|
|
492
|
+
this.opts = opts;
|
|
493
|
+
this.root = root;
|
|
494
|
+
this.attachment = attachRef(this.opts.ref);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
readonly props = $derived.by(
|
|
498
|
+
() =>
|
|
499
|
+
({
|
|
500
|
+
id: this.opts.id.current,
|
|
501
|
+
'aria-hidden': boolToStrTrueOrUndef(true),
|
|
502
|
+
'data-disabled': boolToEmptyStrOrUndef(this.root.opts.disabled.current),
|
|
503
|
+
'data-readonly': boolToEmptyStrOrUndef(this.root.opts.readonly.current),
|
|
504
|
+
[this.root.getBitsAttr('heading')]: '',
|
|
505
|
+
...this.attachment,
|
|
506
|
+
}) as const,
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const [getCalendarCell, setCalendarCell] = createContext<CalendarCellState>();
|
|
511
|
+
|
|
512
|
+
interface CalendarCellStateOpts
|
|
513
|
+
extends
|
|
514
|
+
WithRefOpts,
|
|
515
|
+
ReadableBoxedValues<{
|
|
516
|
+
date: DateValue;
|
|
517
|
+
month: DateValue;
|
|
518
|
+
}> {}
|
|
519
|
+
|
|
520
|
+
export class CalendarCellState {
|
|
521
|
+
static create(opts: CalendarCellStateOpts) {
|
|
522
|
+
return setCalendarCell(new CalendarCellState(opts, getCalendarRoot() as CalendarRootState));
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
readonly opts: CalendarCellStateOpts;
|
|
526
|
+
readonly root: CalendarRootState;
|
|
527
|
+
readonly cellDate = $derived.by(() => toDate(this.opts.date.current));
|
|
528
|
+
readonly isUnavailable = $derived.by(() => this.root.opts.isDateUnavailable.current(this.opts.date.current));
|
|
529
|
+
readonly isDateToday = $derived.by(() => isToday(this.opts.date.current, getLocalTimeZone()));
|
|
530
|
+
readonly isOutsideMonth = $derived.by(() => !isSameMonth(this.opts.date.current, this.opts.month.current));
|
|
531
|
+
readonly isOutsideVisibleMonths = $derived.by(() => this.root.isOutsideVisibleMonths(this.opts.date.current));
|
|
532
|
+
readonly isDisabled = $derived.by(
|
|
533
|
+
() => this.root.isDateDisabled(this.opts.date.current) || (this.isOutsideMonth && this.root.opts.disableDaysOutsideMonth.current),
|
|
534
|
+
);
|
|
535
|
+
readonly isFocusedDate = $derived.by(() => isSameDay(this.opts.date.current, this.root.opts.placeholder.current));
|
|
536
|
+
readonly isSelectedDate = $derived.by(() => this.root.isDateSelected(this.opts.date.current));
|
|
537
|
+
readonly labelText = $derived.by(() =>
|
|
538
|
+
this.root.formatter.custom(this.cellDate, {
|
|
539
|
+
weekday: 'long',
|
|
540
|
+
month: 'long',
|
|
541
|
+
day: 'numeric',
|
|
542
|
+
year: 'numeric',
|
|
543
|
+
}),
|
|
544
|
+
);
|
|
545
|
+
readonly attachment: RefAttachment;
|
|
546
|
+
|
|
547
|
+
constructor(opts: CalendarCellStateOpts, root: CalendarRootState) {
|
|
548
|
+
this.opts = opts;
|
|
549
|
+
this.root = root;
|
|
550
|
+
this.attachment = attachRef(this.opts.ref);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
readonly snippetProps = $derived.by(() => ({
|
|
554
|
+
disabled: this.isDisabled,
|
|
555
|
+
unavailable: this.isUnavailable,
|
|
556
|
+
selected: this.isSelectedDate,
|
|
557
|
+
day: `${this.opts.date.current.day}`,
|
|
558
|
+
}));
|
|
559
|
+
|
|
560
|
+
readonly ariaDisabled = $derived.by(() => {
|
|
561
|
+
return this.isDisabled || (this.isOutsideMonth && this.root.opts.disableDaysOutsideMonth.current) || this.isUnavailable;
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
readonly sharedDataAttrs = $derived.by(
|
|
565
|
+
() =>
|
|
566
|
+
({
|
|
567
|
+
'data-unavailable': boolToEmptyStrOrUndef(this.isUnavailable),
|
|
568
|
+
'data-today': this.isDateToday ? '' : undefined,
|
|
569
|
+
'data-outside-month': this.isOutsideMonth ? '' : undefined,
|
|
570
|
+
'data-outside-visible-months': this.isOutsideVisibleMonths ? '' : undefined,
|
|
571
|
+
'data-focused': this.isFocusedDate ? '' : undefined,
|
|
572
|
+
'data-selected': boolToEmptyStrOrUndef(this.isSelectedDate),
|
|
573
|
+
'data-value': this.opts.date.current.toString(),
|
|
574
|
+
'data-type': getDateValueType(this.opts.date.current),
|
|
575
|
+
'data-disabled': boolToEmptyStrOrUndef(this.isDisabled || (this.isOutsideMonth && this.root.opts.disableDaysOutsideMonth.current)),
|
|
576
|
+
}) as const,
|
|
577
|
+
);
|
|
578
|
+
|
|
579
|
+
readonly props = $derived.by(
|
|
580
|
+
() =>
|
|
581
|
+
({
|
|
582
|
+
id: this.opts.id.current,
|
|
583
|
+
role: 'gridcell',
|
|
584
|
+
'aria-selected': boolToStr(this.isSelectedDate),
|
|
585
|
+
'aria-disabled': boolToStr(this.ariaDisabled),
|
|
586
|
+
...this.sharedDataAttrs,
|
|
587
|
+
[this.root.getBitsAttr('cell')]: '',
|
|
588
|
+
...this.attachment,
|
|
589
|
+
}) as const,
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
interface CalendarDayStateOpts extends WithRefOpts {}
|
|
594
|
+
|
|
595
|
+
export class CalendarDayState {
|
|
596
|
+
static create(opts: CalendarDayStateOpts) {
|
|
597
|
+
return new CalendarDayState(opts, getCalendarCell());
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
readonly opts: CalendarDayStateOpts;
|
|
601
|
+
readonly cell: CalendarCellState;
|
|
602
|
+
readonly attachment: RefAttachment;
|
|
603
|
+
|
|
604
|
+
constructor(opts: CalendarDayStateOpts, cell: CalendarCellState) {
|
|
605
|
+
this.opts = opts;
|
|
606
|
+
this.cell = cell;
|
|
607
|
+
this.onclick = this.onclick.bind(this);
|
|
608
|
+
this.attachment = attachRef(this.opts.ref);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
readonly #tabindex = $derived.by(() =>
|
|
612
|
+
(this.cell.isOutsideMonth && this.cell.root.opts.disableDaysOutsideMonth.current) || this.cell.isDisabled
|
|
613
|
+
? undefined
|
|
614
|
+
: this.cell.isFocusedDate
|
|
615
|
+
? 0
|
|
616
|
+
: -1,
|
|
617
|
+
);
|
|
618
|
+
|
|
619
|
+
onclick(e: BitsMouseEvent) {
|
|
620
|
+
if (this.cell.isDisabled) return;
|
|
621
|
+
this.cell.root.handleCellClick(e, this.cell.opts.date.current);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
readonly snippetProps = $derived.by(() => ({
|
|
625
|
+
disabled: this.cell.isDisabled,
|
|
626
|
+
unavailable: this.cell.isUnavailable,
|
|
627
|
+
selected: this.cell.isSelectedDate,
|
|
628
|
+
day: `${this.cell.opts.date.current.day}`,
|
|
629
|
+
}));
|
|
630
|
+
|
|
631
|
+
readonly props = $derived.by(
|
|
632
|
+
() =>
|
|
633
|
+
({
|
|
634
|
+
id: this.opts.id.current,
|
|
635
|
+
role: 'button',
|
|
636
|
+
'aria-label': this.cell.labelText,
|
|
637
|
+
'aria-disabled': boolToStr(this.cell.ariaDisabled),
|
|
638
|
+
...this.cell.sharedDataAttrs,
|
|
639
|
+
tabindex: this.#tabindex,
|
|
640
|
+
[this.cell.root.getBitsAttr('day')]: '',
|
|
641
|
+
// Shared logic for range calendar and calendar
|
|
642
|
+
'data-bits-day': '',
|
|
643
|
+
//
|
|
644
|
+
onclick: this.onclick,
|
|
645
|
+
...this.attachment,
|
|
646
|
+
}) as const,
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
interface CalendarNextButtonStateOpts extends WithRefOpts {}
|
|
651
|
+
|
|
652
|
+
export class CalendarNextButtonState {
|
|
653
|
+
static create(opts: CalendarNextButtonStateOpts) {
|
|
654
|
+
return new CalendarNextButtonState(opts, getCalendarRoot());
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
readonly opts: CalendarNextButtonStateOpts;
|
|
658
|
+
readonly root: CalendarRootState | RangeCalendarRootState;
|
|
659
|
+
readonly isDisabled = $derived.by(() => this.root.isNextButtonDisabled);
|
|
660
|
+
readonly attachment: RefAttachment;
|
|
661
|
+
|
|
662
|
+
constructor(opts: CalendarNextButtonStateOpts, root: CalendarRootState | RangeCalendarRootState) {
|
|
663
|
+
this.opts = opts;
|
|
664
|
+
this.root = root;
|
|
665
|
+
this.onclick = this.onclick.bind(this);
|
|
666
|
+
this.attachment = attachRef(this.opts.ref);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
onclick(_: BitsMouseEvent) {
|
|
670
|
+
if (this.isDisabled) return;
|
|
671
|
+
this.root.nextPage();
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
readonly props = $derived.by(
|
|
675
|
+
() =>
|
|
676
|
+
({
|
|
677
|
+
id: this.opts.id.current,
|
|
678
|
+
role: 'button',
|
|
679
|
+
type: 'button',
|
|
680
|
+
'aria-label': 'Next',
|
|
681
|
+
'aria-disabled': boolToStr(this.isDisabled),
|
|
682
|
+
'data-disabled': boolToEmptyStrOrUndef(this.isDisabled),
|
|
683
|
+
disabled: this.isDisabled,
|
|
684
|
+
[this.root.getBitsAttr('next-button')]: '',
|
|
685
|
+
//
|
|
686
|
+
onclick: this.onclick,
|
|
687
|
+
...this.attachment,
|
|
688
|
+
}) as const,
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
interface CalendarPrevButtonStateOpts extends WithRefOpts {}
|
|
693
|
+
|
|
694
|
+
export class CalendarPrevButtonState {
|
|
695
|
+
static create(opts: CalendarPrevButtonStateOpts) {
|
|
696
|
+
return new CalendarPrevButtonState(opts, getCalendarRoot());
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
readonly opts: CalendarPrevButtonStateOpts;
|
|
700
|
+
readonly root: CalendarRootState | RangeCalendarRootState;
|
|
701
|
+
readonly isDisabled = $derived.by(() => this.root.isPrevButtonDisabled);
|
|
702
|
+
readonly attachment: RefAttachment;
|
|
703
|
+
|
|
704
|
+
constructor(opts: CalendarPrevButtonStateOpts, root: CalendarRootState | RangeCalendarRootState) {
|
|
705
|
+
this.opts = opts;
|
|
706
|
+
this.root = root;
|
|
707
|
+
this.onclick = this.onclick.bind(this);
|
|
708
|
+
this.attachment = attachRef(this.opts.ref);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
onclick(_: BitsMouseEvent) {
|
|
712
|
+
if (this.isDisabled) return;
|
|
713
|
+
this.root.prevPage();
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
readonly props = $derived.by(
|
|
717
|
+
() =>
|
|
718
|
+
({
|
|
719
|
+
id: this.opts.id.current,
|
|
720
|
+
role: 'button',
|
|
721
|
+
type: 'button',
|
|
722
|
+
'aria-label': 'Previous',
|
|
723
|
+
'aria-disabled': boolToStr(this.isDisabled),
|
|
724
|
+
'data-disabled': boolToEmptyStrOrUndef(this.isDisabled),
|
|
725
|
+
disabled: this.isDisabled,
|
|
726
|
+
[this.root.getBitsAttr('prev-button')]: '',
|
|
727
|
+
//
|
|
728
|
+
onclick: this.onclick,
|
|
729
|
+
...this.attachment,
|
|
730
|
+
}) as const,
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
interface CalendarGridStateOpts extends WithRefOpts {}
|
|
735
|
+
|
|
736
|
+
export class CalendarGridState {
|
|
737
|
+
static create(opts: CalendarGridStateOpts) {
|
|
738
|
+
return new CalendarGridState(opts, getCalendarRoot());
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
readonly opts: CalendarGridStateOpts;
|
|
742
|
+
readonly root: CalendarRootState | RangeCalendarRootState;
|
|
743
|
+
readonly attachment: RefAttachment;
|
|
744
|
+
|
|
745
|
+
constructor(opts: CalendarGridStateOpts, root: CalendarRootState | RangeCalendarRootState) {
|
|
746
|
+
this.opts = opts;
|
|
747
|
+
this.root = root;
|
|
748
|
+
this.attachment = attachRef(this.opts.ref);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
readonly props = $derived.by(
|
|
752
|
+
() =>
|
|
753
|
+
({
|
|
754
|
+
id: this.opts.id.current,
|
|
755
|
+
tabindex: -1,
|
|
756
|
+
role: 'grid',
|
|
757
|
+
'aria-readonly': boolToStr(this.root.opts.readonly.current),
|
|
758
|
+
'aria-disabled': boolToStr(this.root.opts.disabled.current),
|
|
759
|
+
'data-readonly': boolToEmptyStrOrUndef(this.root.opts.readonly.current),
|
|
760
|
+
'data-disabled': boolToEmptyStrOrUndef(this.root.opts.disabled.current),
|
|
761
|
+
[this.root.getBitsAttr('grid')]: '',
|
|
762
|
+
...this.attachment,
|
|
763
|
+
}) as const,
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
interface CalendarGridBodyStateOpts extends WithRefOpts {}
|
|
768
|
+
|
|
769
|
+
export class CalendarGridBodyState {
|
|
770
|
+
static create(opts: CalendarGridBodyStateOpts) {
|
|
771
|
+
return new CalendarGridBodyState(opts, getCalendarRoot());
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
readonly opts: CalendarGridBodyStateOpts;
|
|
775
|
+
readonly root: CalendarRootState | RangeCalendarRootState;
|
|
776
|
+
readonly attachment: RefAttachment;
|
|
777
|
+
|
|
778
|
+
constructor(opts: CalendarGridBodyStateOpts, root: CalendarRootState | RangeCalendarRootState) {
|
|
779
|
+
this.opts = opts;
|
|
780
|
+
this.root = root;
|
|
781
|
+
this.attachment = attachRef(this.opts.ref);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
readonly props = $derived.by(
|
|
785
|
+
() =>
|
|
786
|
+
({
|
|
787
|
+
id: this.opts.id.current,
|
|
788
|
+
'data-disabled': boolToEmptyStrOrUndef(this.root.opts.disabled.current),
|
|
789
|
+
'data-readonly': boolToEmptyStrOrUndef(this.root.opts.readonly.current),
|
|
790
|
+
[this.root.getBitsAttr('grid-body')]: '',
|
|
791
|
+
...this.attachment,
|
|
792
|
+
}) as const,
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
interface CalendarGridHeadStateOpts extends WithRefOpts {}
|
|
797
|
+
|
|
798
|
+
export class CalendarGridHeadState {
|
|
799
|
+
static create(opts: CalendarGridHeadStateOpts) {
|
|
800
|
+
return new CalendarGridHeadState(opts, getCalendarRoot());
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
readonly opts: CalendarGridHeadStateOpts;
|
|
804
|
+
readonly root: CalendarRootState | RangeCalendarRootState;
|
|
805
|
+
readonly attachment: RefAttachment;
|
|
806
|
+
constructor(opts: CalendarGridHeadStateOpts, root: CalendarRootState | RangeCalendarRootState) {
|
|
807
|
+
this.opts = opts;
|
|
808
|
+
this.root = root;
|
|
809
|
+
this.attachment = attachRef(this.opts.ref);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
readonly props = $derived.by(
|
|
813
|
+
() =>
|
|
814
|
+
({
|
|
815
|
+
id: this.opts.id.current,
|
|
816
|
+
'data-disabled': boolToEmptyStrOrUndef(this.root.opts.disabled.current),
|
|
817
|
+
'data-readonly': boolToEmptyStrOrUndef(this.root.opts.readonly.current),
|
|
818
|
+
[this.root.getBitsAttr('grid-head')]: '',
|
|
819
|
+
...this.attachment,
|
|
820
|
+
}) as const,
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
interface CalendarGridRowStateOpts extends WithRefOpts {}
|
|
825
|
+
|
|
826
|
+
export class CalendarGridRowState {
|
|
827
|
+
static create(opts: CalendarGridRowStateOpts) {
|
|
828
|
+
return new CalendarGridRowState(opts, getCalendarRoot());
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
readonly opts: CalendarGridRowStateOpts;
|
|
832
|
+
readonly root: CalendarRootState | RangeCalendarRootState;
|
|
833
|
+
readonly attachment: RefAttachment;
|
|
834
|
+
constructor(opts: CalendarGridRowStateOpts, root: CalendarRootState | RangeCalendarRootState) {
|
|
835
|
+
this.opts = opts;
|
|
836
|
+
this.root = root;
|
|
837
|
+
this.attachment = attachRef(this.opts.ref);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
readonly props = $derived.by(
|
|
841
|
+
() =>
|
|
842
|
+
({
|
|
843
|
+
id: this.opts.id.current,
|
|
844
|
+
'data-disabled': boolToEmptyStrOrUndef(this.root.opts.disabled.current),
|
|
845
|
+
'data-readonly': boolToEmptyStrOrUndef(this.root.opts.readonly.current),
|
|
846
|
+
[this.root.getBitsAttr('grid-row')]: '',
|
|
847
|
+
...this.attachment,
|
|
848
|
+
}) as const,
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
interface CalendarHeadCellStateOpts extends WithRefOpts {}
|
|
853
|
+
|
|
854
|
+
export class CalendarHeadCellState {
|
|
855
|
+
static create(opts: CalendarHeadCellStateOpts) {
|
|
856
|
+
return new CalendarHeadCellState(opts, getCalendarRoot());
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
readonly opts: CalendarHeadCellStateOpts;
|
|
860
|
+
readonly root: CalendarRootState | RangeCalendarRootState;
|
|
861
|
+
readonly attachment: RefAttachment;
|
|
862
|
+
constructor(opts: CalendarHeadCellStateOpts, root: CalendarRootState | RangeCalendarRootState) {
|
|
863
|
+
this.opts = opts;
|
|
864
|
+
this.root = root;
|
|
865
|
+
this.attachment = attachRef(this.opts.ref);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
readonly props = $derived.by(
|
|
869
|
+
() =>
|
|
870
|
+
({
|
|
871
|
+
id: this.opts.id.current,
|
|
872
|
+
'data-disabled': boolToEmptyStrOrUndef(this.root.opts.disabled.current),
|
|
873
|
+
'data-readonly': boolToEmptyStrOrUndef(this.root.opts.readonly.current),
|
|
874
|
+
[this.root.getBitsAttr('head-cell')]: '',
|
|
875
|
+
...this.attachment,
|
|
876
|
+
}) as const,
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
interface CalendarHeaderStateOpts extends WithRefOpts {}
|
|
881
|
+
|
|
882
|
+
export class CalendarHeaderState {
|
|
883
|
+
static create(opts: CalendarHeaderStateOpts) {
|
|
884
|
+
return new CalendarHeaderState(opts, getCalendarRoot());
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
readonly opts: CalendarHeaderStateOpts;
|
|
888
|
+
readonly root: CalendarRootState | RangeCalendarRootState;
|
|
889
|
+
readonly attachment: RefAttachment;
|
|
890
|
+
constructor(opts: CalendarHeaderStateOpts, root: CalendarRootState | RangeCalendarRootState) {
|
|
891
|
+
this.opts = opts;
|
|
892
|
+
this.root = root;
|
|
893
|
+
this.attachment = attachRef(this.opts.ref);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
readonly props = $derived.by(
|
|
897
|
+
() =>
|
|
898
|
+
({
|
|
899
|
+
id: this.opts.id.current,
|
|
900
|
+
'data-disabled': boolToEmptyStrOrUndef(this.root.opts.disabled.current),
|
|
901
|
+
'data-readonly': boolToEmptyStrOrUndef(this.root.opts.readonly.current),
|
|
902
|
+
[this.root.getBitsAttr('header')]: '',
|
|
903
|
+
...this.attachment,
|
|
904
|
+
}) as const,
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
interface CalendarMonthSelectStateOpts
|
|
909
|
+
extends
|
|
910
|
+
WithRefOpts,
|
|
911
|
+
ReadableBoxedValues<{
|
|
912
|
+
months: number[];
|
|
913
|
+
monthFormat: Intl.DateTimeFormatOptions['month'] | ((month: number) => string);
|
|
914
|
+
disabled: boolean;
|
|
915
|
+
}> {}
|
|
916
|
+
|
|
917
|
+
export class CalendarMonthSelectState {
|
|
918
|
+
static create(opts: CalendarMonthSelectStateOpts) {
|
|
919
|
+
return new CalendarMonthSelectState(opts, getCalendarRoot());
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
readonly opts: CalendarMonthSelectStateOpts;
|
|
923
|
+
readonly root: CalendarRootState | RangeCalendarRootState;
|
|
924
|
+
readonly attachment: RefAttachment;
|
|
925
|
+
constructor(opts: CalendarMonthSelectStateOpts, root: CalendarRootState | RangeCalendarRootState) {
|
|
926
|
+
this.opts = opts;
|
|
927
|
+
this.root = root;
|
|
928
|
+
this.onchange = this.onchange.bind(this);
|
|
929
|
+
this.attachment = attachRef(this.opts.ref);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
readonly monthItems = $derived.by(() => {
|
|
933
|
+
this.root.opts.locale.current;
|
|
934
|
+
const monthNumbers = this.opts.months.current;
|
|
935
|
+
const monthFormat = this.opts.monthFormat.current;
|
|
936
|
+
const months = [];
|
|
937
|
+
|
|
938
|
+
for (const month of monthNumbers) {
|
|
939
|
+
// create a date with the current year and the month to get localized name
|
|
940
|
+
const date = this.root.opts.placeholder.current.set({ month });
|
|
941
|
+
let label: string;
|
|
942
|
+
if (typeof monthFormat === 'function') {
|
|
943
|
+
label = monthFormat(month);
|
|
944
|
+
} else {
|
|
945
|
+
label = this.root.formatter.custom(toDate(date), { month: monthFormat });
|
|
946
|
+
}
|
|
947
|
+
months.push({
|
|
948
|
+
value: month,
|
|
949
|
+
label,
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
return months;
|
|
954
|
+
});
|
|
955
|
+
|
|
956
|
+
readonly currentMonth = $derived.by(() => this.root.opts.placeholder.current.month);
|
|
957
|
+
|
|
958
|
+
readonly isDisabled = $derived.by(() => this.root.opts.disabled.current || this.opts.disabled.current);
|
|
959
|
+
|
|
960
|
+
readonly snippetProps = $derived.by(() => {
|
|
961
|
+
return {
|
|
962
|
+
monthItems: this.monthItems,
|
|
963
|
+
selectedMonthItem: this.monthItems.find((month) => month.value === this.currentMonth) as {
|
|
964
|
+
value: number;
|
|
965
|
+
label: string;
|
|
966
|
+
},
|
|
967
|
+
};
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
onchange(event: Event) {
|
|
971
|
+
if (this.isDisabled) return;
|
|
972
|
+
const target = event.target as HTMLSelectElement;
|
|
973
|
+
const month = parseInt(target.value, 10);
|
|
974
|
+
if (!isNaN(month)) {
|
|
975
|
+
this.root.opts.placeholder.current = this.root.opts.placeholder.current.set({ month });
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
readonly props = $derived.by(
|
|
980
|
+
() =>
|
|
981
|
+
({
|
|
982
|
+
id: this.opts.id.current,
|
|
983
|
+
value: this.currentMonth,
|
|
984
|
+
disabled: this.isDisabled,
|
|
985
|
+
'data-disabled': boolToEmptyStrOrUndef(this.isDisabled),
|
|
986
|
+
[this.root.getBitsAttr('month-select')]: '',
|
|
987
|
+
//
|
|
988
|
+
onchange: this.onchange,
|
|
989
|
+
...this.attachment,
|
|
990
|
+
}) as const,
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
interface CalendarYearSelectStateOpts
|
|
995
|
+
extends
|
|
996
|
+
WithRefOpts,
|
|
997
|
+
ReadableBoxedValues<{
|
|
998
|
+
years: number[] | undefined;
|
|
999
|
+
yearFormat: Intl.DateTimeFormatOptions['year'] | ((year: number) => string);
|
|
1000
|
+
disabled: boolean;
|
|
1001
|
+
}> {}
|
|
1002
|
+
|
|
1003
|
+
export class CalendarYearSelectState {
|
|
1004
|
+
static create(opts: CalendarYearSelectStateOpts) {
|
|
1005
|
+
return new CalendarYearSelectState(opts, getCalendarRoot());
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
readonly opts: CalendarYearSelectStateOpts;
|
|
1009
|
+
readonly root: CalendarRootState | RangeCalendarRootState;
|
|
1010
|
+
readonly attachment: RefAttachment;
|
|
1011
|
+
constructor(opts: CalendarYearSelectStateOpts, root: CalendarRootState | RangeCalendarRootState) {
|
|
1012
|
+
this.opts = opts;
|
|
1013
|
+
this.root = root;
|
|
1014
|
+
this.onchange = this.onchange.bind(this);
|
|
1015
|
+
this.attachment = attachRef(this.opts.ref);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
readonly years = $derived.by(() => {
|
|
1019
|
+
if (this.opts.years.current && this.opts.years.current.length) return this.opts.years.current;
|
|
1020
|
+
return this.root.defaultYears;
|
|
1021
|
+
});
|
|
1022
|
+
|
|
1023
|
+
readonly yearItems = $derived.by(() => {
|
|
1024
|
+
this.root.opts.locale.current;
|
|
1025
|
+
const yearFormat = this.opts.yearFormat.current;
|
|
1026
|
+
const localYears = [];
|
|
1027
|
+
for (const year of this.years) {
|
|
1028
|
+
// create a date with the year to get localized formatting
|
|
1029
|
+
const date = this.root.opts.placeholder.current.set({ year });
|
|
1030
|
+
let label: string;
|
|
1031
|
+
if (typeof yearFormat === 'function') {
|
|
1032
|
+
label = yearFormat(year);
|
|
1033
|
+
} else {
|
|
1034
|
+
label = this.root.formatter.custom(toDate(date), { year: yearFormat });
|
|
1035
|
+
}
|
|
1036
|
+
localYears.push({
|
|
1037
|
+
value: year,
|
|
1038
|
+
label,
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
return localYears;
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
readonly currentYear = $derived.by(() => this.root.opts.placeholder.current.year);
|
|
1046
|
+
|
|
1047
|
+
readonly isDisabled = $derived.by(() => this.root.opts.disabled.current || this.opts.disabled.current);
|
|
1048
|
+
|
|
1049
|
+
readonly snippetProps = $derived.by(() => {
|
|
1050
|
+
return {
|
|
1051
|
+
yearItems: this.yearItems,
|
|
1052
|
+
selectedYearItem: this.yearItems.find((year) => year.value === this.currentYear) as {
|
|
1053
|
+
value: number;
|
|
1054
|
+
label: string;
|
|
1055
|
+
},
|
|
1056
|
+
};
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
onchange(event: Event) {
|
|
1060
|
+
if (this.isDisabled) return;
|
|
1061
|
+
const target = event.target as HTMLSelectElement;
|
|
1062
|
+
const year = parseInt(target.value, 10);
|
|
1063
|
+
if (!isNaN(year)) {
|
|
1064
|
+
this.root.opts.placeholder.current = this.root.opts.placeholder.current.set({ year });
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
readonly props = $derived.by(
|
|
1069
|
+
() =>
|
|
1070
|
+
({
|
|
1071
|
+
id: this.opts.id.current,
|
|
1072
|
+
value: this.currentYear,
|
|
1073
|
+
disabled: this.isDisabled,
|
|
1074
|
+
'data-disabled': boolToEmptyStrOrUndef(this.isDisabled),
|
|
1075
|
+
[this.root.getBitsAttr('year-select')]: '',
|
|
1076
|
+
//
|
|
1077
|
+
onchange: this.onchange,
|
|
1078
|
+
...this.attachment,
|
|
1079
|
+
}) as const,
|
|
1080
|
+
);
|
|
1081
|
+
}
|