@codefast/ui 0.5.0-canary.4 → 0.5.0-canary.6
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/CHANGELOG.md +67 -0
- package/README.md +59 -355
- package/dist/components/accordion.d.ts +37 -0
- package/dist/components/accordion.d.ts.map +1 -0
- package/dist/components/accordion.js +33 -0
- package/dist/components/accordion.js.map +1 -0
- package/dist/components/alert-dialog.d.ts +102 -0
- package/dist/components/alert-dialog.d.ts.map +1 -0
- package/dist/components/alert-dialog.js +75 -0
- package/dist/components/alert-dialog.js.map +1 -0
- package/dist/components/alert.d.ts +38 -0
- package/dist/components/alert.d.ts.map +1 -0
- package/dist/components/alert.js +32 -0
- package/dist/components/alert.js.map +1 -0
- package/dist/components/aspect-ratio.d.ts +13 -0
- package/dist/components/aspect-ratio.d.ts.map +1 -0
- package/dist/components/aspect-ratio.js +13 -0
- package/dist/components/aspect-ratio.js.map +1 -0
- package/dist/components/{attachment.d.mts → attachment.d.ts} +21 -55
- package/dist/components/attachment.d.ts.map +1 -0
- package/dist/components/attachment.js +65 -0
- package/dist/components/attachment.js.map +1 -0
- package/dist/components/avatar.d.ts +55 -0
- package/dist/components/avatar.d.ts.map +1 -0
- package/dist/components/avatar.js +44 -0
- package/dist/components/avatar.js.map +1 -0
- package/dist/components/badge.d.ts +15 -0
- package/dist/components/badge.d.ts.map +1 -0
- package/dist/components/badge.js +15 -0
- package/dist/components/badge.js.map +1 -0
- package/dist/components/breadcrumb.d.ts +62 -0
- package/dist/components/breadcrumb.d.ts.map +1 -0
- package/dist/components/breadcrumb.js +52 -0
- package/dist/components/breadcrumb.js.map +1 -0
- package/dist/components/bubble.d.ts +50 -0
- package/dist/components/bubble.d.ts.map +1 -0
- package/dist/components/bubble.js +34 -0
- package/dist/components/bubble.js.map +1 -0
- package/dist/components/button-group.d.ts +32 -0
- package/dist/components/button-group.d.ts.map +1 -0
- package/dist/components/button-group.js +29 -0
- package/dist/components/button-group.js.map +1 -0
- package/dist/components/button.d.ts +16 -0
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +18 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/calendar.d.ts +27 -0
- package/dist/components/calendar.d.ts.map +1 -0
- package/dist/components/calendar.js +96 -0
- package/dist/components/calendar.js.map +1 -0
- package/dist/components/card.d.ts +62 -0
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +49 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/{carousel.d.mts → carousel.d.ts} +25 -52
- package/dist/components/carousel.d.ts.map +1 -0
- package/dist/components/carousel.js +137 -0
- package/dist/components/carousel.js.map +1 -0
- package/dist/components/chart.d.ts +101 -0
- package/dist/components/chart.d.ts.map +1 -0
- package/dist/components/chart.js +217 -0
- package/dist/components/chart.js.map +1 -0
- package/dist/components/checkbox-cards.d.ts +23 -0
- package/dist/components/checkbox-cards.d.ts.map +1 -0
- package/dist/components/checkbox-cards.js +22 -0
- package/dist/components/checkbox-cards.js.map +1 -0
- package/dist/components/checkbox-group.d.ts +21 -0
- package/dist/components/checkbox-group.d.ts.map +1 -0
- package/dist/components/checkbox-group.js +21 -0
- package/dist/components/checkbox-group.js.map +1 -0
- package/dist/components/checkbox.d.ts +13 -0
- package/dist/components/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox.js +15 -0
- package/dist/components/checkbox.js.map +1 -0
- package/dist/components/collapsible.d.ts +29 -0
- package/dist/components/collapsible.d.ts.map +1 -0
- package/dist/components/collapsible.js +25 -0
- package/dist/components/collapsible.js.map +1 -0
- package/dist/components/command.d.ts +91 -0
- package/dist/components/command.d.ts.map +1 -0
- package/dist/components/command.js +71 -0
- package/dist/components/command.js.map +1 -0
- package/dist/components/context-menu.d.ts +136 -0
- package/dist/components/context-menu.d.ts.map +1 -0
- package/dist/components/context-menu.js +99 -0
- package/dist/components/context-menu.js.map +1 -0
- package/dist/components/dialog.d.ts +86 -0
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.js +64 -0
- package/dist/components/dialog.js.map +1 -0
- package/dist/components/direction.d.ts +19 -0
- package/dist/components/direction.d.ts.map +1 -0
- package/dist/components/direction.js +17 -0
- package/dist/components/direction.js.map +1 -0
- package/dist/components/drawer.d.ts +74 -0
- package/dist/components/drawer.d.ts.map +1 -0
- package/dist/components/drawer.js +57 -0
- package/dist/components/drawer.js.map +1 -0
- package/dist/components/dropdown-menu.d.ts +136 -0
- package/dist/components/dropdown-menu.d.ts.map +1 -0
- package/dist/components/dropdown-menu.js +99 -0
- package/dist/components/dropdown-menu.js.map +1 -0
- package/dist/components/empty.d.ts +53 -0
- package/dist/components/empty.d.ts.map +1 -0
- package/dist/components/empty.js +44 -0
- package/dist/components/empty.js.map +1 -0
- package/dist/components/field.d.ts +95 -0
- package/dist/components/field.d.ts.map +1 -0
- package/dist/components/field.js +86 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/{form.d.mts → form.d.ts} +15 -33
- package/dist/components/form.d.ts.map +1 -0
- package/dist/components/form.js +97 -0
- package/dist/components/form.js.map +1 -0
- package/dist/components/hover-card.d.ts +37 -0
- package/dist/components/hover-card.d.ts.map +1 -0
- package/dist/components/hover-card.js +32 -0
- package/dist/components/hover-card.js.map +1 -0
- package/dist/components/input-group.d.ts +56 -0
- package/dist/components/input-group.d.ts.map +1 -0
- package/dist/components/input-group.js +56 -0
- package/dist/components/input-group.js.map +1 -0
- package/dist/components/input-number.d.ts +60 -0
- package/dist/components/input-number.d.ts.map +1 -0
- package/dist/components/input-number.js +68 -0
- package/dist/components/input-number.js.map +1 -0
- package/dist/components/input-otp.d.ts +40 -0
- package/dist/components/input-otp.d.ts.map +1 -0
- package/dist/components/input-otp.js +41 -0
- package/dist/components/input-otp.js.map +1 -0
- package/dist/components/input-password.d.ts +13 -0
- package/dist/components/input-password.d.ts.map +1 -0
- package/dist/components/input-password.js +19 -0
- package/dist/components/input-password.js.map +1 -0
- package/dist/components/input-search.d.ts +17 -0
- package/dist/components/input-search.d.ts.map +1 -0
- package/dist/components/input-search.js +24 -0
- package/dist/components/input-search.js.map +1 -0
- package/dist/components/input.d.ts +12 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +13 -0
- package/dist/components/input.js.map +1 -0
- package/dist/components/item.d.ts +88 -0
- package/dist/components/item.d.ts.map +1 -0
- package/dist/components/item.js +71 -0
- package/dist/components/item.js.map +1 -0
- package/dist/components/kbd.d.ts +20 -0
- package/dist/components/kbd.d.ts.map +1 -0
- package/dist/components/kbd.js +19 -0
- package/dist/components/kbd.js.map +1 -0
- package/dist/components/label.d.ts +13 -0
- package/dist/components/label.d.ts.map +1 -0
- package/dist/components/label.js +14 -0
- package/dist/components/label.js.map +1 -0
- package/dist/components/{marker.d.mts → marker.d.ts} +9 -21
- package/dist/components/marker.d.ts.map +1 -0
- package/dist/components/marker.js +28 -0
- package/dist/components/marker.js.map +1 -0
- package/dist/components/menubar.d.ts +144 -0
- package/dist/components/menubar.d.ts.map +1 -0
- package/dist/components/menubar.js +105 -0
- package/dist/components/menubar.js.map +1 -0
- package/dist/components/message-scroller.d.ts +67 -0
- package/dist/components/message-scroller.d.ts.map +1 -0
- package/dist/components/message-scroller.js +46 -0
- package/dist/components/message-scroller.js.map +1 -0
- package/dist/components/{message.d.mts → message.d.ts} +11 -31
- package/dist/components/message.d.ts.map +1 -0
- package/dist/components/message.js +43 -0
- package/dist/components/message.js.map +1 -0
- package/dist/components/native-select.d.ts +30 -0
- package/dist/components/native-select.d.ts.map +1 -0
- package/dist/components/native-select.js +26 -0
- package/dist/components/native-select.js.map +1 -0
- package/dist/components/navigation-menu.d.ts +71 -0
- package/dist/components/navigation-menu.d.ts.map +1 -0
- package/dist/components/navigation-menu.js +58 -0
- package/dist/components/navigation-menu.js.map +1 -0
- package/dist/components/pagination.d.ts +70 -0
- package/dist/components/pagination.d.ts.map +1 -0
- package/dist/components/pagination.js +51 -0
- package/dist/components/pagination.js.map +1 -0
- package/dist/components/popover.d.ts +69 -0
- package/dist/components/popover.d.ts.map +1 -0
- package/dist/components/popover.js +56 -0
- package/dist/components/popover.js.map +1 -0
- package/dist/components/progress-circle.d.ts +72 -0
- package/dist/components/progress-circle.d.ts.map +1 -0
- package/dist/components/progress-circle.js +58 -0
- package/dist/components/progress-circle.js.map +1 -0
- package/dist/components/progress.d.ts +13 -0
- package/dist/components/progress.d.ts.map +1 -0
- package/dist/components/progress.js +16 -0
- package/dist/components/progress.js.map +1 -0
- package/dist/components/radio-cards.d.ts +21 -0
- package/dist/components/radio-cards.d.ts.map +1 -0
- package/dist/components/radio-cards.js +21 -0
- package/dist/components/radio-cards.js.map +1 -0
- package/dist/components/radio-group.d.ts +21 -0
- package/dist/components/radio-group.d.ts.map +1 -0
- package/dist/components/radio-group.js +20 -0
- package/dist/components/radio-group.js.map +1 -0
- package/dist/components/radio.d.ts +14 -0
- package/dist/components/radio.d.ts.map +1 -0
- package/dist/components/radio.js +14 -0
- package/dist/components/radio.js.map +1 -0
- package/dist/components/resizable.d.ts +31 -0
- package/dist/components/resizable.d.ts.map +1 -0
- package/dist/components/resizable.js +26 -0
- package/dist/components/resizable.js.map +1 -0
- package/dist/components/scroll-area.d.ts +27 -0
- package/dist/components/scroll-area.d.ts.map +1 -0
- package/dist/components/scroll-area.js +29 -0
- package/dist/components/scroll-area.js.map +1 -0
- package/dist/components/select.d.ts +87 -0
- package/dist/components/select.d.ts.map +1 -0
- package/dist/components/select.js +70 -0
- package/dist/components/select.js.map +1 -0
- package/dist/components/separator.d.ts +23 -0
- package/dist/components/separator.d.ts.map +1 -0
- package/dist/components/separator.js +21 -0
- package/dist/components/separator.js.map +1 -0
- package/dist/components/sheet.d.ts +88 -0
- package/dist/components/sheet.d.ts.map +1 -0
- package/dist/components/sheet.js +69 -0
- package/dist/components/sheet.js.map +1 -0
- package/dist/components/sidebar.d.ts +231 -0
- package/dist/components/sidebar.d.ts.map +1 -0
- package/dist/components/sidebar.js +279 -0
- package/dist/components/sidebar.js.map +1 -0
- package/dist/components/skeleton.d.ts +12 -0
- package/dist/components/skeleton.d.ts.map +1 -0
- package/dist/components/skeleton.js +13 -0
- package/dist/components/skeleton.js.map +1 -0
- package/dist/components/slider.d.ts +13 -0
- package/dist/components/slider.d.ts.map +1 -0
- package/dist/components/slider.js +21 -0
- package/dist/components/slider.js.map +1 -0
- package/dist/components/sonner.d.ts +14 -0
- package/dist/components/sonner.d.ts.map +1 -0
- package/dist/components/sonner.js +32 -0
- package/dist/components/sonner.js.map +1 -0
- package/dist/components/spinner.d.ts +14 -0
- package/dist/components/spinner.d.ts.map +1 -0
- package/dist/components/spinner.js +30 -0
- package/dist/components/spinner.js.map +1 -0
- package/dist/components/switch.d.ts +15 -0
- package/dist/components/switch.d.ts.map +1 -0
- package/dist/components/switch.js +14 -0
- package/dist/components/switch.js.map +1 -0
- package/dist/components/table.d.ts +68 -0
- package/dist/components/table.d.ts.map +1 -0
- package/dist/components/table.js +55 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/tabs.d.ts +38 -0
- package/dist/components/tabs.d.ts.map +1 -0
- package/dist/components/tabs.js +33 -0
- package/dist/components/tabs.js.map +1 -0
- package/dist/components/textarea.d.ts +12 -0
- package/dist/components/textarea.d.ts.map +1 -0
- package/dist/components/textarea.js +13 -0
- package/dist/components/textarea.js.map +1 -0
- package/dist/components/toggle-group.d.ts +30 -0
- package/dist/components/toggle-group.d.ts.map +1 -0
- package/dist/components/toggle-group.js +42 -0
- package/dist/components/toggle-group.js.map +1 -0
- package/dist/components/toggle.d.ts +15 -0
- package/dist/components/toggle.d.ts.map +1 -0
- package/dist/components/toggle.js +14 -0
- package/dist/components/toggle.js.map +1 -0
- package/dist/components/tooltip.d.ts +45 -0
- package/dist/components/tooltip.d.ts.map +1 -0
- package/dist/components/tooltip.js +38 -0
- package/dist/components/tooltip.js.map +1 -0
- package/dist/hooks/{use-animated-value.d.mts → use-animated-value.d.ts} +2 -4
- package/dist/hooks/use-animated-value.d.ts.map +1 -0
- package/dist/hooks/use-animated-value.js +73 -0
- package/dist/hooks/use-animated-value.js.map +1 -0
- package/dist/hooks/{use-copy-to-clipboard.d.mts → use-copy-to-clipboard.d.ts} +6 -11
- package/dist/hooks/use-copy-to-clipboard.d.ts.map +1 -0
- package/dist/hooks/use-copy-to-clipboard.js +48 -0
- package/dist/hooks/use-copy-to-clipboard.js.map +1 -0
- package/dist/hooks/{use-is-mobile.d.mts → use-is-mobile.d.ts} +2 -4
- package/dist/hooks/use-is-mobile.d.ts.map +1 -0
- package/dist/hooks/use-is-mobile.js +25 -0
- package/dist/hooks/use-is-mobile.js.map +1 -0
- package/dist/hooks/{use-media-query.d.mts → use-media-query.d.ts} +2 -4
- package/dist/hooks/use-media-query.d.ts.map +1 -0
- package/dist/hooks/use-media-query.js +55 -0
- package/dist/hooks/use-media-query.js.map +1 -0
- package/dist/hooks/use-message-scroller-commands.d.ts +22 -0
- package/dist/hooks/use-message-scroller-commands.d.ts.map +1 -0
- package/dist/hooks/use-message-scroller-commands.js +190 -0
- package/dist/hooks/use-message-scroller-commands.js.map +1 -0
- package/dist/hooks/use-message-scroller-controller.d.ts +12 -0
- package/dist/hooks/use-message-scroller-controller.d.ts.map +1 -0
- package/dist/hooks/use-message-scroller-controller.js +471 -0
- package/dist/hooks/use-message-scroller-controller.js.map +1 -0
- package/dist/hooks/use-message-scroller-refs.d.ts +54 -0
- package/dist/hooks/use-message-scroller-refs.d.ts.map +1 -0
- package/dist/hooks/use-message-scroller-refs.js +88 -0
- package/dist/hooks/use-message-scroller-refs.js.map +1 -0
- package/dist/hooks/{use-mutation-observer.d.mts → use-mutation-observer.d.ts} +3 -6
- package/dist/hooks/use-mutation-observer.d.ts.map +1 -0
- package/dist/hooks/use-mutation-observer.js +42 -0
- package/dist/hooks/use-mutation-observer.js.map +1 -0
- package/dist/hooks/{use-pagination.d.mts → use-pagination.d.ts} +21 -28
- package/dist/hooks/use-pagination.d.ts.map +1 -0
- package/dist/hooks/use-pagination.js +117 -0
- package/dist/hooks/use-pagination.js.map +1 -0
- package/dist/index.d.ts +181 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +94 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/message-scroller/{geometry.d.mts → geometry.d.ts} +40 -73
- package/dist/lib/message-scroller/geometry.d.ts.map +1 -0
- package/dist/lib/message-scroller/geometry.js +246 -0
- package/dist/lib/message-scroller/geometry.js.map +1 -0
- package/dist/lib/message-scroller/{stores.d.mts → stores.d.ts} +3 -5
- package/dist/lib/message-scroller/stores.d.ts.map +1 -0
- package/dist/lib/message-scroller/stores.js +64 -0
- package/dist/lib/message-scroller/stores.js.map +1 -0
- package/dist/lib/message-scroller/types.d.ts +170 -0
- package/dist/lib/message-scroller/types.d.ts.map +1 -0
- package/dist/lib/message-scroller/types.js +66 -0
- package/dist/lib/message-scroller/types.js.map +1 -0
- package/dist/lib/message-scroller/{utils.d.mts → utils.d.ts} +2 -3
- package/dist/lib/message-scroller/utils.d.ts.map +1 -0
- package/dist/lib/message-scroller/utils.js +11 -0
- package/dist/lib/message-scroller/utils.js.map +1 -0
- package/dist/lib/{use-render.d.mts → use-render.d.ts} +14 -19
- package/dist/lib/use-render.d.ts.map +1 -0
- package/dist/lib/use-render.js +119 -0
- package/dist/lib/use-render.js.map +1 -0
- package/dist/lib/utils.d.ts +5 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/{utils.mjs → utils.js} +1 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/primitives/checkbox-group.d.ts +135 -0
- package/dist/primitives/checkbox-group.d.ts.map +1 -0
- package/dist/primitives/checkbox-group.js +120 -0
- package/dist/primitives/checkbox-group.js.map +1 -0
- package/dist/primitives/input-number.d.ts +109 -0
- package/dist/primitives/input-number.d.ts.map +1 -0
- package/dist/primitives/input-number.js +532 -0
- package/dist/primitives/input-number.js.map +1 -0
- package/dist/primitives/input.d.ts +77 -0
- package/dist/primitives/input.d.ts.map +1 -0
- package/dist/primitives/input.js +83 -0
- package/dist/primitives/input.js.map +1 -0
- package/dist/primitives/message-scroller.d.ts +43 -0
- package/dist/primitives/message-scroller.d.ts.map +1 -0
- package/dist/primitives/message-scroller.js +210 -0
- package/dist/primitives/message-scroller.js.map +1 -0
- package/dist/primitives/progress-circle.d.ts +166 -0
- package/dist/primitives/progress-circle.d.ts.map +1 -0
- package/dist/primitives/progress-circle.js +171 -0
- package/dist/primitives/progress-circle.js.map +1 -0
- package/dist/variants/{alert.d.mts → alert.d.ts} +8 -9
- package/dist/variants/alert.d.ts.map +1 -0
- package/dist/variants/alert.js +24 -0
- package/dist/variants/alert.js.map +1 -0
- package/dist/variants/{attachment.d.mts → attachment.d.ts} +17 -18
- package/dist/variants/attachment.d.ts.map +1 -0
- package/dist/variants/attachment.js +54 -0
- package/dist/variants/attachment.js.map +1 -0
- package/dist/variants/badge.d.ts +21 -0
- package/dist/variants/badge.d.ts.map +1 -0
- package/dist/variants/badge.js +28 -0
- package/dist/variants/badge.js.map +1 -0
- package/dist/variants/{bubble.d.mts → bubble.d.ts} +21 -22
- package/dist/variants/bubble.d.ts.map +1 -0
- package/dist/variants/bubble.js +57 -0
- package/dist/variants/bubble.js.map +1 -0
- package/dist/variants/{button-group.d.mts → button-group.d.ts} +8 -9
- package/dist/variants/button-group.d.ts.map +1 -0
- package/dist/variants/button-group.js +24 -0
- package/dist/variants/button-group.js.map +1 -0
- package/dist/variants/button.d.ts +31 -0
- package/dist/variants/button.d.ts.map +1 -0
- package/dist/variants/button.js +39 -0
- package/dist/variants/button.js.map +1 -0
- package/dist/variants/{empty.d.mts → empty.d.ts} +8 -9
- package/dist/variants/empty.d.ts.map +1 -0
- package/dist/variants/empty.js +24 -0
- package/dist/variants/empty.js.map +1 -0
- package/dist/variants/field.d.ts +18 -0
- package/dist/variants/field.d.ts.map +1 -0
- package/dist/variants/field.js +25 -0
- package/dist/variants/field.js.map +1 -0
- package/dist/variants/{input-group.d.mts → input-group.d.ts} +16 -17
- package/dist/variants/input-group.d.ts.map +1 -0
- package/dist/variants/input-group.js +55 -0
- package/dist/variants/input-group.js.map +1 -0
- package/dist/variants/{item.d.mts → item.d.ts} +19 -20
- package/dist/variants/item.d.ts.map +1 -0
- package/dist/variants/item.js +50 -0
- package/dist/variants/item.js.map +1 -0
- package/dist/variants/{marker.d.mts → marker.d.ts} +9 -10
- package/dist/variants/marker.d.ts.map +1 -0
- package/dist/variants/marker.js +27 -0
- package/dist/variants/marker.js.map +1 -0
- package/dist/variants/{navigation-menu.d.mts → navigation-menu.d.ts} +4 -5
- package/dist/variants/navigation-menu.d.ts.map +1 -0
- package/dist/variants/navigation-menu.js +15 -0
- package/dist/variants/navigation-menu.js.map +1 -0
- package/dist/variants/progress-circle.d.ts +51 -0
- package/dist/variants/progress-circle.d.ts.map +1 -0
- package/dist/variants/progress-circle.js +36 -0
- package/dist/variants/progress-circle.js.map +1 -0
- package/dist/variants/scroll-area.d.ts +23 -0
- package/dist/variants/scroll-area.d.ts.map +1 -0
- package/dist/variants/scroll-area.js +63 -0
- package/dist/variants/scroll-area.js.map +1 -0
- package/dist/variants/separator.d.ts +22 -0
- package/dist/variants/separator.d.ts.map +1 -0
- package/dist/variants/separator.js +30 -0
- package/dist/variants/separator.js.map +1 -0
- package/dist/variants/sheet.d.ts +19 -0
- package/dist/variants/sheet.d.ts.map +1 -0
- package/dist/variants/sheet.js +26 -0
- package/dist/variants/sheet.js.map +1 -0
- package/dist/variants/sidebar.d.ts +22 -0
- package/dist/variants/sidebar.d.ts.map +1 -0
- package/dist/variants/sidebar.js +30 -0
- package/dist/variants/sidebar.js.map +1 -0
- package/dist/variants/{tabs.d.mts → tabs.d.ts} +8 -9
- package/dist/variants/tabs.d.ts.map +1 -0
- package/dist/variants/tabs.js +24 -0
- package/dist/variants/tabs.js.map +1 -0
- package/dist/variants/toggle.d.ts +22 -0
- package/dist/variants/toggle.d.ts.map +1 -0
- package/dist/variants/toggle.js +30 -0
- package/dist/variants/toggle.js.map +1 -0
- package/package.json +253 -262
- package/src/components/accordion.tsx +3 -3
- package/src/components/alert-dialog.tsx +7 -7
- package/src/components/alert.tsx +1 -1
- package/src/components/aspect-ratio.tsx +1 -1
- package/src/components/attachment.tsx +1 -1
- package/src/components/avatar.tsx +1 -1
- package/src/components/badge.tsx +1 -1
- package/src/components/breadcrumb.tsx +3 -6
- package/src/components/bubble.tsx +1 -1
- package/src/components/button-group.tsx +2 -2
- package/src/components/button.tsx +1 -1
- package/src/components/calendar.tsx +2 -2
- package/src/components/card.tsx +2 -2
- package/src/components/checkbox-cards.tsx +2 -2
- package/src/components/checkbox.tsx +1 -1
- package/src/components/collapsible.tsx +1 -1
- package/src/components/context-menu.tsx +8 -8
- package/src/components/dialog.tsx +9 -6
- package/src/components/direction.tsx +1 -1
- package/src/components/drawer.tsx +3 -3
- package/src/components/dropdown-menu.tsx +8 -8
- package/src/components/empty.tsx +3 -3
- package/src/components/field.tsx +5 -5
- package/src/components/form.tsx +2 -2
- package/src/components/hover-card.tsx +2 -2
- package/src/components/input-group.tsx +2 -2
- package/src/components/input-number.tsx +166 -112
- package/src/components/input-otp.tsx +2 -2
- package/src/components/input.tsx +1 -1
- package/src/components/item.tsx +1 -1
- package/src/components/label.tsx +1 -1
- package/src/components/marker.tsx +1 -1
- package/src/components/menubar.tsx +12 -12
- package/src/components/native-select.tsx +1 -1
- package/src/components/navigation-menu.tsx +3 -3
- package/src/components/pagination.tsx +4 -4
- package/src/components/popover.tsx +3 -3
- package/src/components/progress.tsx +2 -2
- package/src/components/radio-cards.tsx +3 -3
- package/src/components/radio-group.tsx +2 -2
- package/src/components/scroll-area.tsx +1 -1
- package/src/components/select.tsx +5 -5
- package/src/components/separator.tsx +1 -1
- package/src/components/sheet.tsx +4 -4
- package/src/components/sidebar.tsx +11 -4
- package/src/components/slider.tsx +3 -3
- package/src/components/spinner.tsx +1 -1
- package/src/components/switch.tsx +1 -1
- package/src/components/tabs.tsx +2 -2
- package/src/components/textarea.tsx +1 -1
- package/src/components/toggle-group.tsx +3 -3
- package/src/components/toggle.tsx +1 -1
- package/src/components/tooltip.tsx +1 -1
- package/src/lib/message-scroller/geometry.ts +6 -2
- package/src/lib/message-scroller/stores.ts +2 -2
- package/src/primitives/checkbox-group.tsx +5 -6
- package/src/primitives/input-number.tsx +122 -43
- package/src/variants/alert.ts +1 -1
- package/src/variants/button-group.ts +3 -3
- package/src/variants/button.ts +9 -10
- package/src/variants/empty.ts +1 -1
- package/src/variants/field.ts +3 -3
- package/src/variants/input-group.ts +3 -3
- package/src/variants/item.ts +2 -2
- package/src/variants/navigation-menu.ts +1 -1
- package/src/variants/tabs.ts +1 -1
- package/src/variants/toggle.ts +4 -4
- package/dist/components/accordion.d.mts +0 -52
- package/dist/components/accordion.mjs +0 -65
- package/dist/components/alert-dialog.d.mts +0 -135
- package/dist/components/alert-dialog.mjs +0 -130
- package/dist/components/alert.d.mts +0 -51
- package/dist/components/alert.mjs +0 -50
- package/dist/components/aspect-ratio.d.mts +0 -16
- package/dist/components/aspect-ratio.mjs +0 -14
- package/dist/components/attachment.mjs +0 -112
- package/dist/components/avatar.d.mts +0 -75
- package/dist/components/avatar.mjs +0 -67
- package/dist/components/badge.d.mts +0 -21
- package/dist/components/badge.mjs +0 -20
- package/dist/components/breadcrumb.d.mts +0 -85
- package/dist/components/breadcrumb.mjs +0 -89
- package/dist/components/bubble.d.mts +0 -67
- package/dist/components/bubble.mjs +0 -58
- package/dist/components/button-group.d.mts +0 -45
- package/dist/components/button-group.mjs +0 -43
- package/dist/components/button.d.mts +0 -24
- package/dist/components/button.mjs +0 -35
- package/dist/components/calendar.d.mts +0 -43
- package/dist/components/calendar.mjs +0 -117
- package/dist/components/card.d.mts +0 -85
- package/dist/components/card.mjs +0 -76
- package/dist/components/carousel.mjs +0 -172
- package/dist/components/chart.d.mts +0 -135
- package/dist/components/chart.mjs +0 -214
- package/dist/components/checkbox-cards.d.mts +0 -29
- package/dist/components/checkbox-cards.mjs +0 -36
- package/dist/components/checkbox-group.d.mts +0 -28
- package/dist/components/checkbox-group.mjs +0 -32
- package/dist/components/checkbox.d.mts +0 -17
- package/dist/components/checkbox.mjs +0 -22
- package/dist/components/collapsible.d.mts +0 -36
- package/dist/components/collapsible.mjs +0 -32
- package/dist/components/command.d.mts +0 -127
- package/dist/components/command.mjs +0 -125
- package/dist/components/context-menu.d.mts +0 -188
- package/dist/components/context-menu.mjs +0 -172
- package/dist/components/dialog.d.mts +0 -115
- package/dist/components/dialog.mjs +0 -121
- package/dist/components/direction.d.mts +0 -24
- package/dist/components/direction.mjs +0 -18
- package/dist/components/drawer.d.mts +0 -101
- package/dist/components/drawer.mjs +0 -97
- package/dist/components/dropdown-menu.d.mts +0 -189
- package/dist/components/dropdown-menu.mjs +0 -178
- package/dist/components/empty.d.mts +0 -73
- package/dist/components/empty.mjs +0 -70
- package/dist/components/field.d.mts +0 -131
- package/dist/components/field.mjs +0 -135
- package/dist/components/form.mjs +0 -113
- package/dist/components/hover-card.d.mts +0 -50
- package/dist/components/hover-card.mjs +0 -49
- package/dist/components/input-group.d.mts +0 -79
- package/dist/components/input-group.mjs +0 -87
- package/dist/components/input-number.d.mts +0 -36
- package/dist/components/input-number.mjs +0 -86
- package/dist/components/input-otp.d.mts +0 -53
- package/dist/components/input-otp.mjs +0 -62
- package/dist/components/input-password.d.mts +0 -19
- package/dist/components/input-password.mjs +0 -38
- package/dist/components/input-search.d.mts +0 -26
- package/dist/components/input-search.mjs +0 -51
- package/dist/components/input.d.mts +0 -17
- package/dist/components/input.mjs +0 -16
- package/dist/components/item.d.mts +0 -123
- package/dist/components/item.mjs +0 -120
- package/dist/components/kbd.d.mts +0 -27
- package/dist/components/kbd.mjs +0 -25
- package/dist/components/label.d.mts +0 -17
- package/dist/components/label.mjs +0 -16
- package/dist/components/marker.mjs +0 -42
- package/dist/components/menubar.d.mts +0 -202
- package/dist/components/menubar.mjs +0 -188
- package/dist/components/message-scroller.d.mts +0 -89
- package/dist/components/message-scroller.mjs +0 -77
- package/dist/components/message.mjs +0 -66
- package/dist/components/native-select.d.mts +0 -41
- package/dist/components/native-select.mjs +0 -46
- package/dist/components/navigation-menu.d.mts +0 -100
- package/dist/components/navigation-menu.mjs +0 -103
- package/dist/components/pagination.d.mts +0 -94
- package/dist/components/pagination.mjs +0 -107
- package/dist/components/popover.d.mts +0 -93
- package/dist/components/popover.mjs +0 -88
- package/dist/components/progress-circle.d.mts +0 -89
- package/dist/components/progress-circle.mjs +0 -80
- package/dist/components/progress.d.mts +0 -18
- package/dist/components/progress.mjs +0 -21
- package/dist/components/radio-cards.d.mts +0 -26
- package/dist/components/radio-cards.mjs +0 -35
- package/dist/components/radio-group.d.mts +0 -28
- package/dist/components/radio-group.mjs +0 -31
- package/dist/components/radio.d.mts +0 -20
- package/dist/components/radio.mjs +0 -18
- package/dist/components/resizable.d.mts +0 -41
- package/dist/components/resizable.mjs +0 -36
- package/dist/components/scroll-area.d.mts +0 -39
- package/dist/components/scroll-area.mjs +0 -56
- package/dist/components/select.d.mts +0 -122
- package/dist/components/select.mjs +0 -131
- package/dist/components/separator.d.mts +0 -32
- package/dist/components/separator.mjs +0 -33
- package/dist/components/sheet.d.mts +0 -119
- package/dist/components/sheet.mjs +0 -123
- package/dist/components/sidebar.d.mts +0 -320
- package/dist/components/sidebar.mjs +0 -414
- package/dist/components/skeleton.d.mts +0 -16
- package/dist/components/skeleton.mjs +0 -15
- package/dist/components/slider.d.mts +0 -21
- package/dist/components/slider.mjs +0 -41
- package/dist/components/sonner.d.mts +0 -16
- package/dist/components/sonner.mjs +0 -32
- package/dist/components/spinner.d.mts +0 -20
- package/dist/components/spinner.mjs +0 -42
- package/dist/components/switch.d.mts +0 -20
- package/dist/components/switch.mjs +0 -21
- package/dist/components/table.d.mts +0 -93
- package/dist/components/table.mjs +0 -89
- package/dist/components/tabs.d.mts +0 -53
- package/dist/components/tabs.mjs +0 -53
- package/dist/components/textarea.d.mts +0 -16
- package/dist/components/textarea.mjs +0 -15
- package/dist/components/toggle-group.d.mts +0 -46
- package/dist/components/toggle-group.mjs +0 -58
- package/dist/components/toggle.d.mts +0 -20
- package/dist/components/toggle.mjs +0 -20
- package/dist/components/tooltip.d.mts +0 -61
- package/dist/components/tooltip.mjs +0 -59
- package/dist/hooks/use-animated-value.mjs +0 -65
- package/dist/hooks/use-copy-to-clipboard.mjs +0 -44
- package/dist/hooks/use-is-mobile.mjs +0 -27
- package/dist/hooks/use-media-query.mjs +0 -51
- package/dist/hooks/use-message-scroller-commands.d.mts +0 -39
- package/dist/hooks/use-message-scroller-commands.mjs +0 -165
- package/dist/hooks/use-message-scroller-controller.d.mts +0 -19
- package/dist/hooks/use-message-scroller-controller.mjs +0 -382
- package/dist/hooks/use-message-scroller-refs.d.mts +0 -60
- package/dist/hooks/use-message-scroller-refs.mjs +0 -77
- package/dist/hooks/use-mutation-observer.mjs +0 -42
- package/dist/hooks/use-pagination.mjs +0 -122
- package/dist/index.d.mts +0 -96
- package/dist/index.mjs +0 -95
- package/dist/lib/message-scroller/geometry.mjs +0 -199
- package/dist/lib/message-scroller/stores.mjs +0 -52
- package/dist/lib/message-scroller/types.d.mts +0 -171
- package/dist/lib/message-scroller/types.mjs +0 -53
- package/dist/lib/message-scroller/utils.mjs +0 -12
- package/dist/lib/use-render.mjs +0 -84
- package/dist/lib/utils.d.mts +0 -2
- package/dist/primitives/checkbox-group.d.mts +0 -154
- package/dist/primitives/checkbox-group.mjs +0 -137
- package/dist/primitives/input-number.d.mts +0 -119
- package/dist/primitives/input-number.mjs +0 -532
- package/dist/primitives/input.d.mts +0 -81
- package/dist/primitives/input.mjs +0 -80
- package/dist/primitives/message-scroller.d.mts +0 -88
- package/dist/primitives/message-scroller.mjs +0 -240
- package/dist/primitives/progress-circle.d.mts +0 -195
- package/dist/primitives/progress-circle.mjs +0 -189
- package/dist/variants/alert.mjs +0 -15
- package/dist/variants/attachment.mjs +0 -42
- package/dist/variants/badge.d.mts +0 -22
- package/dist/variants/badge.mjs +0 -19
- package/dist/variants/bubble.mjs +0 -45
- package/dist/variants/button-group.mjs +0 -15
- package/dist/variants/button.d.mts +0 -32
- package/dist/variants/button.mjs +0 -34
- package/dist/variants/empty.mjs +0 -15
- package/dist/variants/field.d.mts +0 -19
- package/dist/variants/field.mjs +0 -16
- package/dist/variants/input-group.mjs +0 -34
- package/dist/variants/input-number.d.mts +0 -45
- package/dist/variants/input-number.mjs +0 -40
- package/dist/variants/item.mjs +0 -38
- package/dist/variants/marker.mjs +0 -18
- package/dist/variants/navigation-menu.mjs +0 -8
- package/dist/variants/progress-circle.d.mts +0 -52
- package/dist/variants/progress-circle.mjs +0 -45
- package/dist/variants/scroll-area.d.mts +0 -24
- package/dist/variants/scroll-area.mjs +0 -58
- package/dist/variants/separator.d.mts +0 -23
- package/dist/variants/separator.mjs +0 -25
- package/dist/variants/sheet.d.mts +0 -20
- package/dist/variants/sheet.mjs +0 -17
- package/dist/variants/sidebar.d.mts +0 -23
- package/dist/variants/sidebar.mjs +0 -25
- package/dist/variants/tabs.mjs +0 -15
- package/dist/variants/toggle.d.mts +0 -23
- package/dist/variants/toggle.mjs +0 -25
- package/src/variants/input-number.ts +0 -65
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
import { EMPTY_MESSAGE_SCROLLER_VISIBILITY_STATE } from "../lib/message-scroller/types.mjs";
|
|
2
|
-
import { getContentBottom, getElementTop, getElementViewportTop, getFirstVisibleMessageItem, getFlexGap, getLastScrollAnchor, getMessageScrollerItems, getMessageScrollerScrollable, getMessageScrollerVisibilityState, getNewScrollAnchor, getUnanchoredScrollAnchor, hasMultipleNewScrollAnchors } from "../lib/message-scroller/geometry.mjs";
|
|
3
|
-
import { useMessageScrollerCommands } from "./use-message-scroller-commands.mjs";
|
|
4
|
-
import { useMessageScrollerRefs } from "./use-message-scroller-refs.mjs";
|
|
5
|
-
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
6
|
-
//#region src/hooks/use-message-scroller-controller.ts
|
|
7
|
-
function useElementRef(elementRef, onMount) {
|
|
8
|
-
return useCallback((element) => {
|
|
9
|
-
elementRef.current = element;
|
|
10
|
-
if (element) onMount();
|
|
11
|
-
}, [elementRef, onMount]);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @since 0.5.0-canary.3
|
|
15
|
-
*/
|
|
16
|
-
function useMessageScrollerController({ autoScroll = false, defaultScrollPosition = "end", scrollEdgeThreshold = 8, scrollPreviousItemPeek = 64, scrollMargin = 0 }) {
|
|
17
|
-
const refs = useMessageScrollerRefs({
|
|
18
|
-
autoScroll,
|
|
19
|
-
scrollEdgeThreshold,
|
|
20
|
-
scrollMargin,
|
|
21
|
-
scrollPreviousItemPeek
|
|
22
|
-
});
|
|
23
|
-
const { streamingTurnRef, autoScrollRef, autoscrollingRef, autoscrollingTimeoutRef, contentRef, defaultScrollPositionAppliedRef, firstItemRef, itemCountRef, messageElementsRef, modeRef, pendingScrollFrameRef, pendingScrollToMessageRef, prependRestoreRef, preserveScrollOnPrependRef, rootRef, scrollEdgeThresholdRef, scrollMarginRef, scrollPreviousItemPeekRef, spacerGapRef, spacerRef, stateFrameRef, stateStore, viewportRef, visibilityFrameRef, visibilityObserverRef, visibilityStore, visibleMessageIdsRef, handledScrollAnchorsRef } = refs;
|
|
24
|
-
const previousDefaultScrollPositionRef = useRef(defaultScrollPosition);
|
|
25
|
-
if (previousDefaultScrollPositionRef.current !== defaultScrollPosition) {
|
|
26
|
-
previousDefaultScrollPositionRef.current = defaultScrollPosition;
|
|
27
|
-
defaultScrollPositionAppliedRef.current = false;
|
|
28
|
-
}
|
|
29
|
-
const writeStateAttributes = useCallback((state) => {
|
|
30
|
-
const root = rootRef.current;
|
|
31
|
-
const viewport = viewportRef.current;
|
|
32
|
-
const scrollable = [state.start && "start", state.end && "end"].filter(Boolean).join(" ");
|
|
33
|
-
const autoScrolling = autoscrollingRef.current;
|
|
34
|
-
for (const element of [root, viewport]) {
|
|
35
|
-
if (!element) continue;
|
|
36
|
-
if (scrollable) element.setAttribute("data-scrollable", scrollable);
|
|
37
|
-
else element.removeAttribute("data-scrollable");
|
|
38
|
-
element.toggleAttribute("data-autoscrolling", autoScrolling);
|
|
39
|
-
}
|
|
40
|
-
}, []);
|
|
41
|
-
const reconcileFollowMode = useCallback((scrollable) => {
|
|
42
|
-
if (autoScrollRef.current && !scrollable.end && modeRef.current !== "settling-jump") modeRef.current = "following-bottom";
|
|
43
|
-
else if (modeRef.current === "following-bottom" && scrollable.end && !autoscrollingRef.current) modeRef.current = "free-scrolling";
|
|
44
|
-
}, []);
|
|
45
|
-
const commitScrollState = useCallback(() => {
|
|
46
|
-
const nextState = getMessageScrollerScrollable({
|
|
47
|
-
content: contentRef.current,
|
|
48
|
-
scrollEdgeThreshold: scrollEdgeThresholdRef.current,
|
|
49
|
-
spacer: spacerRef.current,
|
|
50
|
-
viewport: viewportRef.current
|
|
51
|
-
});
|
|
52
|
-
reconcileFollowMode(nextState);
|
|
53
|
-
writeStateAttributes(nextState);
|
|
54
|
-
stateStore.setSnapshot(nextState);
|
|
55
|
-
}, [
|
|
56
|
-
reconcileFollowMode,
|
|
57
|
-
stateStore,
|
|
58
|
-
writeStateAttributes
|
|
59
|
-
]);
|
|
60
|
-
const scheduleStateCommit = useCallback(() => {
|
|
61
|
-
if (stateFrameRef.current !== null) return;
|
|
62
|
-
stateFrameRef.current = window.requestAnimationFrame(() => {
|
|
63
|
-
stateFrameRef.current = null;
|
|
64
|
-
commitScrollState();
|
|
65
|
-
});
|
|
66
|
-
}, [commitScrollState]);
|
|
67
|
-
const scheduleVisibilitySync = useCallback(() => {
|
|
68
|
-
if (!visibilityStore.hasListeners()) return;
|
|
69
|
-
if (visibilityFrameRef.current !== null) return;
|
|
70
|
-
visibilityFrameRef.current = window.requestAnimationFrame(() => {
|
|
71
|
-
visibilityFrameRef.current = null;
|
|
72
|
-
if (!visibilityStore.hasListeners()) return;
|
|
73
|
-
visibilityStore.setSnapshot(getMessageScrollerVisibilityState({
|
|
74
|
-
content: contentRef.current,
|
|
75
|
-
scrollMargin: scrollMarginRef.current,
|
|
76
|
-
scrollPreviousItemPeek: scrollPreviousItemPeekRef.current,
|
|
77
|
-
spacer: spacerRef.current,
|
|
78
|
-
viewport: viewportRef.current,
|
|
79
|
-
visibleMessageIds: visibleMessageIdsRef.current
|
|
80
|
-
}));
|
|
81
|
-
});
|
|
82
|
-
}, [visibilityStore]);
|
|
83
|
-
const { flushPendingScrollToMessage, reanchorToAnchoredMessage, scrollToElement, scrollToEnd, scrollToMessage, scrollToStart } = useMessageScrollerCommands({
|
|
84
|
-
refs,
|
|
85
|
-
commitScrollState,
|
|
86
|
-
scheduleStateCommit,
|
|
87
|
-
scheduleVisibilitySync
|
|
88
|
-
});
|
|
89
|
-
const restorePrependedAnchor = useCallback(() => {
|
|
90
|
-
const anchor = prependRestoreRef.current;
|
|
91
|
-
const viewport = viewportRef.current;
|
|
92
|
-
if (!anchor || !viewport || !anchor.element.isConnected) return false;
|
|
93
|
-
const delta = getElementViewportTop(anchor.element, viewport) - anchor.viewportTop;
|
|
94
|
-
if (Math.abs(delta) <= .5) return false;
|
|
95
|
-
viewport.scrollTop += delta;
|
|
96
|
-
anchor.viewportTop = getElementViewportTop(anchor.element, viewport);
|
|
97
|
-
scheduleStateCommit();
|
|
98
|
-
scheduleVisibilitySync();
|
|
99
|
-
return true;
|
|
100
|
-
}, [scheduleStateCommit, scheduleVisibilitySync]);
|
|
101
|
-
const capturePrependAnchor = useCallback(() => {
|
|
102
|
-
const content = contentRef.current;
|
|
103
|
-
const viewport = viewportRef.current;
|
|
104
|
-
if (!content || !viewport) {
|
|
105
|
-
prependRestoreRef.current = null;
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const anchor = getFirstVisibleMessageItem({
|
|
109
|
-
content,
|
|
110
|
-
spacer: spacerRef.current,
|
|
111
|
-
viewport
|
|
112
|
-
});
|
|
113
|
-
prependRestoreRef.current = anchor ? {
|
|
114
|
-
element: anchor,
|
|
115
|
-
viewportTop: getElementViewportTop(anchor, viewport)
|
|
116
|
-
} : null;
|
|
117
|
-
}, []);
|
|
118
|
-
const schedulePendingScrollToMessageFlush = useCallback(() => {
|
|
119
|
-
if (pendingScrollFrameRef.current !== null) return;
|
|
120
|
-
pendingScrollFrameRef.current = window.requestAnimationFrame(() => {
|
|
121
|
-
pendingScrollFrameRef.current = null;
|
|
122
|
-
if (flushPendingScrollToMessage()) capturePrependAnchor();
|
|
123
|
-
});
|
|
124
|
-
}, [capturePrependAnchor, flushPendingScrollToMessage]);
|
|
125
|
-
const applyDefaultScrollPosition = useCallback(() => {
|
|
126
|
-
if (!defaultScrollPosition || defaultScrollPositionAppliedRef.current || itemCountRef.current === 0) return false;
|
|
127
|
-
let handled = false;
|
|
128
|
-
if (defaultScrollPosition === "last-anchor") {
|
|
129
|
-
const content = contentRef.current;
|
|
130
|
-
const viewport = viewportRef.current;
|
|
131
|
-
const anchor = content && viewport ? getLastScrollAnchor(getMessageScrollerItems(content, spacerRef.current)) : null;
|
|
132
|
-
if (!content || !viewport || !anchor) handled = scrollToEnd({ behavior: "auto" });
|
|
133
|
-
else {
|
|
134
|
-
const anchorTop = getElementTop(anchor, viewport);
|
|
135
|
-
handled = getContentBottom({
|
|
136
|
-
content,
|
|
137
|
-
spacer: spacerRef.current,
|
|
138
|
-
viewport
|
|
139
|
-
}) - anchorTop <= viewport.clientHeight ? scrollToEnd({ behavior: "auto" }) : scrollToElement(anchor, { align: "start" }, { keepPreviousPeek: true });
|
|
140
|
-
}
|
|
141
|
-
} else handled = defaultScrollPosition === "end" ? scrollToEnd({ behavior: "auto" }) : scrollToStart({ behavior: "auto" });
|
|
142
|
-
if (!handled) return false;
|
|
143
|
-
defaultScrollPositionAppliedRef.current = true;
|
|
144
|
-
return true;
|
|
145
|
-
}, [
|
|
146
|
-
defaultScrollPosition,
|
|
147
|
-
scrollToElement,
|
|
148
|
-
scrollToEnd,
|
|
149
|
-
scrollToStart
|
|
150
|
-
]);
|
|
151
|
-
const handleContentChange = useCallback(() => {
|
|
152
|
-
const content = contentRef.current;
|
|
153
|
-
if (!content) return;
|
|
154
|
-
const items = getMessageScrollerItems(content, spacerRef.current);
|
|
155
|
-
const previousItemCount = itemCountRef.current;
|
|
156
|
-
const previousFirstItem = firstItemRef.current;
|
|
157
|
-
itemCountRef.current = items.length;
|
|
158
|
-
firstItemRef.current = items[0] ?? null;
|
|
159
|
-
const reconcileScrollPosition = () => {
|
|
160
|
-
if (flushPendingScrollToMessage()) return;
|
|
161
|
-
if (previousItemCount === 0) {
|
|
162
|
-
if (applyDefaultScrollPosition()) return;
|
|
163
|
-
if (items.length > 0 && autoScrollRef.current && scrollToEnd({ behavior: "auto" })) return;
|
|
164
|
-
commitScrollState();
|
|
165
|
-
scheduleVisibilitySync();
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const previousFirstItemIndex = previousFirstItem ? items.indexOf(previousFirstItem) : -1;
|
|
169
|
-
if (preserveScrollOnPrependRef.current && previousFirstItemIndex > 0) {
|
|
170
|
-
restorePrependedAnchor();
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
if (items.length > previousItemCount) {
|
|
174
|
-
const anchor = getNewScrollAnchor(items, previousItemCount);
|
|
175
|
-
if (anchor) {
|
|
176
|
-
if (autoScrollRef.current && modeRef.current === "following-bottom" && hasMultipleNewScrollAnchors(items, previousItemCount)) {
|
|
177
|
-
scrollToEnd({ behavior: "auto" });
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
scrollToElement(anchor, { align: "start" }, { keepPreviousPeek: true });
|
|
181
|
-
handledScrollAnchorsRef.current.add(anchor);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (items.length === previousItemCount) {
|
|
186
|
-
const anchor = getUnanchoredScrollAnchor(items, handledScrollAnchorsRef.current);
|
|
187
|
-
if (anchor) {
|
|
188
|
-
scrollToElement(anchor, { align: "start" }, { keepPreviousPeek: true });
|
|
189
|
-
handledScrollAnchorsRef.current.add(anchor);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
if (modeRef.current === "following-bottom" && autoScrollRef.current) scrollToEnd({ behavior: "auto" });
|
|
194
|
-
else {
|
|
195
|
-
commitScrollState();
|
|
196
|
-
scheduleVisibilitySync();
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
reconcileScrollPosition();
|
|
200
|
-
capturePrependAnchor();
|
|
201
|
-
}, [
|
|
202
|
-
applyDefaultScrollPosition,
|
|
203
|
-
capturePrependAnchor,
|
|
204
|
-
commitScrollState,
|
|
205
|
-
flushPendingScrollToMessage,
|
|
206
|
-
restorePrependedAnchor,
|
|
207
|
-
scheduleVisibilitySync,
|
|
208
|
-
scrollToElement,
|
|
209
|
-
scrollToEnd
|
|
210
|
-
]);
|
|
211
|
-
const handleResize = useCallback(() => {
|
|
212
|
-
if (modeRef.current === "following-bottom" && autoScrollRef.current) {
|
|
213
|
-
scrollToEnd({ behavior: "auto" });
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (reanchorToAnchoredMessage()) return;
|
|
217
|
-
scheduleStateCommit();
|
|
218
|
-
scheduleVisibilitySync();
|
|
219
|
-
}, [
|
|
220
|
-
reanchorToAnchoredMessage,
|
|
221
|
-
scheduleStateCommit,
|
|
222
|
-
scheduleVisibilitySync,
|
|
223
|
-
scrollToEnd
|
|
224
|
-
]);
|
|
225
|
-
const observeVisibility = useCallback(() => {
|
|
226
|
-
const viewport = viewportRef.current;
|
|
227
|
-
if (!viewport || !visibilityStore.hasListeners()) return;
|
|
228
|
-
if (typeof IntersectionObserver === "undefined") {
|
|
229
|
-
scheduleVisibilitySync();
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
if (!visibilityObserverRef.current) visibilityObserverRef.current = new IntersectionObserver((entries) => {
|
|
233
|
-
for (const entry of entries) {
|
|
234
|
-
const messageId = entry.target.dataset.messageId;
|
|
235
|
-
if (!messageId) continue;
|
|
236
|
-
if (entry.isIntersecting) visibleMessageIdsRef.current.add(messageId);
|
|
237
|
-
else visibleMessageIdsRef.current.delete(messageId);
|
|
238
|
-
}
|
|
239
|
-
scheduleVisibilitySync();
|
|
240
|
-
}, {
|
|
241
|
-
root: viewport,
|
|
242
|
-
rootMargin: `${-(scrollMarginRef.current + scrollPreviousItemPeekRef.current)}px 0px 0px 0px`,
|
|
243
|
-
threshold: [
|
|
244
|
-
0,
|
|
245
|
-
.01,
|
|
246
|
-
.5,
|
|
247
|
-
1
|
|
248
|
-
]
|
|
249
|
-
});
|
|
250
|
-
messageElementsRef.current.forEach((element) => {
|
|
251
|
-
visibilityObserverRef.current?.observe(element);
|
|
252
|
-
});
|
|
253
|
-
scheduleVisibilitySync();
|
|
254
|
-
}, [scheduleVisibilitySync, visibilityStore]);
|
|
255
|
-
const unobserveVisibility = useCallback(() => {
|
|
256
|
-
if (visibilityFrameRef.current !== null) {
|
|
257
|
-
window.cancelAnimationFrame(visibilityFrameRef.current);
|
|
258
|
-
visibilityFrameRef.current = null;
|
|
259
|
-
}
|
|
260
|
-
visibilityObserverRef.current?.disconnect();
|
|
261
|
-
visibilityObserverRef.current = null;
|
|
262
|
-
visibleMessageIdsRef.current.clear();
|
|
263
|
-
visibilityStore.setSnapshot(EMPTY_MESSAGE_SCROLLER_VISIBILITY_STATE);
|
|
264
|
-
}, [visibilityStore]);
|
|
265
|
-
const registerMessage = useCallback((messageId, element, removedElement) => {
|
|
266
|
-
if (element) {
|
|
267
|
-
messageElementsRef.current.set(messageId, element);
|
|
268
|
-
visibilityObserverRef.current?.observe(element);
|
|
269
|
-
scheduleVisibilitySync();
|
|
270
|
-
if (pendingScrollToMessageRef.current?.messageId === messageId) schedulePendingScrollToMessageFlush();
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
if (removedElement && messageElementsRef.current.get(messageId) === removedElement) {
|
|
274
|
-
messageElementsRef.current.delete(messageId);
|
|
275
|
-
visibleMessageIdsRef.current.delete(messageId);
|
|
276
|
-
visibilityObserverRef.current?.unobserve(removedElement);
|
|
277
|
-
scheduleVisibilitySync();
|
|
278
|
-
}
|
|
279
|
-
}, [schedulePendingScrollToMessageFlush, scheduleVisibilitySync]);
|
|
280
|
-
const userScrollIntent = useCallback(() => {
|
|
281
|
-
if (modeRef.current === "following-bottom" || modeRef.current === "anchored-to-message" || modeRef.current === "settling-jump") {
|
|
282
|
-
streamingTurnRef.current = null;
|
|
283
|
-
modeRef.current = "free-scrolling";
|
|
284
|
-
}
|
|
285
|
-
}, []);
|
|
286
|
-
const mirrorStateAttributes = useCallback(() => writeStateAttributes(stateStore.getSnapshot()), [stateStore, writeStateAttributes]);
|
|
287
|
-
const setRootElement = useElementRef(rootRef, mirrorStateAttributes);
|
|
288
|
-
const setViewportElement = useElementRef(viewportRef, mirrorStateAttributes);
|
|
289
|
-
const setContentElement = useCallback((element) => {
|
|
290
|
-
contentRef.current = element;
|
|
291
|
-
}, []);
|
|
292
|
-
const setSpacerElement = useCallback((element) => {
|
|
293
|
-
spacerRef.current = element;
|
|
294
|
-
spacerGapRef.current = getFlexGap(element?.parentElement ?? null);
|
|
295
|
-
}, []);
|
|
296
|
-
const syncAfterScroll = useCallback(() => {
|
|
297
|
-
commitScrollState();
|
|
298
|
-
scheduleVisibilitySync();
|
|
299
|
-
capturePrependAnchor();
|
|
300
|
-
}, [
|
|
301
|
-
capturePrependAnchor,
|
|
302
|
-
commitScrollState,
|
|
303
|
-
scheduleVisibilitySync
|
|
304
|
-
]);
|
|
305
|
-
const context = useMemo(() => ({
|
|
306
|
-
handleContentChange,
|
|
307
|
-
handleResize,
|
|
308
|
-
observeVisibility,
|
|
309
|
-
preserveScrollOnPrependRef,
|
|
310
|
-
scrollToEnd,
|
|
311
|
-
scrollToMessage,
|
|
312
|
-
scrollToStart,
|
|
313
|
-
setContentElement,
|
|
314
|
-
setRootElement,
|
|
315
|
-
setSpacerElement,
|
|
316
|
-
setViewportElement,
|
|
317
|
-
stateStore,
|
|
318
|
-
syncAfterScroll,
|
|
319
|
-
unobserveVisibility,
|
|
320
|
-
userScrollIntent,
|
|
321
|
-
viewportRef,
|
|
322
|
-
visibilityStore
|
|
323
|
-
}), [
|
|
324
|
-
handleContentChange,
|
|
325
|
-
handleResize,
|
|
326
|
-
observeVisibility,
|
|
327
|
-
scrollToEnd,
|
|
328
|
-
scrollToMessage,
|
|
329
|
-
scrollToStart,
|
|
330
|
-
setContentElement,
|
|
331
|
-
setRootElement,
|
|
332
|
-
setSpacerElement,
|
|
333
|
-
setViewportElement,
|
|
334
|
-
stateStore,
|
|
335
|
-
syncAfterScroll,
|
|
336
|
-
unobserveVisibility,
|
|
337
|
-
userScrollIntent,
|
|
338
|
-
visibilityStore
|
|
339
|
-
]);
|
|
340
|
-
useLayoutEffect(() => {
|
|
341
|
-
applyDefaultScrollPosition();
|
|
342
|
-
}, [applyDefaultScrollPosition]);
|
|
343
|
-
useEffect(() => {
|
|
344
|
-
return () => {
|
|
345
|
-
if (stateFrameRef.current !== null) {
|
|
346
|
-
window.cancelAnimationFrame(stateFrameRef.current);
|
|
347
|
-
stateFrameRef.current = null;
|
|
348
|
-
}
|
|
349
|
-
if (visibilityFrameRef.current !== null) {
|
|
350
|
-
window.cancelAnimationFrame(visibilityFrameRef.current);
|
|
351
|
-
visibilityFrameRef.current = null;
|
|
352
|
-
}
|
|
353
|
-
if (autoscrollingTimeoutRef.current !== null) {
|
|
354
|
-
window.clearTimeout(autoscrollingTimeoutRef.current);
|
|
355
|
-
autoscrollingTimeoutRef.current = null;
|
|
356
|
-
}
|
|
357
|
-
if (pendingScrollFrameRef.current !== null) {
|
|
358
|
-
window.cancelAnimationFrame(pendingScrollFrameRef.current);
|
|
359
|
-
pendingScrollFrameRef.current = null;
|
|
360
|
-
}
|
|
361
|
-
visibilityObserverRef.current?.disconnect();
|
|
362
|
-
visibilityObserverRef.current = null;
|
|
363
|
-
};
|
|
364
|
-
}, []);
|
|
365
|
-
useLayoutEffect(() => {
|
|
366
|
-
if (autoScroll && modeRef.current === "following-bottom" && itemCountRef.current > 0) {
|
|
367
|
-
scrollToEnd({ behavior: "auto" });
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
commitScrollState();
|
|
371
|
-
}, [
|
|
372
|
-
autoScroll,
|
|
373
|
-
commitScrollState,
|
|
374
|
-
scrollToEnd
|
|
375
|
-
]);
|
|
376
|
-
return {
|
|
377
|
-
context,
|
|
378
|
-
registerMessage
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
//#endregion
|
|
382
|
-
export { useMessageScrollerController };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { MessageScrollerMode, MessageScrollerScrollOptions, MessageScrollerScrollable, MessageScrollerStore, MessageScrollerVisibilityStore } from "../lib/message-scroller/types.mjs";
|
|
2
|
-
import { RefObject } from "react";
|
|
3
|
-
|
|
4
|
-
//#region src/hooks/use-message-scroller-refs.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* @since 0.5.0-canary.3
|
|
7
|
-
*/
|
|
8
|
-
type MessageScrollerRefs = {
|
|
9
|
-
autoScrollRef: RefObject<boolean>;
|
|
10
|
-
autoscrollingRef: RefObject<boolean>;
|
|
11
|
-
autoscrollingTimeoutRef: RefObject<number | null>;
|
|
12
|
-
streamingTurnRef: RefObject<HTMLElement | null>;
|
|
13
|
-
contentRef: RefObject<HTMLDivElement | null>;
|
|
14
|
-
defaultScrollPositionAppliedRef: RefObject<boolean>;
|
|
15
|
-
firstItemRef: RefObject<HTMLElement | null>;
|
|
16
|
-
itemCountRef: RefObject<number>;
|
|
17
|
-
messageElementsRef: RefObject<Map<string, HTMLElement>>;
|
|
18
|
-
modeRef: RefObject<MessageScrollerMode>;
|
|
19
|
-
pendingScrollFrameRef: RefObject<number | null>;
|
|
20
|
-
pendingScrollToMessageRef: RefObject<{
|
|
21
|
-
messageId: string;
|
|
22
|
-
options?: MessageScrollerScrollOptions;
|
|
23
|
-
} | null>;
|
|
24
|
-
prependRestoreRef: RefObject<{
|
|
25
|
-
element: HTMLElement;
|
|
26
|
-
viewportTop: number;
|
|
27
|
-
} | null>;
|
|
28
|
-
preserveScrollOnPrependRef: RefObject<boolean>;
|
|
29
|
-
rootRef: RefObject<HTMLDivElement | null>;
|
|
30
|
-
scrollEdgeThresholdRef: RefObject<number>;
|
|
31
|
-
scrollMarginRef: RefObject<number>;
|
|
32
|
-
scrollPreviousItemPeekRef: RefObject<number>;
|
|
33
|
-
spacerGapRef: RefObject<number>;
|
|
34
|
-
spacerHeightRef: RefObject<number>;
|
|
35
|
-
spacerRef: RefObject<HTMLDivElement | null>;
|
|
36
|
-
stateFrameRef: RefObject<number | null>;
|
|
37
|
-
stateStore: MessageScrollerStore<MessageScrollerScrollable>;
|
|
38
|
-
viewportRef: RefObject<HTMLDivElement | null>;
|
|
39
|
-
visibilityFrameRef: RefObject<number | null>;
|
|
40
|
-
visibilityObserverRef: RefObject<IntersectionObserver | null>;
|
|
41
|
-
visibilityStore: MessageScrollerVisibilityStore;
|
|
42
|
-
visibleMessageIdsRef: RefObject<Set<string>>;
|
|
43
|
-
handledScrollAnchorsRef: RefObject<WeakSet<HTMLElement>>;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* @since 0.5.0-canary.3
|
|
47
|
-
*/
|
|
48
|
-
declare function useMessageScrollerRefs({
|
|
49
|
-
autoScroll,
|
|
50
|
-
scrollEdgeThreshold,
|
|
51
|
-
scrollMargin,
|
|
52
|
-
scrollPreviousItemPeek
|
|
53
|
-
}: {
|
|
54
|
-
autoScroll: boolean;
|
|
55
|
-
scrollEdgeThreshold: number;
|
|
56
|
-
scrollMargin: number;
|
|
57
|
-
scrollPreviousItemPeek: number;
|
|
58
|
-
}): MessageScrollerRefs;
|
|
59
|
-
//#endregion
|
|
60
|
-
export { type MessageScrollerRefs, useMessageScrollerRefs };
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { EMPTY_MESSAGE_SCROLLER_SCROLLABLE } from "../lib/message-scroller/types.mjs";
|
|
2
|
-
import { areScrollStatesEqual, createMessageScrollerStore, createMessageScrollerVisibilityStore } from "../lib/message-scroller/stores.mjs";
|
|
3
|
-
import { useRef } from "react";
|
|
4
|
-
//#region src/hooks/use-message-scroller-refs.ts
|
|
5
|
-
/**
|
|
6
|
-
* @since 0.5.0-canary.3
|
|
7
|
-
*/
|
|
8
|
-
function useMessageScrollerRefs({ autoScroll, scrollEdgeThreshold, scrollMargin, scrollPreviousItemPeek }) {
|
|
9
|
-
const autoScrollRef = useRef(autoScroll);
|
|
10
|
-
const autoscrollingRef = useRef(false);
|
|
11
|
-
const contentRef = useRef(null);
|
|
12
|
-
const defaultScrollPositionAppliedRef = useRef(false);
|
|
13
|
-
const scrollEdgeThresholdRef = useRef(scrollEdgeThreshold);
|
|
14
|
-
const itemCountRef = useRef(0);
|
|
15
|
-
const firstItemRef = useRef(null);
|
|
16
|
-
const modeRef = useRef(autoScroll ? "following-bottom" : "free-scrolling");
|
|
17
|
-
const messageElementsRef = useRef(/* @__PURE__ */ new Map());
|
|
18
|
-
const pendingScrollToMessageRef = useRef(null);
|
|
19
|
-
const prependRestoreRef = useRef(null);
|
|
20
|
-
const streamingTurnRef = useRef(null);
|
|
21
|
-
const scrollPreviousItemPeekRef = useRef(scrollPreviousItemPeek);
|
|
22
|
-
const preserveScrollOnPrependRef = useRef(true);
|
|
23
|
-
const rootRef = useRef(null);
|
|
24
|
-
const scrollMarginRef = useRef(scrollMargin);
|
|
25
|
-
const pendingScrollFrameRef = useRef(null);
|
|
26
|
-
const spacerGapRef = useRef(0);
|
|
27
|
-
const spacerHeightRef = useRef(0);
|
|
28
|
-
const spacerRef = useRef(null);
|
|
29
|
-
const stateFrameRef = useRef(null);
|
|
30
|
-
const stateStoreRef = useRef(null);
|
|
31
|
-
const autoscrollingTimeoutRef = useRef(null);
|
|
32
|
-
const viewportRef = useRef(null);
|
|
33
|
-
const visibilityFrameRef = useRef(null);
|
|
34
|
-
const visibilityObserverRef = useRef(null);
|
|
35
|
-
const visibilityStoreRef = useRef(null);
|
|
36
|
-
const visibleMessageIdsRef = useRef(/* @__PURE__ */ new Set());
|
|
37
|
-
const handledScrollAnchorsRef = useRef(/* @__PURE__ */ new WeakSet());
|
|
38
|
-
if (stateStoreRef.current === null) stateStoreRef.current = createMessageScrollerStore(EMPTY_MESSAGE_SCROLLER_SCROLLABLE, areScrollStatesEqual);
|
|
39
|
-
if (visibilityStoreRef.current === null) visibilityStoreRef.current = createMessageScrollerVisibilityStore();
|
|
40
|
-
autoScrollRef.current = autoScroll;
|
|
41
|
-
scrollEdgeThresholdRef.current = scrollEdgeThreshold;
|
|
42
|
-
scrollMarginRef.current = scrollMargin;
|
|
43
|
-
scrollPreviousItemPeekRef.current = scrollPreviousItemPeek;
|
|
44
|
-
return {
|
|
45
|
-
autoScrollRef,
|
|
46
|
-
autoscrollingRef,
|
|
47
|
-
autoscrollingTimeoutRef,
|
|
48
|
-
streamingTurnRef,
|
|
49
|
-
contentRef,
|
|
50
|
-
defaultScrollPositionAppliedRef,
|
|
51
|
-
firstItemRef,
|
|
52
|
-
itemCountRef,
|
|
53
|
-
messageElementsRef,
|
|
54
|
-
modeRef,
|
|
55
|
-
pendingScrollFrameRef,
|
|
56
|
-
pendingScrollToMessageRef,
|
|
57
|
-
prependRestoreRef,
|
|
58
|
-
preserveScrollOnPrependRef,
|
|
59
|
-
rootRef,
|
|
60
|
-
scrollEdgeThresholdRef,
|
|
61
|
-
scrollMarginRef,
|
|
62
|
-
scrollPreviousItemPeekRef,
|
|
63
|
-
spacerGapRef,
|
|
64
|
-
spacerHeightRef,
|
|
65
|
-
spacerRef,
|
|
66
|
-
stateFrameRef,
|
|
67
|
-
stateStore: stateStoreRef.current,
|
|
68
|
-
viewportRef,
|
|
69
|
-
visibilityFrameRef,
|
|
70
|
-
visibilityObserverRef,
|
|
71
|
-
visibilityStore: visibilityStoreRef.current,
|
|
72
|
-
visibleMessageIdsRef,
|
|
73
|
-
handledScrollAnchorsRef
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
//#endregion
|
|
77
|
-
export { useMessageScrollerRefs };
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
//#region src/hooks/use-mutation-observer.ts
|
|
3
|
-
/**
|
|
4
|
-
* Default options for MutationObserver observing common mutation types.
|
|
5
|
-
*/
|
|
6
|
-
const defaultOptions = {
|
|
7
|
-
attributes: true,
|
|
8
|
-
characterData: true,
|
|
9
|
-
childList: true,
|
|
10
|
-
subtree: true
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Observe DOM mutations on a referenced element and invoke a callback.
|
|
14
|
-
*
|
|
15
|
-
* Attaches a MutationObserver to the provided element reference with the given
|
|
16
|
-
* options and calls the callback whenever mutations occur.
|
|
17
|
-
*
|
|
18
|
-
* @param ref - Ref to the target HTMLElement to observe.
|
|
19
|
-
* @param callback - Mutation callback invoked with observed records.
|
|
20
|
-
* @param options - Observer configuration. Defaults watch attributes, characterData, childList, subtree.
|
|
21
|
-
* @returns void
|
|
22
|
-
*
|
|
23
|
-
* @see [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
|
|
24
|
-
*
|
|
25
|
-
* @since 0.3.16-canary.0
|
|
26
|
-
*/
|
|
27
|
-
function useMutationObserver(ref, callback, options = defaultOptions) {
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (!ref.current) return;
|
|
30
|
-
const observer = new MutationObserver(callback);
|
|
31
|
-
observer.observe(ref.current, options);
|
|
32
|
-
return () => {
|
|
33
|
-
observer.disconnect();
|
|
34
|
-
};
|
|
35
|
-
}, [
|
|
36
|
-
ref,
|
|
37
|
-
callback,
|
|
38
|
-
options
|
|
39
|
-
]);
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
export { useMutationObserver };
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
//#region src/hooks/use-pagination.ts
|
|
3
|
-
/**
|
|
4
|
-
* Ellipsis marker used to collapse ranges in pagination output.
|
|
5
|
-
*
|
|
6
|
-
* @since 0.3.16-canary.0
|
|
7
|
-
*/
|
|
8
|
-
const ELLIPSIS = "•••";
|
|
9
|
-
/**
|
|
10
|
-
* Generate a numeric range from start to end inclusive.
|
|
11
|
-
*
|
|
12
|
-
* @param start - Starting number (inclusive).
|
|
13
|
-
* @param end - Ending number (inclusive).
|
|
14
|
-
* @returns Array of numbers from start to end.
|
|
15
|
-
*/
|
|
16
|
-
const createRange = (start, end) => {
|
|
17
|
-
const length = end - start + 1;
|
|
18
|
-
return Array.from({ length }, (_, index) => start + index);
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Compute a pagination structure for result sets.
|
|
22
|
-
*
|
|
23
|
-
* Returns a mixed array of page numbers and the `ELLIPSIS` marker representing
|
|
24
|
-
* collapsed ranges. The shape adapts to the total pages and the requested
|
|
25
|
-
* sibling window around the current page.
|
|
26
|
-
*
|
|
27
|
-
* @param props - Pagination options. See {@link UsePaginationOptions}.
|
|
28
|
-
* @returns Array of page numbers and `ELLIPSIS` representing the pagination model.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```tsx
|
|
32
|
-
* const paginationRange = usePagination({
|
|
33
|
-
* currentPage: 3,
|
|
34
|
-
* resultsPerPage: 10,
|
|
35
|
-
* siblingPagesCount: 1,
|
|
36
|
-
* totalResults: 100
|
|
37
|
-
* });
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @since 0.3.16-canary.0
|
|
41
|
-
*/
|
|
42
|
-
function usePagination({ currentPage, resultsPerPage, siblingPagesCount = 1, totalResults }) {
|
|
43
|
-
return useMemo(() => {
|
|
44
|
-
const totalPages = Math.ceil(totalResults / Math.floor(resultsPerPage));
|
|
45
|
-
if (totalPages <= 0) return [];
|
|
46
|
-
/**
|
|
47
|
-
* Case 1: If the number of pages is less than or equal to the visible page
|
|
48
|
-
* numbers, return an array of all page numbers.
|
|
49
|
-
*/
|
|
50
|
-
if (siblingPagesCount + 5 >= totalPages) return createRange(1, totalPages);
|
|
51
|
-
/**
|
|
52
|
-
* Left sibling boundary (min 1).
|
|
53
|
-
*/
|
|
54
|
-
const leftSiblingIndex = Math.max(currentPage - siblingPagesCount, 1);
|
|
55
|
-
/**
|
|
56
|
-
* Right sibling boundary (max totalPages).
|
|
57
|
-
*/
|
|
58
|
-
const rightSiblingIndex = Math.min(currentPage + siblingPagesCount, totalPages);
|
|
59
|
-
/**
|
|
60
|
-
* Whether a left-side ellipsis is needed.
|
|
61
|
-
*/
|
|
62
|
-
const shouldShowLeftEllipsis = leftSiblingIndex > 2;
|
|
63
|
-
/**
|
|
64
|
-
* Whether a right-side ellipsis is needed.
|
|
65
|
-
*/
|
|
66
|
-
const shouldShowRightEllipsis = rightSiblingIndex < totalPages - 2;
|
|
67
|
-
/**
|
|
68
|
-
* First page number (always 1).
|
|
69
|
-
*/
|
|
70
|
-
const firstPage = 1;
|
|
71
|
-
/**
|
|
72
|
-
* Last page number (equals totalPages).
|
|
73
|
-
*/
|
|
74
|
-
const lastPage = totalPages;
|
|
75
|
-
/**
|
|
76
|
-
* Case 2: No left ellipsis, but right ellipsis is necessary.
|
|
77
|
-
* This occurs when the current page is close to the start of the
|
|
78
|
-
* pagination range.
|
|
79
|
-
*/
|
|
80
|
-
if (!shouldShowLeftEllipsis && shouldShowRightEllipsis) return [
|
|
81
|
-
...createRange(1, 3 + 2 * siblingPagesCount),
|
|
82
|
-
ELLIPSIS,
|
|
83
|
-
lastPage
|
|
84
|
-
];
|
|
85
|
-
/**
|
|
86
|
-
* Case 3: No right ellipsis, but left ellipsis is necessary.
|
|
87
|
-
* This occurs when the current page is close to the end of the pagination
|
|
88
|
-
* range.
|
|
89
|
-
*/
|
|
90
|
-
if (shouldShowLeftEllipsis && !shouldShowRightEllipsis) {
|
|
91
|
-
const rightRange = createRange(totalPages - (3 + 2 * siblingPagesCount) + 1, totalPages);
|
|
92
|
-
return [
|
|
93
|
-
firstPage,
|
|
94
|
-
ELLIPSIS,
|
|
95
|
-
...rightRange
|
|
96
|
-
];
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Case 4: Both left and right ellipsis are necessary.
|
|
100
|
-
* This occurs when the current page is far enough from both the start and
|
|
101
|
-
* end of the pagination range.
|
|
102
|
-
*/
|
|
103
|
-
if (shouldShowLeftEllipsis && shouldShowRightEllipsis) {
|
|
104
|
-
const middleRange = createRange(leftSiblingIndex, rightSiblingIndex);
|
|
105
|
-
return [
|
|
106
|
-
firstPage,
|
|
107
|
-
ELLIPSIS,
|
|
108
|
-
...middleRange,
|
|
109
|
-
ELLIPSIS,
|
|
110
|
-
lastPage
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
|
-
return [];
|
|
114
|
-
}, [
|
|
115
|
-
totalResults,
|
|
116
|
-
resultsPerPage,
|
|
117
|
-
siblingPagesCount,
|
|
118
|
-
currentPage
|
|
119
|
-
]);
|
|
120
|
-
}
|
|
121
|
-
//#endregion
|
|
122
|
-
export { ELLIPSIS, usePagination };
|