tempest-react-sdk 0.39.0 → 0.40.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/dist/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/access/access-control-context.cjs.map +1 -1
- package/dist/access/use-can.cjs.map +1 -1
- package/dist/app/AppProviders.cjs.map +1 -1
- package/dist/app/AppProviders.js.map +1 -1
- package/dist/audio/use-audio-recorder.cjs.map +1 -1
- package/dist/audio/use-audio.cjs.map +1 -1
- package/dist/audio/use-microphone.cjs.map +1 -1
- package/dist/auth/create-auth-store.cjs.map +1 -1
- package/dist/auth/lazy-with-retry.cjs.map +1 -1
- package/dist/auth/passkey.cjs.map +1 -1
- package/dist/auth/passkey.js.map +1 -1
- package/dist/auth/use-passkey.cjs.map +1 -1
- package/dist/br/BrazilMap.cjs +1 -1
- package/dist/br/BrazilMap.cjs.map +1 -1
- package/dist/br/BrazilMap.js +2 -2
- package/dist/br/BrazilMap.js.map +1 -1
- package/dist/br/BrazilStateCitySelect.cjs.map +1 -1
- package/dist/br/BrazilStateCitySelect.js.map +1 -1
- package/dist/br/BrazilStateMap.cjs +1 -1
- package/dist/br/BrazilStateMap.cjs.map +1 -1
- package/dist/br/BrazilStateMap.js +2 -2
- package/dist/br/BrazilStateMap.js.map +1 -1
- package/dist/br/MapLegend.cjs.map +1 -1
- package/dist/br/MapLegend.js.map +1 -1
- package/dist/br/MapMarkers.cjs.map +1 -1
- package/dist/br/MapMarkers.js.map +1 -1
- package/dist/br/MunicipalitySearch.cjs.map +1 -1
- package/dist/br/MunicipalitySearch.js.map +1 -1
- package/dist/br/PixQRCode.cjs.map +1 -1
- package/dist/br/PixQRCode.js.map +1 -1
- package/dist/br/use-map-hover.cjs.map +1 -1
- package/dist/br/use-map-zoom.cjs.map +1 -1
- package/dist/capture/media-recorder.cjs +1 -1
- package/dist/capture/media-recorder.js +2 -2
- package/dist/capture/use-barcode-scanner.cjs +1 -1
- package/dist/capture/use-barcode-scanner.cjs.map +1 -1
- package/dist/capture/use-barcode-scanner.js +2 -2
- package/dist/capture/use-barcode-scanner.js.map +1 -1
- package/dist/capture/use-screen-capture.cjs.map +1 -1
- package/dist/capture/use-speech-recognition.cjs.map +1 -1
- package/dist/capture/use-torch.cjs.map +1 -1
- package/dist/capture/use-video-recorder.cjs.map +1 -1
- package/dist/charts/AreaChart.cjs.map +1 -1
- package/dist/charts/AreaChart.js.map +1 -1
- package/dist/charts/BarChart.cjs.map +1 -1
- package/dist/charts/BarChart.js.map +1 -1
- package/dist/charts/LineChart.cjs.map +1 -1
- package/dist/charts/LineChart.js.map +1 -1
- package/dist/charts/PieChart.cjs.map +1 -1
- package/dist/charts/PieChart.js.map +1 -1
- package/dist/charts/RadarChart.cjs.map +1 -1
- package/dist/charts/RadarChart.js.map +1 -1
- package/dist/charts/use-chart-colors.cjs.map +1 -1
- package/dist/components/AIChat/AIChat.cjs.map +1 -1
- package/dist/components/AIChat/AIChat.js.map +1 -1
- package/dist/components/AIChat/AIChatComposer.cjs.map +1 -1
- package/dist/components/AIChat/AIChatComposer.js.map +1 -1
- package/dist/components/AIChat/AIChatTurn.cjs.map +1 -1
- package/dist/components/AIChat/AIChatTurn.js.map +1 -1
- package/dist/components/Accordion/Accordion.cjs.map +1 -1
- package/dist/components/Accordion/Accordion.js.map +1 -1
- package/dist/components/Alert/Alert.cjs.map +1 -1
- package/dist/components/Alert/Alert.js.map +1 -1
- package/dist/components/AppBar/AppBar.cjs.map +1 -1
- package/dist/components/AppBar/AppBar.js.map +1 -1
- package/dist/components/AppShell/AppShell.cjs.map +1 -1
- package/dist/components/AppShell/AppShell.js.map +1 -1
- package/dist/components/AudioPlayer/AudioPlayer.cjs.map +1 -1
- package/dist/components/AudioPlayer/AudioPlayer.js.map +1 -1
- package/dist/components/AudioRecorder/AudioRecorder.cjs.map +1 -1
- package/dist/components/AudioRecorder/AudioRecorder.js.map +1 -1
- package/dist/components/Avatar/Avatar.cjs.map +1 -1
- package/dist/components/Avatar/Avatar.js.map +1 -1
- package/dist/components/AvatarGroup/AvatarGroup.cjs.map +1 -1
- package/dist/components/AvatarGroup/AvatarGroup.js.map +1 -1
- package/dist/components/Badge/Badge.cjs.map +1 -1
- package/dist/components/Badge/Badge.js.map +1 -1
- package/dist/components/Banner/Banner.cjs.map +1 -1
- package/dist/components/Banner/Banner.js.map +1 -1
- package/dist/components/BarcodeScanner/BarcodeScanner.cjs.map +1 -1
- package/dist/components/BarcodeScanner/BarcodeScanner.js.map +1 -1
- package/dist/components/BottomNavigation/BottomNavigation.cjs.map +1 -1
- package/dist/components/BottomNavigation/BottomNavigation.js.map +1 -1
- package/dist/components/BottomSheet/BottomSheet.cjs.map +1 -1
- package/dist/components/BottomSheet/BottomSheet.js.map +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.cjs.map +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.js.map +1 -1
- package/dist/components/Button/Button.cjs.map +1 -1
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Calendar/Calendar.cjs +1 -1
- package/dist/components/Calendar/Calendar.cjs.map +1 -1
- package/dist/components/Calendar/Calendar.js +38 -41
- package/dist/components/Calendar/Calendar.js.map +1 -1
- package/dist/components/Card/Card.cjs.map +1 -1
- package/dist/components/Card/Card.js.map +1 -1
- package/dist/components/Carousel/Carousel.cjs.map +1 -1
- package/dist/components/Carousel/Carousel.js.map +1 -1
- package/dist/components/Chat/Chat.cjs.map +1 -1
- package/dist/components/Chat/Chat.js.map +1 -1
- package/dist/components/Chat/ChatComposer.cjs.map +1 -1
- package/dist/components/Chat/ChatComposer.js.map +1 -1
- package/dist/components/Chat/chat-groups.cjs +1 -1
- package/dist/components/Chat/chat-groups.cjs.map +1 -1
- package/dist/components/Chat/chat-groups.js +2 -2
- package/dist/components/Chat/chat-groups.js.map +1 -1
- package/dist/components/Checkbox/Checkbox.cjs.map +1 -1
- package/dist/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/components/ChipInput/ChipInput.cjs.map +1 -1
- package/dist/components/ChipInput/ChipInput.js.map +1 -1
- package/dist/components/ClickOutside/ClickOutside.cjs.map +1 -1
- package/dist/components/CodeBlock/CodeBlock.cjs.map +1 -1
- package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/components/Collapsible/Collapsible.cjs.map +1 -1
- package/dist/components/Collapsible/Collapsible.js.map +1 -1
- package/dist/components/Combobox/Combobox.cjs.map +1 -1
- package/dist/components/Combobox/Combobox.js.map +1 -1
- package/dist/components/Command/Command.cjs.map +1 -1
- package/dist/components/Command/Command.js.map +1 -1
- package/dist/components/ConfirmDialog/ConfirmDialog.cjs.map +1 -1
- package/dist/components/ConfirmDialog/ConfirmDialog.js.map +1 -1
- package/dist/components/ContextMenu/ContextMenu.cjs.map +1 -1
- package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/components/CopyButton/CopyButton.cjs.map +1 -1
- package/dist/components/CopyButton/CopyButton.js.map +1 -1
- package/dist/components/DataList/DataList.cjs.map +1 -1
- package/dist/components/DataList/DataList.js.map +1 -1
- package/dist/components/DataTable/DataTable.cjs +1 -1
- package/dist/components/DataTable/DataTable.cjs.map +1 -1
- package/dist/components/DataTable/DataTable.js +2 -2
- package/dist/components/DataTable/DataTable.js.map +1 -1
- package/dist/components/DataTable/EditableCell.cjs.map +1 -1
- package/dist/components/DataTable/EditableCell.js.map +1 -1
- package/dist/components/DatePicker/DatePicker.cjs.map +1 -1
- package/dist/components/DateRangePicker/DateRangePicker.cjs.map +1 -1
- package/dist/components/DateRangePicker/DateRangePicker.js.map +1 -1
- package/dist/components/DescriptionList/DescriptionList.cjs.map +1 -1
- package/dist/components/DescriptionList/DescriptionList.js.map +1 -1
- package/dist/components/Divider/Divider.cjs.map +1 -1
- package/dist/components/Divider/Divider.js.map +1 -1
- package/dist/components/Drawer/Drawer.cjs.map +1 -1
- package/dist/components/Drawer/Drawer.js.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.cjs.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.js.map +1 -1
- package/dist/components/Dropzone/Dropzone.cjs.map +1 -1
- package/dist/components/Dropzone/Dropzone.js.map +1 -1
- package/dist/components/EmptyState/EmptyState.cjs.map +1 -1
- package/dist/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/components/ErrorState/ErrorState.cjs.map +1 -1
- package/dist/components/ErrorState/ErrorState.js.map +1 -1
- package/dist/components/FileUpload/FileUpload.cjs +1 -1
- package/dist/components/FileUpload/FileUpload.cjs.map +1 -1
- package/dist/components/FileUpload/FileUpload.js +1 -1
- package/dist/components/FileUpload/FileUpload.js.map +1 -1
- package/dist/components/FilterBar/FilterBar.cjs.map +1 -1
- package/dist/components/FilterBar/FilterBar.js.map +1 -1
- package/dist/components/FloatingActionButton/FloatingActionButton.cjs.map +1 -1
- package/dist/components/FloatingActionButton/FloatingActionButton.js.map +1 -1
- package/dist/components/Form/Form.cjs.map +1 -1
- package/dist/components/Form/Form.js.map +1 -1
- package/dist/components/HoverCard/HoverCard.cjs.map +1 -1
- package/dist/components/HoverCard/HoverCard.js.map +1 -1
- package/dist/components/Image/Image.cjs.map +1 -1
- package/dist/components/ImageCropper/ImageCropper.cjs +1 -1
- package/dist/components/ImageCropper/ImageCropper.cjs.map +1 -1
- package/dist/components/ImageCropper/ImageCropper.js +1 -1
- package/dist/components/ImageCropper/ImageCropper.js.map +1 -1
- package/dist/components/Input/Input.cjs.map +1 -1
- package/dist/components/Input/Input.js.map +1 -1
- package/dist/components/InstallBanner/InstallBanner.cjs.map +1 -1
- package/dist/components/InstallBanner/InstallBanner.js.map +1 -1
- package/dist/components/InstallButton/InstallButton.cjs.map +1 -1
- package/dist/components/InstallButton/InstallButton.js.map +1 -1
- package/dist/components/Kanban/Kanban.cjs.map +1 -1
- package/dist/components/Kanban/Kanban.js.map +1 -1
- package/dist/components/Label/Label.cjs.map +1 -1
- package/dist/components/Label/Label.js.map +1 -1
- package/dist/components/Lightbox/Lightbox.cjs.map +1 -1
- package/dist/components/Lightbox/Lightbox.js.map +1 -1
- package/dist/components/ListTile/ListTile.cjs.map +1 -1
- package/dist/components/ListTile/ListTile.js.map +1 -1
- package/dist/components/Markdown/Markdown.cjs +1 -1
- package/dist/components/Markdown/Markdown.cjs.map +1 -1
- package/dist/components/Markdown/Markdown.js +2 -2
- package/dist/components/Markdown/Markdown.js.map +1 -1
- package/dist/components/Masonry/Masonry.cjs.map +1 -1
- package/dist/components/Masonry/Masonry.js.map +1 -1
- package/dist/components/Menubar/Menubar.cjs.map +1 -1
- package/dist/components/Menubar/Menubar.js.map +1 -1
- package/dist/components/Modal/Modal.cjs.map +1 -1
- package/dist/components/Modal/Modal.js.map +1 -1
- package/dist/components/ModalsManager/ModalsManager.cjs.map +1 -1
- package/dist/components/ModalsManager/ModalsManager.js.map +1 -1
- package/dist/components/Money/Money.cjs.map +1 -1
- package/dist/components/Money/Money.js.map +1 -1
- package/dist/components/MultiSelect/MultiSelect.cjs.map +1 -1
- package/dist/components/MultiSelect/MultiSelect.js.map +1 -1
- package/dist/components/NProgress/NProgress.cjs.map +1 -1
- package/dist/components/Navbar/Navbar.cjs.map +1 -1
- package/dist/components/Navbar/Navbar.js.map +1 -1
- package/dist/components/NavigationMenu/NavigationMenu.cjs.map +1 -1
- package/dist/components/NavigationMenu/NavigationMenu.js.map +1 -1
- package/dist/components/NavigationRail/NavigationRail.cjs.map +1 -1
- package/dist/components/NavigationRail/NavigationRail.js.map +1 -1
- package/dist/components/NotificationCenter/NotificationCenter.cjs.map +1 -1
- package/dist/components/NotificationCenter/NotificationCenter.js.map +1 -1
- package/dist/components/NotificationCenter/use-notification-inbox.cjs.map +1 -1
- package/dist/components/OfflineIndicator/OfflineIndicator.cjs.map +1 -1
- package/dist/components/OfflineIndicator/OfflineIndicator.js.map +1 -1
- package/dist/components/Page/Page.cjs.map +1 -1
- package/dist/components/Page/Page.js.map +1 -1
- package/dist/components/Pagination/Pagination.cjs.map +1 -1
- package/dist/components/Pagination/Pagination.js.map +1 -1
- package/dist/components/PasswordInput/PasswordInput.cjs.map +1 -1
- package/dist/components/PasswordInput/PasswordInput.js.map +1 -1
- package/dist/components/PinInput/PinInput.cjs.map +1 -1
- package/dist/components/PinInput/PinInput.js.map +1 -1
- package/dist/components/Popover/Popover.cjs.map +1 -1
- package/dist/components/Popover/Popover.js.map +1 -1
- package/dist/components/Portal/Portal.cjs.map +1 -1
- package/dist/components/Progress/Progress.cjs.map +1 -1
- package/dist/components/Progress/Progress.js.map +1 -1
- package/dist/components/QRCode/QRCode.cjs.map +1 -1
- package/dist/components/QRCode/QRCode.js.map +1 -1
- package/dist/components/Radio/Radio.cjs.map +1 -1
- package/dist/components/Radio/Radio.js.map +1 -1
- package/dist/components/RangeSlider/RangeSlider.cjs.map +1 -1
- package/dist/components/RangeSlider/RangeSlider.js.map +1 -1
- package/dist/components/RatingStars/RatingStars.cjs.map +1 -1
- package/dist/components/RatingStars/RatingStars.js.map +1 -1
- package/dist/components/RefreshIndicator/RefreshIndicator.cjs.map +1 -1
- package/dist/components/RefreshIndicator/RefreshIndicator.js.map +1 -1
- package/dist/components/RelativeTime/RelativeTime.cjs.map +1 -1
- package/dist/components/RelativeTime/RelativeTime.js.map +1 -1
- package/dist/components/Resizable/Resizable.cjs.map +1 -1
- package/dist/components/Resizable/Resizable.js.map +1 -1
- package/dist/components/Scheduler/Scheduler.cjs.map +1 -1
- package/dist/components/Scheduler/Scheduler.js.map +1 -1
- package/dist/components/ScrollArea/ScrollArea.cjs.map +1 -1
- package/dist/components/SearchBar/SearchBar.cjs.map +1 -1
- package/dist/components/SearchBar/SearchBar.js.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.cjs.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
- package/dist/components/Select/Select.cjs.map +1 -1
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Sidebar/Sidebar.cjs.map +1 -1
- package/dist/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/components/SignaturePad/SignaturePad.cjs.map +1 -1
- package/dist/components/SignaturePad/SignaturePad.js.map +1 -1
- package/dist/components/Slider/Slider.cjs.map +1 -1
- package/dist/components/Slider/Slider.js.map +1 -1
- package/dist/components/Sparkline/Sparkline.cjs.map +1 -1
- package/dist/components/Sparkline/Sparkline.js.map +1 -1
- package/dist/components/Spinner/Spinner.cjs.map +1 -1
- package/dist/components/Spinner/Spinner.js.map +1 -1
- package/dist/components/Stat/Stat.cjs.map +1 -1
- package/dist/components/Stat/Stat.js.map +1 -1
- package/dist/components/Stepper/Stepper.cjs.map +1 -1
- package/dist/components/Stepper/Stepper.js.map +1 -1
- package/dist/components/StepperInput/StepperInput.cjs.map +1 -1
- package/dist/components/StepperInput/StepperInput.js.map +1 -1
- package/dist/components/Switch/Switch.cjs.map +1 -1
- package/dist/components/Switch/Switch.js.map +1 -1
- package/dist/components/SyncStatusBadge/SyncStatusBadge.cjs.map +1 -1
- package/dist/components/SyncStatusBadge/SyncStatusBadge.js.map +1 -1
- package/dist/components/Table/Table.cjs.map +1 -1
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/Tabs/Tabs.cjs.map +1 -1
- package/dist/components/Tabs/Tabs.js.map +1 -1
- package/dist/components/Tag/Tag.cjs.map +1 -1
- package/dist/components/Tag/Tag.js.map +1 -1
- package/dist/components/Textarea/Textarea.cjs.map +1 -1
- package/dist/components/Textarea/Textarea.js.map +1 -1
- package/dist/components/TimePicker/TimePicker.cjs.map +1 -1
- package/dist/components/TimePicker/TimePicker.js.map +1 -1
- package/dist/components/Timeline/Timeline.cjs.map +1 -1
- package/dist/components/Timeline/Timeline.js.map +1 -1
- package/dist/components/Toast/ToastProvider.cjs.map +1 -1
- package/dist/components/Toast/ToastProvider.js.map +1 -1
- package/dist/components/Toggle/Toggle.cjs.map +1 -1
- package/dist/components/ToggleGroup/ToggleGroup.cjs.map +1 -1
- package/dist/components/ToggleGroup/ToggleGroup.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.cjs.map +1 -1
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/components/Tour/Tour.cjs.map +1 -1
- package/dist/components/Tour/Tour.js.map +1 -1
- package/dist/components/Transfer/Transfer.cjs.map +1 -1
- package/dist/components/Transfer/Transfer.js.map +1 -1
- package/dist/components/TreeView/TreeView.cjs +1 -1
- package/dist/components/TreeView/TreeView.cjs.map +1 -1
- package/dist/components/TreeView/TreeView.js +1 -4
- package/dist/components/TreeView/TreeView.js.map +1 -1
- package/dist/components/UpdatePrompt/UpdatePrompt.cjs.map +1 -1
- package/dist/components/UpdatePrompt/UpdatePrompt.js.map +1 -1
- package/dist/components/VirtualList/VirtualList.cjs.map +1 -1
- package/dist/components/VirtualList/VirtualList.js.map +1 -1
- package/dist/components/VirtualTable/VirtualTable.cjs.map +1 -1
- package/dist/components/VirtualTable/VirtualTable.js.map +1 -1
- package/dist/components/VisuallyHidden/VisuallyHidden.cjs.map +1 -1
- package/dist/components/Wizard/Wizard.cjs.map +1 -1
- package/dist/components/Wizard/Wizard.js.map +1 -1
- package/dist/data/data-provider-context.cjs.map +1 -1
- package/dist/data/use-resource.cjs.map +1 -1
- package/dist/editor/RichTextEditor.cjs.map +1 -1
- package/dist/editor/RichTextEditor.js.map +1 -1
- package/dist/error-boundary/use-error-handler.cjs.map +1 -1
- package/dist/feature-flags/FeatureFlagsProvider.cjs.map +1 -1
- package/dist/forms/FormField.cjs.map +1 -1
- package/dist/forms/masked-inputs.cjs +1 -1
- package/dist/forms/masked-inputs.cjs.map +1 -1
- package/dist/forms/masked-inputs.js +1 -1
- package/dist/forms/masked-inputs.js.map +1 -1
- package/dist/forms/use-viacep.cjs.map +1 -1
- package/dist/forms/use-zod-form.cjs.map +1 -1
- package/dist/forms/zod-resolver.cjs.map +1 -1
- package/dist/forms/zod-resolver.js.map +1 -1
- package/dist/geo/TrajectoryMap.cjs.map +1 -1
- package/dist/geo/TrajectoryMap.js.map +1 -1
- package/dist/geo/leaflet-map.cjs.map +1 -1
- package/dist/geo/leaflet-map.js.map +1 -1
- package/dist/geo/use-position-tracker.cjs.map +1 -1
- package/dist/hooks/use-announce.cjs.map +1 -1
- package/dist/hooks/use-async.cjs.map +1 -1
- package/dist/hooks/use-before-install-prompt.cjs.map +1 -1
- package/dist/hooks/use-breakpoint.cjs.map +1 -1
- package/dist/hooks/use-click-outside.cjs.map +1 -1
- package/dist/hooks/use-client-filter.cjs.map +1 -1
- package/dist/hooks/use-clipboard.cjs.map +1 -1
- package/dist/hooks/use-counter.cjs.map +1 -1
- package/dist/hooks/use-debounce.cjs.map +1 -1
- package/dist/hooks/use-deep-memo.cjs.map +1 -1
- package/dist/hooks/use-disclosure.cjs.map +1 -1
- package/dist/hooks/use-document-visibility.cjs.map +1 -1
- package/dist/hooks/use-event-listener.cjs.map +1 -1
- package/dist/hooks/use-geolocation.cjs.map +1 -1
- package/dist/hooks/use-hover.cjs.map +1 -1
- package/dist/hooks/use-idle.cjs.map +1 -1
- package/dist/hooks/use-install-prompt.cjs +1 -1
- package/dist/hooks/use-install-prompt.cjs.map +1 -1
- package/dist/hooks/use-install-prompt.js +1 -1
- package/dist/hooks/use-install-prompt.js.map +1 -1
- package/dist/hooks/use-intersection-observer.cjs.map +1 -1
- package/dist/hooks/use-interval.cjs.map +1 -1
- package/dist/hooks/use-is-first-render.cjs.map +1 -1
- package/dist/hooks/use-keyboard-shortcut.cjs +1 -1
- package/dist/hooks/use-keyboard-shortcut.cjs.map +1 -1
- package/dist/hooks/use-keyboard-shortcut.js +1 -1
- package/dist/hooks/use-keyboard-shortcut.js.map +1 -1
- package/dist/hooks/use-list-state.cjs.map +1 -1
- package/dist/hooks/use-local-storage.cjs.map +1 -1
- package/dist/hooks/use-long-press-handlers.cjs.map +1 -1
- package/dist/hooks/use-long-press.cjs.map +1 -1
- package/dist/hooks/use-map.cjs.map +1 -1
- package/dist/hooks/use-media-devices.cjs.map +1 -1
- package/dist/hooks/use-media-permission.cjs.map +1 -1
- package/dist/hooks/use-media-query.cjs.map +1 -1
- package/dist/hooks/use-object-url.cjs.map +1 -1
- package/dist/hooks/use-online.cjs.map +1 -1
- package/dist/hooks/use-pagination.cjs.map +1 -1
- package/dist/hooks/use-previous.cjs.map +1 -1
- package/dist/hooks/use-queue.cjs.map +1 -1
- package/dist/hooks/use-resize-observer.cjs.map +1 -1
- package/dist/hooks/use-scroll-overflow.cjs.map +1 -1
- package/dist/hooks/use-service-worker-update.cjs.map +1 -1
- package/dist/hooks/use-set.cjs.map +1 -1
- package/dist/hooks/use-sortable.cjs +1 -1
- package/dist/hooks/use-sortable.cjs.map +1 -1
- package/dist/hooks/use-sortable.js +0 -2
- package/dist/hooks/use-sortable.js.map +1 -1
- package/dist/hooks/use-stable-callback.cjs.map +1 -1
- package/dist/hooks/use-storage-estimate.cjs.map +1 -1
- package/dist/hooks/use-throttle.cjs.map +1 -1
- package/dist/hooks/use-timeout.cjs.map +1 -1
- package/dist/hooks/use-toggle.cjs.map +1 -1
- package/dist/hooks/use-window-size.cjs.map +1 -1
- package/dist/http/api-client.cjs +1 -1
- package/dist/http/api-client.cjs.map +1 -1
- package/dist/http/api-client.js +7 -5
- package/dist/http/api-client.js.map +1 -1
- package/dist/http/resumable-upload.cjs +1 -1
- package/dist/http/resumable-upload.cjs.map +1 -1
- package/dist/http/resumable-upload.js +1 -1
- package/dist/http/resumable-upload.js.map +1 -1
- package/dist/http/use-poll.cjs.map +1 -1
- package/dist/i18n/I18nProvider.cjs.map +1 -1
- package/dist/icons/Icon.cjs.map +1 -1
- package/dist/icons/IconProvider.cjs.map +1 -1
- package/dist/icons/icon-context.cjs.map +1 -1
- package/dist/icons/use-icon.cjs.map +1 -1
- package/dist/imaging/use-image-processing.cjs.map +1 -1
- package/dist/oauth/GoogleSignIn.cjs.map +1 -1
- package/dist/oauth/GoogleSignIn.js.map +1 -1
- package/dist/oauth/use-oauth-callback.cjs.map +1 -1
- package/dist/offline/use-offline-sync.cjs.map +1 -1
- package/dist/push/use-push-subscription.cjs.map +1 -1
- package/dist/query/QueryProvider.cjs.map +1 -1
- package/dist/query/constants.cjs +1 -1
- package/dist/query/constants.cjs.map +1 -1
- package/dist/query/constants.js +10 -10
- package/dist/query/constants.js.map +1 -1
- package/dist/query/create-query-keys.cjs +1 -1
- package/dist/query/create-query-keys.cjs.map +1 -1
- package/dist/query/create-query-keys.js +1 -1
- package/dist/query/create-query-keys.js.map +1 -1
- package/dist/query/offline-persistence.cjs.map +1 -1
- package/dist/query/use-cursor-query.cjs.map +1 -1
- package/dist/query/use-offline-mutation.cjs.map +1 -1
- package/dist/query/use-paginated-query.cjs.map +1 -1
- package/dist/router/AppRouter.cjs +1 -1
- package/dist/router/AppRouter.cjs.map +1 -1
- package/dist/router/AppRouter.js +7 -2
- package/dist/router/AppRouter.js.map +1 -1
- package/dist/sse/use-event-stream.cjs.map +1 -1
- package/dist/store/create-store.cjs.map +1 -1
- package/dist/tabular/use-tabular-predictor.cjs.map +1 -1
- package/dist/telemetry/TelemetryProvider.cjs.map +1 -1
- package/dist/tempest-react-sdk.d.ts +25 -26
- package/dist/theme/ThemeProvider.cjs.map +1 -1
- package/dist/theme/color.cjs +1 -1
- package/dist/theme/color.cjs.map +1 -1
- package/dist/theme/color.js +1 -1
- package/dist/theme/color.js.map +1 -1
- package/dist/utils/cn.cjs +1 -1
- package/dist/utils/cn.cjs.map +1 -1
- package/dist/utils/cn.js +1 -1
- package/dist/utils/cn.js.map +1 -1
- package/dist/utils/objects.cjs +1 -1
- package/dist/utils/objects.cjs.map +1 -1
- package/dist/utils/objects.js +1 -1
- package/dist/utils/objects.js.map +1 -1
- package/dist/utils/xlsx.cjs +1 -1
- package/dist/utils/xlsx.cjs.map +1 -1
- package/dist/utils/xlsx.js +3 -3
- package/dist/utils/xlsx.js.map +1 -1
- package/dist/vision/core/exceptions.cjs.map +1 -1
- package/dist/vision/core/exceptions.js.map +1 -1
- package/dist/vision/core/metadata.cjs +1 -1
- package/dist/vision/core/metadata.cjs.map +1 -1
- package/dist/vision/core/metadata.js +1 -1
- package/dist/vision/core/metadata.js.map +1 -1
- package/dist/vision/io/image.cjs +1 -1
- package/dist/vision/io/image.cjs.map +1 -1
- package/dist/vision/io/image.js +4 -2
- package/dist/vision/io/image.js.map +1 -1
- package/dist/vision/preprocess/image.cjs +1 -1
- package/dist/vision/preprocess/image.cjs.map +1 -1
- package/dist/vision/preprocess/image.js +4 -2
- package/dist/vision/preprocess/image.js.map +1 -1
- package/dist/vision/tasks/base.cjs +1 -1
- package/dist/vision/tasks/base.cjs.map +1 -1
- package/dist/vision/tasks/base.js +3 -1
- package/dist/vision/tasks/base.js.map +1 -1
- package/dist/vision/tasks/classifier.cjs +1 -1
- package/dist/vision/tasks/classifier.cjs.map +1 -1
- package/dist/vision/tasks/classifier.js +2 -2
- package/dist/vision/tasks/classifier.js.map +1 -1
- package/dist/vision/tasks/detectClassify.cjs +1 -1
- package/dist/vision/tasks/detectClassify.cjs.map +1 -1
- package/dist/vision/tasks/detectClassify.js +16 -15
- package/dist/vision/tasks/detectClassify.js.map +1 -1
- package/dist/vision/use-camera-stream.cjs.map +1 -1
- package/dist/vision/use-live-luminance.cjs.map +1 -1
- package/dist/vite/create-vite-config.cjs +1 -1
- package/dist/vite/create-vite-config.cjs.map +1 -1
- package/dist/vite/create-vite-config.js +3 -3
- package/dist/vite/create-vite-config.js.map +1 -1
- package/dist/vite/tempest-icons.cjs.map +1 -1
- package/dist/vite/tempest-pwa-dev-sw.cjs.map +1 -1
- package/dist/vite/tempest-pwa-icons.cjs.map +1 -1
- package/dist/ws/use-web-socket.cjs +1 -1
- package/dist/ws/use-web-socket.cjs.map +1 -1
- package/dist/ws/use-web-socket.js +5 -3
- package/dist/ws/use-web-socket.js.map +1 -1
- package/package.json +2 -2
- package/template/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageCropper.js","names":[],"sources":["../../../src/components/ImageCropper/ImageCropper.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — pointer drag, wheel\n * zoom, aspect clamping and canvas export share one piece of geometry state, and the\n * props are the two halves of that: the frame (aspect, shape, maxZoom, label) and\n * the export (maxSize, outputType, outputQuality, onCropChange, ref). Threading the\n * geometry through props would duplicate the clamp maths.\n */\nimport {\n type HTMLAttributes,\n type KeyboardEvent,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useId,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport { cn } from \"@/utils/cn\";\n\nimport {\n clampOffset,\n computeCropRect,\n coverScale,\n type Offset,\n outputSize,\n type Size,\n} from \"./crop-geometry\";\nimport styles from \"./ImageCropper.module.css\";\n\n/** Imperative handle for exporting the current crop. */\nexport interface ImageCropperHandle {\n /**\n * Render the current crop and resolve with it.\n *\n * Resolves `null` when the image has not loaded yet or the browser refuses to\n * encode — never throws, so a submit handler does not need a try/catch.\n */\n crop: () => Promise<Blob | null>;\n /** Recentre at zoom 1. */\n reset: () => void;\n}\n\nexport interface ImageCropperProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** The image to crop: a `File`/`Blob` from an input, or a URL. */\n src: File | Blob | string;\n /** Crop aspect ratio as `width / height`. Default `1` (square). */\n aspect?: number;\n /** Maximum zoom over the cover scale. Default `4`. */\n maxZoom?: number;\n /**\n * Cap on the longest edge of the exported image, in px.\n *\n * Without it the export keeps the source resolution, which is right for a\n * document scan and wasteful for an avatar.\n */\n maxSize?: number;\n /** Output MIME type. Default `\"image/png\"`. */\n outputType?: string;\n /** Output quality for lossy types, `0`–`1`. Default `0.92`. */\n outputQuality?: number;\n /** Overlay shape. `\"circle\"` for an avatar, `\"rect\"` for a document. Default `\"rect\"`. */\n shape?: \"rect\" | \"circle\";\n /** Called whenever the crop changes, e.g. to enable a submit button. */\n onCropChange?: (state: { zoom: number; offset: Offset }) => void;\n /** Accessible name for the crop area. */\n label?: string;\n ref?: React.Ref<ImageCropperHandle>;\n}\n\n/** Pixels moved per arrow-key press. */\nconst KEY_STEP = 12;\n\n/** Zoom added or removed per `+`/`-` press, and per wheel notch. */\nconst ZOOM_STEP = 0.15;\n\n/**\n * Crop an image to a fixed aspect ratio.\n *\n * The frame stays put and the image pans and zooms behind it — the model an avatar\n * or document-photo flow wants, where the output shape is decided by the app and\n * the user only chooses what lands inside it. (A free-form draggable rectangle is a\n * different component; this one cannot produce an off-ratio crop by construction.)\n *\n * The export reads the *natural* pixels through a canvas, so a 4000 px photo is not\n * silently downsampled to whatever the on-screen preview measured. The image is\n * also always clamped to cover the frame, so an export can never contain the empty\n * bands you get from panning past an edge.\n *\n * Works by pointer, wheel and keyboard: arrows pan, `+`/`-` zoom, `0` resets.\n *\n * @example\n * const cropper = useRef<ImageCropperHandle>(null);\n *\n * <ImageCropper ref={cropper} src={file} aspect={1} shape=\"circle\" maxSize={512} />\n * <Button onClick={async () => upload(await cropper.current?.crop())}>Salvar</Button>\n */\nexport function ImageCropper({\n src,\n aspect = 1,\n maxZoom = 4,\n maxSize,\n outputType = \"image/png\",\n outputQuality = 0.92,\n shape = \"rect\",\n onCropChange,\n label = \"Área de recorte\",\n className,\n ref,\n ...rest\n}: ImageCropperProps) {\n /**\n * Id for the shortcut hint.\n *\n * Generated rather than derived from `label`: a label with spaces would produce\n * an id with spaces, and `aria-describedby` splits on whitespace — so the\n * description would silently never associate with the frame.\n */\n const hintId = `${useId()}-hint`;\n\n const frameRef = useRef<HTMLDivElement>(null);\n const imageRef = useRef<HTMLImageElement | null>(null);\n const dragRef = useRef<{\n pointerId: number;\n startX: number;\n startY: number;\n from: Offset;\n } | null>(null);\n\n const [url, setUrl] = useState<string | null>(null);\n const [natural, setNatural] = useState<Size | null>(null);\n const [frame, setFrame] = useState<Size>({ width: 0, height: 0 });\n const [zoom, setZoom] = useState(1);\n const [offset, setOffset] = useState<Offset>({ x: 0, y: 0 });\n\n /**\n * Resolve `src` to a displayable URL.\n *\n * A `File`/`Blob` needs `createObjectURL`, and the URL must be revoked when the\n * source changes or the component unmounts — otherwise every re-pick of a photo\n * leaks the previous one for the lifetime of the document.\n */\n useEffect(() => {\n if (typeof src === \"string\") {\n setUrl(src);\n return;\n }\n const objectUrl = URL.createObjectURL(src);\n setUrl(objectUrl);\n return () => URL.revokeObjectURL(objectUrl);\n }, [src]);\n\n // A new source invalidates the previous framing.\n useEffect(() => {\n setNatural(null);\n setZoom(1);\n setOffset({ x: 0, y: 0 });\n }, [url]);\n\n /** Track the frame's rendered size — the crop math is all relative to it. */\n useEffect(() => {\n const element = frameRef.current;\n if (!element) return;\n const measure = () =>\n setFrame({ width: element.clientWidth, height: element.clientHeight });\n measure();\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(measure);\n observer.observe(element);\n return () => observer.disconnect();\n }, []);\n\n const scale = natural ? coverScale(natural, frame) * zoom : 0;\n\n /**\n * On-screen image size.\n *\n * Memoized because the pan callback depends on it: a fresh object every render\n * would rebuild that callback every render, and the pointer handlers close over\n * it during a drag.\n */\n const displayed = useMemo<Size>(\n () =>\n natural\n ? { width: natural.width * scale, height: natural.height * scale }\n : { width: 0, height: 0 },\n [natural, scale],\n );\n\n /** Apply a pan, clamped so the frame stays covered. */\n const pan = useCallback(\n (next: Offset) => {\n setOffset((current) => {\n const clamped = clampOffset(next, displayed, frame);\n if (clamped.x === current.x && clamped.y === current.y) return current;\n onCropChange?.({ zoom, offset: clamped });\n return clamped;\n });\n },\n [displayed, frame, onCropChange, zoom],\n );\n\n /**\n * Apply a zoom, then re-clamp the offset.\n *\n * Re-clamping is not optional: zooming *out* shrinks the image, so an offset\n * that was legal a moment ago can now expose background.\n */\n const applyZoom = useCallback(\n (next: number) => {\n const clampedZoom = Math.min(maxZoom, Math.max(1, next));\n setZoom(clampedZoom);\n if (!natural) return;\n const nextScale = coverScale(natural, frame) * clampedZoom;\n const nextDisplayed = {\n width: natural.width * nextScale,\n height: natural.height * nextScale,\n };\n setOffset((current) => {\n const clamped = clampOffset(current, nextDisplayed, frame);\n onCropChange?.({ zoom: clampedZoom, offset: clamped });\n return clamped;\n });\n },\n [frame, maxZoom, natural, onCropChange],\n );\n\n const reset = useCallback(() => {\n setZoom(1);\n setOffset({ x: 0, y: 0 });\n onCropChange?.({ zoom: 1, offset: { x: 0, y: 0 } });\n }, [onCropChange]);\n\n /**\n * Draw the current crop and encode it.\n *\n * Returns `null` rather than throwing on the paths a caller cannot do anything\n * about: no image yet, no 2D context, or an encoder that declined.\n */\n const crop = useCallback(async (): Promise<Blob | null> => {\n const image = imageRef.current;\n if (!image || !natural) return null;\n\n const rect = computeCropRect({ image: natural, frame, zoom, offset });\n if (rect.sWidth <= 0 || rect.sHeight <= 0) return null;\n\n const out = outputSize(rect, maxSize);\n const canvas = document.createElement(\"canvas\");\n canvas.width = out.width;\n canvas.height = out.height;\n const context = canvas.getContext(\"2d\");\n if (!context) return null;\n\n context.drawImage(\n image,\n rect.sx,\n rect.sy,\n rect.sWidth,\n rect.sHeight,\n 0,\n 0,\n out.width,\n out.height,\n );\n\n return new Promise((resolve) => {\n canvas.toBlob((blob) => resolve(blob), outputType, outputQuality);\n });\n }, [frame, maxSize, natural, offset, outputQuality, outputType, zoom]);\n\n useImperativeHandle(ref, () => ({ crop, reset }), [crop, reset]);\n\n const onPointerDown = (event: ReactPointerEvent<HTMLDivElement>): void => {\n if (!natural) return;\n dragRef.current = {\n pointerId: event.pointerId,\n startX: event.clientX,\n startY: event.clientY,\n from: offset,\n };\n event.currentTarget.setPointerCapture?.(event.pointerId);\n };\n\n const onPointerMove = (event: ReactPointerEvent<HTMLDivElement>): void => {\n const drag = dragRef.current;\n if (!drag || drag.pointerId !== event.pointerId) return;\n pan({\n x: drag.from.x + (event.clientX - drag.startX),\n y: drag.from.y + (event.clientY - drag.startY),\n });\n };\n\n const endDrag = (event: ReactPointerEvent<HTMLDivElement>): void => {\n if (dragRef.current?.pointerId !== event.pointerId) return;\n dragRef.current = null;\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {\n const step = event.shiftKey ? KEY_STEP * 4 : KEY_STEP;\n const moves: Record<string, Offset> = {\n ArrowLeft: { x: -step, y: 0 },\n ArrowRight: { x: step, y: 0 },\n ArrowUp: { x: 0, y: -step },\n ArrowDown: { x: 0, y: step },\n };\n const move = moves[event.key];\n if (move) {\n event.preventDefault();\n pan({ x: offset.x + move.x, y: offset.y + move.y });\n return;\n }\n if (event.key === \"+\" || event.key === \"=\") {\n event.preventDefault();\n applyZoom(zoom + ZOOM_STEP);\n } else if (event.key === \"-\" || event.key === \"_\") {\n event.preventDefault();\n applyZoom(zoom - ZOOM_STEP);\n } else if (event.key === \"0\") {\n event.preventDefault();\n reset();\n }\n };\n\n return (\n <div className={cn(styles.wrapper, className)} {...rest}>\n <div\n ref={frameRef}\n className={cn(styles.frame, shape === \"circle\" && styles.circle)}\n style={{ aspectRatio: String(aspect) }}\n role=\"group\"\n aria-label={label}\n aria-describedby={hintId}\n tabIndex={0}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={endDrag}\n onPointerCancel={endDrag}\n onKeyDown={onKeyDown}\n onWheel={(event) => {\n event.preventDefault();\n applyZoom(zoom + (event.deltaY < 0 ? ZOOM_STEP : -ZOOM_STEP));\n }}\n >\n {url && (\n <img\n ref={imageRef}\n src={url}\n alt=\"\"\n draggable={false}\n className={styles.image}\n style={{\n width: displayed.width || undefined,\n height: displayed.height || undefined,\n transform: `translate(${offset.x}px, ${offset.y}px)`,\n }}\n onLoad={(event) => {\n const element = event.currentTarget;\n // A decode can succeed and still report no intrinsic size —\n // an SVG without a viewBox is the common case. Accepting\n // that would enable the controls over an image the crop\n // maths can do nothing with.\n if (element.naturalWidth > 0 && element.naturalHeight > 0) {\n setNatural({\n width: element.naturalWidth,\n height: element.naturalHeight,\n });\n }\n }}\n />\n )}\n </div>\n\n <div className={styles.controls}>\n <input\n type=\"range\"\n className={styles.zoom}\n min={1}\n max={maxZoom}\n step={0.01}\n value={zoom}\n onChange={(event) => applyZoom(Number(event.target.value))}\n aria-label=\"Zoom\"\n disabled={!natural}\n />\n <button type=\"button\" className={styles.reset} onClick={reset} disabled={!natural}>\n Centralizar\n </button>\n </div>\n\n <p id={hintId} className={styles.hint}>\n Arraste para reposicionar. Setas movem, <kbd>+</kbd> e <kbd>−</kbd> dão zoom,{\" \"}\n <kbd>0</kbd> centraliza.\n </p>\n </div>\n );\n}\n"],"mappings":";;;;;;AAyEA,IAAM,IAAW,IAGX,IAAY;AAuBlB,SAAgB,EAAa,EACzB,QACA,YAAS,GACT,aAAU,GACV,YACA,gBAAa,aACb,mBAAgB,KAChB,WAAQ,QACR,iBACA,WAAQ,mBACR,cACA,QACA,GAAG,KACe;CAQlB,IAAM,IAAS,GAAG,EAAM,EAAE,QAEpB,IAAW,EAAuB,IAAI,GACtC,IAAW,EAAgC,IAAI,GAC/C,IAAU,EAKN,IAAI,GAER,CAAC,GAAK,KAAU,EAAwB,IAAI,GAC5C,CAAC,GAAS,KAAc,EAAsB,IAAI,GAClD,CAAC,GAAO,KAAY,EAAe;EAAE,OAAO;EAAG,QAAQ;CAAE,CAAC,GAC1D,CAAC,GAAM,KAAW,EAAS,CAAC,GAC5B,CAAC,GAAQ,KAAa,EAAiB;EAAE,GAAG;EAAG,GAAG;CAAE,CAAC;CA2B3D,AAlBA,QAAgB;EACZ,IAAI,OAAO,KAAQ,UAAU;GACzB,EAAO,CAAG;GACV;EACJ;EACA,IAAM,IAAY,IAAI,gBAAgB,CAAG;EAEzC,OADA,EAAO,CAAS,SACH,IAAI,gBAAgB,CAAS;CAC9C,GAAG,CAAC,CAAG,CAAC,GAGR,QAAgB;EAGZ,AAFA,EAAW,IAAI,GACf,EAAQ,CAAC,GACT,EAAU;GAAE,GAAG;GAAG,GAAG;EAAE,CAAC;CAC5B,GAAG,CAAC,CAAG,CAAC,GAGR,QAAgB;EACZ,IAAM,IAAU,EAAS;EACzB,IAAI,CAAC,GAAS;EACd,IAAM,UACF,EAAS;GAAE,OAAO,EAAQ;GAAa,QAAQ,EAAQ;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f,IAAM,IAAU,EAAM;MAKtB,AAAI,EAAQ,eAAe,KAAK,EAAQ,gBAAgB,KACpD,EAAW;OACP,OAAO,EAAQ;OACf,QAAQ,EAAQ;MACpB,CAAC;KAET;IACH,CAAA;GAEJ,CAAA;GAEL,kBAAC,OAAD;IAAK,WAAW,EAAO;cAAvB,CACI,kBAAC,SAAD;KACI,MAAK;KACL,WAAW,EAAO;KAClB,KAAK;KACL,KAAK;KACL,MAAM;KACN,OAAO;KACP,WAAW,MAAU,EAAU,OAAO,EAAM,OAAO,KAAK,CAAC;KACzD,cAAW;KACX,UAAU,CAAC;IACd,CAAA,GACD,kBAAC,UAAD;KAAQ,MAAK;KAAS,WAAW,EAAO;KAAO,SAAS;KAAO,UAAU,CAAC;eAAS;IAE3E,CAAA,CACP;;GAEL,kBAAC,KAAD;IAAG,IAAI;IAAQ,WAAW,EAAO;cAAjC;KAAuC;KACK,kBAAC,OAAD,EAAA,UAAK,IAAM,CAAA;KAAC;KAAG,kBAAC,OAAD,EAAA,UAAK,IAAM,CAAA;KAAC;KAAW;KAC9E,kBAAC,OAAD,EAAA,UAAK,IAAM,CAAA;KAAC;IACb;;EACF;;AAEb"}
|
|
1
|
+
{"version":3,"file":"ImageCropper.js","names":[],"sources":["../../../src/components/ImageCropper/ImageCropper.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — pointer drag, wheel\n * zoom, aspect clamping and canvas export share one piece of geometry state, and the\n * props are the two halves of that: the frame (aspect, shape, maxZoom, label) and\n * the export (maxSize, outputType, outputQuality, onCropChange, ref). Threading the\n * geometry through props would duplicate the clamp maths.\n */\nimport {\n type HTMLAttributes,\n type KeyboardEvent,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useId,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport { cn } from \"@/utils/cn\";\n\nimport {\n clampOffset,\n computeCropRect,\n coverScale,\n type Offset,\n outputSize,\n type Size,\n} from \"./crop-geometry\";\nimport styles from \"./ImageCropper.module.css\";\n\n/** Imperative handle for exporting the current crop. */\nexport interface ImageCropperHandle {\n /**\n * Render the current crop and resolve with it.\n *\n * Resolves `null` when the image has not loaded yet or the browser refuses to\n * encode — never throws, so a submit handler does not need a try/catch.\n */\n crop: () => Promise<Blob | null>;\n /** Recentre at zoom 1. */\n reset: () => void;\n}\n\nexport interface ImageCropperProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** The image to crop: a `File`/`Blob` from an input, or a URL. */\n src: File | Blob | string;\n /** Crop aspect ratio as `width / height`. Default `1` (square). */\n aspect?: number;\n /** Maximum zoom over the cover scale. Default `4`. */\n maxZoom?: number;\n /**\n * Cap on the longest edge of the exported image, in px.\n *\n * Without it the export keeps the source resolution, which is right for a\n * document scan and wasteful for an avatar.\n */\n maxSize?: number;\n /** Output MIME type. Default `\"image/png\"`. */\n outputType?: string;\n /** Output quality for lossy types, `0`–`1`. Default `0.92`. */\n outputQuality?: number;\n /** Overlay shape. `\"circle\"` for an avatar, `\"rect\"` for a document. Default `\"rect\"`. */\n shape?: \"rect\" | \"circle\";\n /** Called whenever the crop changes, e.g. to enable a submit button. */\n onCropChange?: (state: { zoom: number; offset: Offset }) => void;\n /** Accessible name for the crop area. */\n label?: string;\n ref?: React.Ref<ImageCropperHandle>;\n}\n\n/** Pixels moved per arrow-key press. */\nconst KEY_STEP = 12;\n\n/** Zoom added or removed per `+`/`-` press, and per wheel notch. */\nconst ZOOM_STEP = 0.15;\n\n/**\n * Crop an image to a fixed aspect ratio.\n *\n * The frame stays put and the image pans and zooms behind it — the model an avatar\n * or document-photo flow wants, where the output shape is decided by the app and\n * the user only chooses what lands inside it. (A free-form draggable rectangle is a\n * different component; this one cannot produce an off-ratio crop by construction.)\n *\n * The export reads the *natural* pixels through a canvas, so a 4000 px photo is not\n * silently downsampled to whatever the on-screen preview measured. The image is\n * also always clamped to cover the frame, so an export can never contain the empty\n * bands you get from panning past an edge.\n *\n * Works by pointer, wheel and keyboard: arrows pan, `+`/`-` zoom, `0` resets.\n *\n * @example\n * const cropper = useRef<ImageCropperHandle>(null);\n *\n * <ImageCropper ref={cropper} src={file} aspect={1} shape=\"circle\" maxSize={512} />\n * <Button onClick={async () => upload(await cropper.current?.crop())}>Salvar</Button>\n */\nexport function ImageCropper({\n src,\n aspect = 1,\n maxZoom = 4,\n maxSize,\n outputType = \"image/png\",\n outputQuality = 0.92,\n shape = \"rect\",\n onCropChange,\n label = \"Área de recorte\",\n className,\n ref,\n ...rest\n}: ImageCropperProps) {\n /**\n * Id for the shortcut hint.\n *\n * Generated rather than derived from `label`: a label with spaces would produce\n * an id with spaces, and `aria-describedby` splits on whitespace — so the\n * description would silently never associate with the frame.\n */\n const hintId = `${useId()}-hint`;\n\n const frameRef = useRef<HTMLDivElement>(null);\n const imageRef = useRef<HTMLImageElement | null>(null);\n const dragRef = useRef<{\n pointerId: number;\n startX: number;\n startY: number;\n from: Offset;\n } | null>(null);\n\n const [url, setUrl] = useState<string | null>(null);\n const [natural, setNatural] = useState<Size | null>(null);\n const [frame, setFrame] = useState<Size>({ width: 0, height: 0 });\n const [zoom, setZoom] = useState(1);\n const [offset, setOffset] = useState<Offset>({ x: 0, y: 0 });\n\n /**\n * Resolve `src` to a displayable URL.\n *\n * A `File`/`Blob` needs `createObjectURL`, and the URL must be revoked when the\n * source changes or the component unmounts — otherwise every re-pick of a photo\n * leaks the previous one for the lifetime of the document.\n */\n useEffect(() => {\n if (typeof src === \"string\") {\n setUrl(src);\n return;\n }\n const objectUrl = URL.createObjectURL(src);\n setUrl(objectUrl);\n return () => URL.revokeObjectURL(objectUrl);\n }, [src]);\n\n // A new source invalidates the previous framing.\n useEffect(() => {\n setNatural(null);\n setZoom(1);\n setOffset({ x: 0, y: 0 });\n }, [url]);\n\n /** Track the frame's rendered size — the crop math is all relative to it. */\n useEffect(() => {\n const element = frameRef.current;\n if (!element) return;\n const measure = () =>\n setFrame({ width: element.clientWidth, height: element.clientHeight });\n measure();\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(measure);\n observer.observe(element);\n return () => observer.disconnect();\n }, []);\n\n const scale = natural ? coverScale(natural, frame) * zoom : 0;\n\n /**\n * On-screen image size.\n *\n * Memoized because the pan callback depends on it: a fresh object every render\n * would rebuild that callback every render, and the pointer handlers close over\n * it during a drag.\n */\n const displayed = useMemo<Size>(\n () =>\n natural\n ? { width: natural.width * scale, height: natural.height * scale }\n : { width: 0, height: 0 },\n [natural, scale],\n );\n\n /** Apply a pan, clamped so the frame stays covered. */\n const pan = useCallback(\n (next: Offset) => {\n setOffset((current) => {\n const clamped = clampOffset(next, displayed, frame);\n if (clamped.x === current.x && clamped.y === current.y) return current;\n onCropChange?.({ zoom, offset: clamped });\n return clamped;\n });\n },\n [displayed, frame, onCropChange, zoom],\n );\n\n /**\n * Apply a zoom, then re-clamp the offset.\n *\n * Re-clamping is not optional: zooming *out* shrinks the image, so an offset\n * that was legal a moment ago can now expose background.\n */\n const applyZoom = useCallback(\n (next: number) => {\n const clampedZoom = Math.min(maxZoom, Math.max(1, next));\n setZoom(clampedZoom);\n if (!natural) return;\n const nextScale = coverScale(natural, frame) * clampedZoom;\n const nextDisplayed = {\n width: natural.width * nextScale,\n height: natural.height * nextScale,\n };\n setOffset((current) => {\n const clamped = clampOffset(current, nextDisplayed, frame);\n onCropChange?.({ zoom: clampedZoom, offset: clamped });\n return clamped;\n });\n },\n [frame, maxZoom, natural, onCropChange],\n );\n\n const reset = useCallback(() => {\n setZoom(1);\n setOffset({ x: 0, y: 0 });\n onCropChange?.({ zoom: 1, offset: { x: 0, y: 0 } });\n }, [onCropChange]);\n\n /**\n * Draw the current crop and encode it.\n *\n * Returns `null` rather than throwing on the paths a caller cannot do anything\n * about: no image yet, no 2D context, or an encoder that declined.\n */\n const crop = useCallback(async (): Promise<Blob | null> => {\n const image = imageRef.current;\n if (!image || !natural) return null;\n\n const rect = computeCropRect({ image: natural, frame, zoom, offset });\n if (rect.sWidth <= 0 || rect.sHeight <= 0) return null;\n\n const out = outputSize(rect, maxSize);\n const canvas = document.createElement(\"canvas\");\n canvas.width = out.width;\n canvas.height = out.height;\n const context = canvas.getContext(\"2d\");\n if (!context) return null;\n\n context.drawImage(\n image,\n rect.sx,\n rect.sy,\n rect.sWidth,\n rect.sHeight,\n 0,\n 0,\n out.width,\n out.height,\n );\n\n return new Promise((resolve) => {\n canvas.toBlob((blob) => resolve(blob), outputType, outputQuality);\n });\n }, [frame, maxSize, natural, offset, outputQuality, outputType, zoom]);\n\n useImperativeHandle(ref, () => ({ crop, reset }), [crop, reset]);\n\n const onPointerDown = (event: ReactPointerEvent<HTMLDivElement>): void => {\n if (!natural) return;\n dragRef.current = {\n pointerId: event.pointerId,\n startX: event.clientX,\n startY: event.clientY,\n from: offset,\n };\n event.currentTarget.setPointerCapture?.(event.pointerId);\n };\n\n const onPointerMove = (event: ReactPointerEvent<HTMLDivElement>): void => {\n const drag = dragRef.current;\n if (!drag || drag.pointerId !== event.pointerId) return;\n pan({\n x: drag.from.x + (event.clientX - drag.startX),\n y: drag.from.y + (event.clientY - drag.startY),\n });\n };\n\n const endDrag = (event: ReactPointerEvent<HTMLDivElement>): void => {\n if (dragRef.current?.pointerId !== event.pointerId) return;\n dragRef.current = null;\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {\n const step = event.shiftKey ? KEY_STEP * 4 : KEY_STEP;\n const moves: Record<string, Offset> = {\n ArrowLeft: { x: -step, y: 0 },\n ArrowRight: { x: step, y: 0 },\n ArrowUp: { x: 0, y: -step },\n ArrowDown: { x: 0, y: step },\n };\n const move = moves[event.key];\n if (move) {\n event.preventDefault();\n pan({ x: offset.x + move.x, y: offset.y + move.y });\n return;\n }\n if (event.key === \"+\" || event.key === \"=\") {\n event.preventDefault();\n applyZoom(zoom + ZOOM_STEP);\n } else if (event.key === \"-\" || event.key === \"_\") {\n event.preventDefault();\n applyZoom(zoom - ZOOM_STEP);\n } else if (event.key === \"0\") {\n event.preventDefault();\n reset();\n }\n };\n\n return (\n <div className={cn(styles.wrapper, className)} {...rest}>\n <div\n ref={frameRef}\n className={cn(styles.frame, shape === \"circle\" && styles.circle)}\n style={{ aspectRatio: String(aspect) }}\n role=\"group\"\n aria-label={label}\n aria-describedby={hintId}\n tabIndex={0}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={endDrag}\n onPointerCancel={endDrag}\n onKeyDown={onKeyDown}\n onWheel={(event) => {\n event.preventDefault();\n applyZoom(zoom + (event.deltaY < 0 ? ZOOM_STEP : -ZOOM_STEP));\n }}\n >\n {url && (\n <img\n ref={imageRef}\n src={url}\n alt=\"\"\n draggable={false}\n className={styles.image}\n style={{\n width: displayed.width || undefined,\n height: displayed.height || undefined,\n transform: `translate(${offset.x}px, ${offset.y}px)`,\n }}\n onLoad={(event) => {\n const element = event.currentTarget;\n // A decode can succeed and still report no intrinsic size —\n // an SVG without a viewBox is the common case. Accepting\n // that would enable the controls over an image the crop\n // maths can do nothing with.\n if (element.naturalWidth > 0 && element.naturalHeight > 0) {\n setNatural({\n width: element.naturalWidth,\n height: element.naturalHeight,\n });\n }\n }}\n />\n )}\n </div>\n\n <div className={styles.controls}>\n <input\n type=\"range\"\n className={styles.zoom}\n min={1}\n max={maxZoom}\n step={0.01}\n value={zoom}\n onChange={(event) => applyZoom(Number(event.target.value))}\n aria-label=\"Zoom\"\n disabled={!natural}\n />\n <button type=\"button\" className={styles.reset} onClick={reset} disabled={!natural}>\n Centralizar\n </button>\n </div>\n\n <p id={hintId} className={styles.hint}>\n Arraste para reposicionar. Setas movem, <kbd>+</kbd> e <kbd>−</kbd> dão zoom,{\" \"}\n <kbd>0</kbd> centraliza.\n </p>\n </div>\n );\n}\n"],"mappings":";;;;;;AAyEA,IAAM,IAAW,IAGX,IAAY;AAuBlB,SAAgB,EAAa,EACzB,QACA,YAAS,GACT,aAAU,GACV,YACA,gBAAa,aACb,mBAAgB,KAChB,WAAQ,QACR,iBACA,WAAQ,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AC;IACd,CAAA,GACD,kBAAC,UAAD;KAAQ,MAAK;KAAS,WAAW,EAAO;KAAO,SAAS;KAAO,UAAU,CAAC;KAAS,UAAA;IAE3E,CAAA,CACP;;GAEL,kBAAC,KAAD;IAAG,IAAI;IAAQ,WAAW,EAAO;IAAjC,UAAA;KAAuC;KACK,kBAAC,OAAD,EAAA,UAAK,IAAM,CAAA;KAAC;KAAG,kBAAC,OAAD,EAAA,UAAK,IAAM,CAAA;KAAC;KAAW;KAC9E,kBAAC,OAAD,EAAA,UAAK,IAAM,CAAA;KAAC;IACb;;EACF;;AAEb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.cjs","names":[],"sources":["../../../src/components/Input/Input.tsx"],"sourcesContent":["import { forwardRef, useId } from \"react\";\nimport type { InputHTMLAttributes, ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Input.module.css\";\n\nexport type InputSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, \"size\"> {\n label?: string;\n helperText?: string;\n error?: string;\n leftIcon?: ReactNode;\n rightIcon?: ReactNode;\n wrapperClassName?: string;\n /** Visual size — drives height, padding and font via density-aware tokens. */\n size?: InputSize;\n}\n\n/**\n * Labelled text input with helper/error slots and optional adornment icons.\n * Forwards refs to the underlying `<input>` for integration with form libraries.\n */\nexport const Input = forwardRef<HTMLInputElement, InputProps>(function Input(\n {\n label,\n helperText,\n error,\n leftIcon,\n rightIcon,\n wrapperClassName,\n className,\n id,\n required,\n size = \"md\",\n ...props\n },\n ref,\n) {\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const describedById = error ? `${inputId}-error` : helperText ? `${inputId}-helper` : undefined;\n const sizeClass = size === \"sm\" ? styles.sizeSm : size === \"lg\" ? styles.sizeLg : styles.sizeMd;\n\n return (\n <div className={cn(styles.wrapper, error && styles.error, wrapperClassName)}>\n {label && (\n <label htmlFor={inputId} className={styles.label}>\n {label}\n {required && <span className={styles.required}>*</span>}\n </label>\n )}\n <div className={styles.field}>\n {leftIcon && <span className={styles.iconLeft}>{leftIcon}</span>}\n <input\n ref={ref}\n id={inputId}\n aria-invalid={!!error}\n aria-describedby={describedById}\n required={required}\n className={cn(\n styles.input,\n sizeClass,\n leftIcon && styles.hasLeftIcon,\n rightIcon && styles.hasRightIcon,\n className,\n )}\n {...props}\n />\n {rightIcon && <span className={styles.iconRight}>{rightIcon}</span>}\n </div>\n {error ? (\n <span id={`${inputId}-error`} className={styles.errorText}>\n {error}\n </span>\n ) : helperText ? (\n <span id={`${inputId}-helper`} className={styles.helper}>\n {helperText}\n </span>\n ) : null}\n </div>\n );\n});\n"],"mappings":"4HAsBA,IAAa,GAAA,
|
|
1
|
+
{"version":3,"file":"Input.cjs","names":[],"sources":["../../../src/components/Input/Input.tsx"],"sourcesContent":["import { forwardRef, useId } from \"react\";\nimport type { InputHTMLAttributes, ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Input.module.css\";\n\nexport type InputSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, \"size\"> {\n label?: string;\n helperText?: string;\n error?: string;\n leftIcon?: ReactNode;\n rightIcon?: ReactNode;\n wrapperClassName?: string;\n /** Visual size — drives height, padding and font via density-aware tokens. */\n size?: InputSize;\n}\n\n/**\n * Labelled text input with helper/error slots and optional adornment icons.\n * Forwards refs to the underlying `<input>` for integration with form libraries.\n */\nexport const Input = forwardRef<HTMLInputElement, InputProps>(function Input(\n {\n label,\n helperText,\n error,\n leftIcon,\n rightIcon,\n wrapperClassName,\n className,\n id,\n required,\n size = \"md\",\n ...props\n },\n ref,\n) {\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const describedById = error ? `${inputId}-error` : helperText ? `${inputId}-helper` : undefined;\n const sizeClass = size === \"sm\" ? styles.sizeSm : size === \"lg\" ? styles.sizeLg : styles.sizeMd;\n\n return (\n <div className={cn(styles.wrapper, error && styles.error, wrapperClassName)}>\n {label && (\n <label htmlFor={inputId} className={styles.label}>\n {label}\n {required && <span className={styles.required}>*</span>}\n </label>\n )}\n <div className={styles.field}>\n {leftIcon && <span className={styles.iconLeft}>{leftIcon}</span>}\n <input\n ref={ref}\n id={inputId}\n aria-invalid={!!error}\n aria-describedby={describedById}\n required={required}\n className={cn(\n styles.input,\n sizeClass,\n leftIcon && styles.hasLeftIcon,\n rightIcon && styles.hasRightIcon,\n className,\n )}\n {...props}\n />\n {rightIcon && <span className={styles.iconRight}>{rightIcon}</span>}\n </div>\n {error ? (\n <span id={`${inputId}-error`} className={styles.errorText}>\n {error}\n </span>\n ) : helperText ? (\n <span id={`${inputId}-helper`} className={styles.helper}>\n {helperText}\n </span>\n ) : null}\n </div>\n );\n});\n"],"mappings":"4HAsBA,IAAa,GAAA,EAAQ,EAAA,WAAA,CAAyC,SAC1D,CACI,QACA,aACA,QACA,WACA,YACA,mBACA,YACA,KACA,WACA,OAAO,KACP,GAAG,GAEP,EACF,CACE,IAAM,GAAA,EAAc,EAAA,MAAA,CAAM,EACpB,EAAU,GAAM,EAChB,EAAgB,EAAQ,GAAG,EAAQ,QAAU,EAAa,GAAG,EAAQ,SAAW,IAAA,GAChF,EAAY,IAAS,KAAO,EAAA,QAAO,OAAS,IAAS,KAAO,EAAA,QAAO,OAAS,EAAA,QAAO,OAEzF,OACI,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAW,EAAA,GAAG,EAAA,QAAO,QAAS,GAAS,EAAA,QAAO,MAAO,CAAgB,EAA1E,SAAA,CACK,IACG,EAAA,EAAA,KAAA,CAAC,QAAD,CAAO,QAAS,EAAS,UAAW,EAAA,QAAO,MAA3C,SAAA,CACK,EACA,IAAY,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,SAAU,SAAA,GAAO,CAAA,CACnD,KAEX,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAW,EAAA,QAAO,MAAvB,SAAA,CACK,IAAY,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,SAAW,SAAA,CAAe,CAAA,GAC/D,EAAA,EAAA,IAAA,CAAC,QAAD,CACS,MACL,GAAI,EACJ,eAAc,CAAC,CAAC,EAChB,mBAAkB,EACR,WACV,UAAW,EAAA,GACP,EAAA,QAAO,MACP,EACA,GAAY,EAAA,QAAO,YACnB,GAAa,EAAA,QAAO,aACpB,CACJ,EACA,GAAI,CACP,CAAA,EACA,IAAa,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,UAAY,SAAA,CAAgB,CAAA,CACjE,IACJ,GACG,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,GAAI,GAAG,EAAQ,QAAS,UAAW,EAAA,QAAO,UAC3C,SAAA,CACC,CAAA,EACN,GACA,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,GAAI,GAAG,EAAQ,SAAU,UAAW,EAAA,QAAO,OAC5C,SAAA,CACC,CAAA,EACN,IACH,GAEb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","names":[],"sources":["../../../src/components/Input/Input.tsx"],"sourcesContent":["import { forwardRef, useId } from \"react\";\nimport type { InputHTMLAttributes, ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Input.module.css\";\n\nexport type InputSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, \"size\"> {\n label?: string;\n helperText?: string;\n error?: string;\n leftIcon?: ReactNode;\n rightIcon?: ReactNode;\n wrapperClassName?: string;\n /** Visual size — drives height, padding and font via density-aware tokens. */\n size?: InputSize;\n}\n\n/**\n * Labelled text input with helper/error slots and optional adornment icons.\n * Forwards refs to the underlying `<input>` for integration with form libraries.\n */\nexport const Input = forwardRef<HTMLInputElement, InputProps>(function Input(\n {\n label,\n helperText,\n error,\n leftIcon,\n rightIcon,\n wrapperClassName,\n className,\n id,\n required,\n size = \"md\",\n ...props\n },\n ref,\n) {\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const describedById = error ? `${inputId}-error` : helperText ? `${inputId}-helper` : undefined;\n const sizeClass = size === \"sm\" ? styles.sizeSm : size === \"lg\" ? styles.sizeLg : styles.sizeMd;\n\n return (\n <div className={cn(styles.wrapper, error && styles.error, wrapperClassName)}>\n {label && (\n <label htmlFor={inputId} className={styles.label}>\n {label}\n {required && <span className={styles.required}>*</span>}\n </label>\n )}\n <div className={styles.field}>\n {leftIcon && <span className={styles.iconLeft}>{leftIcon}</span>}\n <input\n ref={ref}\n id={inputId}\n aria-invalid={!!error}\n aria-describedby={describedById}\n required={required}\n className={cn(\n styles.input,\n sizeClass,\n leftIcon && styles.hasLeftIcon,\n rightIcon && styles.hasRightIcon,\n className,\n )}\n {...props}\n />\n {rightIcon && <span className={styles.iconRight}>{rightIcon}</span>}\n </div>\n {error ? (\n <span id={`${inputId}-error`} className={styles.errorText}>\n {error}\n </span>\n ) : helperText ? (\n <span id={`${inputId}-helper`} className={styles.helper}>\n {helperText}\n </span>\n ) : null}\n </div>\n );\n});\n"],"mappings":";;;;;AAsBA,IAAa,IAAQ,EAAyC,SAC1D,EACI,UACA,eACA,UACA,aACA,cACA,qBACA,cACA,OACA,aACA,UAAO,MACP,GAAG,KAEP,GACF;CACE,IAAM,IAAc,EAAM,GACpB,IAAU,KAAM,GAChB,IAAgB,IAAQ,GAAG,EAAQ,UAAU,IAAa,GAAG,EAAQ,WAAW,KAAA,GAChF,IAAY,MAAS,OAAO,EAAO,SAAS,MAAS,OAAO,EAAO,SAAS,EAAO;CAEzF,OACI,kBAAC,OAAD;EAAK,WAAW,EAAG,EAAO,SAAS,KAAS,EAAO,OAAO,CAAgB;
|
|
1
|
+
{"version":3,"file":"Input.js","names":[],"sources":["../../../src/components/Input/Input.tsx"],"sourcesContent":["import { forwardRef, useId } from \"react\";\nimport type { InputHTMLAttributes, ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Input.module.css\";\n\nexport type InputSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, \"size\"> {\n label?: string;\n helperText?: string;\n error?: string;\n leftIcon?: ReactNode;\n rightIcon?: ReactNode;\n wrapperClassName?: string;\n /** Visual size — drives height, padding and font via density-aware tokens. */\n size?: InputSize;\n}\n\n/**\n * Labelled text input with helper/error slots and optional adornment icons.\n * Forwards refs to the underlying `<input>` for integration with form libraries.\n */\nexport const Input = forwardRef<HTMLInputElement, InputProps>(function Input(\n {\n label,\n helperText,\n error,\n leftIcon,\n rightIcon,\n wrapperClassName,\n className,\n id,\n required,\n size = \"md\",\n ...props\n },\n ref,\n) {\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const describedById = error ? `${inputId}-error` : helperText ? `${inputId}-helper` : undefined;\n const sizeClass = size === \"sm\" ? styles.sizeSm : size === \"lg\" ? styles.sizeLg : styles.sizeMd;\n\n return (\n <div className={cn(styles.wrapper, error && styles.error, wrapperClassName)}>\n {label && (\n <label htmlFor={inputId} className={styles.label}>\n {label}\n {required && <span className={styles.required}>*</span>}\n </label>\n )}\n <div className={styles.field}>\n {leftIcon && <span className={styles.iconLeft}>{leftIcon}</span>}\n <input\n ref={ref}\n id={inputId}\n aria-invalid={!!error}\n aria-describedby={describedById}\n required={required}\n className={cn(\n styles.input,\n sizeClass,\n leftIcon && styles.hasLeftIcon,\n rightIcon && styles.hasRightIcon,\n className,\n )}\n {...props}\n />\n {rightIcon && <span className={styles.iconRight}>{rightIcon}</span>}\n </div>\n {error ? (\n <span id={`${inputId}-error`} className={styles.errorText}>\n {error}\n </span>\n ) : helperText ? (\n <span id={`${inputId}-helper`} className={styles.helper}>\n {helperText}\n </span>\n ) : null}\n </div>\n );\n});\n"],"mappings":";;;;;AAsBA,IAAa,IAAQ,EAAyC,SAC1D,EACI,UACA,eACA,UACA,aACA,cACA,qBACA,cACA,OACA,aACA,UAAO,MACP,GAAG,KAEP,GACF;CACE,IAAM,IAAc,EAAM,GACpB,IAAU,KAAM,GAChB,IAAgB,IAAQ,GAAG,EAAQ,UAAU,IAAa,GAAG,EAAQ,WAAW,KAAA,GAChF,IAAY,MAAS,OAAO,EAAO,SAAS,MAAS,OAAO,EAAO,SAAS,EAAO;CAEzF,OACI,kBAAC,OAAD;EAAK,WAAW,EAAG,EAAO,SAAS,KAAS,EAAO,OAAO,CAAgB;EAA1E,UAAA;GACK,KACG,kBAAC,SAAD;IAAO,SAAS;IAAS,WAAW,EAAO;IAA3C,UAAA,CACK,GACA,KAAY,kBAAC,QAAD;KAAM,WAAW,EAAO;KAAU,UAAA;IAAO,CAAA,CACnD;;GAEX,kBAAC,OAAD;IAAK,WAAW,EAAO;IAAvB,UAAA;KACK,KAAY,kBAAC,QAAD;MAAM,WAAW,EAAO;MAAW,UAAA;KAAe,CAAA;KAC/D,kBAAC,SAAD;MACS;MACL,IAAI;MACJ,gBAAc,CAAC,CAAC;MAChB,oBAAkB;MACR;MACV,WAAW,EACP,EAAO,OACP,GACA,KAAY,EAAO,aACnB,KAAa,EAAO,cACpB,CACJ;MACA,GAAI;KACP,CAAA;KACA,KAAa,kBAAC,QAAD;MAAM,WAAW,EAAO;MAAY,UAAA;KAAgB,CAAA;IACjE;;GACJ,IACG,kBAAC,QAAD;IAAM,IAAI,GAAG,EAAQ;IAAS,WAAW,EAAO;IAC3C,UAAA;GACC,CAAA,IACN,IACA,kBAAC,QAAD;IAAM,IAAI,GAAG,EAAQ;IAAU,WAAW,EAAO;IAC5C,UAAA;GACC,CAAA,IACN;EACH;;AAEb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InstallBanner.cjs","names":[],"sources":["../../../src/components/InstallBanner/InstallBanner.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — title, description, installLabel and dismissLabel\n * are four strings the app has to write, icon and className the look, storageKey the\n * dismissal memory and onResult the outcome. An install prompt with SDK-authored\n * copy is the one thing nobody ships.\n */\nimport { useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { X } from \"lucide-react\";\nimport { cn } from \"@/utils/cn\";\nimport { Button } from \"@/components/Button\";\nimport { useBeforeInstallPrompt } from \"@/hooks/use-before-install-prompt\";\nimport type { InstallOutcome } from \"@/components/InstallButton\";\nimport styles from \"./InstallBanner.module.css\";\n\nexport interface InstallBannerProps {\n /** Headline. Default `\"Instale o app\"`. */\n title?: ReactNode;\n /** Supporting copy under the title. */\n description?: ReactNode;\n /** Install button label. Default `\"Instalar\"`. */\n installLabel?: string;\n /** Accessible label for the dismiss button. Default `\"Dispensar\"`. */\n dismissLabel?: string;\n /** Optional leading icon. */\n icon?: ReactNode;\n /**\n * `localStorage` key used to remember dismissal across reloads. Omit to\n * make dismissal last only for the current session (component state).\n */\n storageKey?: string;\n /** Called with the user's choice after the install prompt resolves. */\n onResult?: (outcome: InstallOutcome) => void;\n className?: string;\n}\n\nfunction readDismissed(storageKey?: string): boolean {\n if (!storageKey || typeof window === \"undefined\") return false;\n try {\n return window.localStorage.getItem(storageKey) === \"1\";\n } catch {\n return false;\n }\n}\n\n/**\n * Dismissible bottom banner that invites the user to install the PWA. Wired to\n * {@link useBeforeInstallPrompt}: it renders only when the browser captured an\n * install prompt and the app is not already running standalone — so on\n * platforms that never fire `beforeinstallprompt` (e.g. iOS Safari) it stays\n * hidden and you can surface manual instructions elsewhere.\n *\n * @tempest-limits empty-catch — persisting the dismissal is a courtesy, not the\n * feature. When `localStorage` refuses the write (quota, private mode) the banner\n * still hides for this session; the worst case is that it comes back next visit,\n * which beats an error thrown out of a click handler that only closed a banner.\n *\n * @example\n * <InstallBanner\n * title=\"Instale o FAMACHApp\"\n * description=\"Acesso offline e atalho na tela inicial.\"\n * storageKey=\"famacha:install-dismissed\"\n * />\n */\nexport function InstallBanner({\n title = \"Instale o app\",\n description,\n installLabel = \"Instalar\",\n dismissLabel = \"Dispensar\",\n icon,\n storageKey,\n onResult,\n className,\n}: InstallBannerProps) {\n const { installable, installed, isStandalone, prompt } = useBeforeInstallPrompt();\n const [dismissed, setDismissed] = useState<boolean>(() => readDismissed(storageKey));\n\n if (!installable || installed || isStandalone || dismissed) return null;\n\n const dismiss = (): void => {\n setDismissed(true);\n if (storageKey && typeof window !== \"undefined\") {\n try {\n window.localStorage.setItem(storageKey, \"1\");\n } catch {\n /* empty */\n }\n }\n };\n\n return (\n <div className={cn(styles.banner, className)} role=\"region\" aria-label={String(title)}>\n {icon && <span className={styles.icon}>{icon}</span>}\n <div className={styles.body}>\n <p className={styles.title}>{title}</p>\n {description && <p className={styles.description}>{description}</p>}\n </div>\n <Button\n size=\"sm\"\n onClick={async () => {\n onResult?.(await prompt());\n }}\n >\n {installLabel}\n </Button>\n <button\n type=\"button\"\n className={styles.close}\n aria-label={dismissLabel}\n onClick={dismiss}\n >\n <X size={18} aria-hidden />\n </button>\n </div>\n );\n}\n"],"mappings":"uPAoCA,SAAS,EAAc,EAA8B,CACjD,GAAI,CAAC,GAAc,OAAO,OAAW,IAAa,MAAO,GACzD,GAAI,CACA,OAAO,OAAO,aAAa,QAAQ,CAAU,IAAM,GACvD,MAAQ,CACJ,MAAO,EACX,CACJ,CAqBA,SAAgB,EAAc,CAC1B,QAAQ,gBACR,cACA,eAAe,WACf,eAAe,YACf,OACA,aACA,WACA,aACmB,CACnB,GAAM,CAAE,cAAa,YAAW,eAAc,UAAW,EAAA,uBAAuB,EAC1E,CAAC,EAAW,IAAA,
|
|
1
|
+
{"version":3,"file":"InstallBanner.cjs","names":[],"sources":["../../../src/components/InstallBanner/InstallBanner.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — title, description, installLabel and dismissLabel\n * are four strings the app has to write, icon and className the look, storageKey the\n * dismissal memory and onResult the outcome. An install prompt with SDK-authored\n * copy is the one thing nobody ships.\n */\nimport { useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { X } from \"lucide-react\";\nimport { cn } from \"@/utils/cn\";\nimport { Button } from \"@/components/Button\";\nimport { useBeforeInstallPrompt } from \"@/hooks/use-before-install-prompt\";\nimport type { InstallOutcome } from \"@/components/InstallButton\";\nimport styles from \"./InstallBanner.module.css\";\n\nexport interface InstallBannerProps {\n /** Headline. Default `\"Instale o app\"`. */\n title?: ReactNode;\n /** Supporting copy under the title. */\n description?: ReactNode;\n /** Install button label. Default `\"Instalar\"`. */\n installLabel?: string;\n /** Accessible label for the dismiss button. Default `\"Dispensar\"`. */\n dismissLabel?: string;\n /** Optional leading icon. */\n icon?: ReactNode;\n /**\n * `localStorage` key used to remember dismissal across reloads. Omit to\n * make dismissal last only for the current session (component state).\n */\n storageKey?: string;\n /** Called with the user's choice after the install prompt resolves. */\n onResult?: (outcome: InstallOutcome) => void;\n className?: string;\n}\n\nfunction readDismissed(storageKey?: string): boolean {\n if (!storageKey || typeof window === \"undefined\") return false;\n try {\n return window.localStorage.getItem(storageKey) === \"1\";\n } catch {\n return false;\n }\n}\n\n/**\n * Dismissible bottom banner that invites the user to install the PWA. Wired to\n * {@link useBeforeInstallPrompt}: it renders only when the browser captured an\n * install prompt and the app is not already running standalone — so on\n * platforms that never fire `beforeinstallprompt` (e.g. iOS Safari) it stays\n * hidden and you can surface manual instructions elsewhere.\n *\n * @tempest-limits empty-catch — persisting the dismissal is a courtesy, not the\n * feature. When `localStorage` refuses the write (quota, private mode) the banner\n * still hides for this session; the worst case is that it comes back next visit,\n * which beats an error thrown out of a click handler that only closed a banner.\n *\n * @example\n * <InstallBanner\n * title=\"Instale o FAMACHApp\"\n * description=\"Acesso offline e atalho na tela inicial.\"\n * storageKey=\"famacha:install-dismissed\"\n * />\n */\nexport function InstallBanner({\n title = \"Instale o app\",\n description,\n installLabel = \"Instalar\",\n dismissLabel = \"Dispensar\",\n icon,\n storageKey,\n onResult,\n className,\n}: InstallBannerProps) {\n const { installable, installed, isStandalone, prompt } = useBeforeInstallPrompt();\n const [dismissed, setDismissed] = useState<boolean>(() => readDismissed(storageKey));\n\n if (!installable || installed || isStandalone || dismissed) return null;\n\n const dismiss = (): void => {\n setDismissed(true);\n if (storageKey && typeof window !== \"undefined\") {\n try {\n window.localStorage.setItem(storageKey, \"1\");\n } catch {\n /* empty */\n }\n }\n };\n\n return (\n <div className={cn(styles.banner, className)} role=\"region\" aria-label={String(title)}>\n {icon && <span className={styles.icon}>{icon}</span>}\n <div className={styles.body}>\n <p className={styles.title}>{title}</p>\n {description && <p className={styles.description}>{description}</p>}\n </div>\n <Button\n size=\"sm\"\n onClick={async () => {\n onResult?.(await prompt());\n }}\n >\n {installLabel}\n </Button>\n <button\n type=\"button\"\n className={styles.close}\n aria-label={dismissLabel}\n onClick={dismiss}\n >\n <X size={18} aria-hidden />\n </button>\n </div>\n );\n}\n"],"mappings":"uPAoCA,SAAS,EAAc,EAA8B,CACjD,GAAI,CAAC,GAAc,OAAO,OAAW,IAAa,MAAO,GACzD,GAAI,CACA,OAAO,OAAO,aAAa,QAAQ,CAAU,IAAM,GACvD,MAAQ,CACJ,MAAO,EACX,CACJ,CAqBA,SAAgB,EAAc,CAC1B,QAAQ,gBACR,cACA,eAAe,WACf,eAAe,YACf,OACA,aACA,WACA,aACmB,CACnB,GAAM,CAAE,cAAa,YAAW,eAAc,UAAW,EAAA,uBAAuB,EAC1E,CAAC,EAAW,IAAA,EAAgB,EAAA,SAAA,KAAwB,EAAc,CAAU,CAAC,EAenF,MAbI,CAAC,GAAe,GAAa,GAAgB,EAAkB,MAc/D,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAW,EAAA,GAAG,EAAA,QAAO,OAAQ,CAAS,EAAG,KAAK,SAAS,aAAY,OAAO,CAAK,EAApF,SAAA,CACK,IAAQ,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,KAAO,SAAA,CAAW,CAAA,GACnD,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAW,EAAA,QAAO,KAAvB,SAAA,EACI,EAAA,EAAA,IAAA,CAAC,IAAD,CAAG,UAAW,EAAA,QAAO,MAAQ,SAAA,CAAS,CAAA,EACrC,IAAe,EAAA,EAAA,IAAA,CAAC,IAAD,CAAG,UAAW,EAAA,QAAO,YAAc,SAAA,CAAe,CAAA,CACjE,KACL,EAAA,EAAA,IAAA,CAAC,EAAA,OAAD,CACI,KAAK,KACL,QAAS,SAAY,CACjB,IAAW,MAAM,EAAO,CAAC,CAC7B,EAEC,SAAA,CACG,CAAA,GACR,EAAA,EAAA,IAAA,CAAC,SAAD,CACI,KAAK,SACL,UAAW,EAAA,QAAO,MAClB,aAAY,EACZ,YA9BgB,CAExB,GADA,EAAa,EAAI,EACb,GAAc,OAAO,OAAW,IAChC,GAAI,CACA,OAAO,aAAa,QAAQ,EAAY,GAAG,CAC/C,MAAQ,CAER,CAER,EAuBY,UAAA,EAAA,EAAA,IAAA,CAAC,EAAA,EAAD,CAAG,KAAM,GAAI,cAAA,EAAa,CAAA,CACtB,CAAA,CACP,GAEb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InstallBanner.js","names":[],"sources":["../../../src/components/InstallBanner/InstallBanner.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — title, description, installLabel and dismissLabel\n * are four strings the app has to write, icon and className the look, storageKey the\n * dismissal memory and onResult the outcome. An install prompt with SDK-authored\n * copy is the one thing nobody ships.\n */\nimport { useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { X } from \"lucide-react\";\nimport { cn } from \"@/utils/cn\";\nimport { Button } from \"@/components/Button\";\nimport { useBeforeInstallPrompt } from \"@/hooks/use-before-install-prompt\";\nimport type { InstallOutcome } from \"@/components/InstallButton\";\nimport styles from \"./InstallBanner.module.css\";\n\nexport interface InstallBannerProps {\n /** Headline. Default `\"Instale o app\"`. */\n title?: ReactNode;\n /** Supporting copy under the title. */\n description?: ReactNode;\n /** Install button label. Default `\"Instalar\"`. */\n installLabel?: string;\n /** Accessible label for the dismiss button. Default `\"Dispensar\"`. */\n dismissLabel?: string;\n /** Optional leading icon. */\n icon?: ReactNode;\n /**\n * `localStorage` key used to remember dismissal across reloads. Omit to\n * make dismissal last only for the current session (component state).\n */\n storageKey?: string;\n /** Called with the user's choice after the install prompt resolves. */\n onResult?: (outcome: InstallOutcome) => void;\n className?: string;\n}\n\nfunction readDismissed(storageKey?: string): boolean {\n if (!storageKey || typeof window === \"undefined\") return false;\n try {\n return window.localStorage.getItem(storageKey) === \"1\";\n } catch {\n return false;\n }\n}\n\n/**\n * Dismissible bottom banner that invites the user to install the PWA. Wired to\n * {@link useBeforeInstallPrompt}: it renders only when the browser captured an\n * install prompt and the app is not already running standalone — so on\n * platforms that never fire `beforeinstallprompt` (e.g. iOS Safari) it stays\n * hidden and you can surface manual instructions elsewhere.\n *\n * @tempest-limits empty-catch — persisting the dismissal is a courtesy, not the\n * feature. When `localStorage` refuses the write (quota, private mode) the banner\n * still hides for this session; the worst case is that it comes back next visit,\n * which beats an error thrown out of a click handler that only closed a banner.\n *\n * @example\n * <InstallBanner\n * title=\"Instale o FAMACHApp\"\n * description=\"Acesso offline e atalho na tela inicial.\"\n * storageKey=\"famacha:install-dismissed\"\n * />\n */\nexport function InstallBanner({\n title = \"Instale o app\",\n description,\n installLabel = \"Instalar\",\n dismissLabel = \"Dispensar\",\n icon,\n storageKey,\n onResult,\n className,\n}: InstallBannerProps) {\n const { installable, installed, isStandalone, prompt } = useBeforeInstallPrompt();\n const [dismissed, setDismissed] = useState<boolean>(() => readDismissed(storageKey));\n\n if (!installable || installed || isStandalone || dismissed) return null;\n\n const dismiss = (): void => {\n setDismissed(true);\n if (storageKey && typeof window !== \"undefined\") {\n try {\n window.localStorage.setItem(storageKey, \"1\");\n } catch {\n /* empty */\n }\n }\n };\n\n return (\n <div className={cn(styles.banner, className)} role=\"region\" aria-label={String(title)}>\n {icon && <span className={styles.icon}>{icon}</span>}\n <div className={styles.body}>\n <p className={styles.title}>{title}</p>\n {description && <p className={styles.description}>{description}</p>}\n </div>\n <Button\n size=\"sm\"\n onClick={async () => {\n onResult?.(await prompt());\n }}\n >\n {installLabel}\n </Button>\n <button\n type=\"button\"\n className={styles.close}\n aria-label={dismissLabel}\n onClick={dismiss}\n >\n <X size={18} aria-hidden />\n </button>\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAoCA,SAAS,EAAc,GAA8B;CACjD,IAAI,CAAC,KAAc,OAAO,SAAW,KAAa,OAAO;CACzD,IAAI;EACA,OAAO,OAAO,aAAa,QAAQ,CAAU,MAAM;CACvD,QAAQ;EACJ,OAAO;CACX;AACJ;AAqBA,SAAgB,EAAc,EAC1B,WAAQ,iBACR,gBACA,kBAAe,YACf,kBAAe,aACf,SACA,eACA,aACA,gBACmB;CACnB,IAAM,EAAE,gBAAa,cAAW,iBAAc,cAAW,EAAuB,GAC1E,CAAC,GAAW,KAAgB,QAAwB,EAAc,CAAU,CAAC;CAenF,OAbI,CAAC,KAAe,KAAa,KAAgB,IAAkB,OAc/D,kBAAC,OAAD;EAAK,WAAW,EAAG,EAAO,QAAQ,CAAS;EAAG,MAAK;EAAS,cAAY,OAAO,CAAK;
|
|
1
|
+
{"version":3,"file":"InstallBanner.js","names":[],"sources":["../../../src/components/InstallBanner/InstallBanner.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — title, description, installLabel and dismissLabel\n * are four strings the app has to write, icon and className the look, storageKey the\n * dismissal memory and onResult the outcome. An install prompt with SDK-authored\n * copy is the one thing nobody ships.\n */\nimport { useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { X } from \"lucide-react\";\nimport { cn } from \"@/utils/cn\";\nimport { Button } from \"@/components/Button\";\nimport { useBeforeInstallPrompt } from \"@/hooks/use-before-install-prompt\";\nimport type { InstallOutcome } from \"@/components/InstallButton\";\nimport styles from \"./InstallBanner.module.css\";\n\nexport interface InstallBannerProps {\n /** Headline. Default `\"Instale o app\"`. */\n title?: ReactNode;\n /** Supporting copy under the title. */\n description?: ReactNode;\n /** Install button label. Default `\"Instalar\"`. */\n installLabel?: string;\n /** Accessible label for the dismiss button. Default `\"Dispensar\"`. */\n dismissLabel?: string;\n /** Optional leading icon. */\n icon?: ReactNode;\n /**\n * `localStorage` key used to remember dismissal across reloads. Omit to\n * make dismissal last only for the current session (component state).\n */\n storageKey?: string;\n /** Called with the user's choice after the install prompt resolves. */\n onResult?: (outcome: InstallOutcome) => void;\n className?: string;\n}\n\nfunction readDismissed(storageKey?: string): boolean {\n if (!storageKey || typeof window === \"undefined\") return false;\n try {\n return window.localStorage.getItem(storageKey) === \"1\";\n } catch {\n return false;\n }\n}\n\n/**\n * Dismissible bottom banner that invites the user to install the PWA. Wired to\n * {@link useBeforeInstallPrompt}: it renders only when the browser captured an\n * install prompt and the app is not already running standalone — so on\n * platforms that never fire `beforeinstallprompt` (e.g. iOS Safari) it stays\n * hidden and you can surface manual instructions elsewhere.\n *\n * @tempest-limits empty-catch — persisting the dismissal is a courtesy, not the\n * feature. When `localStorage` refuses the write (quota, private mode) the banner\n * still hides for this session; the worst case is that it comes back next visit,\n * which beats an error thrown out of a click handler that only closed a banner.\n *\n * @example\n * <InstallBanner\n * title=\"Instale o FAMACHApp\"\n * description=\"Acesso offline e atalho na tela inicial.\"\n * storageKey=\"famacha:install-dismissed\"\n * />\n */\nexport function InstallBanner({\n title = \"Instale o app\",\n description,\n installLabel = \"Instalar\",\n dismissLabel = \"Dispensar\",\n icon,\n storageKey,\n onResult,\n className,\n}: InstallBannerProps) {\n const { installable, installed, isStandalone, prompt } = useBeforeInstallPrompt();\n const [dismissed, setDismissed] = useState<boolean>(() => readDismissed(storageKey));\n\n if (!installable || installed || isStandalone || dismissed) return null;\n\n const dismiss = (): void => {\n setDismissed(true);\n if (storageKey && typeof window !== \"undefined\") {\n try {\n window.localStorage.setItem(storageKey, \"1\");\n } catch {\n /* empty */\n }\n }\n };\n\n return (\n <div className={cn(styles.banner, className)} role=\"region\" aria-label={String(title)}>\n {icon && <span className={styles.icon}>{icon}</span>}\n <div className={styles.body}>\n <p className={styles.title}>{title}</p>\n {description && <p className={styles.description}>{description}</p>}\n </div>\n <Button\n size=\"sm\"\n onClick={async () => {\n onResult?.(await prompt());\n }}\n >\n {installLabel}\n </Button>\n <button\n type=\"button\"\n className={styles.close}\n aria-label={dismissLabel}\n onClick={dismiss}\n >\n <X size={18} aria-hidden />\n </button>\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAoCA,SAAS,EAAc,GAA8B;CACjD,IAAI,CAAC,KAAc,OAAO,SAAW,KAAa,OAAO;CACzD,IAAI;EACA,OAAO,OAAO,aAAa,QAAQ,CAAU,MAAM;CACvD,QAAQ;EACJ,OAAO;CACX;AACJ;AAqBA,SAAgB,EAAc,EAC1B,WAAQ,iBACR,gBACA,kBAAe,YACf,kBAAe,aACf,SACA,eACA,aACA,gBACmB;CACnB,IAAM,EAAE,gBAAa,cAAW,iBAAc,cAAW,EAAuB,GAC1E,CAAC,GAAW,KAAgB,QAAwB,EAAc,CAAU,CAAC;CAenF,OAbI,CAAC,KAAe,KAAa,KAAgB,IAAkB,OAc/D,kBAAC,OAAD;EAAK,WAAW,EAAG,EAAO,QAAQ,CAAS;EAAG,MAAK;EAAS,cAAY,OAAO,CAAK;EAApF,UAAA;GACK,KAAQ,kBAAC,QAAD;IAAM,WAAW,EAAO;IAAO,UAAA;GAAW,CAAA;GACnD,kBAAC,OAAD;IAAK,WAAW,EAAO;IAAvB,UAAA,CACI,kBAAC,KAAD;KAAG,WAAW,EAAO;KAAQ,UAAA;IAAS,CAAA,GACrC,KAAe,kBAAC,KAAD;KAAG,WAAW,EAAO;KAAc,UAAA;IAAe,CAAA,CACjE;;GACL,kBAAC,GAAD;IACI,MAAK;IACL,SAAS,YAAY;KACjB,IAAW,MAAM,EAAO,CAAC;IAC7B;IAEC,UAAA;GACG,CAAA;GACR,kBAAC,UAAD;IACI,MAAK;IACL,WAAW,EAAO;IAClB,cAAY;IACZ,eA9BgB;KAExB,IADA,EAAa,EAAI,GACb,KAAc,OAAO,SAAW,KAChC,IAAI;MACA,OAAO,aAAa,QAAQ,GAAY,GAAG;KAC/C,QAAQ,CAER;IAER;IAuBY,UAAA,kBAAC,GAAD;KAAG,MAAM;KAAI,eAAA;IAAa,CAAA;GACtB,CAAA;EACP;;AAEb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InstallButton.cjs","names":[],"sources":["../../../src/components/InstallButton/InstallButton.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { Button, type ButtonProps } from \"@/components/Button\";\nimport { useBeforeInstallPrompt } from \"@/hooks/use-before-install-prompt\";\n\nexport type InstallOutcome = \"accepted\" | \"dismissed\" | \"unsupported\";\n\nexport interface InstallButtonProps extends Omit<ButtonProps, \"onClick\" | \"children\"> {\n /** Button label. Default `\"Instalar app\"`. */\n label?: ReactNode;\n /** Called with the user's choice after the install prompt resolves. */\n onResult?: (outcome: InstallOutcome) => void;\n}\n\n/**\n * Button wired to the PWA install prompt ({@link useBeforeInstallPrompt}).\n * Renders nothing when the app can't be installed — no prompt captured yet,\n * already installed, or running standalone — so you can drop it anywhere\n * without guarding visibility yourself.\n *\n * Inherits every {@link Button} prop (`variant`, `size`, `leftIcon`, …).\n *\n * @example\n * <InstallButton variant=\"primary\" leftIcon={<Download />} />\n */\nexport function InstallButton({ label = \"Instalar app\", onResult, ...props }: InstallButtonProps) {\n const { installable, installed, isStandalone, prompt } = useBeforeInstallPrompt();\n if (!installable || installed || isStandalone) return null;\n return (\n <Button\n onClick={async () => {\n onResult?.(await prompt());\n }}\n {...props}\n >\n {label}\n </Button>\n );\n}\n"],"mappings":"kIAwBA,SAAgB,EAAc,CAAE,QAAQ,eAAgB,WAAU,GAAG,GAA6B,CAC9F,GAAM,CAAE,cAAa,YAAW,eAAc,UAAW,EAAA,uBAAuB,EAEhF,MADI,CAAC,GAAe,GAAa,EAAqB,MAElD,EAAA,EAAA,IAAA,CAAC,EAAA,OAAD,CACI,QAAS,SAAY,CACjB,IAAW,MAAM,EAAO,CAAC,CAC7B,EACA,GAAI,
|
|
1
|
+
{"version":3,"file":"InstallButton.cjs","names":[],"sources":["../../../src/components/InstallButton/InstallButton.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { Button, type ButtonProps } from \"@/components/Button\";\nimport { useBeforeInstallPrompt } from \"@/hooks/use-before-install-prompt\";\n\nexport type InstallOutcome = \"accepted\" | \"dismissed\" | \"unsupported\";\n\nexport interface InstallButtonProps extends Omit<ButtonProps, \"onClick\" | \"children\"> {\n /** Button label. Default `\"Instalar app\"`. */\n label?: ReactNode;\n /** Called with the user's choice after the install prompt resolves. */\n onResult?: (outcome: InstallOutcome) => void;\n}\n\n/**\n * Button wired to the PWA install prompt ({@link useBeforeInstallPrompt}).\n * Renders nothing when the app can't be installed — no prompt captured yet,\n * already installed, or running standalone — so you can drop it anywhere\n * without guarding visibility yourself.\n *\n * Inherits every {@link Button} prop (`variant`, `size`, `leftIcon`, …).\n *\n * @example\n * <InstallButton variant=\"primary\" leftIcon={<Download />} />\n */\nexport function InstallButton({ label = \"Instalar app\", onResult, ...props }: InstallButtonProps) {\n const { installable, installed, isStandalone, prompt } = useBeforeInstallPrompt();\n if (!installable || installed || isStandalone) return null;\n return (\n <Button\n onClick={async () => {\n onResult?.(await prompt());\n }}\n {...props}\n >\n {label}\n </Button>\n );\n}\n"],"mappings":"kIAwBA,SAAgB,EAAc,CAAE,QAAQ,eAAgB,WAAU,GAAG,GAA6B,CAC9F,GAAM,CAAE,cAAa,YAAW,eAAc,UAAW,EAAA,uBAAuB,EAEhF,MADI,CAAC,GAAe,GAAa,EAAqB,MAElD,EAAA,EAAA,IAAA,CAAC,EAAA,OAAD,CACI,QAAS,SAAY,CACjB,IAAW,MAAM,EAAO,CAAC,CAC7B,EACA,GAAI,EAEH,SAAA,CACG,CAAA,CAEhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InstallButton.js","names":[],"sources":["../../../src/components/InstallButton/InstallButton.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { Button, type ButtonProps } from \"@/components/Button\";\nimport { useBeforeInstallPrompt } from \"@/hooks/use-before-install-prompt\";\n\nexport type InstallOutcome = \"accepted\" | \"dismissed\" | \"unsupported\";\n\nexport interface InstallButtonProps extends Omit<ButtonProps, \"onClick\" | \"children\"> {\n /** Button label. Default `\"Instalar app\"`. */\n label?: ReactNode;\n /** Called with the user's choice after the install prompt resolves. */\n onResult?: (outcome: InstallOutcome) => void;\n}\n\n/**\n * Button wired to the PWA install prompt ({@link useBeforeInstallPrompt}).\n * Renders nothing when the app can't be installed — no prompt captured yet,\n * already installed, or running standalone — so you can drop it anywhere\n * without guarding visibility yourself.\n *\n * Inherits every {@link Button} prop (`variant`, `size`, `leftIcon`, …).\n *\n * @example\n * <InstallButton variant=\"primary\" leftIcon={<Download />} />\n */\nexport function InstallButton({ label = \"Instalar app\", onResult, ...props }: InstallButtonProps) {\n const { installable, installed, isStandalone, prompt } = useBeforeInstallPrompt();\n if (!installable || installed || isStandalone) return null;\n return (\n <Button\n onClick={async () => {\n onResult?.(await prompt());\n }}\n {...props}\n >\n {label}\n </Button>\n );\n}\n"],"mappings":";;;;AAwBA,SAAgB,EAAc,EAAE,WAAQ,gBAAgB,aAAU,GAAG,KAA6B;CAC9F,IAAM,EAAE,gBAAa,cAAW,iBAAc,cAAW,EAAuB;CAEhF,OADI,CAAC,KAAe,KAAa,IAAqB,OAElD,kBAAC,GAAD;EACI,SAAS,YAAY;GACjB,IAAW,MAAM,EAAO,CAAC;EAC7B;EACA,GAAI;
|
|
1
|
+
{"version":3,"file":"InstallButton.js","names":[],"sources":["../../../src/components/InstallButton/InstallButton.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { Button, type ButtonProps } from \"@/components/Button\";\nimport { useBeforeInstallPrompt } from \"@/hooks/use-before-install-prompt\";\n\nexport type InstallOutcome = \"accepted\" | \"dismissed\" | \"unsupported\";\n\nexport interface InstallButtonProps extends Omit<ButtonProps, \"onClick\" | \"children\"> {\n /** Button label. Default `\"Instalar app\"`. */\n label?: ReactNode;\n /** Called with the user's choice after the install prompt resolves. */\n onResult?: (outcome: InstallOutcome) => void;\n}\n\n/**\n * Button wired to the PWA install prompt ({@link useBeforeInstallPrompt}).\n * Renders nothing when the app can't be installed — no prompt captured yet,\n * already installed, or running standalone — so you can drop it anywhere\n * without guarding visibility yourself.\n *\n * Inherits every {@link Button} prop (`variant`, `size`, `leftIcon`, …).\n *\n * @example\n * <InstallButton variant=\"primary\" leftIcon={<Download />} />\n */\nexport function InstallButton({ label = \"Instalar app\", onResult, ...props }: InstallButtonProps) {\n const { installable, installed, isStandalone, prompt } = useBeforeInstallPrompt();\n if (!installable || installed || isStandalone) return null;\n return (\n <Button\n onClick={async () => {\n onResult?.(await prompt());\n }}\n {...props}\n >\n {label}\n </Button>\n );\n}\n"],"mappings":";;;;AAwBA,SAAgB,EAAc,EAAE,WAAQ,gBAAgB,aAAU,GAAG,KAA6B;CAC9F,IAAM,EAAE,gBAAa,cAAW,iBAAc,cAAW,EAAuB;CAEhF,OADI,CAAC,KAAe,KAAa,IAAqB,OAElD,kBAAC,GAAD;EACI,SAAS,YAAY;GACjB,IAAW,MAAM,EAAO,CAAC;EAC7B;EACA,GAAI;EAEH,UAAA;CACG,CAAA;AAEhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Kanban.cjs","names":[],"sources":["../../../src/components/Kanban/Kanban.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — drag-and-drop needs an\n * accessible twin: cardRoleDescription and label exist so the keyboard path\n * announces what the pointer path shows, and renderCard/emptyLabel are the slots.\n * The body is the move calculation shared by both paths.\n */\n/* eslint-disable react-hooks/refs -- `getItemProps` is called during render and its\n handlers close over `useSortable`'s mirror refs, so the rule reports the call site\n here. The refs are only written from event handlers and read from a window\n listener; the two reads that were genuinely render-time (the drag group in the\n rendered class/aria, and the group lookup inside `commit`) were fixed instead of\n silenced — see the hook's docstring. */\nimport { useMemo } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { useSortable } from \"@/hooks/use-sortable\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Kanban.module.css\";\n\n/** One card on the board. */\nexport interface KanbanCard {\n /** Stable identifier, unique across the whole board. */\n id: string;\n /** Card body. A string renders as the card's title. */\n content: ReactNode;\n}\n\n/** One column of the board. */\nexport interface KanbanColumn {\n /** Stable identifier, used as the drop group. */\n id: string;\n /** Column heading. */\n title: ReactNode;\n /** Cards in display order. */\n cards: KanbanCard[];\n /**\n * Refuses drops into this column. The cards inside can still be picked up and\n * moved elsewhere — a \"done\" column that no longer accepts work, for instance.\n */\n locked?: boolean;\n}\n\n/** Where a card ended up. */\nexport interface KanbanMove {\n cardId: string;\n fromColumn: string;\n toColumn: string;\n /** Index within the destination column. */\n toIndex: number;\n}\n\nexport interface KanbanProps {\n columns: KanbanColumn[];\n /**\n * Called once per committed move — on pointer release or on a keyboard drop.\n * You own the data: apply the move and pass the new `columns` back.\n */\n onMove: (move: KanbanMove) => void;\n /** Renders a card. Defaults to its `content`. */\n renderCard?: (card: KanbanCard, column: KanbanColumn) => ReactNode;\n /** Text shown in a column with no cards. */\n emptyLabel?: ReactNode;\n /** Announced per card, so a screen reader user learns the keyboard contract. */\n cardRoleDescription?: string;\n /**\n * Accessible name of the board. A `listbox` without a name is unusable with a\n * screen reader, so this has a default rather than being optional in practice.\n */\n label?: string;\n /** Blocks all dragging. */\n disabled?: boolean;\n className?: string;\n}\n\n/**\n * Kanban board: columns of cards, reorderable within a column and movable across\n * columns, by pointer **or** keyboard.\n *\n * The drag machine is `useSortable` — the board does not reimplement it. Cards are\n * indexed globally across columns so a single sortable can span the whole board;\n * the component translates that flat index back into `{ column, index }` for\n * `onMove`, which is the shape an app actually needs.\n *\n * Nothing is mutated here: `onMove` reports the intent once and the parent applies\n * it. That keeps the board a controlled value and avoids a re-render per pointer\n * frame.\n *\n * ARIA shape: **one `listbox` per column**, named by the column title, containing\n * only `option` cards. A single board-wide listbox does not survive the markup a\n * board needs — `listbox` requires `option`/`group` children, and the column header\n * and card wrapper in between break that ownership. Per-column listboxes also read\n * better: a screen reader announces which column it is in and how many cards it\n * holds. The column header is a plain `div`, not a `<header>`, because outside a\n * sectioning element every `<header>` becomes a page-level banner landmark — with\n * three columns that is three duplicate banners. An **empty** column is not marked\n * as a listbox at all: a listbox with zero options fails `aria-required-children`,\n * and \"no cards\" is exactly zero options.\n *\n * Known limitation: a **keyboard** move can only target positions that hold a card,\n * because the move walks the flat index space of existing cards. Dropping into an\n * empty column works by pointer; by keyboard it does not. Moving a card to a column\n * that already has one card, then reordering, is the workaround until column-switch\n * keys land.\n *\n * @example\n * ```tsx\n * const [columns, setColumns] = useState<KanbanColumn[]>([\n * { id: \"todo\", title: \"A fazer\", cards: [{ id: \"1\", content: \"Corrigir login\" }] },\n * { id: \"doing\", title: \"Fazendo\", cards: [] },\n * { id: \"done\", title: \"Feito\", cards: [], locked: true },\n * ]);\n *\n * <Kanban\n * columns={columns}\n * onMove={({ cardId, fromColumn, toColumn, toIndex }) =>\n * setColumns((current) => applyKanbanMove(current, { cardId, fromColumn, toColumn, toIndex }))\n * }\n * />\n * ```\n */\nexport function Kanban({\n columns,\n onMove,\n renderCard,\n emptyLabel = \"Nenhum card\",\n cardRoleDescription = \"Card do quadro — Espaço pega, setas movem, Espaço solta\",\n label = \"Quadro\",\n disabled = false,\n className,\n}: KanbanProps) {\n /**\n * Flat view of every card, in column order.\n *\n * `useSortable` works on a single index space, so the board flattens itself and\n * keeps the mapping back to `{ column, index }` here — the only place that has\n * to know both shapes.\n */\n const flat = useMemo(\n () =>\n columns.flatMap((column, columnIndex) =>\n column.cards.map((card, cardIndex) => ({ card, column, columnIndex, cardIndex })),\n ),\n [columns],\n );\n\n const sortable = useSortable({\n itemCount: flat.length,\n disabled,\n roleDescription: cardRoleDescription,\n onReorder: ({ from, to, fromGroup, toGroup }) => {\n const source = flat[from];\n if (!source) return;\n\n const destinationId = toGroup ?? fromGroup ?? source.column.id;\n const destination = columns.find((column) => column.id === destinationId);\n if (!destination || destination.locked) return;\n\n const target = flat[to];\n const toIndex =\n target && target.column.id === destinationId\n ? target.cardIndex\n : destination.cards.length;\n\n onMove({\n cardId: source.card.id,\n fromColumn: source.column.id,\n toColumn: destinationId,\n toIndex,\n });\n },\n });\n\n /**\n * First flat index of each column.\n *\n * Derived instead of counted with a mutable `flatIndex++` during render: a\n * render-scoped counter mutated inside the map is exactly the pattern the React\n * Compiler rules reject, and for good reason — a partial or replayed render\n * would resume from a half-advanced counter.\n */\n const columnOffsets = useMemo(() => {\n const offsets: number[] = [];\n let start = 0;\n for (const column of columns) {\n offsets.push(start);\n start += column.cards.length;\n }\n return offsets;\n }, [columns]);\n\n return (\n <div className={cn(styles.board, className)} aria-label={label} ref={sortable.setContainer}>\n {columns.map((column, columnIndex) => {\n const isDropTarget = sortable.overGroup === column.id && !column.locked;\n return (\n <div\n key={column.id}\n className={cn(\n styles.column,\n isDropTarget && styles.columnActive,\n column.locked && styles.columnLocked,\n )}\n >\n <div className={styles.columnHeader}>\n <span className={styles.columnTitle}>{column.title}</span>\n <span className={styles.count}>{column.cards.length}</span>\n </div>\n\n <div\n className={styles.cards}\n {...(column.cards.length > 0 ? sortable.getListProps() : {})}\n aria-label={typeof column.title === \"string\" ? column.title : column.id}\n >\n {column.cards.map((card, cardIndex) => {\n const index = columnOffsets[columnIndex] + cardIndex;\n const isActive = sortable.activeIndex === index;\n const isOver = sortable.overIndex === index && !isActive;\n return (\n <div\n key={card.id}\n {...sortable.getItemProps(index, column.id)}\n className={cn(\n styles.card,\n isActive && styles.cardActive,\n isOver && styles.cardOver,\n )}\n >\n {renderCard ? renderCard(card, column) : card.content}\n </div>\n );\n })}\n\n {column.cards.length === 0 ? (\n <div\n {...sortable.getEmptyGroupProps(column.id)}\n className={styles.empty}\n >\n {emptyLabel}\n </div>\n ) : null}\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n\n/**\n * Apply a {@link KanbanMove} to a column list, returning new arrays.\n *\n * Exported because every consumer needs the same reducer.\n *\n * `toIndex` is the position of the card that was dropped **onto**, read from the\n * board as it looked before the move. Inserting at that same index *after* removing\n * the dragged card lands where the user aimed in both directions — moving down, the\n * removal shifts the target up by one and the insertion lands after it; moving up,\n * nothing shifted. Compensating for the shift (the \"obvious\" `toIndex - 1`) is what\n * turns a one-step move down into a no-op.\n *\n * @param columns - Current board.\n * @param move - The move reported by `onMove`.\n * @returns A new column list, or the same reference when the move cannot apply.\n */\nexport function applyKanbanMove(columns: KanbanColumn[], move: KanbanMove): KanbanColumn[] {\n const fromColumn = columns.find((column) => column.id === move.fromColumn);\n const card = fromColumn?.cards.find((candidate) => candidate.id === move.cardId);\n if (!fromColumn || !card) return columns;\n\n const insertAt = move.toIndex;\n\n return columns.map((column) => {\n if (column.id === move.fromColumn && column.id === move.toColumn) {\n const without = column.cards.filter((candidate) => candidate.id !== move.cardId);\n without.splice(insertAt, 0, card);\n return { ...column, cards: without };\n }\n if (column.id === move.fromColumn) {\n return { ...column, cards: column.cards.filter((c) => c.id !== move.cardId) };\n }\n if (column.id === move.toColumn) {\n const next = column.cards.slice();\n next.splice(insertAt, 0, card);\n return { ...column, cards: next };\n }\n return column;\n });\n}\n"],"mappings":"uKAuHA,SAAgB,EAAO,CACnB,UACA,SACA,aACA,aAAa,cACb,sBAAsB,0DACtB,QAAQ,SACR,WAAW,GACX,aACY,CAQZ,IAAM,GAAA,EAAA,EAAA,QAAA,KAEE,EAAQ,SAAS,EAAQ,IACrB,EAAO,MAAM,KAAK,EAAM,KAAe,CAAE,OAAM,SAAQ,cAAa,WAAU,EAAE,CACpF,EACJ,CAAC,CAAO,CACZ,EAEM,EAAW,EAAA,YAAY,CACzB,UAAW,EAAK,OAChB,WACA,gBAAiB,EACjB,WAAY,CAAE,OAAM,KAAI,YAAW,aAAc,CAC7C,IAAM,EAAS,EAAK,GACpB,GAAI,CAAC,EAAQ,OAEb,IAAM,EAAgB,GAAW,GAAa,EAAO,OAAO,GACtD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,SAAU,CAC7B,IAAM,EAAO,EAAO,MAAM,MAAM,EAEhC,OADA,EAAK,OAAO,EAAU,EAAG,CAAI,EACtB,CAAE,GAAG,EAAQ,MAAO,CAAK,CACpC,CACA,OAAO,CACX,CAAC,CACL"}
|
|
1
|
+
{"version":3,"file":"Kanban.cjs","names":[],"sources":["../../../src/components/Kanban/Kanban.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — drag-and-drop needs an\n * accessible twin: cardRoleDescription and label exist so the keyboard path\n * announces what the pointer path shows, and renderCard/emptyLabel are the slots.\n * The body is the move calculation shared by both paths.\n */\n/* eslint-disable react-hooks/refs -- `getItemProps` is called during render and its\n handlers close over `useSortable`'s mirror refs, so the rule reports the call site\n here. The refs are only written from event handlers and read from a window\n listener; the two reads that were genuinely render-time (the drag group in the\n rendered class/aria, and the group lookup inside `commit`) were fixed instead of\n silenced — see the hook's docstring. */\nimport { useMemo } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { useSortable } from \"@/hooks/use-sortable\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Kanban.module.css\";\n\n/** One card on the board. */\nexport interface KanbanCard {\n /** Stable identifier, unique across the whole board. */\n id: string;\n /** Card body. A string renders as the card's title. */\n content: ReactNode;\n}\n\n/** One column of the board. */\nexport interface KanbanColumn {\n /** Stable identifier, used as the drop group. */\n id: string;\n /** Column heading. */\n title: ReactNode;\n /** Cards in display order. */\n cards: KanbanCard[];\n /**\n * Refuses drops into this column. The cards inside can still be picked up and\n * moved elsewhere — a \"done\" column that no longer accepts work, for instance.\n */\n locked?: boolean;\n}\n\n/** Where a card ended up. */\nexport interface KanbanMove {\n cardId: string;\n fromColumn: string;\n toColumn: string;\n /** Index within the destination column. */\n toIndex: number;\n}\n\nexport interface KanbanProps {\n columns: KanbanColumn[];\n /**\n * Called once per committed move — on pointer release or on a keyboard drop.\n * You own the data: apply the move and pass the new `columns` back.\n */\n onMove: (move: KanbanMove) => void;\n /** Renders a card. Defaults to its `content`. */\n renderCard?: (card: KanbanCard, column: KanbanColumn) => ReactNode;\n /** Text shown in a column with no cards. */\n emptyLabel?: ReactNode;\n /** Announced per card, so a screen reader user learns the keyboard contract. */\n cardRoleDescription?: string;\n /**\n * Accessible name of the board. A `listbox` without a name is unusable with a\n * screen reader, so this has a default rather than being optional in practice.\n */\n label?: string;\n /** Blocks all dragging. */\n disabled?: boolean;\n className?: string;\n}\n\n/**\n * Kanban board: columns of cards, reorderable within a column and movable across\n * columns, by pointer **or** keyboard.\n *\n * The drag machine is `useSortable` — the board does not reimplement it. Cards are\n * indexed globally across columns so a single sortable can span the whole board;\n * the component translates that flat index back into `{ column, index }` for\n * `onMove`, which is the shape an app actually needs.\n *\n * Nothing is mutated here: `onMove` reports the intent once and the parent applies\n * it. That keeps the board a controlled value and avoids a re-render per pointer\n * frame.\n *\n * ARIA shape: **one `listbox` per column**, named by the column title, containing\n * only `option` cards. A single board-wide listbox does not survive the markup a\n * board needs — `listbox` requires `option`/`group` children, and the column header\n * and card wrapper in between break that ownership. Per-column listboxes also read\n * better: a screen reader announces which column it is in and how many cards it\n * holds. The column header is a plain `div`, not a `<header>`, because outside a\n * sectioning element every `<header>` becomes a page-level banner landmark — with\n * three columns that is three duplicate banners. An **empty** column is not marked\n * as a listbox at all: a listbox with zero options fails `aria-required-children`,\n * and \"no cards\" is exactly zero options.\n *\n * Known limitation: a **keyboard** move can only target positions that hold a card,\n * because the move walks the flat index space of existing cards. Dropping into an\n * empty column works by pointer; by keyboard it does not. Moving a card to a column\n * that already has one card, then reordering, is the workaround until column-switch\n * keys land.\n *\n * @example\n * ```tsx\n * const [columns, setColumns] = useState<KanbanColumn[]>([\n * { id: \"todo\", title: \"A fazer\", cards: [{ id: \"1\", content: \"Corrigir login\" }] },\n * { id: \"doing\", title: \"Fazendo\", cards: [] },\n * { id: \"done\", title: \"Feito\", cards: [], locked: true },\n * ]);\n *\n * <Kanban\n * columns={columns}\n * onMove={({ cardId, fromColumn, toColumn, toIndex }) =>\n * setColumns((current) => applyKanbanMove(current, { cardId, fromColumn, toColumn, toIndex }))\n * }\n * />\n * ```\n */\nexport function Kanban({\n columns,\n onMove,\n renderCard,\n emptyLabel = \"Nenhum card\",\n cardRoleDescription = \"Card do quadro — Espaço pega, setas movem, Espaço solta\",\n label = \"Quadro\",\n disabled = false,\n className,\n}: KanbanProps) {\n /**\n * Flat view of every card, in column order.\n *\n * `useSortable` works on a single index space, so the board flattens itself and\n * keeps the mapping back to `{ column, index }` here — the only place that has\n * to know both shapes.\n */\n const flat = useMemo(\n () =>\n columns.flatMap((column, columnIndex) =>\n column.cards.map((card, cardIndex) => ({ card, column, columnIndex, cardIndex })),\n ),\n [columns],\n );\n\n const sortable = useSortable({\n itemCount: flat.length,\n disabled,\n roleDescription: cardRoleDescription,\n onReorder: ({ from, to, fromGroup, toGroup }) => {\n const source = flat[from];\n if (!source) return;\n\n const destinationId = toGroup ?? fromGroup ?? source.column.id;\n const destination = columns.find((column) => column.id === destinationId);\n if (!destination || destination.locked) return;\n\n const target = flat[to];\n const toIndex =\n target && target.column.id === destinationId\n ? target.cardIndex\n : destination.cards.length;\n\n onMove({\n cardId: source.card.id,\n fromColumn: source.column.id,\n toColumn: destinationId,\n toIndex,\n });\n },\n });\n\n /**\n * First flat index of each column.\n *\n * Derived instead of counted with a mutable `flatIndex++` during render: a\n * render-scoped counter mutated inside the map is exactly the pattern the React\n * Compiler rules reject, and for good reason — a partial or replayed render\n * would resume from a half-advanced counter.\n */\n const columnOffsets = useMemo(() => {\n const offsets: number[] = [];\n let start = 0;\n for (const column of columns) {\n offsets.push(start);\n start += column.cards.length;\n }\n return offsets;\n }, [columns]);\n\n return (\n <div className={cn(styles.board, className)} aria-label={label} ref={sortable.setContainer}>\n {columns.map((column, columnIndex) => {\n const isDropTarget = sortable.overGroup === column.id && !column.locked;\n return (\n <div\n key={column.id}\n className={cn(\n styles.column,\n isDropTarget && styles.columnActive,\n column.locked && styles.columnLocked,\n )}\n >\n <div className={styles.columnHeader}>\n <span className={styles.columnTitle}>{column.title}</span>\n <span className={styles.count}>{column.cards.length}</span>\n </div>\n\n <div\n className={styles.cards}\n {...(column.cards.length > 0 ? sortable.getListProps() : {})}\n aria-label={typeof column.title === \"string\" ? column.title : column.id}\n >\n {column.cards.map((card, cardIndex) => {\n const index = columnOffsets[columnIndex] + cardIndex;\n const isActive = sortable.activeIndex === index;\n const isOver = sortable.overIndex === index && !isActive;\n return (\n <div\n key={card.id}\n {...sortable.getItemProps(index, column.id)}\n className={cn(\n styles.card,\n isActive && styles.cardActive,\n isOver && styles.cardOver,\n )}\n >\n {renderCard ? renderCard(card, column) : card.content}\n </div>\n );\n })}\n\n {column.cards.length === 0 ? (\n <div\n {...sortable.getEmptyGroupProps(column.id)}\n className={styles.empty}\n >\n {emptyLabel}\n </div>\n ) : null}\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n\n/**\n * Apply a {@link KanbanMove} to a column list, returning new arrays.\n *\n * Exported because every consumer needs the same reducer.\n *\n * `toIndex` is the position of the card that was dropped **onto**, read from the\n * board as it looked before the move. Inserting at that same index *after* removing\n * the dragged card lands where the user aimed in both directions — moving down, the\n * removal shifts the target up by one and the insertion lands after it; moving up,\n * nothing shifted. Compensating for the shift (the \"obvious\" `toIndex - 1`) is what\n * turns a one-step move down into a no-op.\n *\n * @param columns - Current board.\n * @param move - The move reported by `onMove`.\n * @returns A new column list, or the same reference when the move cannot apply.\n */\nexport function applyKanbanMove(columns: KanbanColumn[], move: KanbanMove): KanbanColumn[] {\n const fromColumn = columns.find((column) => column.id === move.fromColumn);\n const card = fromColumn?.cards.find((candidate) => candidate.id === move.cardId);\n if (!fromColumn || !card) return columns;\n\n const insertAt = move.toIndex;\n\n return columns.map((column) => {\n if (column.id === move.fromColumn && column.id === move.toColumn) {\n const without = column.cards.filter((candidate) => candidate.id !== move.cardId);\n without.splice(insertAt, 0, card);\n return { ...column, cards: without };\n }\n if (column.id === move.fromColumn) {\n return { ...column, cards: column.cards.filter((c) => c.id !== move.cardId) };\n }\n if (column.id === move.toColumn) {\n const next = column.cards.slice();\n next.splice(insertAt, 0, card);\n return { ...column, cards: next };\n }\n return column;\n });\n}\n"],"mappings":"uKAuHA,SAAgB,EAAO,CACnB,UACA,SACA,aACA,aAAa,cACb,sBAAsB,0DACtB,QAAQ,SACR,WAAW,GACX,aACY,CAQZ,IAAM,GAAA,EAAO,EAAA,QAAA,KAEL,EAAQ,SAAS,EAAQ,IACrB,EAAO,MAAM,KAAK,EAAM,KAAe,CAAE,OAAM,SAAQ,cAAa,WAAU,EAAE,CACpF,EACJ,CAAC,CAAO,CACZ,EAEM,EAAW,EAAA,YAAY,CACzB,UAAW,EAAK,OAChB,WACA,gBAAiB,EACjB,WAAY,CAAE,OAAM,KAAI,YAAW,aAAc,CAC7C,IAAM,EAAS,EAAK,GACpB,GAAI,CAAC,EAAQ,OAEb,IAAM,EAAgB,GAAW,GAAa,EAAO,OAAO,GACtD,EAAc,EAAQ,KAAM,GAAW,EAAO,KAAO,CAAa,EACxE,GAAI,CAAC,GAAe,EAAY,OAAQ,OAExC,IAAM,EAAS,EAAK,GACd,EACF,GAAU,EAAO,OAAO,KAAO,EACzB,EAAO,UACP,EAAY,MAAM,OAE5B,EAAO,CACH,OAAQ,EAAO,KAAK,GACpB,WAAY,EAAO,OAAO,GAC1B,SAAU,EACV,SACJ,CAAC,CACL,CACJ,CAAC,EAUK,GAAA,EAAgB,EAAA,QAAA,KAAc,CAChC,IAAM,EAAoB,CAAC,EACvB,EAAQ,EACZ,IAAK,IAAM,KAAU,EACjB,EAAQ,KAAK,CAAK,EAClB,GAAS,EAAO,MAAM,OAE1B,OAAO,CACX,EAAG,CAAC,CAAO,CAAC,EAEZ,OACI,EAAA,EAAA,IAAA,CAAC,MAAD,CAAK,UAAW,EAAA,GAAG,EAAA,QAAO,MAAO,CAAS,EAAG,aAAY,EAAO,IAAK,EAAS,aACzE,SAAA,EAAQ,KAAK,EAAQ,IAAgB,CAClC,IAAM,EAAe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6CX,CAEb,CAAC,CACA,CAAA,CAEb,CAkBA,SAAgB,EAAgB,EAAyB,EAAkC,CACvF,IAAM,EAAa,EAAQ,KAAM,GAAW,EAAO,KAAO,EAAK,UAAU,EACnE,EAAO,GAAY,MAAM,KAAM,GAAc,EAAU,KAAO,EAAK,MAAM,EAC/E,GAAI,CAAC,GAAc,CAAC,EAAM,OAAO,EAEjC,IAAM,EAAW,EAAK,QAEtB,OAAO,EAAQ,IAAK,GAAW,CAC3B,GAAI,EAAO,KAAO,EAAK,YAAc,EAAO,KAAO,EAAK,SAAU,CAC9D,IAAM,EAAU,EAAO,MAAM,OAAQ,GAAc,EAAU,KAAO,EAAK,MAAM,EAE/E,OADA,EAAQ,OAAO,EAAU,EAAG,CAAI,EACzB,CAAE,GAAG,EAAQ,MAAO,CAAQ,CACvC,CACA,GAAI,EAAO,KAAO,EAAK,WACnB,MAAO,CAAE,GAAG,EAAQ,MAAO,EAAO,MAAM,OAAQ,GAAM,EAAE,KAAO,EAAK,MAAM,CAAE,EAEhF,GAAI,EAAO,KAAO,EAAK,SAAU,CAC7B,IAAM,EAAO,EAAO,MAAM,MAAM,EAEhC,OADA,EAAK,OAAO,EAAU,EAAG,CAAI,EACtB,CAAE,GAAG,EAAQ,MAAO,CAAK,CACpC,CACA,OAAO,CACX,CAAC,CACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Kanban.js","names":[],"sources":["../../../src/components/Kanban/Kanban.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — drag-and-drop needs an\n * accessible twin: cardRoleDescription and label exist so the keyboard path\n * announces what the pointer path shows, and renderCard/emptyLabel are the slots.\n * The body is the move calculation shared by both paths.\n */\n/* eslint-disable react-hooks/refs -- `getItemProps` is called during render and its\n handlers close over `useSortable`'s mirror refs, so the rule reports the call site\n here. The refs are only written from event handlers and read from a window\n listener; the two reads that were genuinely render-time (the drag group in the\n rendered class/aria, and the group lookup inside `commit`) were fixed instead of\n silenced — see the hook's docstring. */\nimport { useMemo } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { useSortable } from \"@/hooks/use-sortable\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Kanban.module.css\";\n\n/** One card on the board. */\nexport interface KanbanCard {\n /** Stable identifier, unique across the whole board. */\n id: string;\n /** Card body. A string renders as the card's title. */\n content: ReactNode;\n}\n\n/** One column of the board. */\nexport interface KanbanColumn {\n /** Stable identifier, used as the drop group. */\n id: string;\n /** Column heading. */\n title: ReactNode;\n /** Cards in display order. */\n cards: KanbanCard[];\n /**\n * Refuses drops into this column. The cards inside can still be picked up and\n * moved elsewhere — a \"done\" column that no longer accepts work, for instance.\n */\n locked?: boolean;\n}\n\n/** Where a card ended up. */\nexport interface KanbanMove {\n cardId: string;\n fromColumn: string;\n toColumn: string;\n /** Index within the destination column. */\n toIndex: number;\n}\n\nexport interface KanbanProps {\n columns: KanbanColumn[];\n /**\n * Called once per committed move — on pointer release or on a keyboard drop.\n * You own the data: apply the move and pass the new `columns` back.\n */\n onMove: (move: KanbanMove) => void;\n /** Renders a card. Defaults to its `content`. */\n renderCard?: (card: KanbanCard, column: KanbanColumn) => ReactNode;\n /** Text shown in a column with no cards. */\n emptyLabel?: ReactNode;\n /** Announced per card, so a screen reader user learns the keyboard contract. */\n cardRoleDescription?: string;\n /**\n * Accessible name of the board. A `listbox` without a name is unusable with a\n * screen reader, so this has a default rather than being optional in practice.\n */\n label?: string;\n /** Blocks all dragging. */\n disabled?: boolean;\n className?: string;\n}\n\n/**\n * Kanban board: columns of cards, reorderable within a column and movable across\n * columns, by pointer **or** keyboard.\n *\n * The drag machine is `useSortable` — the board does not reimplement it. Cards are\n * indexed globally across columns so a single sortable can span the whole board;\n * the component translates that flat index back into `{ column, index }` for\n * `onMove`, which is the shape an app actually needs.\n *\n * Nothing is mutated here: `onMove` reports the intent once and the parent applies\n * it. That keeps the board a controlled value and avoids a re-render per pointer\n * frame.\n *\n * ARIA shape: **one `listbox` per column**, named by the column title, containing\n * only `option` cards. A single board-wide listbox does not survive the markup a\n * board needs — `listbox` requires `option`/`group` children, and the column header\n * and card wrapper in between break that ownership. Per-column listboxes also read\n * better: a screen reader announces which column it is in and how many cards it\n * holds. The column header is a plain `div`, not a `<header>`, because outside a\n * sectioning element every `<header>` becomes a page-level banner landmark — with\n * three columns that is three duplicate banners. An **empty** column is not marked\n * as a listbox at all: a listbox with zero options fails `aria-required-children`,\n * and \"no cards\" is exactly zero options.\n *\n * Known limitation: a **keyboard** move can only target positions that hold a card,\n * because the move walks the flat index space of existing cards. Dropping into an\n * empty column works by pointer; by keyboard it does not. Moving a card to a column\n * that already has one card, then reordering, is the workaround until column-switch\n * keys land.\n *\n * @example\n * ```tsx\n * const [columns, setColumns] = useState<KanbanColumn[]>([\n * { id: \"todo\", title: \"A fazer\", cards: [{ id: \"1\", content: \"Corrigir login\" }] },\n * { id: \"doing\", title: \"Fazendo\", cards: [] },\n * { id: \"done\", title: \"Feito\", cards: [], locked: true },\n * ]);\n *\n * <Kanban\n * columns={columns}\n * onMove={({ cardId, fromColumn, toColumn, toIndex }) =>\n * setColumns((current) => applyKanbanMove(current, { cardId, fromColumn, toColumn, toIndex }))\n * }\n * />\n * ```\n */\nexport function Kanban({\n columns,\n onMove,\n renderCard,\n emptyLabel = \"Nenhum card\",\n cardRoleDescription = \"Card do quadro — Espaço pega, setas movem, Espaço solta\",\n label = \"Quadro\",\n disabled = false,\n className,\n}: KanbanProps) {\n /**\n * Flat view of every card, in column order.\n *\n * `useSortable` works on a single index space, so the board flattens itself and\n * keeps the mapping back to `{ column, index }` here — the only place that has\n * to know both shapes.\n */\n const flat = useMemo(\n () =>\n columns.flatMap((column, columnIndex) =>\n column.cards.map((card, cardIndex) => ({ card, column, columnIndex, cardIndex })),\n ),\n [columns],\n );\n\n const sortable = useSortable({\n itemCount: flat.length,\n disabled,\n roleDescription: cardRoleDescription,\n onReorder: ({ from, to, fromGroup, toGroup }) => {\n const source = flat[from];\n if (!source) return;\n\n const destinationId = toGroup ?? fromGroup ?? source.column.id;\n const destination = columns.find((column) => column.id === destinationId);\n if (!destination || destination.locked) return;\n\n const target = flat[to];\n const toIndex =\n target && target.column.id === destinationId\n ? target.cardIndex\n : destination.cards.length;\n\n onMove({\n cardId: source.card.id,\n fromColumn: source.column.id,\n toColumn: destinationId,\n toIndex,\n });\n },\n });\n\n /**\n * First flat index of each column.\n *\n * Derived instead of counted with a mutable `flatIndex++` during render: a\n * render-scoped counter mutated inside the map is exactly the pattern the React\n * Compiler rules reject, and for good reason — a partial or replayed render\n * would resume from a half-advanced counter.\n */\n const columnOffsets = useMemo(() => {\n const offsets: number[] = [];\n let start = 0;\n for (const column of columns) {\n offsets.push(start);\n start += column.cards.length;\n }\n return offsets;\n }, [columns]);\n\n return (\n <div className={cn(styles.board, className)} aria-label={label} ref={sortable.setContainer}>\n {columns.map((column, columnIndex) => {\n const isDropTarget = sortable.overGroup === column.id && !column.locked;\n return (\n <div\n key={column.id}\n className={cn(\n styles.column,\n isDropTarget && styles.columnActive,\n column.locked && styles.columnLocked,\n )}\n >\n <div className={styles.columnHeader}>\n <span className={styles.columnTitle}>{column.title}</span>\n <span className={styles.count}>{column.cards.length}</span>\n </div>\n\n <div\n className={styles.cards}\n {...(column.cards.length > 0 ? sortable.getListProps() : {})}\n aria-label={typeof column.title === \"string\" ? column.title : column.id}\n >\n {column.cards.map((card, cardIndex) => {\n const index = columnOffsets[columnIndex] + cardIndex;\n const isActive = sortable.activeIndex === index;\n const isOver = sortable.overIndex === index && !isActive;\n return (\n <div\n key={card.id}\n {...sortable.getItemProps(index, column.id)}\n className={cn(\n styles.card,\n isActive && styles.cardActive,\n isOver && styles.cardOver,\n )}\n >\n {renderCard ? renderCard(card, column) : card.content}\n </div>\n );\n })}\n\n {column.cards.length === 0 ? (\n <div\n {...sortable.getEmptyGroupProps(column.id)}\n className={styles.empty}\n >\n {emptyLabel}\n </div>\n ) : null}\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n\n/**\n * Apply a {@link KanbanMove} to a column list, returning new arrays.\n *\n * Exported because every consumer needs the same reducer.\n *\n * `toIndex` is the position of the card that was dropped **onto**, read from the\n * board as it looked before the move. Inserting at that same index *after* removing\n * the dragged card lands where the user aimed in both directions — moving down, the\n * removal shifts the target up by one and the insertion lands after it; moving up,\n * nothing shifted. Compensating for the shift (the \"obvious\" `toIndex - 1`) is what\n * turns a one-step move down into a no-op.\n *\n * @param columns - Current board.\n * @param move - The move reported by `onMove`.\n * @returns A new column list, or the same reference when the move cannot apply.\n */\nexport function applyKanbanMove(columns: KanbanColumn[], move: KanbanMove): KanbanColumn[] {\n const fromColumn = columns.find((column) => column.id === move.fromColumn);\n const card = fromColumn?.cards.find((candidate) => candidate.id === move.cardId);\n if (!fromColumn || !card) return columns;\n\n const insertAt = move.toIndex;\n\n return columns.map((column) => {\n if (column.id === move.fromColumn && column.id === move.toColumn) {\n const without = column.cards.filter((candidate) => candidate.id !== move.cardId);\n without.splice(insertAt, 0, card);\n return { ...column, cards: without };\n }\n if (column.id === move.fromColumn) {\n return { ...column, cards: column.cards.filter((c) => c.id !== move.cardId) };\n }\n if (column.id === move.toColumn) {\n const next = column.cards.slice();\n next.splice(insertAt, 0, card);\n return { ...column, cards: next };\n }\n return column;\n });\n}\n"],"mappings":";;;;;;AAuHA,SAAgB,EAAO,EACnB,YACA,WACA,eACA,gBAAa,eACb,yBAAsB,2DACtB,WAAQ,UACR,cAAW,IACX,gBACY;CAQZ,IAAM,IAAO,QAEL,EAAQ,SAAS,GAAQ,MACrB,EAAO,MAAM,KAAK,GAAM,OAAe;EAAE;EAAM;EAAQ;EAAa;CAAU,EAAE,CACpF,GACJ,CAAC,CAAO,CACZ,GAEM,IAAW,EAAY;EACzB,WAAW,EAAK;EAChB;EACA,iBAAiB;EACjB,YAAY,EAAE,SAAM,OAAI,cAAW,iBAAc;GAC7C,IAAM,IAAS,EAAK;GACpB,IAAI,CAAC,GAAQ;GAEb,IAAM,IAAgB,KAAW,KA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ban/Kanban.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — drag-and-drop needs an\n * accessible twin: cardRoleDescription and label exist so the keyboard path\n * announces what the pointer path shows, and renderCard/emptyLabel are the slots.\n * The body is the move calculation shared by both paths.\n */\n/* eslint-disable react-hooks/refs -- `getItemProps` is called during render and its\n handlers close over `useSortable`'s mirror refs, so the rule reports the call site\n here. The refs are only written from event handlers and read from a window\n listener; the two reads that were genuinely render-time (the drag group in the\n rendered class/aria, and the group lookup inside `commit`) were fixed instead of\n silenced — see the hook's docstring. */\nimport { useMemo } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { useSortable } from \"@/hooks/use-sortable\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Kanban.module.css\";\n\n/** One card on the board. */\nexport interface KanbanCard {\n /** Stable identifier, unique across the whole board. */\n id: string;\n /** Card body. A string renders as the card's title. */\n content: ReactNode;\n}\n\n/** One column of the board. */\nexport interface KanbanColumn {\n /** Stable identifier, used as the drop group. */\n id: string;\n /** Column heading. */\n title: ReactNode;\n /** Cards in display order. */\n cards: KanbanCard[];\n /**\n * Refuses drops into this column. The cards inside can still be picked up and\n * moved elsewhere — a \"done\" column that no longer accepts work, for instance.\n */\n locked?: boolean;\n}\n\n/** Where a card ended up. */\nexport interface KanbanMove {\n cardId: string;\n fromColumn: string;\n toColumn: string;\n /** Index within the destination column. */\n toIndex: number;\n}\n\nexport interface KanbanProps {\n columns: KanbanColumn[];\n /**\n * Called once per committed move — on pointer release or on a keyboard drop.\n * You own the data: apply the move and pass the new `columns` back.\n */\n onMove: (move: KanbanMove) => void;\n /** Renders a card. Defaults to its `content`. */\n renderCard?: (card: KanbanCard, column: KanbanColumn) => ReactNode;\n /** Text shown in a column with no cards. */\n emptyLabel?: ReactNode;\n /** Announced per card, so a screen reader user learns the keyboard contract. */\n cardRoleDescription?: string;\n /**\n * Accessible name of the board. A `listbox` without a name is unusable with a\n * screen reader, so this has a default rather than being optional in practice.\n */\n label?: string;\n /** Blocks all dragging. */\n disabled?: boolean;\n className?: string;\n}\n\n/**\n * Kanban board: columns of cards, reorderable within a column and movable across\n * columns, by pointer **or** keyboard.\n *\n * The drag machine is `useSortable` — the board does not reimplement it. Cards are\n * indexed globally across columns so a single sortable can span the whole board;\n * the component translates that flat index back into `{ column, index }` for\n * `onMove`, which is the shape an app actually needs.\n *\n * Nothing is mutated here: `onMove` reports the intent once and the parent applies\n * it. That keeps the board a controlled value and avoids a re-render per pointer\n * frame.\n *\n * ARIA shape: **one `listbox` per column**, named by the column title, containing\n * only `option` cards. A single board-wide listbox does not survive the markup a\n * board needs — `listbox` requires `option`/`group` children, and the column header\n * and card wrapper in between break that ownership. Per-column listboxes also read\n * better: a screen reader announces which column it is in and how many cards it\n * holds. The column header is a plain `div`, not a `<header>`, because outside a\n * sectioning element every `<header>` becomes a page-level banner landmark — with\n * three columns that is three duplicate banners. An **empty** column is not marked\n * as a listbox at all: a listbox with zero options fails `aria-required-children`,\n * and \"no cards\" is exactly zero options.\n *\n * Known limitation: a **keyboard** move can only target positions that hold a card,\n * because the move walks the flat index space of existing cards. Dropping into an\n * empty column works by pointer; by keyboard it does not. Moving a card to a column\n * that already has one card, then reordering, is the workaround until column-switch\n * keys land.\n *\n * @example\n * ```tsx\n * const [columns, setColumns] = useState<KanbanColumn[]>([\n * { id: \"todo\", title: \"A fazer\", cards: [{ id: \"1\", content: \"Corrigir login\" }] },\n * { id: \"doing\", title: \"Fazendo\", cards: [] },\n * { id: \"done\", title: \"Feito\", cards: [], locked: true },\n * ]);\n *\n * <Kanban\n * columns={columns}\n * onMove={({ cardId, fromColumn, toColumn, toIndex }) =>\n * setColumns((current) => applyKanbanMove(current, { cardId, fromColumn, toColumn, toIndex }))\n * }\n * />\n * ```\n */\nexport function Kanban({\n columns,\n onMove,\n renderCard,\n emptyLabel = \"Nenhum card\",\n cardRoleDescription = \"Card do quadro — Espaço pega, setas movem, Espaço solta\",\n label = \"Quadro\",\n disabled = false,\n className,\n}: KanbanProps) {\n /**\n * Flat view of every card, in column order.\n *\n * `useSortable` works on a single index space, so the board flattens itself and\n * keeps the mapping back to `{ column, index }` here — the only place that has\n * to know both shapes.\n */\n const flat = useMemo(\n () =>\n columns.flatMap((column, columnIndex) =>\n column.cards.map((card, cardIndex) => ({ card, column, columnIndex, cardIndex })),\n ),\n [columns],\n );\n\n const sortable = useSortable({\n itemCount: flat.length,\n disabled,\n roleDescription: cardRoleDescription,\n onReorder: ({ from, to, fromGroup, toGroup }) => {\n const source = flat[from];\n if (!source) return;\n\n const destinationId = toGroup ?? fromGroup ?? source.column.id;\n const destination = columns.find((column) => column.id === destinationId);\n if (!destination || destination.locked) return;\n\n const target = flat[to];\n const toIndex =\n target && target.column.id === destinationId\n ? target.cardIndex\n : destination.cards.length;\n\n onMove({\n cardId: source.card.id,\n fromColumn: source.column.id,\n toColumn: destinationId,\n toIndex,\n });\n },\n });\n\n /**\n * First flat index of each column.\n *\n * Derived instead of counted with a mutable `flatIndex++` during render: a\n * render-scoped counter mutated inside the map is exactly the pattern the React\n * Compiler rules reject, and for good reason — a partial or replayed render\n * would resume from a half-advanced counter.\n */\n const columnOffsets = useMemo(() => {\n const offsets: number[] = [];\n let start = 0;\n for (const column of columns) {\n offsets.push(start);\n start += column.cards.length;\n }\n return offsets;\n }, [columns]);\n\n return (\n <div className={cn(styles.board, className)} aria-label={label} ref={sortable.setContainer}>\n {columns.map((column, columnIndex) => {\n const isDropTarget = sortable.overGroup === column.id && !column.locked;\n return (\n <div\n key={column.id}\n className={cn(\n styles.column,\n isDropTarget && styles.columnActive,\n column.locked && styles.columnLocked,\n )}\n >\n <div className={styles.columnHeader}>\n <span className={styles.columnTitle}>{column.title}</span>\n <span className={styles.count}>{column.cards.length}</span>\n </div>\n\n <div\n className={styles.cards}\n {...(column.cards.length > 0 ? sortable.getListProps() : {})}\n aria-label={typeof column.title === \"string\" ? column.title : column.id}\n >\n {column.cards.map((card, cardIndex) => {\n const index = columnOffsets[columnIndex] + cardIndex;\n const isActive = sortable.activeIndex === index;\n const isOver = sortable.overIndex === index && !isActive;\n return (\n <div\n key={card.id}\n {...sortable.getItemProps(index, column.id)}\n className={cn(\n styles.card,\n isActive && styles.cardActive,\n isOver && styles.cardOver,\n )}\n >\n {renderCard ? renderCard(card, column) : card.content}\n </div>\n );\n })}\n\n {column.cards.length === 0 ? (\n <div\n {...sortable.getEmptyGroupProps(column.id)}\n className={styles.empty}\n >\n {emptyLabel}\n </div>\n ) : null}\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n\n/**\n * Apply a {@link KanbanMove} to a column list, returning new arrays.\n *\n * Exported because every consumer needs the same reducer.\n *\n * `toIndex` is the position of the card that was dropped **onto**, read from the\n * board as it looked before the move. Inserting at that same index *after* removing\n * the dragged card lands where the user aimed in both directions — moving down, the\n * removal shifts the target up by one and the insertion lands after it; moving up,\n * nothing shifted. Compensating for the shift (the \"obvious\" `toIndex - 1`) is what\n * turns a one-step move down into a no-op.\n *\n * @param columns - Current board.\n * @param move - The move reported by `onMove`.\n * @returns A new column list, or the same reference when the move cannot apply.\n */\nexport function applyKanbanMove(columns: KanbanColumn[], move: KanbanMove): KanbanColumn[] {\n const fromColumn = columns.find((column) => column.id === move.fromColumn);\n const card = fromColumn?.cards.find((candidate) => candidate.id === move.cardId);\n if (!fromColumn || !card) return columns;\n\n const insertAt = move.toIndex;\n\n return columns.map((column) => {\n if (column.id === move.fromColumn && column.id === move.toColumn) {\n const without = column.cards.filter((candidate) => candidate.id !== move.cardId);\n without.splice(insertAt, 0, card);\n return { ...column, cards: without };\n }\n if (column.id === move.fromColumn) {\n return { ...column, cards: column.cards.filter((c) => c.id !== move.cardId) };\n }\n if (column.id === move.toColumn) {\n const next = column.cards.slice();\n next.splice(insertAt, 0, card);\n return { ...column, cards: next };\n }\n return column;\n });\n}\n"],"mappings":";;;;;;AAuHA,SAAgB,EAAO,EACnB,YACA,WACA,eACA,gBAAa,eACb,yBAAsB,2DACtB,WAAQ,UACR,cAAW,IAC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zB;IAAE,GAAG;IAAQ,OAAO;GAAQ;EACvC;EACA,IAAI,EAAO,OAAO,EAAK,YACnB,OAAO;GAAE,GAAG;GAAQ,OAAO,EAAO,MAAM,QAAQ,MAAM,EAAE,OAAO,EAAK,MAAM;EAAE;EAEhF,IAAI,EAAO,OAAO,EAAK,UAAU;GAC7B,IAAM,IAAO,EAAO,MAAM,MAAM;GAEhC,OADA,EAAK,OAAO,GAAU,GAAG,CAAI,GACtB;IAAE,GAAG;IAAQ,OAAO;GAAK;EACpC;EACA,OAAO;CACX,CAAC;AACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.cjs","names":[],"sources":["../../../src/components/Label/Label.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport type { LabelHTMLAttributes } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Label.module.css\";\n\nexport interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> {\n /** When `true` appends a danger-colored asterisk marking the field as required. */\n required?: boolean;\n}\n\n/**\n * A form `<label>`. Associate it with a control via `htmlFor`. When `required`\n * is set, a decorative asterisk (`aria-hidden`) is appended.\n *\n * @param props - {@link LabelProps}.\n * @returns The label element.\n */\nexport const Label = forwardRef<HTMLLabelElement, LabelProps>(function Label(\n { required = false, className, children, ...props },\n ref,\n) {\n return (\n <label ref={ref} className={cn(styles.label, className)} {...props}>\n {children}\n {required && (\n <span className={styles.asterisk} aria-hidden>\n *\n </span>\n )}\n </label>\n );\n});\n"],"mappings":"4HAiBA,IAAa,GAAA,
|
|
1
|
+
{"version":3,"file":"Label.cjs","names":[],"sources":["../../../src/components/Label/Label.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport type { LabelHTMLAttributes } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Label.module.css\";\n\nexport interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> {\n /** When `true` appends a danger-colored asterisk marking the field as required. */\n required?: boolean;\n}\n\n/**\n * A form `<label>`. Associate it with a control via `htmlFor`. When `required`\n * is set, a decorative asterisk (`aria-hidden`) is appended.\n *\n * @param props - {@link LabelProps}.\n * @returns The label element.\n */\nexport const Label = forwardRef<HTMLLabelElement, LabelProps>(function Label(\n { required = false, className, children, ...props },\n ref,\n) {\n return (\n <label ref={ref} className={cn(styles.label, className)} {...props}>\n {children}\n {required && (\n <span className={styles.asterisk} aria-hidden>\n *\n </span>\n )}\n </label>\n );\n});\n"],"mappings":"4HAiBA,IAAa,GAAA,EAAQ,EAAA,WAAA,CAAyC,SAC1D,CAAE,WAAW,GAAO,YAAW,WAAU,GAAG,GAC5C,EACF,CACE,OACI,EAAA,EAAA,KAAA,CAAC,QAAD,CAAY,MAAK,UAAW,EAAA,GAAG,EAAA,QAAO,MAAO,CAAS,EAAG,GAAI,EAA7D,SAAA,CACK,EACA,IACG,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,SAAU,cAAA,GAAY,SAAA,GAExC,CAAA,CAEP,GAEf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.js","names":[],"sources":["../../../src/components/Label/Label.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport type { LabelHTMLAttributes } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Label.module.css\";\n\nexport interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> {\n /** When `true` appends a danger-colored asterisk marking the field as required. */\n required?: boolean;\n}\n\n/**\n * A form `<label>`. Associate it with a control via `htmlFor`. When `required`\n * is set, a decorative asterisk (`aria-hidden`) is appended.\n *\n * @param props - {@link LabelProps}.\n * @returns The label element.\n */\nexport const Label = forwardRef<HTMLLabelElement, LabelProps>(function Label(\n { required = false, className, children, ...props },\n ref,\n) {\n return (\n <label ref={ref} className={cn(styles.label, className)} {...props}>\n {children}\n {required && (\n <span className={styles.asterisk} aria-hidden>\n *\n </span>\n )}\n </label>\n );\n});\n"],"mappings":";;;;;AAiBA,IAAa,IAAQ,EAAyC,SAC1D,EAAE,cAAW,IAAO,cAAW,aAAU,GAAG,KAC5C,GACF;CACE,OACI,kBAAC,SAAD;EAAY;EAAK,WAAW,EAAG,EAAO,OAAO,CAAS;EAAG,GAAI;
|
|
1
|
+
{"version":3,"file":"Label.js","names":[],"sources":["../../../src/components/Label/Label.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport type { LabelHTMLAttributes } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Label.module.css\";\n\nexport interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> {\n /** When `true` appends a danger-colored asterisk marking the field as required. */\n required?: boolean;\n}\n\n/**\n * A form `<label>`. Associate it with a control via `htmlFor`. When `required`\n * is set, a decorative asterisk (`aria-hidden`) is appended.\n *\n * @param props - {@link LabelProps}.\n * @returns The label element.\n */\nexport const Label = forwardRef<HTMLLabelElement, LabelProps>(function Label(\n { required = false, className, children, ...props },\n ref,\n) {\n return (\n <label ref={ref} className={cn(styles.label, className)} {...props}>\n {children}\n {required && (\n <span className={styles.asterisk} aria-hidden>\n *\n </span>\n )}\n </label>\n );\n});\n"],"mappings":";;;;;AAiBA,IAAa,IAAQ,EAAyC,SAC1D,EAAE,cAAW,IAAO,cAAW,aAAU,GAAG,KAC5C,GACF;CACE,OACI,kBAAC,SAAD;EAAY;EAAK,WAAW,EAAG,EAAO,OAAO,CAAS;EAAG,GAAI;EAA7D,UAAA,CACK,GACA,KACG,kBAAC,QAAD;GAAM,WAAW,EAAO;GAAU,eAAA;GAAY,UAAA;EAExC,CAAA,CAEP;;AAEf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lightbox.cjs","names":[],"sources":["../../../src/components/Lightbox/Lightbox.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — closeLabel,\n * previousLabel and nextLabel are three separate strings an app has to translate,\n * showThumbnails/showCounter/loop are the chrome, and items/index/\n * onIndexChange/open/onClose are the controlled contract. The body is the focus\n * trap, the key handling and the swipe, which all move the same index.\n */\nimport { ChevronLeft, ChevronRight, X } from \"lucide-react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useFocusTrap } from \"@/hooks/use-focus-trap\";\nimport { useScrollLock } from \"@/hooks/use-scroll-lock\";\nimport { cn } from \"@/utils/cn\";\nimport { Portal } from \"../Portal\";\nimport styles from \"./Lightbox.module.css\";\n\n/** One item of the gallery. */\nexport interface LightboxItem {\n /** Full-size image URL. */\n src: string;\n /** Alt text. Required: a gallery of unlabeled images is unusable with a screen reader. */\n alt: string;\n /** Caption rendered under the image. */\n caption?: string;\n /** Thumbnail URL for the strip. Falls back to `src`. */\n thumbnail?: string;\n}\n\nexport interface LightboxProps {\n items: LightboxItem[];\n /** Whether the overlay is open. */\n open: boolean;\n /** Index shown while open. Default `0`. */\n index?: number;\n onIndexChange?: (index: number) => void;\n onClose: () => void;\n /** Renders the thumbnail strip. Default `true` when there is more than one item. */\n showThumbnails?: boolean;\n /** Renders the `3 / 12` counter. Default `true`. */\n showCounter?: boolean;\n /**\n * Wrap around at the ends. Default `true` — in a photo viewer, hitting a dead\n * end at the last image reads as a bug more often than as a boundary.\n */\n loop?: boolean;\n closeLabel?: string;\n previousLabel?: string;\n nextLabel?: string;\n className?: string;\n}\n\n/**\n * Full-screen image viewer with keyboard navigation.\n *\n * `Esc` closes, `←`/`→` walk the gallery, `Home`/`End` jump to the ends. Focus is\n * trapped inside while open and the page behind is scroll-locked, so the overlay\n * behaves like the dialog it is instead of a fancy `<div>` the keyboard can escape.\n *\n * Only the current image is mounted; neighbours are **preloaded** via `Image()` so\n * pressing `→` does not flash an empty frame.\n *\n * @example\n * ```tsx\n * const [open, setOpen] = useState(false);\n * const [index, setIndex] = useState(0);\n *\n * <Lightbox\n * open={open}\n * items={photos.map((p) => ({ src: p.url, alt: p.description }))}\n * index={index}\n * onIndexChange={setIndex}\n * onClose={() => setOpen(false)}\n * />\n * ```\n */\nexport function Lightbox({\n items,\n open,\n index = 0,\n onIndexChange,\n onClose,\n showThumbnails,\n showCounter = true,\n loop = true,\n closeLabel = \"Close\",\n previousLabel = \"Previous image\",\n nextLabel = \"Next image\",\n className,\n}: LightboxProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [internalIndex, setInternalIndex] = useState(index);\n const isControlled = onIndexChange !== undefined;\n const current = isControlled ? index : internalIndex;\n\n useFocusTrap(containerRef, open);\n useScrollLock(open);\n\n const move = useCallback(\n (next: number): void => {\n if (items.length === 0) return;\n const target = loop\n ? (next + items.length) % items.length\n : Math.max(0, Math.min(next, items.length - 1));\n if (!isControlled) setInternalIndex(target);\n onIndexChange?.(target);\n },\n [isControlled, items.length, loop, onIndexChange],\n );\n\n useEffect(() => {\n if (!isControlled) setInternalIndex(index);\n }, [index, isControlled]);\n\n useEffect(() => {\n if (!open) return;\n function onKeyDown(event: KeyboardEvent): void {\n switch (event.key) {\n case \"Escape\":\n onClose();\n break;\n case \"ArrowRight\":\n move(current + 1);\n break;\n case \"ArrowLeft\":\n move(current - 1);\n break;\n case \"Home\":\n move(0);\n break;\n case \"End\":\n move(items.length - 1);\n break;\n default:\n return;\n }\n event.preventDefault();\n }\n document.addEventListener(\"keydown\", onKeyDown);\n return () => document.removeEventListener(\"keydown\", onKeyDown);\n }, [current, items.length, move, onClose, open]);\n\n useEffect(() => {\n if (!open || typeof Image === \"undefined\") return;\n for (const offset of [-1, 1]) {\n const neighbour = items[(current + offset + items.length) % items.length];\n if (!neighbour) continue;\n const preload = new Image();\n preload.src = neighbour.src;\n }\n }, [current, items, open]);\n\n if (!open || items.length === 0) return null;\n\n const item = items[Math.max(0, Math.min(current, items.length - 1))];\n const withThumbnails = showThumbnails ?? items.length > 1;\n const multiple = items.length > 1;\n\n return (\n <Portal>\n <div\n ref={containerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={item.alt}\n className={cn(styles.overlay, className)}\n >\n <div className={styles.topBar}>\n {showCounter && multiple ? (\n <span className={styles.counter}>\n {current + 1} / {items.length}\n </span>\n ) : (\n <span />\n )}\n <button\n type=\"button\"\n className={styles.iconButton}\n aria-label={closeLabel}\n onClick={onClose}\n >\n <X size={20} />\n </button>\n </div>\n\n <div className={styles.stage}>\n {multiple ? (\n <button\n type=\"button\"\n className={cn(styles.iconButton, styles.nav)}\n aria-label={previousLabel}\n disabled={!loop && current === 0}\n onClick={() => move(current - 1)}\n >\n <ChevronLeft size={24} />\n </button>\n ) : null}\n\n <figure className={styles.figure}>\n <img src={item.src} alt={item.alt} className={styles.image} />\n {item.caption ? (\n <figcaption className={styles.caption}>{item.caption}</figcaption>\n ) : null}\n </figure>\n\n {multiple ? (\n <button\n type=\"button\"\n className={cn(styles.iconButton, styles.nav)}\n aria-label={nextLabel}\n disabled={!loop && current === items.length - 1}\n onClick={() => move(current + 1)}\n >\n <ChevronRight size={24} />\n </button>\n ) : null}\n </div>\n\n {withThumbnails && multiple ? (\n <div className={styles.thumbnails} role=\"tablist\" aria-label={item.alt}>\n {items.map((entry, entryIndex) => (\n <button\n key={`${entry.src}-${entryIndex}`}\n type=\"button\"\n role=\"tab\"\n aria-selected={entryIndex === current}\n aria-label={entry.alt}\n className={cn(\n styles.thumbnail,\n entryIndex === current && styles.thumbnailActive,\n )}\n onClick={() => move(entryIndex)}\n >\n <img\n src={entry.thumbnail ?? entry.src}\n alt=\"\"\n className={styles.thumbnailImage}\n />\n </button>\n ))}\n </div>\n ) : null}\n </div>\n </Portal>\n );\n}\n"],"mappings":"oRA0EA,SAAgB,EAAS,CACrB,QACA,OACA,QAAQ,EACR,gBACA,UACA,iBACA,cAAc,GACd,OAAO,GACP,aAAa,QACb,gBAAgB,iBAChB,YAAY,aACZ,aACc,CACd,IAAM,GAAA,EAAA,EAAA,OAAA,CAAsC,IAAI,EAC1C,CAAC,EAAe,IAAA,EAAA,EAAA,SAAA,CAA6B,CAAK,EAClD,EAAe,IAAkB,IAAA,GACjC,EAAU,EAAe,EAAQ,EAEvC,E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AAK,UAAW,EAAA,QAAO,KAAQ,CAAA,EAC5D,EAAK,SACF,EAAA,EAAA,IAAA,CAAC,aAAD,CAAY,UAAW,EAAA,QAAO,iBAAU,EAAK,OAAoB,CAAA,EACjE,IACA,IAEP,GACG,EAAA,EAAA,IAAA,CAAC,SAAD,CACI,KAAK,SACL,UAAW,EAAA,GAAG,EAAA,QAAO,WAAY,EAAA,QAAO,GAAG,EAC3C,aAAY,EACZ,SAAU,CAAC,GAAQ,IAAY,EAAM,OAAS,EAC9C,YAAe,EAAK,EAAU,CAAC,YAE/B,EAAA,EAAA,IAAA,CAAC,EAAA,aAAD,CAAc,KAAM,EAAK,CAAA,CACrB,CAAA,EACR,IACH,IAEJ,GAAkB,GACf,EAAA,EAAA,IAAA,CAAC,MAAD,CAAK,UAAW,EAAA,QAAO,WAAY,KAAK,UAAU,aAAY,EAAK,aAC9D,EAAM,KAAK,EAAO,KACf,EAAA,EAAA,IAAA,CAAC,SAAD,CAEI,KAAK,SACL,KAAK,MACL,gBAAe,IAAe,EAC9B,aAAY,EAAM,IAClB,UAAW,EAAA,GACP,EAAA,QAAO,UACP,IAAe,GAAW,EAAA,QAAO,eACrC,EACA,YAAe,EAAK,CAAU,YAE9B,EAAA,EAAA,IAAA,CAAC,MAAD,CACI,IAAK,EAAM,WAAa,EAAM,IAC9B,IAAI,GACJ,UAAW,EAAA,QAAO,cACrB,CAAA,CACG,EAhBC,GAAG,EAAM,IAAI,GAAG,GAgBjB,CACX,CACA,CAAA,EACL,IACH,GACD,CAAA,CAEhB"}
|
|
1
|
+
{"version":3,"file":"Lightbox.cjs","names":[],"sources":["../../../src/components/Lightbox/Lightbox.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — closeLabel,\n * previousLabel and nextLabel are three separate strings an app has to translate,\n * showThumbnails/showCounter/loop are the chrome, and items/index/\n * onIndexChange/open/onClose are the controlled contract. The body is the focus\n * trap, the key handling and the swipe, which all move the same index.\n */\nimport { ChevronLeft, ChevronRight, X } from \"lucide-react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useFocusTrap } from \"@/hooks/use-focus-trap\";\nimport { useScrollLock } from \"@/hooks/use-scroll-lock\";\nimport { cn } from \"@/utils/cn\";\nimport { Portal } from \"../Portal\";\nimport styles from \"./Lightbox.module.css\";\n\n/** One item of the gallery. */\nexport interface LightboxItem {\n /** Full-size image URL. */\n src: string;\n /** Alt text. Required: a gallery of unlabeled images is unusable with a screen reader. */\n alt: string;\n /** Caption rendered under the image. */\n caption?: string;\n /** Thumbnail URL for the strip. Falls back to `src`. */\n thumbnail?: string;\n}\n\nexport interface LightboxProps {\n items: LightboxItem[];\n /** Whether the overlay is open. */\n open: boolean;\n /** Index shown while open. Default `0`. */\n index?: number;\n onIndexChange?: (index: number) => void;\n onClose: () => void;\n /** Renders the thumbnail strip. Default `true` when there is more than one item. */\n showThumbnails?: boolean;\n /** Renders the `3 / 12` counter. Default `true`. */\n showCounter?: boolean;\n /**\n * Wrap around at the ends. Default `true` — in a photo viewer, hitting a dead\n * end at the last image reads as a bug more often than as a boundary.\n */\n loop?: boolean;\n closeLabel?: string;\n previousLabel?: string;\n nextLabel?: string;\n className?: string;\n}\n\n/**\n * Full-screen image viewer with keyboard navigation.\n *\n * `Esc` closes, `←`/`→` walk the gallery, `Home`/`End` jump to the ends. Focus is\n * trapped inside while open and the page behind is scroll-locked, so the overlay\n * behaves like the dialog it is instead of a fancy `<div>` the keyboard can escape.\n *\n * Only the current image is mounted; neighbours are **preloaded** via `Image()` so\n * pressing `→` does not flash an empty frame.\n *\n * @example\n * ```tsx\n * const [open, setOpen] = useState(false);\n * const [index, setIndex] = useState(0);\n *\n * <Lightbox\n * open={open}\n * items={photos.map((p) => ({ src: p.url, alt: p.description }))}\n * index={index}\n * onIndexChange={setIndex}\n * onClose={() => setOpen(false)}\n * />\n * ```\n */\nexport function Lightbox({\n items,\n open,\n index = 0,\n onIndexChange,\n onClose,\n showThumbnails,\n showCounter = true,\n loop = true,\n closeLabel = \"Close\",\n previousLabel = \"Previous image\",\n nextLabel = \"Next image\",\n className,\n}: LightboxProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [internalIndex, setInternalIndex] = useState(index);\n const isControlled = onIndexChange !== undefined;\n const current = isControlled ? index : internalIndex;\n\n useFocusTrap(containerRef, open);\n useScrollLock(open);\n\n const move = useCallback(\n (next: number): void => {\n if (items.length === 0) return;\n const target = loop\n ? (next + items.length) % items.length\n : Math.max(0, Math.min(next, items.length - 1));\n if (!isControlled) setInternalIndex(target);\n onIndexChange?.(target);\n },\n [isControlled, items.length, loop, onIndexChange],\n );\n\n useEffect(() => {\n if (!isControlled) setInternalIndex(index);\n }, [index, isControlled]);\n\n useEffect(() => {\n if (!open) return;\n function onKeyDown(event: KeyboardEvent): void {\n switch (event.key) {\n case \"Escape\":\n onClose();\n break;\n case \"ArrowRight\":\n move(current + 1);\n break;\n case \"ArrowLeft\":\n move(current - 1);\n break;\n case \"Home\":\n move(0);\n break;\n case \"End\":\n move(items.length - 1);\n break;\n default:\n return;\n }\n event.preventDefault();\n }\n document.addEventListener(\"keydown\", onKeyDown);\n return () => document.removeEventListener(\"keydown\", onKeyDown);\n }, [current, items.length, move, onClose, open]);\n\n useEffect(() => {\n if (!open || typeof Image === \"undefined\") return;\n for (const offset of [-1, 1]) {\n const neighbour = items[(current + offset + items.length) % items.length];\n if (!neighbour) continue;\n const preload = new Image();\n preload.src = neighbour.src;\n }\n }, [current, items, open]);\n\n if (!open || items.length === 0) return null;\n\n const item = items[Math.max(0, Math.min(current, items.length - 1))];\n const withThumbnails = showThumbnails ?? items.length > 1;\n const multiple = items.length > 1;\n\n return (\n <Portal>\n <div\n ref={containerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={item.alt}\n className={cn(styles.overlay, className)}\n >\n <div className={styles.topBar}>\n {showCounter && multiple ? (\n <span className={styles.counter}>\n {current + 1} / {items.length}\n </span>\n ) : (\n <span />\n )}\n <button\n type=\"button\"\n className={styles.iconButton}\n aria-label={closeLabel}\n onClick={onClose}\n >\n <X size={20} />\n </button>\n </div>\n\n <div className={styles.stage}>\n {multiple ? (\n <button\n type=\"button\"\n className={cn(styles.iconButton, styles.nav)}\n aria-label={previousLabel}\n disabled={!loop && current === 0}\n onClick={() => move(current - 1)}\n >\n <ChevronLeft size={24} />\n </button>\n ) : null}\n\n <figure className={styles.figure}>\n <img src={item.src} alt={item.alt} className={styles.image} />\n {item.caption ? (\n <figcaption className={styles.caption}>{item.caption}</figcaption>\n ) : null}\n </figure>\n\n {multiple ? (\n <button\n type=\"button\"\n className={cn(styles.iconButton, styles.nav)}\n aria-label={nextLabel}\n disabled={!loop && current === items.length - 1}\n onClick={() => move(current + 1)}\n >\n <ChevronRight size={24} />\n </button>\n ) : null}\n </div>\n\n {withThumbnails && multiple ? (\n <div className={styles.thumbnails} role=\"tablist\" aria-label={item.alt}>\n {items.map((entry, entryIndex) => (\n <button\n key={`${entry.src}-${entryIndex}`}\n type=\"button\"\n role=\"tab\"\n aria-selected={entryIndex === current}\n aria-label={entry.alt}\n className={cn(\n styles.thumbnail,\n entryIndex === current && styles.thumbnailActive,\n )}\n onClick={() => move(entryIndex)}\n >\n <img\n src={entry.thumbnail ?? entry.src}\n alt=\"\"\n className={styles.thumbnailImage}\n />\n </button>\n ))}\n </div>\n ) : null}\n </div>\n </Portal>\n );\n}\n"],"mappings":"oRA0EA,SAAgB,EAAS,CACrB,QACA,OACA,QAAQ,EACR,gBACA,UACA,iBACA,cAAc,GACd,OAAO,GACP,aAAa,QACb,gBAAgB,iBAChB,YAAY,aACZ,aACc,CACd,IAAM,GAAA,EAAe,EAAA,OAAA,CAAuB,IAAI,EAC1C,CAAC,EAAe,IAAA,EAAoB,EAAA,SAAA,CAAS,CAAK,EAClD,EAAe,IAAkB,IAAA,GACjC,EAAU,EAAe,EAAQ,EAEvC,EAAA,aAAa,EAAc,CAAI,EAC/B,EAAA,cAAc,CAAI,EAElB,IAAM,GAAA,EAAO,EAA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AQ,CAAA,EAC5D,EAAK,SACF,EAAA,EAAA,IAAA,CAAC,aAAD,CAAY,UAAW,EAAA,QAAO,QAAU,SAAA,EAAK,OAAoB,CAAA,EACjE,IACA,IAEP,GACG,EAAA,EAAA,IAAA,CAAC,SAAD,CACI,KAAK,SACL,UAAW,EAAA,GAAG,EAAA,QAAO,WAAY,EAAA,QAAO,GAAG,EAC3C,aAAY,EACZ,SAAU,CAAC,GAAQ,IAAY,EAAM,OAAS,EAC9C,YAAe,EAAK,EAAU,CAAC,EAE/B,UAAA,EAAA,EAAA,IAAA,CAAC,EAAA,aAAD,CAAc,KAAM,EAAK,CAAA,CACrB,CAAA,EACR,IACH,IAEJ,GAAkB,GACf,EAAA,EAAA,IAAA,CAAC,MAAD,CAAK,UAAW,EAAA,QAAO,WAAY,KAAK,UAAU,aAAY,EAAK,IAC9D,SAAA,EAAM,KAAK,EAAO,KACf,EAAA,EAAA,IAAA,CAAC,SAAD,CAEI,KAAK,SACL,KAAK,MACL,gBAAe,IAAe,EAC9B,aAAY,EAAM,IAClB,UAAW,EAAA,GACP,EAAA,QAAO,UACP,IAAe,GAAW,EAAA,QAAO,eACrC,EACA,YAAe,EAAK,CAAU,EAE9B,UAAA,EAAA,EAAA,IAAA,CAAC,MAAD,CACI,IAAK,EAAM,WAAa,EAAM,IAC9B,IAAI,GACJ,UAAW,EAAA,QAAO,cACrB,CAAA,CACG,EAhBC,GAAG,EAAM,IAAI,GAAG,GAgBjB,CACX,CACA,CAAA,EACL,IACH,CACD,CAAA,CAAA,CAAA,CAEhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lightbox.js","names":[],"sources":["../../../src/components/Lightbox/Lightbox.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — closeLabel,\n * previousLabel and nextLabel are three separate strings an app has to translate,\n * showThumbnails/showCounter/loop are the chrome, and items/index/\n * onIndexChange/open/onClose are the controlled contract. The body is the focus\n * trap, the key handling and the swipe, which all move the same index.\n */\nimport { ChevronLeft, ChevronRight, X } from \"lucide-react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useFocusTrap } from \"@/hooks/use-focus-trap\";\nimport { useScrollLock } from \"@/hooks/use-scroll-lock\";\nimport { cn } from \"@/utils/cn\";\nimport { Portal } from \"../Portal\";\nimport styles from \"./Lightbox.module.css\";\n\n/** One item of the gallery. */\nexport interface LightboxItem {\n /** Full-size image URL. */\n src: string;\n /** Alt text. Required: a gallery of unlabeled images is unusable with a screen reader. */\n alt: string;\n /** Caption rendered under the image. */\n caption?: string;\n /** Thumbnail URL for the strip. Falls back to `src`. */\n thumbnail?: string;\n}\n\nexport interface LightboxProps {\n items: LightboxItem[];\n /** Whether the overlay is open. */\n open: boolean;\n /** Index shown while open. Default `0`. */\n index?: number;\n onIndexChange?: (index: number) => void;\n onClose: () => void;\n /** Renders the thumbnail strip. Default `true` when there is more than one item. */\n showThumbnails?: boolean;\n /** Renders the `3 / 12` counter. Default `true`. */\n showCounter?: boolean;\n /**\n * Wrap around at the ends. Default `true` — in a photo viewer, hitting a dead\n * end at the last image reads as a bug more often than as a boundary.\n */\n loop?: boolean;\n closeLabel?: string;\n previousLabel?: string;\n nextLabel?: string;\n className?: string;\n}\n\n/**\n * Full-screen image viewer with keyboard navigation.\n *\n * `Esc` closes, `←`/`→` walk the gallery, `Home`/`End` jump to the ends. Focus is\n * trapped inside while open and the page behind is scroll-locked, so the overlay\n * behaves like the dialog it is instead of a fancy `<div>` the keyboard can escape.\n *\n * Only the current image is mounted; neighbours are **preloaded** via `Image()` so\n * pressing `→` does not flash an empty frame.\n *\n * @example\n * ```tsx\n * const [open, setOpen] = useState(false);\n * const [index, setIndex] = useState(0);\n *\n * <Lightbox\n * open={open}\n * items={photos.map((p) => ({ src: p.url, alt: p.description }))}\n * index={index}\n * onIndexChange={setIndex}\n * onClose={() => setOpen(false)}\n * />\n * ```\n */\nexport function Lightbox({\n items,\n open,\n index = 0,\n onIndexChange,\n onClose,\n showThumbnails,\n showCounter = true,\n loop = true,\n closeLabel = \"Close\",\n previousLabel = \"Previous image\",\n nextLabel = \"Next image\",\n className,\n}: LightboxProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [internalIndex, setInternalIndex] = useState(index);\n const isControlled = onIndexChange !== undefined;\n const current = isControlled ? index : internalIndex;\n\n useFocusTrap(containerRef, open);\n useScrollLock(open);\n\n const move = useCallback(\n (next: number): void => {\n if (items.length === 0) return;\n const target = loop\n ? (next + items.length) % items.length\n : Math.max(0, Math.min(next, items.length - 1));\n if (!isControlled) setInternalIndex(target);\n onIndexChange?.(target);\n },\n [isControlled, items.length, loop, onIndexChange],\n );\n\n useEffect(() => {\n if (!isControlled) setInternalIndex(index);\n }, [index, isControlled]);\n\n useEffect(() => {\n if (!open) return;\n function onKeyDown(event: KeyboardEvent): void {\n switch (event.key) {\n case \"Escape\":\n onClose();\n break;\n case \"ArrowRight\":\n move(current + 1);\n break;\n case \"ArrowLeft\":\n move(current - 1);\n break;\n case \"Home\":\n move(0);\n break;\n case \"End\":\n move(items.length - 1);\n break;\n default:\n return;\n }\n event.preventDefault();\n }\n document.addEventListener(\"keydown\", onKeyDown);\n return () => document.removeEventListener(\"keydown\", onKeyDown);\n }, [current, items.length, move, onClose, open]);\n\n useEffect(() => {\n if (!open || typeof Image === \"undefined\") return;\n for (const offset of [-1, 1]) {\n const neighbour = items[(current + offset + items.length) % items.length];\n if (!neighbour) continue;\n const preload = new Image();\n preload.src = neighbour.src;\n }\n }, [current, items, open]);\n\n if (!open || items.length === 0) return null;\n\n const item = items[Math.max(0, Math.min(current, items.length - 1))];\n const withThumbnails = showThumbnails ?? items.length > 1;\n const multiple = items.length > 1;\n\n return (\n <Portal>\n <div\n ref={containerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={item.alt}\n className={cn(styles.overlay, className)}\n >\n <div className={styles.topBar}>\n {showCounter && multiple ? (\n <span className={styles.counter}>\n {current + 1} / {items.length}\n </span>\n ) : (\n <span />\n )}\n <button\n type=\"button\"\n className={styles.iconButton}\n aria-label={closeLabel}\n onClick={onClose}\n >\n <X size={20} />\n </button>\n </div>\n\n <div className={styles.stage}>\n {multiple ? (\n <button\n type=\"button\"\n className={cn(styles.iconButton, styles.nav)}\n aria-label={previousLabel}\n disabled={!loop && current === 0}\n onClick={() => move(current - 1)}\n >\n <ChevronLeft size={24} />\n </button>\n ) : null}\n\n <figure className={styles.figure}>\n <img src={item.src} alt={item.alt} className={styles.image} />\n {item.caption ? (\n <figcaption className={styles.caption}>{item.caption}</figcaption>\n ) : null}\n </figure>\n\n {multiple ? (\n <button\n type=\"button\"\n className={cn(styles.iconButton, styles.nav)}\n aria-label={nextLabel}\n disabled={!loop && current === items.length - 1}\n onClick={() => move(current + 1)}\n >\n <ChevronRight size={24} />\n </button>\n ) : null}\n </div>\n\n {withThumbnails && multiple ? (\n <div className={styles.thumbnails} role=\"tablist\" aria-label={item.alt}>\n {items.map((entry, entryIndex) => (\n <button\n key={`${entry.src}-${entryIndex}`}\n type=\"button\"\n role=\"tab\"\n aria-selected={entryIndex === current}\n aria-label={entry.alt}\n className={cn(\n styles.thumbnail,\n entryIndex === current && styles.thumbnailActive,\n )}\n onClick={() => move(entryIndex)}\n >\n <img\n src={entry.thumbnail ?? entry.src}\n alt=\"\"\n className={styles.thumbnailImage}\n />\n </button>\n ))}\n </div>\n ) : null}\n </div>\n </Portal>\n );\n}\n"],"mappings":";;;;;;;;;AA0EA,SAAgB,EAAS,EACrB,UACA,SACA,WAAQ,GACR,kBACA,YACA,mBACA,iBAAc,IACd,UAAO,IACP,gBAAa,SACb,mBAAgB,kBAChB,eAAY,cACZ,gBACc;CACd,IAAM,IAAe,EAAuB,IAAI,GAC1C,CAAC,GAAe,KAAoB,EAAS,CAAK,GAClD,IAAe,MAAkB,KAAA,GACjC,IAAU,IAAe,IAAQ;CAGvC,AADA,EAAa,GAAc,CAAI,GAC/B,EAAc,CAAI;CAElB,IAAM,IAAO,GACR,MAAuB;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IAAU,cAAY,EAAK;cAC9D,EAAM,KAAK,GAAO,MACf,kBAAC,UAAD;KAEI,MAAK;KACL,MAAK;KACL,iBAAe,MAAe;KAC9B,cAAY,EAAM;KAClB,WAAW,EACP,EAAO,WACP,MAAe,KAAW,EAAO,eACrC;KACA,eAAe,EAAK,CAAU;eAE9B,kBAAC,OAAD;MACI,KAAK,EAAM,aAAa,EAAM;MAC9B,KAAI;MACJ,WAAW,EAAO;KACrB,CAAA;IACG,GAhBC,GAAG,EAAM,IAAI,GAAG,GAgBjB,CACX;GACA,CAAA,IACL;EACH;IACD,CAAA;AAEhB"}
|
|
1
|
+
{"version":3,"file":"Lightbox.js","names":[],"sources":["../../../src/components/Lightbox/Lightbox.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — closeLabel,\n * previousLabel and nextLabel are three separate strings an app has to translate,\n * showThumbnails/showCounter/loop are the chrome, and items/index/\n * onIndexChange/open/onClose are the controlled contract. The body is the focus\n * trap, the key handling and the swipe, which all move the same index.\n */\nimport { ChevronLeft, ChevronRight, X } from \"lucide-react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useFocusTrap } from \"@/hooks/use-focus-trap\";\nimport { useScrollLock } from \"@/hooks/use-scroll-lock\";\nimport { cn } from \"@/utils/cn\";\nimport { Portal } from \"../Portal\";\nimport styles from \"./Lightbox.module.css\";\n\n/** One item of the gallery. */\nexport interface LightboxItem {\n /** Full-size image URL. */\n src: string;\n /** Alt text. Required: a gallery of unlabeled images is unusable with a screen reader. */\n alt: string;\n /** Caption rendered under the image. */\n caption?: string;\n /** Thumbnail URL for the strip. Falls back to `src`. */\n thumbnail?: string;\n}\n\nexport interface LightboxProps {\n items: LightboxItem[];\n /** Whether the overlay is open. */\n open: boolean;\n /** Index shown while open. Default `0`. */\n index?: number;\n onIndexChange?: (index: number) => void;\n onClose: () => void;\n /** Renders the thumbnail strip. Default `true` when there is more than one item. */\n showThumbnails?: boolean;\n /** Renders the `3 / 12` counter. Default `true`. */\n showCounter?: boolean;\n /**\n * Wrap around at the ends. Default `true` — in a photo viewer, hitting a dead\n * end at the last image reads as a bug more often than as a boundary.\n */\n loop?: boolean;\n closeLabel?: string;\n previousLabel?: string;\n nextLabel?: string;\n className?: string;\n}\n\n/**\n * Full-screen image viewer with keyboard navigation.\n *\n * `Esc` closes, `←`/`→` walk the gallery, `Home`/`End` jump to the ends. Focus is\n * trapped inside while open and the page behind is scroll-locked, so the overlay\n * behaves like the dialog it is instead of a fancy `<div>` the keyboard can escape.\n *\n * Only the current image is mounted; neighbours are **preloaded** via `Image()` so\n * pressing `→` does not flash an empty frame.\n *\n * @example\n * ```tsx\n * const [open, setOpen] = useState(false);\n * const [index, setIndex] = useState(0);\n *\n * <Lightbox\n * open={open}\n * items={photos.map((p) => ({ src: p.url, alt: p.description }))}\n * index={index}\n * onIndexChange={setIndex}\n * onClose={() => setOpen(false)}\n * />\n * ```\n */\nexport function Lightbox({\n items,\n open,\n index = 0,\n onIndexChange,\n onClose,\n showThumbnails,\n showCounter = true,\n loop = true,\n closeLabel = \"Close\",\n previousLabel = \"Previous image\",\n nextLabel = \"Next image\",\n className,\n}: LightboxProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [internalIndex, setInternalIndex] = useState(index);\n const isControlled = onIndexChange !== undefined;\n const current = isControlled ? index : internalIndex;\n\n useFocusTrap(containerRef, open);\n useScrollLock(open);\n\n const move = useCallback(\n (next: number): void => {\n if (items.length === 0) return;\n const target = loop\n ? (next + items.length) % items.length\n : Math.max(0, Math.min(next, items.length - 1));\n if (!isControlled) setInternalIndex(target);\n onIndexChange?.(target);\n },\n [isControlled, items.length, loop, onIndexChange],\n );\n\n useEffect(() => {\n if (!isControlled) setInternalIndex(index);\n }, [index, isControlled]);\n\n useEffect(() => {\n if (!open) return;\n function onKeyDown(event: KeyboardEvent): void {\n switch (event.key) {\n case \"Escape\":\n onClose();\n break;\n case \"ArrowRight\":\n move(current + 1);\n break;\n case \"ArrowLeft\":\n move(current - 1);\n break;\n case \"Home\":\n move(0);\n break;\n case \"End\":\n move(items.length - 1);\n break;\n default:\n return;\n }\n event.preventDefault();\n }\n document.addEventListener(\"keydown\", onKeyDown);\n return () => document.removeEventListener(\"keydown\", onKeyDown);\n }, [current, items.length, move, onClose, open]);\n\n useEffect(() => {\n if (!open || typeof Image === \"undefined\") return;\n for (const offset of [-1, 1]) {\n const neighbour = items[(current + offset + items.length) % items.length];\n if (!neighbour) continue;\n const preload = new Image();\n preload.src = neighbour.src;\n }\n }, [current, items, open]);\n\n if (!open || items.length === 0) return null;\n\n const item = items[Math.max(0, Math.min(current, items.length - 1))];\n const withThumbnails = showThumbnails ?? items.length > 1;\n const multiple = items.length > 1;\n\n return (\n <Portal>\n <div\n ref={containerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={item.alt}\n className={cn(styles.overlay, className)}\n >\n <div className={styles.topBar}>\n {showCounter && multiple ? (\n <span className={styles.counter}>\n {current + 1} / {items.length}\n </span>\n ) : (\n <span />\n )}\n <button\n type=\"button\"\n className={styles.iconButton}\n aria-label={closeLabel}\n onClick={onClose}\n >\n <X size={20} />\n </button>\n </div>\n\n <div className={styles.stage}>\n {multiple ? (\n <button\n type=\"button\"\n className={cn(styles.iconButton, styles.nav)}\n aria-label={previousLabel}\n disabled={!loop && current === 0}\n onClick={() => move(current - 1)}\n >\n <ChevronLeft size={24} />\n </button>\n ) : null}\n\n <figure className={styles.figure}>\n <img src={item.src} alt={item.alt} className={styles.image} />\n {item.caption ? (\n <figcaption className={styles.caption}>{item.caption}</figcaption>\n ) : null}\n </figure>\n\n {multiple ? (\n <button\n type=\"button\"\n className={cn(styles.iconButton, styles.nav)}\n aria-label={nextLabel}\n disabled={!loop && current === items.length - 1}\n onClick={() => move(current + 1)}\n >\n <ChevronRight size={24} />\n </button>\n ) : null}\n </div>\n\n {withThumbnails && multiple ? (\n <div className={styles.thumbnails} role=\"tablist\" aria-label={item.alt}>\n {items.map((entry, entryIndex) => (\n <button\n key={`${entry.src}-${entryIndex}`}\n type=\"button\"\n role=\"tab\"\n aria-selected={entryIndex === current}\n aria-label={entry.alt}\n className={cn(\n styles.thumbnail,\n entryIndex === current && styles.thumbnailActive,\n )}\n onClick={() => move(entryIndex)}\n >\n <img\n src={entry.thumbnail ?? entry.src}\n alt=\"\"\n className={styles.thumbnailImage}\n />\n </button>\n ))}\n </div>\n ) : null}\n </div>\n </Portal>\n );\n}\n"],"mappings":";;;;;;;;;AA0EA,SAAgB,EAAS,EACrB,UACA,SACA,WAAQ,GACR,kBACA,YACA,mBACA,iBAAc,IACd,UAAO,IACP,gBAAa,SACb,mBAAgB,kBAChB,eAAY,cACZ,gBACc;CACd,IAAM,IAAe,EAAuB,IAAI,GAC1C,CAAC,GAAe,KAAoB,EAAS,CAAK,GAClD,IAAe,MAAkB,KAAA,GACjC,IAAU,IAAe,IAAQ;CAGvC,AADA,EAAa,GAAc,CAAI,GAC/B,EAAc,CAAI;CAElB,IAAM,IAAO,GACR,MAAuB;EACpB,IAAI,EAAM,WAAW,GAAG;EACxB,IAAM,IAAS,KACR,IAAO,EAAM,UAAU,EAAM,SAC9B,KAAK,IAAI,GAAG,KAAK,IAAI,GAAM,EAAM,SAAS,CAAC,CAAC;EAElD,AADK,KAAc,EAAiB,CAAM,GAC1C,IAAgB,CAAM;CAC1B,GACA;EAAC;EAAc,EAAM;EAAQ;EAAM;CAAa,CACpD;CA4CA,IA1CA,QAAgB;EACZ,AAAK,KAAc,EAAiB,CAAK;CAC7C,GAAG,CAAC,GAAO,CAAY,CAAC,GAExB,QAAgB;EACZ,IAAI,CAAC,GAAM;EACX,SAAS,EAAU,GAA4B;GAC3C,QAAQ,EAAM,KAAd;IACI,KAAK;KACD,EAAQ;KACR;IACJ,KAAK;KACD,EAAK,IAAU,CAAC;KAChB;IACJ,KAAK;KACD,EAAK,IAAU,CAAC;KAChB;IACJ,KAAK;KACD,EAAK,CAAC;KACN;IACJ,KAAK;KACD,EAAK,EAAM,SAAS,C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EAAO,GAAG;MAC3C,cAAY;MACZ,UAAU,CAAC,KAAQ,MAAY;MAC/B,eAAe,EAAK,IAAU,CAAC;MAE/B,UAAA,kBAAC,GAAD,EAAa,MAAM,GAAK,CAAA;KACpB,CAAA,IACR;KAEJ,kBAAC,UAAD;MAAQ,WAAW,EAAO;MAA1B,UAAA,CACI,kBAAC,OAAD;OAAK,KAAK,EAAK;OAAK,KAAK,EAAK;OAAK,WAAW,EAAO;MAAQ,CAAA,GAC5D,EAAK,UACF,kBAAC,cAAD;OAAY,WAAW,EAAO;OAAU,UAAA,EAAK;MAAoB,CAAA,IACjE,IACA;;KAEP,IACG,kBAAC,UAAD;MACI,MAAK;MACL,WAAW,EAAG,EAAO,YAAY,EAAO,GAAG;MAC3C,cAAY;MACZ,UAAU,CAAC,KAAQ,MAAY,EAAM,SAAS;MAC9C,eAAe,EAAK,IAAU,CAAC;MAE/B,UAAA,kBAAC,GAAD,EAAc,MAAM,GAAK,CAAA;KACrB,CAAA,IACR;IACH;;GAEJ,KAAkB,IACf,kBAAC,OAAD;IAAK,WAAW,EAAO;IAAY,MAAK;IAAU,cAAY,EAAK;IAC9D,UAAA,EAAM,KAAK,GAAO,MACf,kBAAC,UAAD;KAEI,MAAK;KACL,MAAK;KACL,iBAAe,MAAe;KAC9B,cAAY,EAAM;KAClB,WAAW,EACP,EAAO,WACP,MAAe,KAAW,EAAO,eACrC;KACA,eAAe,EAAK,CAAU;KAE9B,UAAA,kBAAC,OAAD;MACI,KAAK,EAAM,aAAa,EAAM;MAC9B,KAAI;MACJ,WAAW,EAAO;KACrB,CAAA;IACG,GAhBC,GAAG,EAAM,IAAI,GAAG,GAgBjB,CACX;GACA,CAAA,IACL;EACH;CACD,CAAA,EAAA,CAAA;AAEhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListTile.cjs","names":[],"sources":["../../../src/components/ListTile/ListTile.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — leading, title, subtitle and trailing are the four\n * slots of a list row, and onClick/disabled/selected are what make it a row you can\n * pick. That is the whole component — there is no second one inside it.\n */\nimport type { ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./ListTile.module.css\";\n\nexport interface ListTileProps {\n /** Left slot — typically an icon or avatar. */\n leading?: ReactNode;\n /** Primary line. Required. */\n title: ReactNode;\n /** Secondary line rendered under the title. */\n subtitle?: ReactNode;\n /** Right slot — typically an icon, switch or meta text. */\n trailing?: ReactNode;\n /** When provided, the tile becomes an interactive button. */\n onClick?: () => void;\n /** When true, the tile is dimmed and non-interactive. */\n disabled?: boolean;\n /** When true, the tile is highlighted as the active row. */\n selected?: boolean;\n /** Extra class names merged onto the root. */\n className?: string;\n}\n\n/**\n * The canonical Material list row: an optional leading slot, a title with an\n * optional subtitle, and an optional trailing slot. When `onClick` is supplied\n * the tile renders as a full-width, keyboard-accessible `<button>`; otherwise it\n * renders as a static `<div>`.\n *\n * @example\n * <ListTile\n * leading={<User />}\n * title=\"Maria Silva\"\n * subtitle=\"maria@example.com\"\n * trailing={<ChevronRight />}\n * onClick={() => open(user)}\n * />\n */\nexport function ListTile({\n leading,\n title,\n subtitle,\n trailing,\n onClick,\n disabled = false,\n selected = false,\n className,\n}: ListTileProps) {\n const content = (\n <>\n {leading !== undefined && <span className={styles.leading}>{leading}</span>}\n <span className={styles.body}>\n <span className={styles.title}>{title}</span>\n {subtitle !== undefined && <span className={styles.subtitle}>{subtitle}</span>}\n </span>\n {trailing !== undefined && <span className={styles.trailing}>{trailing}</span>}\n </>\n );\n\n const rootClassName = cn(\n styles.tile,\n selected && styles.selected,\n disabled && styles.disabled,\n className,\n );\n\n if (onClick) {\n return (\n <button\n type=\"button\"\n className={cn(rootClassName, styles.interactive)}\n aria-pressed={selected ? true : undefined}\n disabled={disabled}\n onClick={onClick}\n >\n {content}\n </button>\n );\n }\n\n return <div className={rootClassName}>{content}</div>;\n}\n"],"mappings":"4GA2CA,SAAgB,EAAS,CACrB,UACA,QACA,WACA,WACA,UACA,WAAW,GACX,WAAW,GACX,aACc,CACd,IAAM,GACF,EAAA,EAAA,KAAA,CAAA,EAAA,SAAA,CAAA,SAAA,CACK,IAAY,IAAA,KAAa,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,
|
|
1
|
+
{"version":3,"file":"ListTile.cjs","names":[],"sources":["../../../src/components/ListTile/ListTile.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — leading, title, subtitle and trailing are the four\n * slots of a list row, and onClick/disabled/selected are what make it a row you can\n * pick. That is the whole component — there is no second one inside it.\n */\nimport type { ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./ListTile.module.css\";\n\nexport interface ListTileProps {\n /** Left slot — typically an icon or avatar. */\n leading?: ReactNode;\n /** Primary line. Required. */\n title: ReactNode;\n /** Secondary line rendered under the title. */\n subtitle?: ReactNode;\n /** Right slot — typically an icon, switch or meta text. */\n trailing?: ReactNode;\n /** When provided, the tile becomes an interactive button. */\n onClick?: () => void;\n /** When true, the tile is dimmed and non-interactive. */\n disabled?: boolean;\n /** When true, the tile is highlighted as the active row. */\n selected?: boolean;\n /** Extra class names merged onto the root. */\n className?: string;\n}\n\n/**\n * The canonical Material list row: an optional leading slot, a title with an\n * optional subtitle, and an optional trailing slot. When `onClick` is supplied\n * the tile renders as a full-width, keyboard-accessible `<button>`; otherwise it\n * renders as a static `<div>`.\n *\n * @example\n * <ListTile\n * leading={<User />}\n * title=\"Maria Silva\"\n * subtitle=\"maria@example.com\"\n * trailing={<ChevronRight />}\n * onClick={() => open(user)}\n * />\n */\nexport function ListTile({\n leading,\n title,\n subtitle,\n trailing,\n onClick,\n disabled = false,\n selected = false,\n className,\n}: ListTileProps) {\n const content = (\n <>\n {leading !== undefined && <span className={styles.leading}>{leading}</span>}\n <span className={styles.body}>\n <span className={styles.title}>{title}</span>\n {subtitle !== undefined && <span className={styles.subtitle}>{subtitle}</span>}\n </span>\n {trailing !== undefined && <span className={styles.trailing}>{trailing}</span>}\n </>\n );\n\n const rootClassName = cn(\n styles.tile,\n selected && styles.selected,\n disabled && styles.disabled,\n className,\n );\n\n if (onClick) {\n return (\n <button\n type=\"button\"\n className={cn(rootClassName, styles.interactive)}\n aria-pressed={selected ? true : undefined}\n disabled={disabled}\n onClick={onClick}\n >\n {content}\n </button>\n );\n }\n\n return <div className={rootClassName}>{content}</div>;\n}\n"],"mappings":"4GA2CA,SAAgB,EAAS,CACrB,UACA,QACA,WACA,WACA,UACA,WAAW,GACX,WAAW,GACX,aACc,CACd,IAAM,GACF,EAAA,EAAA,KAAA,CAAA,EAAA,SAAA,CAAA,SAAA,CACK,IAAY,IAAA,KAAa,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,QAAU,SAAA,CAAc,CAAA,GAC1E,EAAA,EAAA,KAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,KAAxB,SAAA,EACI,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,MAAQ,SAAA,CAAY,CAAA,EAC3C,IAAa,IAAA,KAAa,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,SAAW,SAAA,CAAe,CAAA,CAC3E,IACL,IAAa,IAAA,KAAa,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,SAAW,SAAA,CAAe,CAAA,CAC/E,CAAA,CAAA,EAGA,EAAgB,EAAA,GAClB,EAAA,QAAO,KACP,GAAY,EAAA,QAAO,SACnB,GAAY,EAAA,QAAO,SACnB,CACJ,EAgBA,OAdI,GAEI,EAAA,EAAA,IAAA,CAAC,SAAD,CACI,KAAK,SACL,UAAW,EAAA,GAAG,EAAe,EAAA,QAAO,WAAW,EAC/C,eAAc,EAAW,GAAO,IAAA,GACtB,WACD,UAER,SAAA,CACG,CAAA,GAIT,EAAA,EAAA,IAAA,CAAC,MAAD,CAAK,UAAW,EAAgB,SAAA,CAAa,CAAA,CACxD"}
|