@knk1313/plain-ui 0.0.0-stage → 0.2.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 +86 -2
- package/dist/components/accordion/Accordion.d.ts +27 -0
- package/dist/components/accordion/Accordion.js +18 -0
- package/dist/components/accordion/index.d.ts +1 -0
- package/dist/components/accordion/index.js +1 -0
- package/dist/components/agent-form/AgentForm.d.ts +40 -0
- package/dist/components/agent-form/AgentForm.js +100 -0
- package/dist/components/agent-form/index.d.ts +1 -0
- package/dist/components/agent-form/index.js +1 -0
- package/dist/components/agent-steps/AgentSteps.d.ts +21 -0
- package/dist/components/agent-steps/AgentSteps.js +42 -0
- package/dist/components/agent-steps/index.d.ts +1 -0
- package/dist/components/agent-steps/index.js +1 -0
- package/dist/components/agent-thinking/AgentThinking.d.ts +12 -0
- package/dist/components/agent-thinking/AgentThinking.js +18 -0
- package/dist/components/agent-thinking/index.d.ts +1 -0
- package/dist/components/agent-thinking/index.js +1 -0
- package/dist/components/area-chart/AreaChart.d.ts +10 -0
- package/dist/components/area-chart/AreaChart.js +83 -0
- package/dist/components/area-chart/index.d.ts +1 -0
- package/dist/components/area-chart/index.js +1 -0
- package/dist/components/auth-card/AuthCard.d.ts +14 -0
- package/dist/components/auth-card/AuthCard.js +9 -0
- package/dist/components/auth-card/PasswordInput.d.ts +13 -0
- package/dist/components/auth-card/PasswordInput.js +26 -0
- package/dist/components/auth-card/index.d.ts +2 -0
- package/dist/components/auth-card/index.js +2 -0
- package/dist/components/avatar/Avatar.d.ts +14 -0
- package/dist/components/avatar/Avatar.js +42 -0
- package/dist/components/avatar/index.d.ts +1 -0
- package/dist/components/avatar/index.js +1 -0
- package/dist/components/badge/Badge.d.ts +9 -0
- package/dist/components/badge/Badge.js +15 -0
- package/dist/components/badge/index.d.ts +1 -0
- package/dist/components/badge/index.js +1 -0
- package/dist/components/banner/Banner.d.ts +9 -0
- package/dist/components/banner/Banner.js +36 -0
- package/dist/components/banner/index.d.ts +1 -0
- package/dist/components/banner/index.js +1 -0
- package/dist/components/bar-chart/BarChart.d.ts +3 -0
- package/dist/components/bar-chart/BarChart.js +47 -0
- package/dist/components/bar-chart/index.d.ts +1 -0
- package/dist/components/bar-chart/index.js +1 -0
- package/dist/components/bar-list/BarList.d.ts +26 -0
- package/dist/components/bar-list/BarList.js +24 -0
- package/dist/components/bar-list/index.d.ts +1 -0
- package/dist/components/bar-list/index.js +1 -0
- package/dist/components/breadcrumb/Breadcrumb.d.ts +12 -0
- package/dist/components/breadcrumb/Breadcrumb.js +9 -0
- package/dist/components/breadcrumb/index.d.ts +1 -0
- package/dist/components/breadcrumb/index.js +1 -0
- package/dist/components/button/Button.d.ts +24 -0
- package/dist/components/button/Button.js +31 -0
- package/dist/components/button/buttonStyle.d.ts +9 -0
- package/dist/components/button/buttonStyle.js +41 -0
- package/dist/components/button/index.d.ts +1 -0
- package/dist/components/button/index.js +1 -0
- package/dist/components/button-group/ButtonGroup.d.ts +18 -0
- package/dist/components/button-group/ButtonGroup.js +26 -0
- package/dist/components/button-group/index.d.ts +1 -0
- package/dist/components/button-group/index.js +1 -0
- package/dist/components/calendar/Calendar.d.ts +20 -0
- package/dist/components/calendar/Calendar.js +98 -0
- package/dist/components/calendar/index.d.ts +1 -0
- package/dist/components/calendar/index.js +1 -0
- package/dist/components/calendar-view/CalendarView.d.ts +34 -0
- package/dist/components/calendar-view/CalendarView.js +111 -0
- package/dist/components/calendar-view/index.d.ts +1 -0
- package/dist/components/calendar-view/index.js +1 -0
- package/dist/components/card/Card.d.ts +6 -0
- package/dist/components/card/Card.js +6 -0
- package/dist/components/card/index.d.ts +1 -0
- package/dist/components/card/index.js +1 -0
- package/dist/components/carousel/Carousel.d.ts +18 -0
- package/dist/components/carousel/Carousel.js +58 -0
- package/dist/components/carousel/index.d.ts +1 -0
- package/dist/components/carousel/index.js +1 -0
- package/dist/components/chart/Axis.d.ts +51 -0
- package/dist/components/chart/Axis.js +127 -0
- package/dist/components/chart/ChartFrame.d.ts +79 -0
- package/dist/components/chart/ChartFrame.js +80 -0
- package/dist/components/chart/ChartTooltip.d.ts +12 -0
- package/dist/components/chart/ChartTooltip.js +57 -0
- package/dist/components/chart/Legend.d.ts +11 -0
- package/dist/components/chart/Legend.js +6 -0
- package/dist/components/chart/Sparkline.d.ts +5 -0
- package/dist/components/chart/Sparkline.js +20 -0
- package/dist/components/chart/format.d.ts +2 -0
- package/dist/components/chart/format.js +17 -0
- package/dist/components/chart/heatmap.d.ts +18 -0
- package/dist/components/chart/heatmap.js +47 -0
- package/dist/components/chart/index.d.ts +1 -0
- package/dist/components/chart/index.js +1 -0
- package/dist/components/chart/line.d.ts +1 -0
- package/dist/components/chart/line.js +15 -0
- package/dist/components/chart/scale.d.ts +15 -0
- package/dist/components/chart/scale.js +100 -0
- package/dist/components/chart/series.d.ts +44 -0
- package/dist/components/chart/series.js +86 -0
- package/dist/components/chart/spacing.d.ts +29 -0
- package/dist/components/chart/spacing.js +34 -0
- package/dist/components/chart/types.d.ts +29 -0
- package/dist/components/chart/types.js +2 -0
- package/dist/components/chart/useChartHover.d.ts +34 -0
- package/dist/components/chart/useChartHover.js +97 -0
- package/dist/components/checkbox/Checkbox.d.ts +10 -0
- package/dist/components/checkbox/Checkbox.js +38 -0
- package/dist/components/checkbox/index.d.ts +1 -0
- package/dist/components/checkbox/index.js +1 -0
- package/dist/components/chip/Chip.d.ts +21 -0
- package/dist/components/chip/Chip.js +10 -0
- package/dist/components/chip/index.d.ts +1 -0
- package/dist/components/chip/index.js +1 -0
- package/dist/components/close-button/CloseButton.d.ts +14 -0
- package/dist/components/close-button/CloseButton.js +9 -0
- package/dist/components/close-button/index.d.ts +1 -0
- package/dist/components/close-button/index.js +1 -0
- package/dist/components/color-picker/ColorPicker.d.ts +21 -0
- package/dist/components/color-picker/ColorPicker.js +20 -0
- package/dist/components/color-picker/index.d.ts +1 -0
- package/dist/components/color-picker/index.js +1 -0
- package/dist/components/combo-chart/ComboChart.d.ts +12 -0
- package/dist/components/combo-chart/ComboChart.js +84 -0
- package/dist/components/combo-chart/index.d.ts +1 -0
- package/dist/components/combo-chart/index.js +1 -0
- package/dist/components/combobox/Combobox.d.ts +33 -0
- package/dist/components/combobox/Combobox.js +246 -0
- package/dist/components/combobox/index.d.ts +1 -0
- package/dist/components/combobox/index.js +1 -0
- package/dist/components/command-palette/CommandPalette.d.ts +36 -0
- package/dist/components/command-palette/CommandPalette.js +156 -0
- package/dist/components/command-palette/index.d.ts +1 -0
- package/dist/components/command-palette/index.js +1 -0
- package/dist/components/composer/Composer.d.ts +32 -0
- package/dist/components/composer/Composer.js +101 -0
- package/dist/components/composer/index.d.ts +1 -0
- package/dist/components/composer/index.js +1 -0
- package/dist/components/composer-attachments/ComposerAttachments.d.ts +25 -0
- package/dist/components/composer-attachments/ComposerAttachments.js +52 -0
- package/dist/components/composer-attachments/index.d.ts +1 -0
- package/dist/components/composer-attachments/index.js +1 -0
- package/dist/components/composer-panel/ComposerPanel.d.ts +26 -0
- package/dist/components/composer-panel/ComposerPanel.js +154 -0
- package/dist/components/composer-panel/index.d.ts +1 -0
- package/dist/components/composer-panel/index.js +1 -0
- package/dist/components/contribution-chart/ContributionChart.d.ts +25 -0
- package/dist/components/contribution-chart/ContributionChart.js +127 -0
- package/dist/components/contribution-chart/index.d.ts +1 -0
- package/dist/components/contribution-chart/index.js +1 -0
- package/dist/components/data-grid/DataGrid.d.ts +40 -0
- package/dist/components/data-grid/DataGrid.js +157 -0
- package/dist/components/data-grid/index.d.ts +1 -0
- package/dist/components/data-grid/index.js +1 -0
- package/dist/components/data-table/DataTable.d.ts +87 -0
- package/dist/components/data-table/DataTable.js +150 -0
- package/dist/components/data-table/index.d.ts +2 -0
- package/dist/components/data-table/index.js +2 -0
- package/dist/components/data-table/query.d.ts +54 -0
- package/dist/components/data-table/query.js +70 -0
- package/dist/components/date-picker/DatePicker.d.ts +25 -0
- package/dist/components/date-picker/DatePicker.js +154 -0
- package/dist/components/date-picker/index.d.ts +1 -0
- package/dist/components/date-picker/index.js +1 -0
- package/dist/components/dialog/ConfirmDialog.d.ts +25 -0
- package/dist/components/dialog/ConfirmDialog.js +69 -0
- package/dist/components/dialog/Dialog.d.ts +25 -0
- package/dist/components/dialog/Dialog.js +11 -0
- package/dist/components/dialog/DialogFrame.d.ts +22 -0
- package/dist/components/dialog/DialogFrame.js +21 -0
- package/dist/components/dialog/DiscardChangesDialog.d.ts +10 -0
- package/dist/components/dialog/DiscardChangesDialog.js +10 -0
- package/dist/components/dialog/index.d.ts +2 -0
- package/dist/components/dialog/index.js +2 -0
- package/dist/components/dialog/useDiscardOnClose.d.ts +20 -0
- package/dist/components/dialog/useDiscardOnClose.js +26 -0
- package/dist/components/dialog/useModalDialog.d.ts +20 -0
- package/dist/components/dialog/useModalDialog.js +85 -0
- package/dist/components/drawer/Drawer.d.ts +14 -0
- package/dist/components/drawer/Drawer.js +22 -0
- package/dist/components/drawer/index.d.ts +1 -0
- package/dist/components/drawer/index.js +1 -0
- package/dist/components/empty-state/EmptyState.d.ts +11 -0
- package/dist/components/empty-state/EmptyState.js +7 -0
- package/dist/components/empty-state/index.d.ts +1 -0
- package/dist/components/empty-state/index.js +1 -0
- package/dist/components/error-state/ErrorState.d.ts +8 -0
- package/dist/components/error-state/ErrorState.js +7 -0
- package/dist/components/error-state/index.d.ts +1 -0
- package/dist/components/error-state/index.js +1 -0
- package/dist/components/error-summary/ErrorSummary.d.ts +21 -0
- package/dist/components/error-summary/ErrorSummary.js +16 -0
- package/dist/components/error-summary/index.d.ts +1 -0
- package/dist/components/error-summary/index.js +1 -0
- package/dist/components/field/Field.d.ts +23 -0
- package/dist/components/field/Field.js +20 -0
- package/dist/components/field/index.d.ts +1 -0
- package/dist/components/field/index.js +1 -0
- package/dist/components/field-error/FieldError.d.ts +10 -0
- package/dist/components/field-error/FieldError.js +52 -0
- package/dist/components/field-error/index.d.ts +1 -0
- package/dist/components/field-error/index.js +1 -0
- package/dist/components/file-upload/FileUpload.d.ts +50 -0
- package/dist/components/file-upload/FileUpload.js +169 -0
- package/dist/components/file-upload/fileSize.d.ts +1 -0
- package/dist/components/file-upload/fileSize.js +13 -0
- package/dist/components/file-upload/index.d.ts +1 -0
- package/dist/components/file-upload/index.js +1 -0
- package/dist/components/form-section/FormSection.d.ts +16 -0
- package/dist/components/form-section/FormSection.js +14 -0
- package/dist/components/form-section/index.d.ts +1 -0
- package/dist/components/form-section/index.js +1 -0
- package/dist/components/form-steps/FormSteps.d.ts +18 -0
- package/dist/components/form-steps/FormSteps.js +26 -0
- package/dist/components/form-steps/index.d.ts +1 -0
- package/dist/components/form-steps/index.js +1 -0
- package/dist/components/funnel-chart/FunnelChart.d.ts +12 -0
- package/dist/components/funnel-chart/FunnelChart.js +69 -0
- package/dist/components/funnel-chart/index.d.ts +1 -0
- package/dist/components/funnel-chart/index.js +1 -0
- package/dist/components/header/Header.d.ts +14 -0
- package/dist/components/header/Header.js +31 -0
- package/dist/components/header/index.d.ts +1 -0
- package/dist/components/header/index.js +1 -0
- package/dist/components/heatmap-chart/HeatmapChart.d.ts +10 -0
- package/dist/components/heatmap-chart/HeatmapChart.js +76 -0
- package/dist/components/heatmap-chart/index.d.ts +1 -0
- package/dist/components/heatmap-chart/index.js +1 -0
- package/dist/components/image-error/ImageError.d.ts +11 -0
- package/dist/components/image-error/ImageError.js +16 -0
- package/dist/components/image-error/index.d.ts +1 -0
- package/dist/components/image-error/index.js +1 -0
- package/dist/components/image-loader/ImageLoader.d.ts +9 -0
- package/dist/components/image-loader/ImageLoader.js +10 -0
- package/dist/components/image-loader/index.d.ts +1 -0
- package/dist/components/image-loader/index.js +1 -0
- package/dist/components/index.d.ts +98 -0
- package/dist/components/index.js +97 -0
- package/dist/components/input/Input.d.ts +6 -0
- package/dist/components/input/Input.js +8 -0
- package/dist/components/input/index.d.ts +1 -0
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/inputStyle.d.ts +14 -0
- package/dist/components/input/inputStyle.js +35 -0
- package/dist/components/item-range/ItemRange.d.ts +11 -0
- package/dist/components/item-range/ItemRange.js +13 -0
- package/dist/components/item-range/index.d.ts +1 -0
- package/dist/components/item-range/index.js +1 -0
- package/dist/components/label/Label.d.ts +8 -0
- package/dist/components/label/Label.js +5 -0
- package/dist/components/label/index.d.ts +1 -0
- package/dist/components/label/index.js +1 -0
- package/dist/components/line-chart/LineChart.d.ts +10 -0
- package/dist/components/line-chart/LineChart.js +29 -0
- package/dist/components/line-chart/index.d.ts +1 -0
- package/dist/components/line-chart/index.js +1 -0
- package/dist/components/link-button/LinkButton.d.ts +29 -0
- package/dist/components/link-button/LinkButton.js +15 -0
- package/dist/components/link-button/index.d.ts +1 -0
- package/dist/components/link-button/index.js +1 -0
- package/dist/components/menu/Menu.d.ts +33 -0
- package/dist/components/menu/Menu.js +113 -0
- package/dist/components/menu/index.d.ts +1 -0
- package/dist/components/menu/index.js +1 -0
- package/dist/components/meter/Meter.d.ts +24 -0
- package/dist/components/meter/Meter.js +65 -0
- package/dist/components/meter/index.d.ts +1 -0
- package/dist/components/meter/index.js +1 -0
- package/dist/components/nav-group/NavGroup.d.ts +24 -0
- package/dist/components/nav-group/NavGroup.js +23 -0
- package/dist/components/nav-group/index.d.ts +1 -0
- package/dist/components/nav-group/index.js +1 -0
- package/dist/components/notification/Notification.d.ts +25 -0
- package/dist/components/notification/Notification.js +13 -0
- package/dist/components/notification/index.d.ts +1 -0
- package/dist/components/notification/index.js +1 -0
- package/dist/components/notification-center/NotificationCenter.d.ts +33 -0
- package/dist/components/notification-center/NotificationCenter.js +29 -0
- package/dist/components/notification-center/index.d.ts +1 -0
- package/dist/components/notification-center/index.js +1 -0
- package/dist/components/number-field/NumberField.d.ts +28 -0
- package/dist/components/number-field/NumberField.js +155 -0
- package/dist/components/number-field/index.d.ts +1 -0
- package/dist/components/number-field/index.js +1 -0
- package/dist/components/otp-input/OtpInput.d.ts +14 -0
- package/dist/components/otp-input/OtpInput.js +70 -0
- package/dist/components/otp-input/index.d.ts +1 -0
- package/dist/components/otp-input/index.js +1 -0
- package/dist/components/pagination/Pagination.d.ts +21 -0
- package/dist/components/pagination/Pagination.js +51 -0
- package/dist/components/pagination/index.d.ts +1 -0
- package/dist/components/pagination/index.js +1 -0
- package/dist/components/popover/Popover.d.ts +23 -0
- package/dist/components/popover/Popover.js +83 -0
- package/dist/components/popover/index.d.ts +1 -0
- package/dist/components/popover/index.js +1 -0
- package/dist/components/progress/Progress.d.ts +12 -0
- package/dist/components/progress/Progress.js +30 -0
- package/dist/components/progress/index.d.ts +1 -0
- package/dist/components/progress/index.js +1 -0
- package/dist/components/question-form/QuestionForm.d.ts +59 -0
- package/dist/components/question-form/QuestionForm.js +128 -0
- package/dist/components/question-form/index.d.ts +1 -0
- package/dist/components/question-form/index.js +1 -0
- package/dist/components/radar-chart/RadarChart.d.ts +3 -0
- package/dist/components/radar-chart/RadarChart.js +72 -0
- package/dist/components/radar-chart/geometry.d.ts +16 -0
- package/dist/components/radar-chart/geometry.js +56 -0
- package/dist/components/radar-chart/index.d.ts +1 -0
- package/dist/components/radar-chart/index.js +1 -0
- package/dist/components/radial-chart/RadialChart.d.ts +39 -0
- package/dist/components/radial-chart/RadialChart.js +135 -0
- package/dist/components/radial-chart/index.d.ts +1 -0
- package/dist/components/radial-chart/index.js +1 -0
- package/dist/components/radio/Radio.d.ts +31 -0
- package/dist/components/radio/Radio.js +24 -0
- package/dist/components/radio/index.d.ts +1 -0
- package/dist/components/radio/index.js +1 -0
- package/dist/components/reply-loader/ReplyLoader.d.ts +10 -0
- package/dist/components/reply-loader/ReplyLoader.js +9 -0
- package/dist/components/reply-loader/index.d.ts +1 -0
- package/dist/components/reply-loader/index.js +1 -0
- package/dist/components/sankey-chart/SankeyChart.d.ts +35 -0
- package/dist/components/sankey-chart/SankeyChart.js +218 -0
- package/dist/components/sankey-chart/index.d.ts +1 -0
- package/dist/components/sankey-chart/index.js +1 -0
- package/dist/components/scatter-chart/ScatterChart.d.ts +38 -0
- package/dist/components/scatter-chart/ScatterChart.js +69 -0
- package/dist/components/scatter-chart/index.d.ts +1 -0
- package/dist/components/scatter-chart/index.js +1 -0
- package/dist/components/search-field/SearchField.d.ts +17 -0
- package/dist/components/search-field/SearchField.js +92 -0
- package/dist/components/search-field/index.d.ts +1 -0
- package/dist/components/search-field/index.js +1 -0
- package/dist/components/segmented-control/SegmentedControl.d.ts +26 -0
- package/dist/components/segmented-control/SegmentedControl.js +38 -0
- package/dist/components/segmented-control/index.d.ts +1 -0
- package/dist/components/segmented-control/index.js +1 -0
- package/dist/components/select/Select.d.ts +11 -0
- package/dist/components/select/Select.js +30 -0
- package/dist/components/select/index.d.ts +1 -0
- package/dist/components/select/index.js +1 -0
- package/dist/components/separator/Separator.d.ts +14 -0
- package/dist/components/separator/Separator.js +12 -0
- package/dist/components/separator/index.d.ts +1 -0
- package/dist/components/separator/index.js +1 -0
- package/dist/components/settings-modal/SettingsModal.d.ts +35 -0
- package/dist/components/settings-modal/SettingsModal.js +120 -0
- package/dist/components/settings-modal/index.d.ts +1 -0
- package/dist/components/settings-modal/index.js +1 -0
- package/dist/components/sidebar/Sidebar.d.ts +30 -0
- package/dist/components/sidebar/Sidebar.js +30 -0
- package/dist/components/sidebar/index.d.ts +1 -0
- package/dist/components/sidebar/index.js +1 -0
- package/dist/components/skeleton/Skeleton.d.ts +6 -0
- package/dist/components/skeleton/Skeleton.js +6 -0
- package/dist/components/skeleton/index.d.ts +1 -0
- package/dist/components/skeleton/index.js +1 -0
- package/dist/components/skip-link/SkipLink.d.ts +8 -0
- package/dist/components/skip-link/SkipLink.js +10 -0
- package/dist/components/skip-link/index.d.ts +1 -0
- package/dist/components/skip-link/index.js +1 -0
- package/dist/components/slider/Slider.d.ts +19 -0
- package/dist/components/slider/Slider.js +49 -0
- package/dist/components/slider/index.d.ts +1 -0
- package/dist/components/slider/index.js +1 -0
- package/dist/components/spinner/Spinner.d.ts +5 -0
- package/dist/components/spinner/Spinner.js +7 -0
- package/dist/components/spinner/index.d.ts +1 -0
- package/dist/components/spinner/index.js +1 -0
- package/dist/components/stacked-bar/StackedBar.d.ts +29 -0
- package/dist/components/stacked-bar/StackedBar.js +77 -0
- package/dist/components/stacked-bar/index.d.ts +1 -0
- package/dist/components/stacked-bar/index.js +1 -0
- package/dist/components/stat-card/StatCard.d.ts +19 -0
- package/dist/components/stat-card/StatCard.js +32 -0
- package/dist/components/stat-card/index.d.ts +1 -0
- package/dist/components/stat-card/index.js +1 -0
- package/dist/components/switch/Switch.d.ts +10 -0
- package/dist/components/switch/Switch.js +22 -0
- package/dist/components/switch/index.d.ts +1 -0
- package/dist/components/switch/index.js +1 -0
- package/dist/components/table/SortableHeader.d.ts +12 -0
- package/dist/components/table/SortableHeader.js +11 -0
- package/dist/components/table/Table.d.ts +15 -0
- package/dist/components/table/Table.js +26 -0
- package/dist/components/table/align.d.ts +1 -0
- package/dist/components/table/align.js +5 -0
- package/dist/components/table/index.d.ts +4 -0
- package/dist/components/table/index.js +2 -0
- package/dist/components/tabs/Tabs.d.ts +38 -0
- package/dist/components/tabs/Tabs.js +137 -0
- package/dist/components/tabs/fitTabs.d.ts +18 -0
- package/dist/components/tabs/fitTabs.js +46 -0
- package/dist/components/tabs/index.d.ts +1 -0
- package/dist/components/tabs/index.js +1 -0
- package/dist/components/tag-group/TagGroup.d.ts +29 -0
- package/dist/components/tag-group/TagGroup.js +82 -0
- package/dist/components/tag-group/index.d.ts +1 -0
- package/dist/components/tag-group/index.js +1 -0
- package/dist/components/task-list/TaskList.d.ts +46 -0
- package/dist/components/task-list/TaskList.js +30 -0
- package/dist/components/task-list/index.d.ts +1 -0
- package/dist/components/task-list/index.js +1 -0
- package/dist/components/text-link/TextLink.d.ts +27 -0
- package/dist/components/text-link/TextLink.js +22 -0
- package/dist/components/text-link/index.d.ts +1 -0
- package/dist/components/text-link/index.js +1 -0
- package/dist/components/textarea/Textarea.d.ts +6 -0
- package/dist/components/textarea/Textarea.js +9 -0
- package/dist/components/textarea/index.d.ts +1 -0
- package/dist/components/textarea/index.js +1 -0
- package/dist/components/time-field/TimeField.d.ts +6 -0
- package/dist/components/time-field/TimeField.js +9 -0
- package/dist/components/time-field/index.d.ts +1 -0
- package/dist/components/time-field/index.js +1 -0
- package/dist/components/toast/Toast.d.ts +19 -0
- package/dist/components/toast/Toast.js +190 -0
- package/dist/components/toast/index.d.ts +1 -0
- package/dist/components/toast/index.js +1 -0
- package/dist/components/token-input/TokenInput.d.ts +27 -0
- package/dist/components/token-input/TokenInput.js +153 -0
- package/dist/components/token-input/index.d.ts +1 -0
- package/dist/components/token-input/index.js +1 -0
- package/dist/components/tooltip/Tooltip.d.ts +17 -0
- package/dist/components/tooltip/Tooltip.js +144 -0
- package/dist/components/tooltip/index.d.ts +1 -0
- package/dist/components/tooltip/index.js +1 -0
- package/dist/components/tree-view/TreeView.d.ts +29 -0
- package/dist/components/tree-view/TreeView.js +140 -0
- package/dist/components/tree-view/index.d.ts +1 -0
- package/dist/components/tree-view/index.js +1 -0
- package/dist/components/unsaved-changes/index.d.ts +1 -0
- package/dist/components/unsaved-changes/index.js +1 -0
- package/dist/components/unsaved-changes/useUnsavedChanges.d.ts +12 -0
- package/dist/components/unsaved-changes/useUnsavedChanges.js +45 -0
- package/dist/components/usage-limit/UsageLimit.d.ts +15 -0
- package/dist/components/usage-limit/UsageLimit.js +21 -0
- package/dist/components/usage-limit/index.d.ts +1 -0
- package/dist/components/usage-limit/index.js +1 -0
- package/dist/components/web-search-results/WebSearchResults.d.ts +21 -0
- package/dist/components/web-search-results/WebSearchResults.js +17 -0
- package/dist/components/web-search-results/index.d.ts +1 -0
- package/dist/components/web-search-results/index.js +1 -0
- package/dist/lib/anchor.d.ts +21 -0
- package/dist/lib/anchor.js +50 -0
- package/dist/lib/cn.d.ts +1 -0
- package/dist/lib/cn.js +5 -0
- package/dist/lib/date.d.ts +77 -0
- package/dist/lib/date.js +165 -0
- package/dist/lib/icon-message.d.ts +16 -0
- package/dist/lib/icon-message.js +7 -0
- package/dist/lib/number.d.ts +1 -0
- package/dist/lib/number.js +5 -0
- package/dist/lib/slot.d.ts +8 -0
- package/dist/lib/slot.js +53 -0
- package/dist/lib/variant.d.ts +1 -0
- package/dist/lib/variant.js +1 -0
- package/docs/a11y.md +320 -0
- package/docs/chart/axis.md +82 -0
- package/docs/chart/color.md +120 -0
- package/docs/chart/drawing.md +283 -0
- package/docs/chart/reading.md +79 -0
- package/docs/chart/size-and-spacing.md +85 -0
- package/docs/chart.md +47 -0
- package/docs/color/contrast.md +80 -0
- package/docs/color/data-viz.md +66 -0
- package/docs/color/foundation.md +91 -0
- package/docs/color/neutral.md +88 -0
- package/docs/color/state.md +111 -0
- package/docs/color.md +22 -0
- package/docs/components/accordion.md +51 -0
- package/docs/components/agent-form.md +56 -0
- package/docs/components/agent-steps.md +75 -0
- package/docs/components/agent-thinking.md +70 -0
- package/docs/components/area-chart.md +55 -0
- package/docs/components/auth-card.md +126 -0
- package/docs/components/avatar.md +38 -0
- package/docs/components/badge.md +28 -0
- package/docs/components/banner.md +19 -0
- package/docs/components/bar-list.md +77 -0
- package/docs/components/button-group.md +74 -0
- package/docs/components/button.md +49 -0
- package/docs/components/calendar-view.md +106 -0
- package/docs/components/calendar.md +44 -0
- package/docs/components/carousel.md +81 -0
- package/docs/components/chart.md +45 -0
- package/docs/components/chat-message.md +199 -0
- package/docs/components/checkbox.md +27 -0
- package/docs/components/chip.md +34 -0
- package/docs/components/choosing.md +26 -0
- package/docs/components/close-button.md +17 -0
- package/docs/components/color-picker.md +52 -0
- package/docs/components/combo-chart.md +74 -0
- package/docs/components/combobox.md +60 -0
- package/docs/components/command-palette.md +151 -0
- package/docs/components/composer-attachments.md +116 -0
- package/docs/components/composer-panel.md +106 -0
- package/docs/components/composer.md +163 -0
- package/docs/components/contribution-chart.md +70 -0
- package/docs/components/data-grid.md +132 -0
- package/docs/components/data-table.md +165 -0
- package/docs/components/date-picker.md +120 -0
- package/docs/components/dialog.md +211 -0
- package/docs/components/drawer.md +38 -0
- package/docs/components/empty-state.md +17 -0
- package/docs/components/error-state.md +13 -0
- package/docs/components/error-summary.md +49 -0
- package/docs/components/field.md +84 -0
- package/docs/components/file-upload.md +161 -0
- package/docs/components/focus.md +25 -0
- package/docs/components/form-section.md +49 -0
- package/docs/components/form-steps.md +63 -0
- package/docs/components/funnel-chart.md +49 -0
- package/docs/components/heatmap-chart.md +64 -0
- package/docs/components/image-error.md +73 -0
- package/docs/components/image-loader.md +53 -0
- package/docs/components/input.md +21 -0
- package/docs/components/item-range.md +10 -0
- package/docs/components/link-button.md +16 -0
- package/docs/components/menu.md +115 -0
- package/docs/components/meter.md +83 -0
- package/docs/components/nav-group.md +33 -0
- package/docs/components/notification-center.md +100 -0
- package/docs/components/notification.md +127 -0
- package/docs/components/number-field.md +128 -0
- package/docs/components/otp-input.md +86 -0
- package/docs/components/pagination.md +29 -0
- package/docs/components/popover.md +43 -0
- package/docs/components/progress.md +25 -0
- package/docs/components/prohibitions.md +58 -0
- package/docs/components/props.md +20 -0
- package/docs/components/question-form.md +125 -0
- package/docs/components/radar-chart.md +61 -0
- package/docs/components/radial-chart.md +74 -0
- package/docs/components/radio.md +24 -0
- package/docs/components/reply-loader.md +80 -0
- package/docs/components/sankey-chart.md +71 -0
- package/docs/components/scatter-chart.md +61 -0
- package/docs/components/search-field.md +44 -0
- package/docs/components/segmented-control.md +35 -0
- package/docs/components/select.md +28 -0
- package/docs/components/separator.md +23 -0
- package/docs/components/settings-modal.md +128 -0
- package/docs/components/sidebar.md +145 -0
- package/docs/components/skeleton.md +27 -0
- package/docs/components/skip-link.md +17 -0
- package/docs/components/slider.md +82 -0
- package/docs/components/spinner.md +8 -0
- package/docs/components/stacked-bar.md +66 -0
- package/docs/components/stat-card.md +78 -0
- package/docs/components/switch.md +61 -0
- package/docs/components/table.md +43 -0
- package/docs/components/tabs.md +104 -0
- package/docs/components/tag-group.md +115 -0
- package/docs/components/task-list.md +99 -0
- package/docs/components/text-link.md +17 -0
- package/docs/components/textarea.md +27 -0
- package/docs/components/time-field.md +97 -0
- package/docs/components/toast.md +73 -0
- package/docs/components/token-input.md +135 -0
- package/docs/components/tooltip.md +41 -0
- package/docs/components/tree-view.md +71 -0
- package/docs/components/usage-limit.md +47 -0
- package/docs/components/web-search-results.md +60 -0
- package/docs/components.md +234 -0
- package/docs/design.md +31 -0
- package/docs/form/clearing-errors.md +28 -0
- package/docs/form/error-announcement.md +69 -0
- package/docs/form/long-forms.md +103 -0
- package/docs/form/placeholder.md +40 -0
- package/docs/form/submit-errors.md +102 -0
- package/docs/form/submitting.md +72 -0
- package/docs/form/unsaved-changes.md +146 -0
- package/docs/form/validation-timing.md +44 -0
- package/docs/form.md +39 -0
- package/docs/glossary.md +169 -0
- package/docs/icon.md +245 -0
- package/docs/interaction/before.md +64 -0
- package/docs/interaction/motion.md +38 -0
- package/docs/interaction/pending.md +38 -0
- package/docs/interaction/permissions.md +133 -0
- package/docs/interaction/result.md +38 -0
- package/docs/interaction/states.md +159 -0
- package/docs/interaction.md +31 -0
- package/docs/layout/alignment.md +145 -0
- package/docs/layout/hit-area.md +58 -0
- package/docs/layout/mobile.md +200 -0
- package/docs/layout/responsive.md +73 -0
- package/docs/layout/scroll.md +51 -0
- package/docs/layout/surface.md +110 -0
- package/docs/layout.md +31 -0
- package/docs/list/board.md +85 -0
- package/docs/list/paging.md +146 -0
- package/docs/list/search.md +98 -0
- package/docs/list/toolbar.md +91 -0
- package/docs/list.md +39 -0
- package/docs/log.md +94 -0
- package/docs/manual.md +183 -0
- package/docs/navigation/header-and-transition.md +82 -0
- package/docs/navigation/location.md +68 -0
- package/docs/navigation/menu-items.md +152 -0
- package/docs/navigation/menu-structure.md +68 -0
- package/docs/navigation.md +23 -0
- package/docs/publish.md +26 -0
- package/docs/rules.md +246 -0
- package/docs/scenario.md +218 -0
- package/docs/spacing/placement.md +219 -0
- package/docs/spacing/radius.md +45 -0
- package/docs/spacing/scale.md +91 -0
- package/docs/spacing.md +17 -0
- package/docs/typography.md +233 -0
- package/docs/writing/date-and-number.md +25 -0
- package/docs/writing/error-and-empty.md +58 -0
- package/docs/writing/label-and-button.md +124 -0
- package/docs/writing/tone.md +156 -0
- package/docs/writing.md +27 -0
- package/icons/index.d.ts +1 -0
- package/icons/index.js +3 -0
- package/package.json +117 -4
- package/scripts/lint/colors.mjs +103 -0
- package/scripts/lint/deps.mjs +33 -0
- package/scripts/lint/icons.mjs +177 -0
- package/scripts/lint/interaction.mjs +163 -0
- package/scripts/lint/layout.mjs +103 -0
- package/scripts/lint/markup.mjs +271 -0
- package/scripts/lint/shared.mjs +340 -0
- package/scripts/lint/spacing.mjs +70 -0
- package/scripts/lint/typography.mjs +141 -0
- package/scripts/lint/writing.mjs +107 -0
- package/scripts/lint.mjs +166 -0
- package/scripts/plain-ui-lint.mjs +33 -0
- package/tokens/tokens.css +482 -0
- package/tokens/tokens.values.json +234 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { ChevronRightIcon } from "lucide-react";
|
|
5
|
+
import { cn } from "../../lib/cn.js";
|
|
6
|
+
function visibleItems(items, expanded, parentId = null) {
|
|
7
|
+
return items.flatMap(item => [
|
|
8
|
+
{ item, parentId },
|
|
9
|
+
...(item.children?.length && expanded.has(item.id) ? visibleItems(item.children, expanded, item.id) : []),
|
|
10
|
+
]);
|
|
11
|
+
}
|
|
12
|
+
const hasChildren = (item) => Boolean(item.children?.length);
|
|
13
|
+
// ツリービュー。入れ子の項目を開閉し、1つを選ぶ。複数の選択とドラッグは作らない(docs/components/tree-view.md)。
|
|
14
|
+
// WAI-ARIA の Tree View パターンで作る:role="tree" の中に role="treeitem" を入れ子の role="group" で並べ、
|
|
15
|
+
// フォーカスはロービングの tabindex で1つの項目だけに置く。キーボードの操作は handleKeyDown に書く
|
|
16
|
+
export function TreeView({ items, value, defaultValue = null, onChange, defaultExpanded = [], className, ...props }) {
|
|
17
|
+
const [internal, setInternal] = useState(defaultValue);
|
|
18
|
+
const selected = value !== undefined ? value : internal;
|
|
19
|
+
const [expanded, setExpanded] = useState(() => new Set(defaultExpanded));
|
|
20
|
+
const visible = visibleItems(items, expanded);
|
|
21
|
+
// Tab キーで止まる項目。選択中の項目が見えていればそれ、なければ最初の項目
|
|
22
|
+
const [focusedId, setFocusedId] = useState(null);
|
|
23
|
+
const tabStop = visible.find(v => v.item.id === focusedId)?.item.id ?? visible.find(v => v.item.id === selected)?.item.id ?? visible[0]?.item.id;
|
|
24
|
+
const itemRefs = useRef(new Map());
|
|
25
|
+
// キーボードで移った項目へ、描いた後にフォーカスを動かす
|
|
26
|
+
const [pendingFocus, setPendingFocus] = useState(null);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (pendingFocus === null)
|
|
29
|
+
return;
|
|
30
|
+
itemRefs.current.get(pendingFocus)?.focus();
|
|
31
|
+
setPendingFocus(null);
|
|
32
|
+
}, [pendingFocus]);
|
|
33
|
+
const unlabeled = !props["aria-label"] && !props["aria-labelledby"];
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (unlabeled)
|
|
36
|
+
console.warn("TreeView: aria-label か aria-labelledby で、ツリーの名前を付ける");
|
|
37
|
+
}, [unlabeled]);
|
|
38
|
+
function select(id) {
|
|
39
|
+
if (value === undefined)
|
|
40
|
+
setInternal(id);
|
|
41
|
+
if (id !== selected)
|
|
42
|
+
onChange?.(id);
|
|
43
|
+
}
|
|
44
|
+
function moveTo(id) {
|
|
45
|
+
setFocusedId(id);
|
|
46
|
+
setPendingFocus(id);
|
|
47
|
+
}
|
|
48
|
+
function setOpen(id, open) {
|
|
49
|
+
setExpanded(prev => {
|
|
50
|
+
const next = new Set(prev);
|
|
51
|
+
if (open)
|
|
52
|
+
next.add(id);
|
|
53
|
+
else
|
|
54
|
+
next.delete(id);
|
|
55
|
+
return next;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const handleKeyDown = (event, { item, parentId }) => {
|
|
59
|
+
// 入れ子の項目のキーは、その項目だけで受ける。親の項目へ伝わらないようにする
|
|
60
|
+
if (event.target !== event.currentTarget)
|
|
61
|
+
return;
|
|
62
|
+
const position = visible.findIndex(v => v.item.id === item.id);
|
|
63
|
+
const open = expanded.has(item.id);
|
|
64
|
+
let handled = true;
|
|
65
|
+
switch (event.key) {
|
|
66
|
+
case "ArrowDown":
|
|
67
|
+
if (position < visible.length - 1)
|
|
68
|
+
moveTo(visible[position + 1].item.id);
|
|
69
|
+
break;
|
|
70
|
+
case "ArrowUp":
|
|
71
|
+
if (position > 0)
|
|
72
|
+
moveTo(visible[position - 1].item.id);
|
|
73
|
+
break;
|
|
74
|
+
case "ArrowRight":
|
|
75
|
+
// 閉じた親は開き、開いた親は最初の子へ移る。子のない項目では何もしない
|
|
76
|
+
if (hasChildren(item)) {
|
|
77
|
+
if (!open)
|
|
78
|
+
setOpen(item.id, true);
|
|
79
|
+
else
|
|
80
|
+
moveTo(item.children[0].id);
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case "ArrowLeft":
|
|
84
|
+
// 開いた親は閉じ、それ以外は親の項目へ移る
|
|
85
|
+
if (hasChildren(item) && open)
|
|
86
|
+
setOpen(item.id, false);
|
|
87
|
+
else if (parentId !== null)
|
|
88
|
+
moveTo(parentId);
|
|
89
|
+
break;
|
|
90
|
+
case "Home":
|
|
91
|
+
moveTo(visible[0].item.id);
|
|
92
|
+
break;
|
|
93
|
+
case "End":
|
|
94
|
+
moveTo(visible[visible.length - 1].item.id);
|
|
95
|
+
break;
|
|
96
|
+
case "Enter":
|
|
97
|
+
case " ":
|
|
98
|
+
select(item.id);
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
handled = false;
|
|
102
|
+
}
|
|
103
|
+
if (handled)
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
};
|
|
106
|
+
const handleClick = (event, item) => {
|
|
107
|
+
// 押された項目を、event.target から最も近い treeitem で決める。入れ子の子を押したときに、親の項目でも受けないようにする
|
|
108
|
+
const target = event.target;
|
|
109
|
+
if (target.closest('[role="treeitem"]') !== event.currentTarget)
|
|
110
|
+
return;
|
|
111
|
+
setFocusedId(item.id);
|
|
112
|
+
// 開閉の印を押したときは開閉だけ、行のほかの所を押したときは選ぶ
|
|
113
|
+
if (target.closest("[data-tree-toggle]"))
|
|
114
|
+
setOpen(item.id, !expanded.has(item.id));
|
|
115
|
+
else
|
|
116
|
+
select(item.id);
|
|
117
|
+
};
|
|
118
|
+
function renderItems(list, level, parentId) {
|
|
119
|
+
return list.map((item, i) => {
|
|
120
|
+
const parent = hasChildren(item);
|
|
121
|
+
const open = parent && expanded.has(item.id);
|
|
122
|
+
const isSelected = item.id === selected;
|
|
123
|
+
return (_jsxs("li", { ref: el => {
|
|
124
|
+
if (el)
|
|
125
|
+
itemRefs.current.set(item.id, el);
|
|
126
|
+
else
|
|
127
|
+
itemRefs.current.delete(item.id);
|
|
128
|
+
}, role: "treeitem", "aria-level": level, "aria-setsize": list.length, "aria-posinset": i + 1, "aria-expanded": parent ? open : undefined, "aria-selected": isSelected, tabIndex: item.id === tabStop ? 0 : -1, onKeyDown: event => handleKeyDown(event, { item, parentId }), onClick: event => handleClick(event, item), onFocus: event => {
|
|
129
|
+
if (event.target === event.currentTarget)
|
|
130
|
+
setFocusedId(item.id);
|
|
131
|
+
},
|
|
132
|
+
// フォーカスの輪は、入れ子の子まで囲まないように、この項目の行(直下の div)にだけ描く
|
|
133
|
+
// lint-ignore INTERACTION-013 輪は treeitem ではなく直下の行に [&:focus-visible>div]:ring-2 で描く(docs/components/tree-view.md の「ツリービューの作り方」)
|
|
134
|
+
className: "outline-none [&:focus-visible>div]:ring-2 [&:focus-visible>div]:ring-ring", children: [_jsxs("div", {
|
|
135
|
+
// 階層ごとに 1.5rem(24px)ずつ字下げする。階層の数で決まる値なので、クラスではなく style で渡す
|
|
136
|
+
style: { paddingInlineStart: `${(level - 1) * 1.5}rem` }, className: cn("flex min-h-11 cursor-pointer items-center rounded-md pe-4 text-sm leading-tight", isSelected ? "bg-accent font-semibold text-accent-foreground" : "text-foreground hover:bg-secondary"), children: [_jsx("span", { "data-tree-toggle": parent || undefined, "aria-hidden": "true", className: "flex size-11 shrink-0 items-center justify-center", children: parent && (_jsx(ChevronRightIcon, { "aria-hidden": "true", className: cn("size-4 text-icon transition-transform duration-150 motion-reduce:transition-none", open && "rotate-90") })) }), item.icon && _jsx("span", { className: "me-2 flex shrink-0 items-center text-icon", children: item.icon }), _jsx("span", { className: "min-w-0 py-2 break-words", children: item.label })] }), parent && open && (_jsx("ul", { role: "group", children: renderItems(item.children, level + 1, item.id) }))] }, item.id));
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return (_jsx("ul", { role: "tree", className: className, ...props, children: renderItems(items, 1, null) }));
|
|
140
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./TreeView.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./TreeView.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useUnsavedChanges.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useUnsavedChanges.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface UnsavedChanges {
|
|
3
|
+
/**
|
|
4
|
+
* アプリの中で別の画面へ移る前に呼ぶ。保存していない変更がなければ、すぐに leave を呼ぶ。
|
|
5
|
+
* あれば確認のダイアログを開き、「変更を破棄する」で leave を、キャンセルかEscキーで stay を呼ぶ。
|
|
6
|
+
* ルーターとのつなぎ(移動を止める、移る、止めた移動を取り消す)は、leave と stay に書く
|
|
7
|
+
*/
|
|
8
|
+
confirmLeave: (leave: () => void, stay?: () => void) => void;
|
|
9
|
+
/** 確認のダイアログ。フォームの画面のどこかに置く */
|
|
10
|
+
confirmDialog: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare function useUnsavedChanges(dirty: boolean): UnsavedChanges;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { DiscardChangesDialog } from "../dialog/DiscardChangesDialog.js";
|
|
4
|
+
// 保存していない変更があるまま画面を離れるときの確認(docs/form/unsaved-changes.md)。
|
|
5
|
+
// タブやウィンドウを閉じる、再読み込み、アプリの外へ移るときは、dirty の間だけ beforeunload を登録して、ブラウザの確認を出す。
|
|
6
|
+
// アプリの中の移動はルーターによって作り方が違うので、確認のダイアログを開く confirmLeave を返し、つなぎは使う側が書く
|
|
7
|
+
export function useUnsavedChanges(dirty) {
|
|
8
|
+
const [pending, setPending] = useState(null);
|
|
9
|
+
// confirmLeave を描くたびに作り直さないように、今の dirty を ref で読む(ルーターの effect の依存に入れても動き直さない)
|
|
10
|
+
const dirtyRef = useRef(dirty);
|
|
11
|
+
dirtyRef.current = dirty;
|
|
12
|
+
// 確認で破棄を選んだ後の移動(location.assign など)で、ブラウザの確認をもう一度出さない
|
|
13
|
+
const leaving = useRef(false);
|
|
14
|
+
// 確認のダイアログが閉じたのが、破棄したためか(そうでなければ、留まる)
|
|
15
|
+
const discarded = useRef(false);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!dirty)
|
|
18
|
+
return;
|
|
19
|
+
leaving.current = false;
|
|
20
|
+
const onBeforeUnload = (event) => {
|
|
21
|
+
if (!leaving.current)
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
};
|
|
24
|
+
window.addEventListener("beforeunload", onBeforeUnload);
|
|
25
|
+
return () => window.removeEventListener("beforeunload", onBeforeUnload);
|
|
26
|
+
}, [dirty]);
|
|
27
|
+
const confirmLeave = useCallback((leave, stay) => {
|
|
28
|
+
if (!dirtyRef.current) {
|
|
29
|
+
leave();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
setPending({ leave, stay });
|
|
33
|
+
}, []);
|
|
34
|
+
const confirmDialog = (_jsx(DiscardChangesDialog, { open: pending !== null, action: "leave", onDiscard: () => {
|
|
35
|
+
discarded.current = true;
|
|
36
|
+
leaving.current = true;
|
|
37
|
+
pending?.leave();
|
|
38
|
+
}, onClose: () => {
|
|
39
|
+
if (!discarded.current)
|
|
40
|
+
pending?.stay?.();
|
|
41
|
+
discarded.current = false;
|
|
42
|
+
setPending(null);
|
|
43
|
+
} }));
|
|
44
|
+
return { confirmLeave, confirmDialog };
|
|
45
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface UsageLimitProps {
|
|
2
|
+
/** 何の上限かを書いた名前(「今週の利用」)。メーターの名前にもなる */
|
|
3
|
+
title: string;
|
|
4
|
+
/** 使える残りの量 */
|
|
5
|
+
remaining: number;
|
|
6
|
+
/** 上限の量。省いたときは100 */
|
|
7
|
+
max?: number;
|
|
8
|
+
/** メーターの右に出す残りの文字(「残り 120回 / 500回」)。読み上げでもこの文字を読む。省いたときは「残り30%」のように割合を出す */
|
|
9
|
+
valueText?: string;
|
|
10
|
+
/** 使える量が戻る日時 */
|
|
11
|
+
resetsAt: Date;
|
|
12
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function UsageLimit({ title, remaining, max, valueText, resetsAt, className }: UsageLimitProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { cn } from "../../lib/cn.js";
|
|
4
|
+
import { formatDate, formatTime } from "../../lib/date.js";
|
|
5
|
+
import { formatNumber } from "../../lib/number.js";
|
|
6
|
+
import { Meter } from "../meter/Meter.js";
|
|
7
|
+
// 残りが上限のこの割合より少ないと「残りわずか」、この割合以下を「少なめ」にする(docs/components/usage-limit.md)
|
|
8
|
+
const LOW_RATIO = 0.1;
|
|
9
|
+
const HIGH_RATIO = 0.3;
|
|
10
|
+
// AI を使える残りの量と、いつ戻るかを示す(docs/components/usage-limit.md)。
|
|
11
|
+
// 残りの量は Meter で示し、多いほど良い範囲として、色と文字の両方で範囲を示す(COMPONENTS-114)。
|
|
12
|
+
// いつ戻るかは、メーターの下に日付と時刻の文字で書き、メーターの説明(aria-describedby)として続けて読ませる
|
|
13
|
+
export function UsageLimit({ title, remaining, max = 100, valueText, resetsAt, className }) {
|
|
14
|
+
const titleId = useId();
|
|
15
|
+
const resetId = useId();
|
|
16
|
+
const top = max > 0 ? max : 1;
|
|
17
|
+
const percent = Math.round((Math.min(Math.max(remaining, 0), top) / top) * 100);
|
|
18
|
+
const exhausted = remaining <= 0;
|
|
19
|
+
const when = `${formatDate(resetsAt)} ${formatTime(resetsAt)}`;
|
|
20
|
+
return (_jsxs("div", { className: cn("space-y-2", className), children: [_jsx("p", { id: titleId, className: "text-sm leading-tight font-medium text-foreground", children: title }), _jsx(Meter, { "aria-labelledby": titleId, "aria-describedby": resetId, value: Math.max(remaining, 0), max: top, low: top * LOW_RATIO, high: top * HIGH_RATIO, optimum: top, valueText: valueText ?? `残り${formatNumber(percent)}%`, levelLabels: { good: "余裕あり", fair: "少なめ", poor: exhausted ? "上限に達した" : "残りわずか" } }), _jsx("p", { id: resetId, className: "text-sm leading-relaxed text-muted-foreground", children: exhausted ? `${when}に、使える量が戻ります。それまでは使えません。` : `${when}に、使える量が戻ります。` })] }));
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./UsageLimit.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./UsageLimit.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DetailsHTMLAttributes } from "react";
|
|
2
|
+
/** 見つけたページ */
|
|
3
|
+
export interface WebSearchResult {
|
|
4
|
+
/** ページの題 */
|
|
5
|
+
title: string;
|
|
6
|
+
/** ページのURL */
|
|
7
|
+
url: string;
|
|
8
|
+
/** サイトの名前(「Plain UI のドキュメント」「example.com」) */
|
|
9
|
+
site: string;
|
|
10
|
+
}
|
|
11
|
+
export interface WebSearchResultsProps extends Omit<DetailsHTMLAttributes<HTMLDetailsElement>, "open" | "title" | "children" | "results"> {
|
|
12
|
+
/** 検索した言葉。検索した順に並べる */
|
|
13
|
+
queries: string[];
|
|
14
|
+
/** 見つけたページ。検索している間は、見つかった分だけを渡す */
|
|
15
|
+
results: WebSearchResult[];
|
|
16
|
+
/** 検索している間は true にする */
|
|
17
|
+
searching?: boolean;
|
|
18
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function WebSearchResults({ queries, results, searching, className, ...props }: WebSearchResultsProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronDownIcon } from "lucide-react";
|
|
3
|
+
import { cn } from "../../lib/cn.js";
|
|
4
|
+
import { formatNumber } from "../../lib/number.js";
|
|
5
|
+
import { Spinner } from "../spinner/Spinner.js";
|
|
6
|
+
import { TextLink } from "../text-link/TextLink.js";
|
|
7
|
+
// 返答の上に、検索した言葉と見つけたページの一覧を、たためる形で置く(docs/components/web-search-results.md)。
|
|
8
|
+
// ネイティブの <details> と <summary> で作り、開閉はブラウザーに任せる(Accordion、AgentThinking と同じ)。
|
|
9
|
+
// 既定はたたんでおき、閉じた行に件数を書く。ページは新しいタブで開く本文の中のリンクにする(返答を読みながら出典を開くため)
|
|
10
|
+
export function WebSearchResults({ queries, results, searching = false, className, ...props }) {
|
|
11
|
+
const summary = searching
|
|
12
|
+
? "ウェブを検索しています"
|
|
13
|
+
: results.length > 0
|
|
14
|
+
? `ウェブを検索し、${formatNumber(results.length)}件のページを見つけました`
|
|
15
|
+
: "ウェブを検索しましたが、ページは見つかりませんでした";
|
|
16
|
+
return (_jsxs("details", { className: cn("group", className), ...props, children: [_jsxs("summary", { className: "flex min-h-11 w-fit cursor-pointer list-none items-center gap-2 rounded-md text-sm leading-tight text-muted-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring [&::-webkit-details-marker]:hidden", children: [searching && _jsx(Spinner, {}), _jsx("span", { className: "text-trim", children: summary }), _jsx(ChevronDownIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-icon transition-transform duration-150 group-open:rotate-180 motion-reduce:transition-none" })] }), _jsxs("div", { className: "mt-2 space-y-4 border-l pl-4 text-sm leading-relaxed", children: [queries.length > 0 && (_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground", children: "\u691C\u7D22\u3057\u305F\u8A00\u8449" }), _jsx("ul", { className: "space-y-1 text-foreground", children: queries.map((query, index) => (_jsxs("li", { className: "break-words", children: ["\u300C", query, "\u300D"] }, index))) })] })), results.length > 0 && (_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground", children: "\u898B\u3064\u3051\u305F\u30DA\u30FC\u30B8" }), _jsx("ol", { className: "space-y-2", children: results.map((result, index) => (_jsxs("li", { className: "min-w-0", children: [_jsx("p", { className: "break-words", children: _jsx(TextLink, { href: result.url, external: true, children: result.title }) }), _jsx("p", { className: "break-words text-muted-foreground", children: result.site })] }, index))) })] }))] })] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./WebSearchResults.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./WebSearchResults.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare function supportsAnchorPositioning(): boolean;
|
|
2
|
+
export interface PlaceBelowAnchorOptions {
|
|
3
|
+
/** 横の揃え。start は対象の左端に合わせ、center は対象の中央に合わせる。既定は start */
|
|
4
|
+
align?: "start" | "center";
|
|
5
|
+
/** 対象との間の隙間(px)。既定は0 */
|
|
6
|
+
gap?: number;
|
|
7
|
+
/**
|
|
8
|
+
* 下に入りきらないときに上に出し、左右を画面の中に収める。収めるときに画面の端から離す幅(px)を渡す。
|
|
9
|
+
* 渡さなければ、常に真下に置き、はみ出しても動かさない。
|
|
10
|
+
* popover の大きさを測るので、出した後(showPopover の後)に呼ぶ
|
|
11
|
+
*/
|
|
12
|
+
edge?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function placeBelowAnchor(popover: HTMLElement, anchor: HTMLElement | null, options?: PlaceBelowAnchorOptions): void;
|
|
15
|
+
export interface PlaceAboveAnchorOptions {
|
|
16
|
+
/** 対象との間の隙間(px)。既定は0 */
|
|
17
|
+
gap?: number;
|
|
18
|
+
/** 上に入りきらないときに対象の下に出すかを決めるときの、画面の端から離す幅(px)。既定は0 */
|
|
19
|
+
edge?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function placeAboveAnchor(popover: HTMLElement, anchor: HTMLElement | null, options?: PlaceAboveAnchorOptions): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// 開いたボタンや対象の近くに popover を置く処理(Menu、Popover、Tooltip、Combobox、ComposerPanel で共有する)。
|
|
2
|
+
// 位置は CSS の anchor positioning(position-area)で決め、対応しないブラウザでだけ、ここで計算して置く。
|
|
3
|
+
// position-area のクラスは、Tailwind が読み取れるように、使う部品の側にそのまま書く(lib/ は @source の外にあるため)
|
|
4
|
+
// anchor positioning に対応しているか
|
|
5
|
+
export function supportsAnchorPositioning() {
|
|
6
|
+
return typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("position-area", "block-end");
|
|
7
|
+
}
|
|
8
|
+
// 対応しないブラウザで呼ぶ。対象の真下に置く(popover は position: fixed)。対応していれば何もしない。
|
|
9
|
+
// 揃えと隙間を渡さなければ、対象の左端に合わせて隙間なしで置くだけなので、開く直前(beforetoggle で開くとき)に呼べる
|
|
10
|
+
export function placeBelowAnchor(popover, anchor, options = {}) {
|
|
11
|
+
if (supportsAnchorPositioning())
|
|
12
|
+
return;
|
|
13
|
+
const rect = anchor?.getBoundingClientRect();
|
|
14
|
+
if (!rect)
|
|
15
|
+
return;
|
|
16
|
+
const { align = "start", gap = 0, edge } = options;
|
|
17
|
+
const needsSize = align === "center" || edge !== undefined;
|
|
18
|
+
const size = needsSize ? popover.getBoundingClientRect() : undefined;
|
|
19
|
+
let left = align === "center" && size ? rect.left + rect.width / 2 - size.width / 2 : rect.left;
|
|
20
|
+
let top = rect.bottom + gap;
|
|
21
|
+
if (edge !== undefined && size) {
|
|
22
|
+
const view = popover.ownerDocument.defaultView;
|
|
23
|
+
const width = view?.innerWidth ?? Infinity;
|
|
24
|
+
const height = view?.innerHeight ?? Infinity;
|
|
25
|
+
// 左右は画面の中に収める。popover が画面より広いときは、左端に寄せる
|
|
26
|
+
left = Math.max(Math.min(Math.max(left, edge), width - size.width - edge), edge);
|
|
27
|
+
// 下に入りきらなければ、対象の上に出す
|
|
28
|
+
if (top + size.height > height)
|
|
29
|
+
top = rect.top - gap - size.height;
|
|
30
|
+
}
|
|
31
|
+
popover.style.top = `${top}px`;
|
|
32
|
+
popover.style.left = `${left}px`;
|
|
33
|
+
}
|
|
34
|
+
// 対応しないブラウザで呼ぶ。対象の真上に、対象の左端に合わせて置く(popover は position: fixed)。対応していれば何もしない。
|
|
35
|
+
// 上に入りきらないときは、対象の真下に出す。入力欄の上に開くパネル(ComposerPanel)に使う。
|
|
36
|
+
// popover の高さを測るので、出した後(showPopover の後)に呼ぶ
|
|
37
|
+
export function placeAboveAnchor(popover, anchor, options = {}) {
|
|
38
|
+
if (supportsAnchorPositioning())
|
|
39
|
+
return;
|
|
40
|
+
const rect = anchor?.getBoundingClientRect();
|
|
41
|
+
if (!rect)
|
|
42
|
+
return;
|
|
43
|
+
const { gap = 0, edge = 0 } = options;
|
|
44
|
+
const height = popover.getBoundingClientRect().height;
|
|
45
|
+
let top = rect.top - gap - height;
|
|
46
|
+
if (top < edge)
|
|
47
|
+
top = rect.bottom + gap;
|
|
48
|
+
popover.style.top = `${top}px`;
|
|
49
|
+
popover.style.left = `${rect.left}px`;
|
|
50
|
+
}
|
package/dist/lib/cn.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cn(...classes: Array<string | false | null | undefined>): string;
|
package/dist/lib/cn.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** 週の始まりの曜日。0 が日曜、1 が月曜(Date#getDay と同じ数え方) */
|
|
2
|
+
export type WeekStart = 0 | 1;
|
|
3
|
+
/** その日の 0:00 */
|
|
4
|
+
export declare function startOfDay(date: Date): Date;
|
|
5
|
+
/** n 日後(負の数なら前) */
|
|
6
|
+
export declare function addDays(date: Date, days: number): Date;
|
|
7
|
+
/**
|
|
8
|
+
* n か月後(負の数なら前)。移った先の月にその日がなければ、月末にそろえる(1月31日の1か月後は2月28日か29日)。
|
|
9
|
+
* Date に任せると3月3日のように次の月へあふれるため、ここで切り詰める
|
|
10
|
+
*/
|
|
11
|
+
export declare function addMonths(date: Date, months: number): Date;
|
|
12
|
+
/** その月の日数 */
|
|
13
|
+
export declare function daysInMonth(date: Date): number;
|
|
14
|
+
/** その月の1日 */
|
|
15
|
+
export declare function startOfMonth(date: Date): Date;
|
|
16
|
+
/** その日を含む週の始まりの日 */
|
|
17
|
+
export declare function startOfWeek(date: Date, weekStartsOn: WeekStart): Date;
|
|
18
|
+
/** その日を含む週の終わりの日 */
|
|
19
|
+
export declare function endOfWeek(date: Date, weekStartsOn: WeekStart): Date;
|
|
20
|
+
/** 同じ日か(時刻は見ない) */
|
|
21
|
+
export declare function isSameDay(a: Date, b: Date): boolean;
|
|
22
|
+
/** 同じ月か */
|
|
23
|
+
export declare function isSameMonth(a: Date, b: Date): boolean;
|
|
24
|
+
/** 日付の前後を比べる(時刻は見ない)。a が前なら負、同じ日なら 0、後なら正 */
|
|
25
|
+
export declare function compareDays(a: Date, b: Date): number;
|
|
26
|
+
/** min から max の間に収める。省いた端は制限しない */
|
|
27
|
+
export declare function clampDay(date: Date, min?: Date, max?: Date): Date;
|
|
28
|
+
/** min から max の間(両端を含む)にあるか */
|
|
29
|
+
export declare function isDayInRange(date: Date, min?: Date, max?: Date): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* 月の日付を、週ごとの行に並べる。月の外の日は null にする。
|
|
32
|
+
* 行の数は月によって4〜6になる
|
|
33
|
+
*/
|
|
34
|
+
export declare function monthWeeks(month: Date, weekStartsOn: WeekStart): Array<Array<Date | null>>;
|
|
35
|
+
/** 週の始まりから並べた7つの曜日(その曜日の日付を1つずつ) */
|
|
36
|
+
export declare function weekDays(weekStartsOn: WeekStart): Date[];
|
|
37
|
+
/** 「2026年11月24日」 */
|
|
38
|
+
export declare function formatDate(date: Date): string;
|
|
39
|
+
/** 「2026年11月」 */
|
|
40
|
+
export declare function formatMonth(date: Date): string;
|
|
41
|
+
/** 曜日の1文字(「月」)と、略さない形(「月曜日」) */
|
|
42
|
+
export declare function formatWeekday(date: Date): {
|
|
43
|
+
narrow: string;
|
|
44
|
+
long: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* 期間を「2026年11月30日〜12月6日」と書く。終わりの日が始まりと同じ年なら、終わりの年を省く。
|
|
48
|
+
* Intl.DateTimeFormat#formatRange は、実行する環境によって「2026/11/30~2026/12/06」の形になるため使わない
|
|
49
|
+
*/
|
|
50
|
+
export declare function formatDateRange(start: Date, end: Date): string;
|
|
51
|
+
/** 「9:05」「14:05」 */
|
|
52
|
+
export declare function formatTime(date: Date): string;
|
|
53
|
+
/** parseDate の結果。読めたら date、形が違えば format、その月にない日(2月30日など)なら day と、その月の1日 */
|
|
54
|
+
export type ParsedDate = {
|
|
55
|
+
date: Date;
|
|
56
|
+
} | {
|
|
57
|
+
error: "format";
|
|
58
|
+
} | {
|
|
59
|
+
error: "day";
|
|
60
|
+
month: Date;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* 打ち込んだ文字を日付として読む(DatePicker で使う)。年は4桁、月と日は1桁か2桁で、年、月、日の順に書いた形だけを読む。
|
|
64
|
+
* 前後の空白は無視する。空の文字は読まず、format を返す(空かどうかは使う側で先に見る)
|
|
65
|
+
*/
|
|
66
|
+
export declare function parseDate(text: string): ParsedDate;
|
|
67
|
+
/** フォームで送る形(2026-12-01)。ネイティブの <input type="date"> の値と同じ形にする */
|
|
68
|
+
export declare function toDateValue(date: Date): string;
|
|
69
|
+
/** 「2026年11月24日 14:05」 */
|
|
70
|
+
export declare function formatDateTime(date: Date): string;
|
|
71
|
+
/**
|
|
72
|
+
* 時刻を、24時間以内なら今からの時間(「3分前」「5時間前」)で、それより前なら「2026年11月24日 14:05」で書く
|
|
73
|
+
* (docs/writing/date-and-number.md の「日付、数値、単位」)。
|
|
74
|
+
* 1分に満たないときと、端末の時計のずれで now より後になったときは「たった今」にする。
|
|
75
|
+
* Intl.RelativeTimeFormat の ja-JP は「3 分前」と数と単位の間を空けるため、使わずに組み立てる
|
|
76
|
+
*/
|
|
77
|
+
export declare function formatRelativeTime(date: Date, now: Date): string;
|
package/dist/lib/date.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// 日付の計算と書き方の小さな関数(Calendar、CalendarView、DatePicker、Notification で使う)。
|
|
2
|
+
// 日付のライブラリは入れず、Date と Intl.DateTimeFormat だけで書く(#65。Temporal は主なブラウザの対応がそろってから移る)。
|
|
3
|
+
// 日付を計算する関数は、端末の時差の日付(年・月・日)だけを見て、時刻は 0:00 にそろえた新しい Date を返す。渡された Date は書き換えない
|
|
4
|
+
// 日付を「2026年11月24日」と書く(docs/writing/date-and-number.md の「日付、数値、単位」)
|
|
5
|
+
const dateFormatter = new Intl.DateTimeFormat("ja-JP", { dateStyle: "long" });
|
|
6
|
+
// 月を「2026年11月」と書く
|
|
7
|
+
const monthFormatter = new Intl.DateTimeFormat("ja-JP", { year: "numeric", month: "long" });
|
|
8
|
+
// 曜日を「月」と「月曜日」で書く
|
|
9
|
+
const narrowWeekdayFormatter = new Intl.DateTimeFormat("ja-JP", { weekday: "narrow" });
|
|
10
|
+
const longWeekdayFormatter = new Intl.DateTimeFormat("ja-JP", { weekday: "long" });
|
|
11
|
+
// 年を省いた日付を「12月6日」と書く(期間の終わりの日)
|
|
12
|
+
const monthDayFormatter = new Intl.DateTimeFormat("ja-JP", { month: "long", day: "numeric" });
|
|
13
|
+
// 時刻を「9:05」「14:05」のように24時間で書く(docs/writing/date-and-number.md の「日付、数値、単位」)
|
|
14
|
+
const timeFormatter = new Intl.DateTimeFormat("ja-JP", { hour: "numeric", minute: "2-digit", hourCycle: "h23" });
|
|
15
|
+
/** その日の 0:00 */
|
|
16
|
+
export function startOfDay(date) {
|
|
17
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
18
|
+
}
|
|
19
|
+
/** n 日後(負の数なら前) */
|
|
20
|
+
export function addDays(date, days) {
|
|
21
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + days);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* n か月後(負の数なら前)。移った先の月にその日がなければ、月末にそろえる(1月31日の1か月後は2月28日か29日)。
|
|
25
|
+
* Date に任せると3月3日のように次の月へあふれるため、ここで切り詰める
|
|
26
|
+
*/
|
|
27
|
+
export function addMonths(date, months) {
|
|
28
|
+
const first = new Date(date.getFullYear(), date.getMonth() + months, 1);
|
|
29
|
+
const day = Math.min(date.getDate(), daysInMonth(first));
|
|
30
|
+
return new Date(first.getFullYear(), first.getMonth(), day);
|
|
31
|
+
}
|
|
32
|
+
/** その月の日数 */
|
|
33
|
+
export function daysInMonth(date) {
|
|
34
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
|
35
|
+
}
|
|
36
|
+
/** その月の1日 */
|
|
37
|
+
export function startOfMonth(date) {
|
|
38
|
+
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
39
|
+
}
|
|
40
|
+
/** その日を含む週の始まりの日 */
|
|
41
|
+
export function startOfWeek(date, weekStartsOn) {
|
|
42
|
+
return addDays(date, -((date.getDay() - weekStartsOn + 7) % 7));
|
|
43
|
+
}
|
|
44
|
+
/** その日を含む週の終わりの日 */
|
|
45
|
+
export function endOfWeek(date, weekStartsOn) {
|
|
46
|
+
return addDays(startOfWeek(date, weekStartsOn), 6);
|
|
47
|
+
}
|
|
48
|
+
/** 同じ日か(時刻は見ない) */
|
|
49
|
+
export function isSameDay(a, b) {
|
|
50
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
51
|
+
}
|
|
52
|
+
/** 同じ月か */
|
|
53
|
+
export function isSameMonth(a, b) {
|
|
54
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
55
|
+
}
|
|
56
|
+
/** 日付の前後を比べる(時刻は見ない)。a が前なら負、同じ日なら 0、後なら正 */
|
|
57
|
+
export function compareDays(a, b) {
|
|
58
|
+
return startOfDay(a).getTime() - startOfDay(b).getTime();
|
|
59
|
+
}
|
|
60
|
+
/** min から max の間に収める。省いた端は制限しない */
|
|
61
|
+
export function clampDay(date, min, max) {
|
|
62
|
+
if (min && compareDays(date, min) < 0)
|
|
63
|
+
return startOfDay(min);
|
|
64
|
+
if (max && compareDays(date, max) > 0)
|
|
65
|
+
return startOfDay(max);
|
|
66
|
+
return startOfDay(date);
|
|
67
|
+
}
|
|
68
|
+
/** min から max の間(両端を含む)にあるか */
|
|
69
|
+
export function isDayInRange(date, min, max) {
|
|
70
|
+
return !(min && compareDays(date, min) < 0) && !(max && compareDays(date, max) > 0);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 月の日付を、週ごとの行に並べる。月の外の日は null にする。
|
|
74
|
+
* 行の数は月によって4〜6になる
|
|
75
|
+
*/
|
|
76
|
+
export function monthWeeks(month, weekStartsOn) {
|
|
77
|
+
const first = startOfMonth(month);
|
|
78
|
+
const last = new Date(first.getFullYear(), first.getMonth(), daysInMonth(first));
|
|
79
|
+
const weeks = [];
|
|
80
|
+
for (let start = startOfWeek(first, weekStartsOn); compareDays(start, last) <= 0; start = addDays(start, 7)) {
|
|
81
|
+
weeks.push(Array.from({ length: 7 }, (_, i) => addDays(start, i)).map(day => (isSameMonth(day, first) ? day : null)));
|
|
82
|
+
}
|
|
83
|
+
return weeks;
|
|
84
|
+
}
|
|
85
|
+
/** 週の始まりから並べた7つの曜日(その曜日の日付を1つずつ) */
|
|
86
|
+
export function weekDays(weekStartsOn) {
|
|
87
|
+
// 2023年1月1日は日曜。そこから週の始まりの曜日まで進めて7日を並べる
|
|
88
|
+
return Array.from({ length: 7 }, (_, i) => new Date(2023, 0, 1 + weekStartsOn + i));
|
|
89
|
+
}
|
|
90
|
+
/** 「2026年11月24日」 */
|
|
91
|
+
export function formatDate(date) {
|
|
92
|
+
return dateFormatter.format(date);
|
|
93
|
+
}
|
|
94
|
+
/** 「2026年11月」 */
|
|
95
|
+
export function formatMonth(date) {
|
|
96
|
+
return monthFormatter.format(date);
|
|
97
|
+
}
|
|
98
|
+
/** 曜日の1文字(「月」)と、略さない形(「月曜日」) */
|
|
99
|
+
export function formatWeekday(date) {
|
|
100
|
+
return { narrow: narrowWeekdayFormatter.format(date), long: longWeekdayFormatter.format(date) };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 期間を「2026年11月30日〜12月6日」と書く。終わりの日が始まりと同じ年なら、終わりの年を省く。
|
|
104
|
+
* Intl.DateTimeFormat#formatRange は、実行する環境によって「2026/11/30~2026/12/06」の形になるため使わない
|
|
105
|
+
*/
|
|
106
|
+
export function formatDateRange(start, end) {
|
|
107
|
+
const last = start.getFullYear() === end.getFullYear() ? monthDayFormatter.format(end) : formatDate(end);
|
|
108
|
+
return `${formatDate(start)}〜${last}`;
|
|
109
|
+
}
|
|
110
|
+
/** 「9:05」「14:05」 */
|
|
111
|
+
export function formatTime(date) {
|
|
112
|
+
return timeFormatter.format(date);
|
|
113
|
+
}
|
|
114
|
+
// 年、月、日を区切って書いた形(2026/12/1、2026-12-01、2026.12.1、2026年12月1日)。
|
|
115
|
+
// 全角の数字と記号は、NFKC で半角にそろえてから読む。かな漢字の変換中に入りやすい「ー」と「−」も区切りに数える
|
|
116
|
+
const separatedDate = /^([1-9]\d{3})\s*(?:[-/.ー−]|年)\s*(\d{1,2})\s*(?:[-/.ー−]|月)\s*(\d{1,2})\s*日?$/;
|
|
117
|
+
// 区切らずに8桁で書いた形(20261201)
|
|
118
|
+
const compactDate = /^([1-9]\d{3})(\d{2})(\d{2})$/;
|
|
119
|
+
/**
|
|
120
|
+
* 打ち込んだ文字を日付として読む(DatePicker で使う)。年は4桁、月と日は1桁か2桁で、年、月、日の順に書いた形だけを読む。
|
|
121
|
+
* 前後の空白は無視する。空の文字は読まず、format を返す(空かどうかは使う側で先に見る)
|
|
122
|
+
*/
|
|
123
|
+
export function parseDate(text) {
|
|
124
|
+
const normalized = text.normalize("NFKC").trim();
|
|
125
|
+
const match = separatedDate.exec(normalized) ?? compactDate.exec(normalized);
|
|
126
|
+
if (!match)
|
|
127
|
+
return { error: "format" };
|
|
128
|
+
const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
129
|
+
if (month < 1 || month > 12 || day < 1)
|
|
130
|
+
return { error: "format" };
|
|
131
|
+
const first = new Date(year, month - 1, 1);
|
|
132
|
+
if (day > daysInMonth(first))
|
|
133
|
+
return { error: "day", month: first };
|
|
134
|
+
return { date: new Date(year, month - 1, day) };
|
|
135
|
+
}
|
|
136
|
+
/** フォームで送る形(2026-12-01)。ネイティブの <input type="date"> の値と同じ形にする */
|
|
137
|
+
export function toDateValue(date) {
|
|
138
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
139
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
140
|
+
}
|
|
141
|
+
// 日付と時刻を「2026年11月24日 14:05」と書く(docs/writing/date-and-number.md の「日付、数値、単位」)
|
|
142
|
+
const dateTimeFormatter = new Intl.DateTimeFormat("ja-JP", { dateStyle: "long", timeStyle: "short" });
|
|
143
|
+
const minute = 60 * 1000;
|
|
144
|
+
const hour = 60 * minute;
|
|
145
|
+
const day = 24 * hour;
|
|
146
|
+
/** 「2026年11月24日 14:05」 */
|
|
147
|
+
export function formatDateTime(date) {
|
|
148
|
+
return dateTimeFormatter.format(date);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 時刻を、24時間以内なら今からの時間(「3分前」「5時間前」)で、それより前なら「2026年11月24日 14:05」で書く
|
|
152
|
+
* (docs/writing/date-and-number.md の「日付、数値、単位」)。
|
|
153
|
+
* 1分に満たないときと、端末の時計のずれで now より後になったときは「たった今」にする。
|
|
154
|
+
* Intl.RelativeTimeFormat の ja-JP は「3 分前」と数と単位の間を空けるため、使わずに組み立てる
|
|
155
|
+
*/
|
|
156
|
+
export function formatRelativeTime(date, now) {
|
|
157
|
+
const elapsed = now.getTime() - date.getTime();
|
|
158
|
+
if (elapsed < minute)
|
|
159
|
+
return "たった今";
|
|
160
|
+
if (elapsed < hour)
|
|
161
|
+
return `${Math.floor(elapsed / minute)}分前`;
|
|
162
|
+
if (elapsed < day)
|
|
163
|
+
return `${Math.floor(elapsed / hour)}時間前`;
|
|
164
|
+
return formatDateTime(date);
|
|
165
|
+
}
|