@kumix/ui 0.3.13 → 0.3.15
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/README.md +12 -12
- package/dist/components/agents/agent-activity/activity-row.js +1 -1
- package/dist/components/agents/agent-activity/activity-row.js.map +1 -1
- package/dist/components/agents/agent-activity/index.js +1 -1
- package/dist/components/agents/agent-activity/index.js.map +1 -1
- package/dist/components/agents/agent-code.d.ts.map +1 -1
- package/dist/components/agents/agent-code.js +1 -1
- package/dist/components/agents/agent-code.js.map +1 -1
- package/dist/components/agents/agent-disclosure.js +1 -1
- package/dist/components/agents/agent-disclosure.js.map +1 -1
- package/dist/components/agents/ai-sidebar.js +1 -1
- package/dist/components/agents/ai-sidebar.js.map +1 -1
- package/dist/components/agents/approval-card/index.js +1 -1
- package/dist/components/agents/approval-card/index.js.map +1 -1
- package/dist/components/agents/chat-app.js +1 -1
- package/dist/components/agents/chat-app.js.map +1 -1
- package/dist/components/agents/citations.js +1 -1
- package/dist/components/agents/citations.js.map +1 -1
- package/dist/components/agents/code-block.js +1 -1
- package/dist/components/agents/code-block.js.map +1 -1
- package/dist/components/agents/file-diff.js +1 -1
- package/dist/components/agents/file-diff.js.map +1 -1
- package/dist/components/agents/image-generation.js +1 -1
- package/dist/components/agents/image-generation.js.map +1 -1
- package/dist/components/agents/loading-states/agent-progress.js +1 -1
- package/dist/components/agents/loading-states/agent-progress.js.map +1 -1
- package/dist/components/agents/loading-states/reasoning-text.js +1 -1
- package/dist/components/agents/loading-states/reasoning-text.js.map +1 -1
- package/dist/components/agents/loading-states/thinking-shimmer.js +1 -1
- package/dist/components/agents/loading-states/thinking-shimmer.js.map +1 -1
- package/dist/components/agents/message-bubble.js +1 -1
- package/dist/components/agents/message-bubble.js.map +1 -1
- package/dist/components/agents/message-scroller.js +1 -1
- package/dist/components/agents/message-scroller.js.map +1 -1
- package/dist/components/agents/message.js +1 -1
- package/dist/components/agents/message.js.map +1 -1
- package/dist/components/agents/prompt-input.js +1 -1
- package/dist/components/agents/prompt-input.js.map +1 -1
- package/dist/components/agents/streaming-response.js +1 -1
- package/dist/components/agents/streaming-response.js.map +1 -1
- package/dist/components/agents/todo-list.js +1 -1
- package/dist/components/agents/todo-list.js.map +1 -1
- package/dist/components/agents/tool-approval.js +1 -1
- package/dist/components/agents/tool-approval.js.map +1 -1
- package/dist/components/agents/tool-result.js +1 -1
- package/dist/components/agents/tool-result.js.map +1 -1
- package/dist/components/motion/action-swap.js +1 -1
- package/dist/components/motion/action-swap.js.map +1 -1
- package/dist/components/motion/adaptive-stepper.js +1 -1
- package/dist/components/motion/adaptive-stepper.js.map +1 -1
- package/dist/components/motion/animated-badge.js +1 -1
- package/dist/components/motion/animated-badge.js.map +1 -1
- package/dist/components/motion/animated-number.js +1 -1
- package/dist/components/motion/animated-number.js.map +1 -1
- package/dist/components/motion/animated-sidebar.js +1 -1
- package/dist/components/motion/animated-sidebar.js.map +1 -1
- package/dist/components/motion/animated-toast-stack.js +5 -4
- package/dist/components/motion/animated-toast-stack.js.map +1 -1
- package/dist/components/motion/attachment-upload.js +1 -1
- package/dist/components/motion/attachment-upload.js.map +1 -1
- package/dist/components/motion/availability-scheduler/icon-button.js +1 -1
- package/dist/components/motion/availability-scheduler/icon-button.js.map +1 -1
- package/dist/components/motion/availability-scheduler/index.js +1 -1
- package/dist/components/motion/availability-scheduler/index.js.map +1 -1
- package/dist/components/motion/bloom-menu.js +1 -1
- package/dist/components/motion/bloom-menu.js.map +1 -1
- package/dist/components/motion/bottom-sheet.js +1 -1
- package/dist/components/motion/bottom-sheet.js.map +1 -1
- package/dist/components/motion/bounce-sidebar.d.ts.map +1 -1
- package/dist/components/motion/bounce-sidebar.js +1 -1
- package/dist/components/motion/bounce-sidebar.js.map +1 -1
- package/dist/components/motion/bouncy-accordion.js +1 -1
- package/dist/components/motion/bouncy-accordion.js.map +1 -1
- package/dist/components/motion/button/base.js +1 -1
- package/dist/components/motion/button/base.js.map +1 -1
- package/dist/components/motion/button/metallic.js +1 -1
- package/dist/components/motion/button/metallic.js.map +1 -1
- package/dist/components/motion/card-folder.js +1 -1
- package/dist/components/motion/card-folder.js.map +1 -1
- package/dist/components/motion/center-morph-modal.js +1 -1
- package/dist/components/motion/center-morph-modal.js.map +1 -1
- package/dist/components/motion/checkbox.js +1 -1
- package/dist/components/motion/checkbox.js.map +1 -1
- package/dist/components/motion/chromatic-text-reveal.js +1 -1
- package/dist/components/motion/chromatic-text-reveal.js.map +1 -1
- package/dist/components/motion/combobox/content.js +1 -1
- package/dist/components/motion/combobox/content.js.map +1 -1
- package/dist/components/motion/combobox/context.js +1 -1
- package/dist/components/motion/combobox/context.js.map +1 -1
- package/dist/components/motion/combobox/list.js +1 -1
- package/dist/components/motion/combobox/list.js.map +1 -1
- package/dist/components/motion/combobox/trigger.js +1 -1
- package/dist/components/motion/combobox/trigger.js.map +1 -1
- package/dist/components/motion/command-palette.d.ts.map +1 -1
- package/dist/components/motion/command-palette.js +3 -22
- package/dist/components/motion/command-palette.js.map +1 -1
- package/dist/components/motion/context-menu.js +1 -1
- package/dist/components/motion/context-menu.js.map +1 -1
- package/dist/components/motion/cylinder-carousel.js +1 -1
- package/dist/components/motion/cylinder-carousel.js.map +1 -1
- package/dist/components/motion/digit-swap.js +1 -1
- package/dist/components/motion/digit-swap.js.map +1 -1
- package/dist/components/motion/dock.js +1 -1
- package/dist/components/motion/dock.js.map +1 -1
- package/dist/components/motion/drawer.js +1 -1
- package/dist/components/motion/drawer.js.map +1 -1
- package/dist/components/motion/dynamic-island.js +1 -1
- package/dist/components/motion/dynamic-island.js.map +1 -1
- package/dist/components/motion/expandable-action-bar.js +1 -1
- package/dist/components/motion/expandable-action-bar.js.map +1 -1
- package/dist/components/motion/expandable-control.d.ts.map +1 -1
- package/dist/components/motion/expandable-control.js +1 -1
- package/dist/components/motion/expandable-control.js.map +1 -1
- package/dist/components/motion/expandable-tabs.js +1 -1
- package/dist/components/motion/expandable-tabs.js.map +1 -1
- package/dist/components/motion/expanding-arrow-button.js +1 -1
- package/dist/components/motion/expanding-arrow-button.js.map +1 -1
- package/dist/components/motion/feedback-widget.js +1 -1
- package/dist/components/motion/feedback-widget.js.map +1 -1
- package/dist/components/motion/file-tree.js +1 -1
- package/dist/components/motion/file-tree.js.map +1 -1
- package/dist/components/motion/file-upload.js +1 -1
- package/dist/components/motion/file-upload.js.map +1 -1
- package/dist/components/motion/hold-action-button.js +1 -1
- package/dist/components/motion/hold-action-button.js.map +1 -1
- package/dist/components/motion/infinite-masonry.js +1 -1
- package/dist/components/motion/infinite-masonry.js.map +1 -1
- package/dist/components/motion/input.d.ts.map +1 -1
- package/dist/components/motion/input.js +1 -1
- package/dist/components/motion/input.js.map +1 -1
- package/dist/components/motion/liquid.js +1 -1
- package/dist/components/motion/liquid.js.map +1 -1
- package/dist/components/motion/loader.js +1 -1
- package/dist/components/motion/loader.js.map +1 -1
- package/dist/components/motion/magnetic.js +1 -1
- package/dist/components/motion/magnetic.js.map +1 -1
- package/dist/components/motion/marquee.d.ts.map +1 -1
- package/dist/components/motion/marquee.js +1 -1
- package/dist/components/motion/marquee.js.map +1 -1
- package/dist/components/motion/morphing-modal.js +1 -1
- package/dist/components/motion/morphing-modal.js.map +1 -1
- package/dist/components/motion/morphing-search.js +1 -1
- package/dist/components/motion/morphing-search.js.map +1 -1
- package/dist/components/motion/morphing-tabs.js +1 -1
- package/dist/components/motion/morphing-tabs.js.map +1 -1
- package/dist/components/motion/multi-select/content.js +1 -1
- package/dist/components/motion/multi-select/content.js.map +1 -1
- package/dist/components/motion/multi-select/context.js +1 -1
- package/dist/components/motion/multi-select/context.js.map +1 -1
- package/dist/components/motion/multi-select/list.js +1 -1
- package/dist/components/motion/multi-select/list.js.map +1 -1
- package/dist/components/motion/multi-select/trigger.js +1 -1
- package/dist/components/motion/multi-select/trigger.js.map +1 -1
- package/dist/components/motion/not-found/magnetic.d.ts.map +1 -1
- package/dist/components/motion/not-found/magnetic.js +1 -1
- package/dist/components/motion/not-found/magnetic.js.map +1 -1
- package/dist/components/motion/not-found/shared.js +1 -1
- package/dist/components/motion/not-found/shared.js.map +1 -1
- package/dist/components/motion/not-found/spotlight.js +1 -1
- package/dist/components/motion/not-found/spotlight.js.map +1 -1
- package/dist/components/motion/notification-stack.js +1 -1
- package/dist/components/motion/notification-stack.js.map +1 -1
- package/dist/components/motion/number-ticker.js +1 -1
- package/dist/components/motion/number-ticker.js.map +1 -1
- package/dist/components/motion/otp-input.js +1 -1
- package/dist/components/motion/otp-input.js.map +1 -1
- package/dist/components/motion/overflow-actions.js +1 -1
- package/dist/components/motion/overflow-actions.js.map +1 -1
- package/dist/components/motion/parallax.d.ts.map +1 -1
- package/dist/components/motion/parallax.js +1 -1
- package/dist/components/motion/parallax.js.map +1 -1
- package/dist/components/motion/popover-morph.js +1 -1
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/popover.js +1 -1
- package/dist/components/motion/popover.js.map +1 -1
- package/dist/components/motion/preview-rail.js +1 -1
- package/dist/components/motion/preview-rail.js.map +1 -1
- package/dist/components/motion/project-folder.js +1 -1
- package/dist/components/motion/project-folder.js.map +1 -1
- package/dist/components/motion/pull-to-refresh.js +1 -1
- package/dist/components/motion/pull-to-refresh.js.map +1 -1
- package/dist/components/motion/radio.js +1 -1
- package/dist/components/motion/radio.js.map +1 -1
- package/dist/components/motion/range-slider-bubble.js +1 -1
- package/dist/components/motion/range-slider-bubble.js.map +1 -1
- package/dist/components/motion/range-slider-fluid.js +1 -1
- package/dist/components/motion/range-slider-fluid.js.map +1 -1
- package/dist/components/motion/range-slider-inline.d.ts +18 -0
- package/dist/components/motion/range-slider-inline.d.ts.map +1 -0
- package/dist/components/motion/range-slider-inline.js +267 -0
- package/dist/components/motion/range-slider-inline.js.map +1 -0
- package/dist/components/motion/range-slider-ruler.js +1 -1
- package/dist/components/motion/range-slider-ruler.js.map +1 -1
- package/dist/components/motion/range-slider-wave.js +1 -1
- package/dist/components/motion/range-slider-wave.js.map +1 -1
- package/dist/components/motion/range-slider.d.ts.map +1 -1
- package/dist/components/motion/range-slider.js +27 -11
- package/dist/components/motion/range-slider.js.map +1 -1
- package/dist/components/motion/scroll-progress.js +1 -1
- package/dist/components/motion/scroll-progress.js.map +1 -1
- package/dist/components/motion/scroll-reveal.js +1 -1
- package/dist/components/motion/scroll-reveal.js.map +1 -1
- package/dist/components/motion/scroll-to.js +1 -1
- package/dist/components/motion/scroll-to.js.map +1 -1
- package/dist/components/motion/select-morph.d.ts.map +1 -1
- package/dist/components/motion/select-morph.js +1 -1
- package/dist/components/motion/select-morph.js.map +1 -1
- package/dist/components/motion/select.js +1 -1
- package/dist/components/motion/select.js.map +1 -1
- package/dist/components/motion/shader-background.d.ts.map +1 -1
- package/dist/components/motion/shader-background.js +1 -1
- package/dist/components/motion/shader-background.js.map +1 -1
- package/dist/components/motion/shared-layout-bg.js +1 -1
- package/dist/components/motion/shared-layout-bg.js.map +1 -1
- package/dist/components/motion/signup-form.js +1 -1
- package/dist/components/motion/signup-form.js.map +1 -1
- package/dist/components/motion/slide-action-button.js +1 -1
- package/dist/components/motion/slide-action-button.js.map +1 -1
- package/dist/components/motion/swipeable-list.js +1 -1
- package/dist/components/motion/swipeable-list.js.map +1 -1
- package/dist/components/motion/switch.d.ts.map +1 -1
- package/dist/components/motion/switch.js +1 -1
- package/dist/components/motion/switch.js.map +1 -1
- package/dist/components/motion/table/index.js +1 -1
- package/dist/components/motion/table/index.js.map +1 -1
- package/dist/components/motion/table/skeleton-rows.d.ts.map +1 -1
- package/dist/components/motion/table/skeleton-rows.js +1 -1
- package/dist/components/motion/table/skeleton-rows.js.map +1 -1
- package/dist/components/motion/table/table-header.js +1 -1
- package/dist/components/motion/table/table-header.js.map +1 -1
- package/dist/components/motion/table/table-menu.js +1 -1
- package/dist/components/motion/table/table-menu.js.map +1 -1
- package/dist/components/motion/tabs.js +2 -2
- package/dist/components/motion/tabs.js.map +1 -1
- package/dist/components/motion/text-reveal.js +1 -1
- package/dist/components/motion/text-reveal.js.map +1 -1
- package/dist/components/motion/text-scramble.d.ts.map +1 -1
- package/dist/components/motion/text-scramble.js +1 -1
- package/dist/components/motion/text-scramble.js.map +1 -1
- package/dist/components/motion/text-shimmer.js +1 -1
- package/dist/components/motion/text-shimmer.js.map +1 -1
- package/dist/components/motion/theme-toggle.js +1 -1
- package/dist/components/motion/theme-toggle.js.map +1 -1
- package/dist/components/motion/tilt-card.js +1 -1
- package/dist/components/motion/tilt-card.js.map +1 -1
- package/dist/components/motion/tooltip-surface.d.ts +12 -0
- package/dist/components/motion/tooltip-surface.d.ts.map +1 -0
- package/dist/components/motion/tooltip-surface.js +97 -0
- package/dist/components/motion/tooltip-surface.js.map +1 -0
- package/dist/components/motion/tooltip.d.ts +13 -3
- package/dist/components/motion/tooltip.d.ts.map +1 -1
- package/dist/components/motion/tooltip.js +75 -104
- package/dist/components/motion/tooltip.js.map +1 -1
- package/dist/components/motion/wheel-picker.js +1 -1
- package/dist/components/motion/wheel-picker.js.map +1 -1
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/alert.d.ts.map +1 -1
- package/dist/components/reui/alert.js +1 -1
- package/dist/components/reui/alert.js.map +1 -1
- package/dist/components/reui/autocomplete.d.ts +1 -1
- package/dist/components/reui/autocomplete.d.ts.map +1 -1
- package/dist/components/reui/autocomplete.js +2 -2
- package/dist/components/reui/autocomplete.js.map +1 -1
- package/dist/components/reui/badge.d.ts +2 -2
- package/dist/components/reui/badge.d.ts.map +1 -1
- package/dist/components/reui/badge.js +1 -1
- package/dist/components/reui/badge.js.map +1 -1
- package/dist/components/reui/cascader/cascader-columns.js +1 -1
- package/dist/components/reui/cascader/cascader-columns.js.map +1 -1
- package/dist/components/reui/cascader/cascader-footer.js +1 -1
- package/dist/components/reui/cascader/cascader-footer.js.map +1 -1
- package/dist/components/reui/cascader/cascader-item.js +1 -1
- package/dist/components/reui/cascader/cascader-item.js.map +1 -1
- package/dist/components/reui/cascader/cascader-nav.js +1 -1
- package/dist/components/reui/cascader/cascader-nav.js.map +1 -1
- package/dist/components/reui/cascader/cascader.js +1 -1
- package/dist/components/reui/cascader/cascader.js.map +1 -1
- package/dist/components/reui/code-block/code-block.js +1 -1
- package/dist/components/reui/code-block/code-block.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-cell-selection.js +1 -1
- package/dist/components/reui/data-grid/data-grid-cell-selection.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-filter.js +1 -1
- package/dist/components/reui/data-grid/data-grid-column-filter.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.js +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-pagination.js +1 -1
- package/dist/components/reui/data-grid/data-grid-pagination.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.js +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.js +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.js +1 -1
- package/dist/components/reui/data-grid/data-grid-table.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid.js +1 -1
- package/dist/components/reui/data-grid/data-grid.js.map +1 -1
- package/dist/components/reui/date-selector.js +1 -1
- package/dist/components/reui/date-selector.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-agenda-view.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-agenda-view.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-content.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-content.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-event.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-event.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-month-view.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-month-view.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-nav.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-nav.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-resource-view.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-resource-view.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-time-grid.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-time-grid.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar.js.map +1 -1
- package/dist/components/reui/filters/filters-advanced.js +1 -1
- package/dist/components/reui/filters/filters-advanced.js.map +1 -1
- package/dist/components/reui/filters/filters-builder.js +1 -1
- package/dist/components/reui/filters/filters-builder.js.map +1 -1
- package/dist/components/reui/filters/filters-chip.js +1 -1
- package/dist/components/reui/filters/filters-chip.js.map +1 -1
- package/dist/components/reui/filters/filters-editors.js +1 -1
- package/dist/components/reui/filters/filters-editors.js.map +1 -1
- package/dist/components/reui/filters/filters.js +1 -1
- package/dist/components/reui/filters/filters.js.map +1 -1
- package/dist/components/reui/frame.d.ts +6 -12
- package/dist/components/reui/frame.d.ts.map +1 -1
- package/dist/components/reui/frame.js +10 -17
- package/dist/components/reui/frame.js.map +1 -1
- package/dist/components/reui/gantt/gantt-bar.js +1 -1
- package/dist/components/reui/gantt/gantt-bar.js.map +1 -1
- package/dist/components/reui/gantt/gantt-nav.js +1 -1
- package/dist/components/reui/gantt/gantt-nav.js.map +1 -1
- package/dist/components/reui/gantt/gantt-view.js +1 -1
- package/dist/components/reui/gantt/gantt-view.js.map +1 -1
- package/dist/components/reui/gantt/gantt.js +1 -1
- package/dist/components/reui/gantt/gantt.js.map +1 -1
- package/dist/components/reui/icon-stack.js +1 -1
- package/dist/components/reui/icon-stack.js.map +1 -1
- package/dist/components/reui/icon-tile.d.ts +2 -2
- package/dist/components/reui/icon-tile.d.ts.map +1 -1
- package/dist/components/reui/icon-tile.js +1 -1
- package/dist/components/reui/icon-tile.js.map +1 -1
- package/dist/components/reui/kanban.d.ts.map +1 -1
- package/dist/components/reui/kanban.js +1 -1
- package/dist/components/reui/kanban.js.map +1 -1
- package/dist/components/reui/number-field.d.ts +3 -3
- package/dist/components/reui/number-field.d.ts.map +1 -1
- package/dist/components/reui/number-field.js +4 -4
- package/dist/components/reui/number-field.js.map +1 -1
- package/dist/components/reui/phone-input.js +1 -1
- package/dist/components/reui/phone-input.js.map +1 -1
- package/dist/components/reui/rating.d.ts +1 -1
- package/dist/components/reui/rating.d.ts.map +1 -1
- package/dist/components/reui/rating.js +1 -1
- package/dist/components/reui/rating.js.map +1 -1
- package/dist/components/reui/sortable.d.ts.map +1 -1
- package/dist/components/reui/sortable.js +1 -1
- package/dist/components/reui/sortable.js.map +1 -1
- package/dist/components/reui/stepper.d.ts.map +1 -1
- package/dist/components/reui/stepper.js +1 -1
- package/dist/components/reui/stepper.js.map +1 -1
- package/dist/components/reui/timeline.d.ts.map +1 -1
- package/dist/components/reui/timeline.js +1 -1
- package/dist/components/reui/timeline.js.map +1 -1
- package/dist/components/reui/tree.d.ts.map +1 -1
- package/dist/components/reui/tree.js +1 -1
- package/dist/components/reui/tree.js.map +1 -1
- package/dist/components/ui/accordion.d.ts.map +1 -1
- package/dist/components/ui/accordion.js +1 -1
- package/dist/components/ui/accordion.js.map +1 -1
- package/dist/components/ui/alert-dialog.js +1 -1
- package/dist/components/ui/alert-dialog.js.map +1 -1
- package/dist/components/ui/alert.d.ts.map +1 -1
- package/dist/components/ui/alert.js +1 -1
- package/dist/components/ui/alert.js.map +1 -1
- package/dist/components/ui/aspect-ratio.js +1 -1
- package/dist/components/ui/aspect-ratio.js.map +1 -1
- package/dist/components/ui/attachment.d.ts +1 -1
- package/dist/components/ui/attachment.js +1 -1
- package/dist/components/ui/attachment.js.map +1 -1
- package/dist/components/ui/avatar.d.ts.map +1 -1
- package/dist/components/ui/avatar.js +1 -1
- package/dist/components/ui/avatar.js.map +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/badge.d.ts.map +1 -1
- package/dist/components/ui/badge.js +1 -1
- package/dist/components/ui/badge.js.map +1 -1
- package/dist/components/ui/breadcrumb.d.ts.map +1 -1
- package/dist/components/ui/breadcrumb.js +1 -1
- package/dist/components/ui/breadcrumb.js.map +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts.map +1 -1
- package/dist/components/ui/bubble.js +1 -1
- package/dist/components/ui/bubble.js.map +1 -1
- package/dist/components/ui/button-group.js +1 -1
- package/dist/components/ui/button-group.js.map +1 -1
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/button.js.map +1 -1
- package/dist/components/ui/calendar.js +1 -1
- package/dist/components/ui/calendar.js.map +1 -1
- package/dist/components/ui/card.d.ts.map +1 -1
- package/dist/components/ui/card.js +1 -1
- package/dist/components/ui/card.js.map +1 -1
- package/dist/components/ui/carousel.js +1 -1
- package/dist/components/ui/carousel.js.map +1 -1
- package/dist/components/ui/chart.d.ts.map +1 -1
- package/dist/components/ui/chart.js +1 -1
- package/dist/components/ui/chart.js.map +1 -1
- package/dist/components/ui/checkbox.d.ts.map +1 -1
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/checkbox.js.map +1 -1
- package/dist/components/ui/combobox.js +1 -1
- package/dist/components/ui/combobox.js.map +1 -1
- package/dist/components/ui/command.js +1 -1
- package/dist/components/ui/command.js.map +1 -1
- package/dist/components/ui/context-menu.d.ts.map +1 -1
- package/dist/components/ui/context-menu.js +1 -1
- package/dist/components/ui/context-menu.js.map +1 -1
- package/dist/components/ui/dialog.js +1 -1
- package/dist/components/ui/dialog.js.map +1 -1
- package/dist/components/ui/drawer.d.ts.map +1 -1
- package/dist/components/ui/drawer.js +1 -1
- package/dist/components/ui/drawer.js.map +1 -1
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
- package/dist/components/ui/dropdown-menu.js +1 -1
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/empty.d.ts.map +1 -1
- package/dist/components/ui/empty.js +1 -1
- package/dist/components/ui/empty.js.map +1 -1
- package/dist/components/ui/field.js +1 -1
- package/dist/components/ui/field.js.map +1 -1
- package/dist/components/ui/hover-card.d.ts.map +1 -1
- package/dist/components/ui/hover-card.js +1 -1
- package/dist/components/ui/hover-card.js.map +1 -1
- package/dist/components/ui/input-group.d.ts +1 -1
- package/dist/components/ui/input-group.js +1 -1
- package/dist/components/ui/input-group.js.map +1 -1
- package/dist/components/ui/input-otp.d.ts.map +1 -1
- package/dist/components/ui/input-otp.js +1 -1
- package/dist/components/ui/input-otp.js.map +1 -1
- package/dist/components/ui/input.d.ts.map +1 -1
- package/dist/components/ui/input.js +1 -1
- package/dist/components/ui/input.js.map +1 -1
- package/dist/components/ui/item.d.ts +2 -2
- package/dist/components/ui/item.js +1 -1
- package/dist/components/ui/item.js.map +1 -1
- package/dist/components/ui/kbd.js +1 -1
- package/dist/components/ui/kbd.js.map +1 -1
- package/dist/components/ui/label.d.ts.map +1 -1
- package/dist/components/ui/label.js +1 -1
- package/dist/components/ui/label.js.map +1 -1
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/marker.d.ts.map +1 -1
- package/dist/components/ui/marker.js +1 -1
- package/dist/components/ui/marker.js.map +1 -1
- package/dist/components/ui/menubar.js +1 -1
- package/dist/components/ui/menubar.js.map +1 -1
- package/dist/components/ui/message-scroller.js +1 -1
- package/dist/components/ui/message-scroller.js.map +1 -1
- package/dist/components/ui/message.d.ts.map +1 -1
- package/dist/components/ui/message.js +1 -1
- package/dist/components/ui/message.js.map +1 -1
- package/dist/components/ui/native-select.d.ts.map +1 -1
- package/dist/components/ui/native-select.js +1 -1
- package/dist/components/ui/native-select.js.map +1 -1
- package/dist/components/ui/navigation-menu.d.ts.map +1 -1
- package/dist/components/ui/navigation-menu.js +1 -1
- package/dist/components/ui/navigation-menu.js.map +1 -1
- package/dist/components/ui/pagination.js +1 -1
- package/dist/components/ui/pagination.js.map +1 -1
- package/dist/components/ui/popover.d.ts.map +1 -1
- package/dist/components/ui/popover.js +1 -1
- package/dist/components/ui/popover.js.map +1 -1
- package/dist/components/ui/progress.d.ts.map +1 -1
- package/dist/components/ui/progress.js +1 -1
- package/dist/components/ui/progress.js.map +1 -1
- package/dist/components/ui/questionnaire.js +1 -1
- package/dist/components/ui/questionnaire.js.map +1 -1
- package/dist/components/ui/radio-group.d.ts.map +1 -1
- package/dist/components/ui/radio-group.js +1 -1
- package/dist/components/ui/radio-group.js.map +1 -1
- package/dist/components/ui/resizable.d.ts.map +1 -1
- package/dist/components/ui/resizable.js +1 -1
- package/dist/components/ui/resizable.js.map +1 -1
- package/dist/components/ui/scroll-area.d.ts.map +1 -1
- package/dist/components/ui/scroll-area.js +1 -1
- package/dist/components/ui/scroll-area.js.map +1 -1
- package/dist/components/ui/select.d.ts.map +1 -1
- package/dist/components/ui/select.js +1 -1
- package/dist/components/ui/select.js.map +1 -1
- package/dist/components/ui/separator.d.ts.map +1 -1
- package/dist/components/ui/separator.js +1 -1
- package/dist/components/ui/separator.js.map +1 -1
- package/dist/components/ui/sheet.js +1 -1
- package/dist/components/ui/sheet.js.map +1 -1
- package/dist/components/ui/sidebar.d.ts +1 -1
- package/dist/components/ui/sidebar.js +1 -1
- package/dist/components/ui/sidebar.js.map +1 -1
- package/dist/components/ui/skeleton.js +1 -1
- package/dist/components/ui/skeleton.js.map +1 -1
- package/dist/components/ui/slider.d.ts.map +1 -1
- package/dist/components/ui/slider.js +1 -1
- package/dist/components/ui/slider.js.map +1 -1
- package/dist/components/ui/spinner.d.ts.map +1 -1
- package/dist/components/ui/spinner.js +1 -1
- package/dist/components/ui/spinner.js.map +1 -1
- package/dist/components/ui/switch.d.ts.map +1 -1
- package/dist/components/ui/switch.js +1 -1
- package/dist/components/ui/switch.js.map +1 -1
- package/dist/components/ui/table.d.ts.map +1 -1
- package/dist/components/ui/table.js +1 -1
- package/dist/components/ui/table.js.map +1 -1
- package/dist/components/ui/tabs.d.ts +1 -1
- package/dist/components/ui/tabs.d.ts.map +1 -1
- package/dist/components/ui/tabs.js +1 -1
- package/dist/components/ui/tabs.js.map +1 -1
- package/dist/components/ui/textarea.d.ts.map +1 -1
- package/dist/components/ui/textarea.js +1 -1
- package/dist/components/ui/textarea.js.map +1 -1
- package/dist/components/ui/toast.js +1 -1
- package/dist/components/ui/toast.js.map +1 -1
- package/dist/components/ui/toggle-group.js +1 -1
- package/dist/components/ui/toggle-group.js.map +1 -1
- package/dist/components/ui/toggle.d.ts +1 -1
- package/dist/components/ui/toggle.d.ts.map +1 -1
- package/dist/components/ui/toggle.js +1 -1
- package/dist/components/ui/toggle.js.map +1 -1
- package/dist/components/ui/tooltip.d.ts.map +1 -1
- package/dist/components/ui/tooltip.js +1 -1
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/hooks/use-dismiss.d.ts +1 -1
- package/dist/hooks/use-dismiss.d.ts.map +1 -1
- package/dist/hooks/use-dismiss.js.map +1 -1
- package/dist/lib/command-search.d.ts +10 -0
- package/dist/lib/command-search.d.ts.map +1 -0
- package/dist/lib/command-search.js +52 -0
- package/dist/lib/command-search.js.map +1 -0
- package/package.json +10 -12
|
@@ -6,7 +6,7 @@ import { Separator } from "../../ui/separator.js";
|
|
|
6
6
|
import { Popover, PopoverContent, PopoverTrigger } from "../../ui/popover.js";
|
|
7
7
|
import { useDataGrid } from "./data-grid.js";
|
|
8
8
|
import { useMemo, useState } from "react";
|
|
9
|
-
import { cn } from "
|
|
9
|
+
import { cn } from "@kumix/utils";
|
|
10
10
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { CheckIcon, CirclePlusIcon } from "lucide-react";
|
|
12
12
|
//#region src/components/reui/data-grid/data-grid-column-filter.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-grid-column-filter.js","names":[],"sources":["../../../../src/components/reui/data-grid/data-grid-column-filter.tsx"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport type { Column } from \"@tanstack/react-table\";\nimport {
|
|
1
|
+
{"version":3,"file":"data-grid-column-filter.js","names":[],"sources":["../../../../src/components/reui/data-grid/data-grid-column-filter.tsx"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport type { Column } from \"@tanstack/react-table\";\nimport { CheckIcon, CirclePlusIcon } from \"lucide-react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { Button } from \"../../ui/button\";\nimport { Input } from \"../../ui/input\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../../ui/popover\";\nimport { Separator } from \"../../ui/separator\";\nimport { Badge } from \"../badge\";\nimport type { DataGridFeatures } from \"./data-grid\";\nimport { useDataGrid } from \"./data-grid\";\n\ninterface DataGridColumnFilterProps<TData extends object, TValue> {\n column?: Column<DataGridFeatures, TData, TValue>;\n title?: string;\n options: {\n label: string;\n value: string;\n icon?: React.ComponentType<{ className?: string }>;\n }[];\n}\n\nfunction DataGridColumnFilter<TData extends object, TValue>({\n column,\n title,\n options,\n}: DataGridColumnFilterProps<TData, TValue>) {\n const { i18n } = useDataGrid();\n const facets = column?.getFacetedUniqueValues();\n const filterValue = column?.getFilterValue();\n const selectedValues = new Set(Array.isArray(filterValue) ? (filterValue as string[]) : []);\n const [searchQuery, setSearchQuery] = useState(\"\");\n\n const filteredOptions = useMemo(() => {\n if (!searchQuery) return options;\n return options.filter((option) =>\n option.label.toLowerCase().includes(searchQuery.toLowerCase()),\n );\n }, [options, searchQuery]);\n\n return (\n <Popover>\n <PopoverTrigger\n render={\n <Button variant=\"outline\" size=\"sm\">\n <CirclePlusIcon className=\"size-4\" />\n {title}\n {selectedValues?.size > 0 && (\n <>\n <Separator orientation=\"vertical\" className=\"mx-2 h-4\" />\n <Badge variant=\"secondary\" className=\"px-1 font-normal lg:hidden\">\n {selectedValues.size}\n </Badge>\n <div className=\"hidden space-x-1 lg:flex\">\n {selectedValues.size > 2 ? (\n <Badge variant=\"secondary\" className=\"px-1 font-normal\">\n {i18n.labels.filterSelectedCount(selectedValues.size)}\n </Badge>\n ) : (\n options\n .filter((option) => selectedValues.has(option.value))\n .map((option) => (\n <Badge variant=\"secondary\" key={option.value} className=\"px-1 font-normal\">\n {option.label}\n </Badge>\n ))\n )}\n </div>\n </>\n )}\n </Button>\n }\n />\n <PopoverContent className=\"w-[200px] p-0\" align=\"start\">\n <div className=\"p-2\">\n <Input\n placeholder={title}\n value={searchQuery}\n onChange={(e) => setSearchQuery(e.target.value)}\n className=\"h-8\"\n />\n </div>\n <div className=\"max-h-[300px] overflow-y-auto\">\n {filteredOptions.length === 0 ? (\n <div className=\"py-6 text-center text-muted-foreground text-sm\">\n {i18n.labels.filterNoResults}\n </div>\n ) : (\n <div className=\"p-1\">\n {filteredOptions.map((option) => {\n const isSelected = selectedValues.has(option.value);\n const facetCount = facets?.get(option.value);\n const toggleOption = () => {\n if (isSelected) {\n selectedValues.delete(option.value);\n } else {\n selectedValues.add(option.value);\n }\n const filterValues = Array.from(selectedValues);\n column?.setFilterValue(filterValues.length ? filterValues : undefined);\n };\n return (\n <div\n key={option.value}\n role=\"button\"\n tabIndex={0}\n aria-pressed={isSelected}\n onClick={toggleOption}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n toggleOption();\n }\n }}\n className={cn(\n \"relative flex cursor-pointer select-none items-center gap-2 rounded-md px-2 py-1.5 text-sm outline-hidden\",\n \"hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground\",\n )}\n >\n <div\n className={cn(\n \"flex h-4 w-4 items-center justify-center rounded-sm border border-primary\",\n isSelected\n ? \"bg-primary text-primary-foreground\"\n : \"opacity-50 [&_svg]:invisible\",\n )}\n >\n <CheckIcon className=\"h-4 w-4\" />\n </div>\n {option.icon && <option.icon className=\"h-4 w-4 text-muted-foreground\" />}\n <span>{option.label}</span>\n {facetCount !== undefined && (\n <span className=\"ms-auto flex h-4 w-4 items-center justify-center font-mono text-xs\">\n {facetCount}\n </span>\n )}\n </div>\n );\n })}\n </div>\n )}\n {selectedValues.size > 0 && (\n <>\n <div className=\"-mx-1 my-1 h-px bg-border\" />\n <div className=\"p-1\">\n <div\n role=\"button\"\n tabIndex={0}\n onClick={() => column?.setFilterValue(undefined)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n column?.setFilterValue(undefined);\n }\n }}\n className=\"relative flex cursor-pointer select-none items-center justify-center rounded-md px-2 py-1.5 text-sm outline-hidden hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground\"\n >\n {i18n.labels.filterClear}\n </div>\n </div>\n </>\n )}\n </div>\n </PopoverContent>\n </Popover>\n );\n}\n\nexport { DataGridColumnFilter, type DataGridColumnFilterProps };\n"],"mappings":";;;;;;;;;;;;AAyBA,SAAS,qBAAmD,EAC1D,QACA,OACA,WAC2C;CAC3C,MAAM,EAAE,SAAS,YAAY;CAC7B,MAAM,SAAS,QAAQ,uBAAuB;CAC9C,MAAM,cAAc,QAAQ,eAAe;CAC3C,MAAM,iBAAiB,IAAI,IAAI,MAAM,QAAQ,WAAW,IAAK,cAA2B,CAAC,CAAC;CAC1F,MAAM,CAAC,aAAa,kBAAkB,SAAS,EAAE;CAEjD,MAAM,kBAAkB,cAAc;EACpC,IAAI,CAAC,aAAa,OAAO;EACzB,OAAO,QAAQ,QAAQ,WACrB,OAAO,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,YAAY,CAAC,CAC/D;CACF,GAAG,CAAC,SAAS,WAAW,CAAC;CAEzB,OACE,qBAAC,SAAD,EAAA,UAAA,CACE,oBAAC,gBAAD,EACE,QACE,qBAAC,QAAD;EAAQ,SAAQ;EAAU,MAAK;EAA/B,UAAA;GACE,oBAAC,gBAAD,EAAgB,WAAU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AAe,KAAA,CAAS;KACvE;KACA,OACE,qBAAC,OAAD;MAEE,MAAK;MACL,UAAU;MACV,gBAAc;MACd,SAAS;MACT,YAAY,MAAM;OAChB,IAAI,EAAE,QAAQ,WAAW,EAAE,QAAQ,KAAK;QACtC,EAAE,eAAe;QACjB,aAAa;OACf;MACF;MACA,WAAW,GACT,6GACA,2FACF;MAfF,UAAA;OAiBE,oBAAC,OAAD;QACE,WAAW,GACT,6EACA,aACI,uCACA,8BACN;QAEA,UAAA,oBAAC,WAAD,EAAW,WAAU,UAAW,CAAA;OAC7B,CAAA;OACJ,OAAO,QAAQ,oBAAC,OAAO,MAAR,EAAa,WAAU,gCAAiC,CAAA;OACxE,oBAAC,QAAD,EAAA,UAAO,OAAO,MAAY,CAAA;OACzB,eAAe,KAAA,KACd,oBAAC,QAAD;QAAM,WAAU;QACb,UAAA;OACG,CAAA;MAEL;KAjCE,GAAA,OAAO,KAiCT;IAET,CAAC;GACE,CAAA,GAEN,eAAe,OAAO,KACrB,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,OAAD,EAAK,WAAU,4BAA6B,CAAA,GAC5C,oBAAC,OAAD;IAAK,WAAU;IACb,UAAA,oBAAC,OAAD;KACE,MAAK;KACL,UAAU;KACV,eAAe,QAAQ,eAAe,KAAA,CAAS;KAC/C,YAAY,MAAM;MAChB,IAAI,EAAE,QAAQ,WAAW,EAAE,QAAQ,KAAK;OACtC,EAAE,eAAe;OACjB,QAAQ,eAAe,KAAA,CAAS;MAClC;KACF;KACA,WAAU;KAET,UAAA,KAAK,OAAO;IACV,CAAA;GACF,CAAA,CACL,EAAA,CAAA,CAED;EACS,CAAA,CAAA;CACT,CAAA,CAAA,EAAA,CAAA;AAEb"}
|
|
@@ -3,7 +3,7 @@ import { Button } from "../../ui/button.js";
|
|
|
3
3
|
import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger } from "../../ui/dropdown-menu.js";
|
|
4
4
|
import { getColumnHeaderLabel, useDataGrid } from "./data-grid.js";
|
|
5
5
|
import { memo, useMemo } from "react";
|
|
6
|
-
import { cn } from "
|
|
6
|
+
import { cn } from "@kumix/utils";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { ArrowDownIcon, ArrowLeftIcon, ArrowLeftToLineIcon, ArrowRightIcon, ArrowRightToLineIcon, ArrowUpIcon, CheckIcon, ChevronsUpDownIcon, PinOffIcon, Settings2Icon } from "lucide-react";
|
|
9
9
|
import { Subscribe } from "@tanstack/react-table";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-grid-column-header.js","names":[],"sources":["../../../../src/components/reui/data-grid/data-grid-column-header.tsx"],"sourcesContent":["\"use client\";\n\nimport type { HTMLAttributes, ReactNode } from \"react\";\nimport { memo, useMemo } from \"react\";\nimport type { Column } from \"@tanstack/react-table\";\nimport { Subscribe } from \"@tanstack/react-table\";\nimport { cn } from \"cn\";\nimport {\n ArrowDownIcon,\n ArrowLeftIcon,\n ArrowLeftToLineIcon,\n ArrowRightIcon,\n ArrowRightToLineIcon,\n ArrowUpIcon,\n CheckIcon,\n ChevronsUpDownIcon,\n PinOffIcon,\n Settings2Icon,\n} from \"lucide-react\";\n\nimport { Button } from \"../../ui/button\";\nimport {\n DropdownMenu,\n DropdownMenuCheckboxItem,\n DropdownMenuContent,\n DropdownMenuGroup,\n DropdownMenuItem,\n DropdownMenuLabel,\n DropdownMenuSeparator,\n DropdownMenuSub,\n DropdownMenuSubContent,\n DropdownMenuSubTrigger,\n DropdownMenuTrigger,\n} from \"../../ui/dropdown-menu\";\nimport type { DataGridFeatures } from \"./data-grid\";\nimport { getColumnHeaderLabel, useDataGrid } from \"./data-grid\";\n\ninterface DataGridColumnHeaderProps<TData extends object, TValue>\n extends HTMLAttributes<HTMLDivElement> {\n column: Column<DataGridFeatures, TData, TValue>;\n /** When omitted, uses `column.columnDef.meta.headerTitle`, then a string `columnDef.header`, then `column.id`. */\n title?: string;\n icon?: ReactNode;\n /** Reserved; pin controls are gated by tableLayout.columnsPinnable + column.getCanPin(). */\n pinnable?: boolean;\n filter?: ReactNode;\n visibility?: boolean;\n}\n\nfunction DataGridColumnHeaderInner<TData extends object, TValue>({\n column,\n title,\n icon,\n className,\n filter,\n visibility = false,\n}: DataGridColumnHeaderProps<TData, TValue>) {\n const { i18n, isLoading, table, props } = useDataGrid();\n const resolvedTitle = title ?? getColumnHeaderLabel(column);\n\n // TanStack's columnOrder defaults to [] until a consumer seeds it; fall\n // back to the definition order so Move Left/Right work out of the box.\n const columnOrderState = table.state.columnOrder;\n const columnOrder =\n columnOrderState.length > 0\n ? columnOrderState\n : table.getAllLeafColumns().map((leafColumn) => leafColumn.id);\n const isSorted = column.getIsSorted();\n const isPinned = column.getIsPinned();\n const canSort = column.getCanSort();\n const canPin = column.getCanPin();\n const canResize = column.getCanResize();\n\n const columnIndex = columnOrder.indexOf(column.id);\n const canMoveLeft = columnIndex > 0;\n const canMoveRight = columnIndex < columnOrder.length - 1;\n\n const handleSort = () => {\n if (isSorted === \"asc\") {\n column.toggleSorting(true);\n } else if (isSorted === \"desc\") {\n column.clearSorting();\n } else {\n column.toggleSorting(false);\n }\n };\n\n const headerLabelClassName = cn(\n \"inline-flex h-full items-center gap-1.5 font-normal text-[0.8125rem] text-secondary-foreground/80 leading-[calc(1.125/0.8125)] [&_svg]:size-3.5 [&_svg]:opacity-60\",\n className,\n );\n\n const headerButtonClassName = cn(\n \"h-6 rounded-lg px-2 font-normal text-secondary-foreground/80 hover:bg-secondary hover:text-foreground data-[state=open]:bg-secondary data-[state=open]:text-foreground\",\n className,\n );\n\n const sortIcon =\n canSort &&\n (isSorted === \"desc\" ? (\n <ArrowDownIcon className=\"size-3.25\" aria-hidden=\"true\" />\n ) : isSorted === \"asc\" ? (\n <ArrowUpIcon className=\"size-3.25\" aria-hidden=\"true\" />\n ) : (\n <ChevronsUpDownIcon className=\"mt-px size-3.25\" aria-hidden=\"true\" />\n ));\n\n const hasControls =\n props.tableLayout?.columnsMovable ||\n (props.tableLayout?.columnsVisibility && visibility) ||\n (props.tableLayout?.columnsPinnable && canPin) ||\n filter;\n\n const menuItems = useMemo(() => {\n const items: ReactNode[] = [];\n let hasPreviousSection = false;\n\n // Filter section\n if (filter) {\n items.push(\n <DropdownMenuGroup key=\"group-filter\">\n <DropdownMenuLabel key=\"filter\">{filter}</DropdownMenuLabel>\n </DropdownMenuGroup>,\n );\n hasPreviousSection = true;\n }\n\n // Sort section\n if (canSort) {\n if (hasPreviousSection) {\n items.push(<DropdownMenuSeparator key=\"sep-sort\" />);\n }\n items.push(\n <DropdownMenuItem\n key=\"sort-asc\"\n onClick={() => {\n if (isSorted === \"asc\") {\n column.clearSorting();\n } else {\n column.toggleSorting(false);\n }\n }}\n disabled={!canSort}\n >\n <ArrowUpIcon className=\"size-3.5!\" />\n <span className=\"grow\">{i18n.labels.sortAscending}</span>\n {isSorted === \"asc\" && <CheckIcon className=\"size-4 text-primary opacity-100!\" />}\n </DropdownMenuItem>,\n <DropdownMenuItem\n key=\"sort-desc\"\n onClick={() => {\n if (isSorted === \"desc\") {\n column.clearSorting();\n } else {\n column.toggleSorting(true);\n }\n }}\n disabled={!canSort}\n >\n <ArrowDownIcon className=\"size-3.5!\" />\n <span className=\"grow\">{i18n.labels.sortDescending}</span>\n {isSorted === \"desc\" && <CheckIcon className=\"size-4 text-primary opacity-100!\" />}\n </DropdownMenuItem>,\n );\n hasPreviousSection = true;\n }\n\n // Pin section\n if (props.tableLayout?.columnsPinnable && canPin) {\n if (hasPreviousSection) {\n items.push(<DropdownMenuSeparator key=\"sep-pin\" />);\n }\n items.push(\n <DropdownMenuItem\n key=\"pin-left\"\n onClick={() => column.pin(isPinned === \"start\" ? false : \"start\")}\n >\n <ArrowLeftToLineIcon className=\"size-3.5!\" aria-hidden=\"true\" />\n <span className=\"grow\">{i18n.labels.pinColumnStart}</span>\n {isPinned === \"start\" && <CheckIcon className=\"size-4 text-primary opacity-100!\" />}\n </DropdownMenuItem>,\n <DropdownMenuItem\n key=\"pin-right\"\n onClick={() => column.pin(isPinned === \"end\" ? false : \"end\")}\n >\n <ArrowRightToLineIcon className=\"size-3.5!\" aria-hidden=\"true\" />\n <span className=\"grow\">{i18n.labels.pinColumnEnd}</span>\n {isPinned === \"end\" && <CheckIcon className=\"size-4 text-primary opacity-100!\" />}\n </DropdownMenuItem>,\n );\n hasPreviousSection = true;\n }\n\n // Move section\n if (props.tableLayout?.columnsMovable) {\n if (hasPreviousSection) {\n items.push(<DropdownMenuSeparator key=\"sep-move\" />);\n }\n items.push(\n <DropdownMenuItem\n key=\"move-left\"\n onClick={() => {\n if (columnIndex > 0) {\n const newOrder = [...columnOrder];\n const [movedColumn] = newOrder.splice(columnIndex, 1);\n newOrder.splice(columnIndex - 1, 0, movedColumn);\n table.setColumnOrder(newOrder);\n }\n }}\n disabled={!canMoveLeft || isPinned !== false}\n >\n <ArrowLeftIcon className=\"size-3.5!\" aria-hidden=\"true\" />\n <span>{i18n.labels.moveColumnStart}</span>\n </DropdownMenuItem>,\n <DropdownMenuItem\n key=\"move-right\"\n onClick={() => {\n if (columnIndex < columnOrder.length - 1) {\n const newOrder = [...columnOrder];\n const [movedColumn] = newOrder.splice(columnIndex, 1);\n newOrder.splice(columnIndex + 1, 0, movedColumn);\n table.setColumnOrder(newOrder);\n }\n }}\n disabled={!canMoveRight || isPinned !== false}\n >\n <ArrowRightIcon className=\"size-3.5!\" aria-hidden=\"true\" />\n <span>{i18n.labels.moveColumnEnd}</span>\n </DropdownMenuItem>,\n );\n hasPreviousSection = true;\n }\n\n // Visibility section\n if (props.tableLayout?.columnsVisibility && visibility) {\n if (hasPreviousSection) {\n items.push(<DropdownMenuSeparator key=\"sep-visibility\" />);\n }\n items.push(\n <DropdownMenuSub key=\"visibility\">\n <DropdownMenuSubTrigger>\n <Settings2Icon className=\"size-3.5!\" />\n <span>{i18n.labels.columnsMenu}</span>\n </DropdownMenuSubTrigger>\n <DropdownMenuSubContent side=\"right\">\n {table\n .getAllColumns()\n .filter((col) => col.getCanHide())\n .map((col) => (\n <DropdownMenuCheckboxItem\n key={col.id}\n checked={col.getIsVisible()}\n onSelect={(event) => event.preventDefault()}\n onCheckedChange={(value) => col.toggleVisibility(!!value)}\n className=\"capitalize\"\n >\n {getColumnHeaderLabel(col)}\n </DropdownMenuCheckboxItem>\n ))}\n </DropdownMenuSubContent>\n </DropdownMenuSub>,\n );\n }\n\n return items;\n }, [\n filter,\n canSort,\n isSorted,\n column,\n props.tableLayout?.columnsPinnable,\n props.tableLayout?.columnsMovable,\n props.tableLayout?.columnsVisibility,\n canPin,\n isPinned,\n canMoveLeft,\n canMoveRight,\n visibility,\n table,\n columnIndex,\n columnOrder,\n i18n.labels.sortAscending,\n i18n.labels.pinColumnStart,\n i18n.labels.moveColumnEnd,\n i18n.labels.sortDescending,\n i18n.labels.pinColumnEnd,\n i18n.labels.moveColumnStart,\n i18n.labels.columnsMenu,\n ]);\n\n if (hasControls) {\n return (\n <div className=\"-ms-2 flex h-full items-center justify-between gap-1.5\">\n <DropdownMenu>\n <DropdownMenuTrigger\n render={\n <Button variant=\"ghost\" className={headerButtonClassName} disabled={isLoading}>\n {icon && icon}\n {resolvedTitle}\n {sortIcon}\n </Button>\n }\n />\n <DropdownMenuContent className=\"w-40\" align=\"start\">\n {menuItems}\n </DropdownMenuContent>\n </DropdownMenu>\n {props.tableLayout?.columnsPinnable && canPin && isPinned && (\n <Button\n size=\"icon-sm\"\n variant=\"ghost\"\n className=\"-me-1 size-7 rounded-lg\"\n onClick={() => column.pin(false)}\n aria-label={i18n.labels.unpinColumn(resolvedTitle)}\n title={i18n.labels.unpinColumn(resolvedTitle)}\n >\n <PinOffIcon className=\"size-3.5! opacity-50!\" aria-hidden=\"true\" />\n </Button>\n )}\n </div>\n );\n }\n\n if (canSort || (props.tableLayout?.columnsResizable && canResize)) {\n return (\n <div className=\"-ms-2 flex h-full items-center\">\n <Button\n variant=\"ghost\"\n className={headerButtonClassName}\n disabled={isLoading}\n onClick={handleSort}\n >\n {icon && icon}\n {resolvedTitle}\n {sortIcon}\n </Button>\n </div>\n );\n }\n\n return (\n <div className={headerLabelClassName}>\n {icon && icon}\n {resolvedTitle}\n </div>\n );\n}\n\nconst DataGridColumnHeaderMemo = memo(DataGridColumnHeaderInner) as <TData extends object, TValue>(\n props: DataGridColumnHeaderProps<TData, TValue> & {\n /** Internal: the state slices the header re-renders on. Not part of the public API. */\n subscribedState?: unknown;\n },\n) => ReactNode;\n\n/**\n * Sort and pin state reaches this header through builder calls on `column`\n * (`getIsSorted()`, `getIsPinned()`), and `column` is a stable reference. That\n * combination is the one v9's fresh-table-per-state-change does NOT cover:\n * React Compiler is free to memoize against the stable column and never\n * re-evaluate those reads, which shows up as frozen sort arrows and pin\n * controls. The `Subscribe` below turns the slices this header actually reads\n * into a real reactive dependency, and threading the selection through as a\n * prop is what lets it past the `memo` - which would otherwise see unchanged\n * props and skip the render anyway.\n */\nfunction DataGridColumnHeader<TData extends object, TValue>(\n props: DataGridColumnHeaderProps<TData, TValue>,\n) {\n const { table } = useDataGrid();\n\n return (\n <Subscribe\n source={table.store}\n selector={(state) => ({\n sorting: state.sorting,\n columnPinning: state.columnPinning,\n columnOrder: state.columnOrder,\n columnVisibility: state.columnVisibility,\n })}\n >\n {(subscribed) => <DataGridColumnHeaderMemo {...props} subscribedState={subscribed} />}\n </Subscribe>\n );\n}\n\nexport { DataGridColumnHeader, type DataGridColumnHeaderProps };\n"],"mappings":";;;;;;;;;;AAiDA,SAAS,0BAAwD,EAC/D,QACA,OACA,MACA,WACA,QACA,aAAa,SAC8B;CAC3C,MAAM,EAAE,MAAM,WAAW,OAAO,UAAU,YAAY;CACtD,MAAM,gBAAgB,SAAS,qBAAqB,MAAM;CAI1D,MAAM,mBAAmB,MAAM,MAAM;CACrC,MAAM,cACJ,i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KAAK,OAAO,YAAY,aAAa;GACjD,OAAO,KAAK,OAAO,YAAY,aAAa;GAE5C,UAAA,oBAAC,YAAD;IAAY,WAAU;IAAwB,eAAY;GAAQ,CAAA;EAC5D,CAAA,CAEP;;CAIT,IAAI,WAAY,MAAM,aAAa,oBAAoB,WACrD,OACE,oBAAC,OAAD;EAAK,WAAU;EACb,UAAA,qBAAC,QAAD;GACE,SAAQ;GACR,WAAW;GACX,UAAU;GACV,SAAS;GAJX,UAAA;IAMG,QAAQ;IACR;IACA;GACK;;CACL,CAAA;CAIT,OACE,qBAAC,OAAD;EAAK,WAAW;EAAhB,UAAA,CACG,QAAQ,MACR,aACE;;AAET;AAEA,MAAM,2BAA2B,KAAK,yBAAyB;;;;;;;;;;;;AAkB/D,SAAS,qBACP,OACA;CACA,MAAM,EAAE,UAAU,YAAY;CAE9B,OACE,oBAAC,WAAD;EACE,QAAQ,MAAM;EACd,WAAW,WAAW;GACpB,SAAS,MAAM;GACf,eAAe,MAAM;GACrB,aAAa,MAAM;GACnB,kBAAkB,MAAM;EAC1B;EAEE,WAAA,eAAe,oBAAC,0BAAD;GAA0B,GAAI;GAAO,iBAAiB;EAAa,CAAA;CAC3E,CAAA;AAEf"}
|
|
1
|
+
{"version":3,"file":"data-grid-column-header.js","names":[],"sources":["../../../../src/components/reui/data-grid/data-grid-column-header.tsx"],"sourcesContent":["\"use client\";\n\nimport type { HTMLAttributes, ReactNode } from \"react\";\nimport { memo, useMemo } from \"react\";\nimport type { Column } from \"@tanstack/react-table\";\nimport { Subscribe } from \"@tanstack/react-table\";\nimport {\n ArrowDownIcon,\n ArrowLeftIcon,\n ArrowLeftToLineIcon,\n ArrowRightIcon,\n ArrowRightToLineIcon,\n ArrowUpIcon,\n CheckIcon,\n ChevronsUpDownIcon,\n PinOffIcon,\n Settings2Icon,\n} from \"lucide-react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { Button } from \"../../ui/button\";\nimport {\n DropdownMenu,\n DropdownMenuCheckboxItem,\n DropdownMenuContent,\n DropdownMenuGroup,\n DropdownMenuItem,\n DropdownMenuLabel,\n DropdownMenuSeparator,\n DropdownMenuSub,\n DropdownMenuSubContent,\n DropdownMenuSubTrigger,\n DropdownMenuTrigger,\n} from \"../../ui/dropdown-menu\";\nimport type { DataGridFeatures } from \"./data-grid\";\nimport { getColumnHeaderLabel, useDataGrid } from \"./data-grid\";\n\ninterface DataGridColumnHeaderProps<TData extends object, TValue>\n extends HTMLAttributes<HTMLDivElement> {\n column: Column<DataGridFeatures, TData, TValue>;\n /** When omitted, uses `column.columnDef.meta.headerTitle`, then a string `columnDef.header`, then `column.id`. */\n title?: string;\n icon?: ReactNode;\n /** Reserved; pin controls are gated by tableLayout.columnsPinnable + column.getCanPin(). */\n pinnable?: boolean;\n filter?: ReactNode;\n visibility?: boolean;\n}\n\nfunction DataGridColumnHeaderInner<TData extends object, TValue>({\n column,\n title,\n icon,\n className,\n filter,\n visibility = false,\n}: DataGridColumnHeaderProps<TData, TValue>) {\n const { i18n, isLoading, table, props } = useDataGrid();\n const resolvedTitle = title ?? getColumnHeaderLabel(column);\n\n // TanStack's columnOrder defaults to [] until a consumer seeds it; fall\n // back to the definition order so Move Left/Right work out of the box.\n const columnOrderState = table.state.columnOrder;\n const columnOrder =\n columnOrderState.length > 0\n ? columnOrderState\n : table.getAllLeafColumns().map((leafColumn) => leafColumn.id);\n const isSorted = column.getIsSorted();\n const isPinned = column.getIsPinned();\n const canSort = column.getCanSort();\n const canPin = column.getCanPin();\n const canResize = column.getCanResize();\n\n const columnIndex = columnOrder.indexOf(column.id);\n const canMoveLeft = columnIndex > 0;\n const canMoveRight = columnIndex < columnOrder.length - 1;\n\n const handleSort = () => {\n if (isSorted === \"asc\") {\n column.toggleSorting(true);\n } else if (isSorted === \"desc\") {\n column.clearSorting();\n } else {\n column.toggleSorting(false);\n }\n };\n\n const headerLabelClassName = cn(\n \"inline-flex h-full items-center gap-1.5 font-normal text-[0.8125rem] text-secondary-foreground/80 leading-[calc(1.125/0.8125)] [&_svg]:size-3.5 [&_svg]:opacity-60\",\n className,\n );\n\n const headerButtonClassName = cn(\n \"h-6 rounded-lg px-2 font-normal text-secondary-foreground/80 hover:bg-secondary hover:text-foreground data-[state=open]:bg-secondary data-[state=open]:text-foreground\",\n className,\n );\n\n const sortIcon =\n canSort &&\n (isSorted === \"desc\" ? (\n <ArrowDownIcon className=\"size-3.25\" aria-hidden=\"true\" />\n ) : isSorted === \"asc\" ? (\n <ArrowUpIcon className=\"size-3.25\" aria-hidden=\"true\" />\n ) : (\n <ChevronsUpDownIcon className=\"mt-px size-3.25\" aria-hidden=\"true\" />\n ));\n\n const hasControls =\n props.tableLayout?.columnsMovable ||\n (props.tableLayout?.columnsVisibility && visibility) ||\n (props.tableLayout?.columnsPinnable && canPin) ||\n filter;\n\n const menuItems = useMemo(() => {\n const items: ReactNode[] = [];\n let hasPreviousSection = false;\n\n // Filter section\n if (filter) {\n items.push(\n <DropdownMenuGroup key=\"group-filter\">\n <DropdownMenuLabel key=\"filter\">{filter}</DropdownMenuLabel>\n </DropdownMenuGroup>,\n );\n hasPreviousSection = true;\n }\n\n // Sort section\n if (canSort) {\n if (hasPreviousSection) {\n items.push(<DropdownMenuSeparator key=\"sep-sort\" />);\n }\n items.push(\n <DropdownMenuItem\n key=\"sort-asc\"\n onClick={() => {\n if (isSorted === \"asc\") {\n column.clearSorting();\n } else {\n column.toggleSorting(false);\n }\n }}\n disabled={!canSort}\n >\n <ArrowUpIcon className=\"size-3.5!\" />\n <span className=\"grow\">{i18n.labels.sortAscending}</span>\n {isSorted === \"asc\" && <CheckIcon className=\"size-4 text-primary opacity-100!\" />}\n </DropdownMenuItem>,\n <DropdownMenuItem\n key=\"sort-desc\"\n onClick={() => {\n if (isSorted === \"desc\") {\n column.clearSorting();\n } else {\n column.toggleSorting(true);\n }\n }}\n disabled={!canSort}\n >\n <ArrowDownIcon className=\"size-3.5!\" />\n <span className=\"grow\">{i18n.labels.sortDescending}</span>\n {isSorted === \"desc\" && <CheckIcon className=\"size-4 text-primary opacity-100!\" />}\n </DropdownMenuItem>,\n );\n hasPreviousSection = true;\n }\n\n // Pin section\n if (props.tableLayout?.columnsPinnable && canPin) {\n if (hasPreviousSection) {\n items.push(<DropdownMenuSeparator key=\"sep-pin\" />);\n }\n items.push(\n <DropdownMenuItem\n key=\"pin-left\"\n onClick={() => column.pin(isPinned === \"start\" ? false : \"start\")}\n >\n <ArrowLeftToLineIcon className=\"size-3.5!\" aria-hidden=\"true\" />\n <span className=\"grow\">{i18n.labels.pinColumnStart}</span>\n {isPinned === \"start\" && <CheckIcon className=\"size-4 text-primary opacity-100!\" />}\n </DropdownMenuItem>,\n <DropdownMenuItem\n key=\"pin-right\"\n onClick={() => column.pin(isPinned === \"end\" ? false : \"end\")}\n >\n <ArrowRightToLineIcon className=\"size-3.5!\" aria-hidden=\"true\" />\n <span className=\"grow\">{i18n.labels.pinColumnEnd}</span>\n {isPinned === \"end\" && <CheckIcon className=\"size-4 text-primary opacity-100!\" />}\n </DropdownMenuItem>,\n );\n hasPreviousSection = true;\n }\n\n // Move section\n if (props.tableLayout?.columnsMovable) {\n if (hasPreviousSection) {\n items.push(<DropdownMenuSeparator key=\"sep-move\" />);\n }\n items.push(\n <DropdownMenuItem\n key=\"move-left\"\n onClick={() => {\n if (columnIndex > 0) {\n const newOrder = [...columnOrder];\n const [movedColumn] = newOrder.splice(columnIndex, 1);\n newOrder.splice(columnIndex - 1, 0, movedColumn);\n table.setColumnOrder(newOrder);\n }\n }}\n disabled={!canMoveLeft || isPinned !== false}\n >\n <ArrowLeftIcon className=\"size-3.5!\" aria-hidden=\"true\" />\n <span>{i18n.labels.moveColumnStart}</span>\n </DropdownMenuItem>,\n <DropdownMenuItem\n key=\"move-right\"\n onClick={() => {\n if (columnIndex < columnOrder.length - 1) {\n const newOrder = [...columnOrder];\n const [movedColumn] = newOrder.splice(columnIndex, 1);\n newOrder.splice(columnIndex + 1, 0, movedColumn);\n table.setColumnOrder(newOrder);\n }\n }}\n disabled={!canMoveRight || isPinned !== false}\n >\n <ArrowRightIcon className=\"size-3.5!\" aria-hidden=\"true\" />\n <span>{i18n.labels.moveColumnEnd}</span>\n </DropdownMenuItem>,\n );\n hasPreviousSection = true;\n }\n\n // Visibility section\n if (props.tableLayout?.columnsVisibility && visibility) {\n if (hasPreviousSection) {\n items.push(<DropdownMenuSeparator key=\"sep-visibility\" />);\n }\n items.push(\n <DropdownMenuSub key=\"visibility\">\n <DropdownMenuSubTrigger>\n <Settings2Icon className=\"size-3.5!\" />\n <span>{i18n.labels.columnsMenu}</span>\n </DropdownMenuSubTrigger>\n <DropdownMenuSubContent side=\"right\">\n {table\n .getAllColumns()\n .filter((col) => col.getCanHide())\n .map((col) => (\n <DropdownMenuCheckboxItem\n key={col.id}\n checked={col.getIsVisible()}\n onSelect={(event) => event.preventDefault()}\n onCheckedChange={(value) => col.toggleVisibility(!!value)}\n className=\"capitalize\"\n >\n {getColumnHeaderLabel(col)}\n </DropdownMenuCheckboxItem>\n ))}\n </DropdownMenuSubContent>\n </DropdownMenuSub>,\n );\n }\n\n return items;\n }, [\n filter,\n canSort,\n isSorted,\n column,\n props.tableLayout?.columnsPinnable,\n props.tableLayout?.columnsMovable,\n props.tableLayout?.columnsVisibility,\n canPin,\n isPinned,\n canMoveLeft,\n canMoveRight,\n visibility,\n table,\n columnIndex,\n columnOrder,\n i18n.labels.sortAscending,\n i18n.labels.pinColumnStart,\n i18n.labels.moveColumnEnd,\n i18n.labels.sortDescending,\n i18n.labels.pinColumnEnd,\n i18n.labels.moveColumnStart,\n i18n.labels.columnsMenu,\n ]);\n\n if (hasControls) {\n return (\n <div className=\"-ms-2 flex h-full items-center justify-between gap-1.5\">\n <DropdownMenu>\n <DropdownMenuTrigger\n render={\n <Button variant=\"ghost\" className={headerButtonClassName} disabled={isLoading}>\n {icon && icon}\n {resolvedTitle}\n {sortIcon}\n </Button>\n }\n />\n <DropdownMenuContent className=\"w-40\" align=\"start\">\n {menuItems}\n </DropdownMenuContent>\n </DropdownMenu>\n {props.tableLayout?.columnsPinnable && canPin && isPinned && (\n <Button\n size=\"icon-sm\"\n variant=\"ghost\"\n className=\"-me-1 size-7 rounded-lg\"\n onClick={() => column.pin(false)}\n aria-label={i18n.labels.unpinColumn(resolvedTitle)}\n title={i18n.labels.unpinColumn(resolvedTitle)}\n >\n <PinOffIcon className=\"size-3.5! opacity-50!\" aria-hidden=\"true\" />\n </Button>\n )}\n </div>\n );\n }\n\n if (canSort || (props.tableLayout?.columnsResizable && canResize)) {\n return (\n <div className=\"-ms-2 flex h-full items-center\">\n <Button\n variant=\"ghost\"\n className={headerButtonClassName}\n disabled={isLoading}\n onClick={handleSort}\n >\n {icon && icon}\n {resolvedTitle}\n {sortIcon}\n </Button>\n </div>\n );\n }\n\n return (\n <div className={headerLabelClassName}>\n {icon && icon}\n {resolvedTitle}\n </div>\n );\n}\n\nconst DataGridColumnHeaderMemo = memo(DataGridColumnHeaderInner) as <TData extends object, TValue>(\n props: DataGridColumnHeaderProps<TData, TValue> & {\n /** Internal: the state slices the header re-renders on. Not part of the public API. */\n subscribedState?: unknown;\n },\n) => ReactNode;\n\n/**\n * Sort and pin state reaches this header through builder calls on `column`\n * (`getIsSorted()`, `getIsPinned()`), and `column` is a stable reference. That\n * combination is the one v9's fresh-table-per-state-change does NOT cover:\n * React Compiler is free to memoize against the stable column and never\n * re-evaluate those reads, which shows up as frozen sort arrows and pin\n * controls. The `Subscribe` below turns the slices this header actually reads\n * into a real reactive dependency, and threading the selection through as a\n * prop is what lets it past the `memo` - which would otherwise see unchanged\n * props and skip the render anyway.\n */\nfunction DataGridColumnHeader<TData extends object, TValue>(\n props: DataGridColumnHeaderProps<TData, TValue>,\n) {\n const { table } = useDataGrid();\n\n return (\n <Subscribe\n source={table.store}\n selector={(state) => ({\n sorting: state.sorting,\n columnPinning: state.columnPinning,\n columnOrder: state.columnOrder,\n columnVisibility: state.columnVisibility,\n })}\n >\n {(subscribed) => <DataGridColumnHeaderMemo {...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AAQ;GAAQ,WAAW;GAAuB,UAAU;GAApE,UAAA;IACG,QAAQ;IACR;IACA;GACK;EAEX,CAAA,EAAA,CAAA,GACD,oBAAC,qBAAD;GAAqB,WAAU;GAAO,OAAM;GACzC,UAAA;EACkB,CAAA,CACT,EAAA,CAAA,GACb,MAAM,aAAa,mBAAmB,UAAU,YAC/C,oBAAC,QAAD;GACE,MAAK;GACL,SAAQ;GACR,WAAU;GACV,eAAe,OAAO,IAAI,KAAK;GAC/B,cAAY,KAAK,OAAO,YAAY,aAAa;GACjD,OAAO,KAAK,OAAO,YAAY,aAAa;GAE5C,UAAA,oBAAC,YAAD;IAAY,WAAU;IAAwB,eAAY;GAAQ,CAAA;EAC5D,CAAA,CAEP;;CAIT,IAAI,WAAY,MAAM,aAAa,oBAAoB,WACrD,OACE,oBAAC,OAAD;EAAK,WAAU;EACb,UAAA,qBAAC,QAAD;GACE,SAAQ;GACR,WAAW;GACX,UAAU;GACV,SAAS;GAJX,UAAA;IAMG,QAAQ;IACR;IACA;GACK;;CACL,CAAA;CAIT,OACE,qBAAC,OAAD;EAAK,WAAW;EAAhB,UAAA,CACG,QAAQ,MACR,aACE;;AAET;AAEA,MAAM,2BAA2B,KAAK,yBAAyB;;;;;;;;;;;;AAkB/D,SAAS,qBACP,OACA;CACA,MAAM,EAAE,UAAU,YAAY;CAE9B,OACE,oBAAC,WAAD;EACE,QAAQ,MAAM;EACd,WAAW,WAAW;GACpB,SAAS,MAAM;GACf,eAAe,MAAM;GACrB,aAAa,MAAM;GACnB,kBAAkB,MAAM;EAC1B;EAEE,WAAA,eAAe,oBAAC,0BAAD;GAA0B,GAAI;GAAO,iBAAiB;EAAa,CAAA;CAC3E,CAAA;AAEf"}
|
|
@@ -3,7 +3,7 @@ import { Button } from "../../ui/button.js";
|
|
|
3
3
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../ui/select.js";
|
|
4
4
|
import { Skeleton } from "../../ui/skeleton.js";
|
|
5
5
|
import { useDataGrid } from "./data-grid.js";
|
|
6
|
-
import { cn } from "
|
|
6
|
+
import { cn } from "@kumix/utils";
|
|
7
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
|
9
9
|
//#region src/components/reui/data-grid/data-grid-pagination.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-grid-pagination.js","names":[],"sources":["../../../../src/components/reui/data-grid/data-grid-pagination.tsx"],"sourcesContent":["\"use client\";\n\nimport type { JSX, ReactNode } from \"react\";\nimport { cn } from \"cn\";\nimport { ChevronLeftIcon, ChevronRightIcon } from \"lucide-react\";\n\nimport { Button } from \"../../ui/button\";\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"../../ui/select\";\nimport { Skeleton } from \"../../ui/skeleton\";\nimport { useDataGrid } from \"./data-grid\";\n\ninterface DataGridPaginationProps {\n sizes?: number[];\n sizesInfo?: string;\n sizesLabel?: string;\n sizesDescription?: string;\n sizesSkeleton?: ReactNode;\n more?: boolean;\n moreLimit?: number;\n info?: string;\n infoSkeleton?: ReactNode;\n className?: string;\n rowsPerPageLabel?: string;\n previousPageLabel?: string;\n nextPageLabel?: string;\n ellipsisText?: string;\n}\n\nfunction DataGridPagination(props: DataGridPaginationProps): JSX.Element {\n const { i18n, table, recordCount, isLoading } = useDataGrid();\n\n const defaultProps: Partial<DataGridPaginationProps> = {\n sizes: [5, 10, 25, 50, 100],\n sizesSkeleton: <Skeleton className=\"h-8 w-44\" />,\n moreLimit: 5,\n infoSkeleton: <Skeleton className=\"h-8 w-60\" />,\n rowsPerPageLabel: i18n.labels.rowsPerPage,\n previousPageLabel: i18n.labels.previousPage,\n nextPageLabel: i18n.labels.nextPage,\n ellipsisText: i18n.labels.paginationEllipsis,\n };\n\n const mergedProps: DataGridPaginationProps = { ...defaultProps, ...props };\n\n const btnBaseClasses = \"p-0 text-sm\";\n const btnArrowClasses = `${btnBaseClasses} rtl:transform rtl:rotate-180`;\n const pageIndex = table.state.pagination.pageIndex;\n const pageSize = table.state.pagination.pageSize;\n const from = recordCount === 0 ? 0 : pageIndex * pageSize + 1;\n const to = Math.min((pageIndex + 1) * pageSize, recordCount);\n const pageCount = table.getPageCount();\n\n // A supplied `info` keeps its placeholder-template contract; the default\n // routes through the i18n label function, where word order is free.\n const paginationInfo = mergedProps.info\n ? mergedProps.info\n .replaceAll(\"{from}\", from.toString())\n .replaceAll(\"{to}\", to.toString())\n .replaceAll(\"{count}\", recordCount.toString())\n : i18n.labels.paginationInfo({ from, to, count: recordCount });\n\n // Pagination limit logic\n const paginationMoreLimit = mergedProps.moreLimit || 5;\n\n // Determine the start and end of the pagination group\n const currentGroupStart = Math.floor(pageIndex / paginationMoreLimit) * paginationMoreLimit;\n const currentGroupEnd = Math.min(currentGroupStart + paginationMoreLimit, pageCount);\n\n // Render page buttons based on the current group\n const renderPageButtons = () => {\n const buttons = [];\n for (let i = currentGroupStart; i < currentGroupEnd; i++) {\n buttons.push(\n <Button\n key={i}\n size=\"icon-sm\"\n variant=\"ghost\"\n aria-label={i18n.labels.goToPage(i + 1)}\n aria-current={pageIndex === i ? \"page\" : undefined}\n className={cn(btnBaseClasses, \"text-muted-foreground\", {\n \"bg-accent text-accent-foreground\": pageIndex === i,\n })}\n onClick={() => {\n if (pageIndex !== i) {\n table.setPageIndex(i);\n }\n }}\n >\n {i + 1}\n </Button>,\n );\n }\n return buttons;\n };\n\n // Render a \"previous\" ellipsis button if there are previous pages to show\n const renderEllipsisPrevButton = () => {\n if (currentGroupStart > 0) {\n return (\n <Button\n size=\"icon-sm\"\n className={btnBaseClasses}\n variant=\"ghost\"\n onClick={() => table.setPageIndex(currentGroupStart - 1)}\n >\n {mergedProps.ellipsisText}\n </Button>\n );\n }\n return null;\n };\n\n // Render a \"next\" ellipsis button if there are more pages to show after the current group\n const renderEllipsisNextButton = () => {\n if (currentGroupEnd < pageCount) {\n return (\n <Button\n className={btnBaseClasses}\n variant=\"ghost\"\n size=\"icon-sm\"\n onClick={() => table.setPageIndex(currentGroupEnd)}\n >\n {mergedProps.ellipsisText}\n </Button>\n );\n }\n return null;\n };\n\n return (\n <div\n data-slot=\"data-grid-pagination\"\n className={cn(\n \"flex grow flex-col flex-wrap items-center justify-between gap-2.5 py-2.5 sm:flex-row sm:py-0\",\n mergedProps.className,\n )}\n >\n <div className=\"order-2 flex flex-wrap items-center space-x-2.5 pb-2.5 sm:order-1 sm:pb-0\">\n {isLoading ? (\n mergedProps.sizesSkeleton\n ) : (\n <>\n <div className=\"text-muted-foreground text-sm\">{mergedProps.rowsPerPageLabel}</div>\n <Select\n value={`${pageSize}`}\n onValueChange={(value) => {\n const newPageSize = Number(value);\n table.setPageSize(newPageSize);\n }}\n >\n {/* w-fit with a min, never a fixed width: a fixed w-16 clipped\n the value \"100\" by 1px at nova's paddings, while fit-content\n grows the trigger for 3-digit sizes and the min keeps the\n 1-2 digit ones from collapsing narrower than 64px. */}\n <SelectTrigger\n aria-label={mergedProps.rowsPerPageLabel}\n className=\"w-fit min-w-16\"\n size=\"sm\"\n >\n <SelectValue />\n </SelectTrigger>\n <SelectContent\n align=\"start\"\n alignItemWithTrigger={false}\n className=\"min-w-(--anchor-width)\"\n >\n {mergedProps.sizes?.map((size: number) => (\n <SelectItem key={size} value={`${size}`}>\n {size}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </>\n )}\n </div>\n <div className=\"order-1 flex flex-col items-center justify-center gap-2.5 pt-2.5 sm:order-2 sm:flex-row sm:justify-end sm:pt-0\">\n {isLoading ? (\n mergedProps.infoSkeleton\n ) : (\n <>\n <div className=\"order-2 text-nowrap text-muted-foreground text-sm sm:order-1\">\n {paginationInfo}\n </div>\n {pageCount > 1 && (\n <div className=\"order-1 flex items-center space-x-1\">\n <Button\n size=\"icon-sm\"\n variant=\"ghost\"\n className={btnArrowClasses}\n onClick={() => table.previousPage()}\n disabled={!table.getCanPreviousPage()}\n >\n <span className=\"sr-only\">{mergedProps.previousPageLabel}</span>\n <ChevronLeftIcon className=\"size-4\" />\n </Button>\n\n {renderEllipsisPrevButton()}\n\n {renderPageButtons()}\n\n {renderEllipsisNextButton()}\n\n <Button\n size=\"icon-sm\"\n variant=\"ghost\"\n className={btnArrowClasses}\n onClick={() => table.nextPage()}\n disabled={!table.getCanNextPage()}\n >\n <span className=\"sr-only\">{mergedProps.nextPageLabel}</span>\n <ChevronRightIcon className=\"size-4\" />\n </Button>\n </div>\n )}\n </>\n )}\n </div>\n </div>\n );\n}\n\nexport { DataGridPagination, type DataGridPaginationProps };\n"],"mappings":";;;;;;;;;AA4BA,SAAS,mBAAmB,OAA6C;CACvE,MAAM,EAAE,MAAM,OAAO,aAAa,cAAc,YAAY;CAa5D,MAAM,cAAuC;EAV3C,OAAO;GAAC;GAAG;GAAI;GAAI;GAAI;EAAG;EAC1B,eAAe,oBAAC,UAAD,EAAU,WAAU,WAAY,CAAA;EAC/C,WAAW;EACX,cAAc,oBAAC,UAAD,EAAU,WAAU,WAAY,CAAA;EAC9C,kBAAkB,KAAK,OAAO;EAC9B,mBAAmB,KAAK,OAAO;EAC/B,eAAe,KAAK,OAAO;EAC3B,cAAc,KAAK,OAAO;EAGoC,GAAG;CAAM;CAEzE,MAAM,iBAAiB;CACvB,MAAM,kBAAkB,GAAG,eAAe;CAC1C,MAAM,YAAY,MAAM,MAAM,WAAW;CACzC,MAAM,WAAW,MAAM,MAAM,WAAW;CACxC,MAAM,OAAO,gBAAgB,IAAI,IAAI,YAAY,WAAW;CAC5D,MAAM,KAAK,KAAK,KAAK,YAAY,KAAK,UAAU,WAAW;CAC3D,MAAM,YAAY,MAAM,aAAa;CAIrC,MAAM,iBAAiB,YAAY,OAC/B,YAAY,KACT,WAAW,UAAU,KAAK,SAAS,CAAC,CAAC,CACrC,WAAW,QAAQ,GAAG,SAAS,CAAC,CAAC,CACjC,WAAW,WAAW,YAAY,SAAS,CAAC,IAC/C,KAAK,OAAO,eAAe;EAAE;EAAM;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cAAc,OAAO,KAAK;KAChC,MAAM,YAAY,WAAW;IAC/B;IALF,UAAA,CAWE,oBAAC,eAAD;KACE,cAAY,YAAY;KACxB,WAAU;KACV,MAAK;KAEL,UAAA,oBAAC,aAAD,CAAc,CAAA;IACD,CAAA,GACf,oBAAC,eAAD;KACE,OAAM;KACN,sBAAsB;KACtB,WAAU;KAET,UAAA,YAAY,OAAO,KAAK,SACvB,oBAAC,YAAD;MAAuB,OAAO,GAAG;MAC9B,UAAA;KACS,GAFK,IAEL,CACb;IACY,CAAA,CACT;GACR,CAAA,CAAA,EAAA,CAAA;EAED,CAAA,GACL,oBAAC,OAAD;GAAK,WAAU;GACZ,UAAA,YACC,YAAY,eAEZ,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA;GACE,CAAA,GACJ,YAAY,KACX,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA;KACE,qBAAC,QAAD;MACE,MAAK;MACL,SAAQ;MACR,WAAW;MACX,eAAe,MAAM,aAAa;MAClC,UAAU,CAAC,MAAM,mBAAmB;MALtC,UAAA,CAOE,oBAAC,QAAD;OAAM,WAAU;OAAW,UAAA,YAAY;MAAwB,CAAA,GAC/D,oBAAC,iBAAD,EAAiB,WAAU,SAAU,CAAA,CAC/B;;KAEP,yBAAyB;KAEzB,kBAAkB;KAElB,yBAAyB;KAE1B,qBAAC,QAAD;MACE,MAAK;MACL,SAAQ;MACR,WAAW;MACX,eAAe,MAAM,SAAS;MAC9B,UAAU,CAAC,MAAM,eAAe;MALlC,UAAA,CAOE,oBAAC,QAAD;OAAM,WAAU;OAAW,UAAA,YAAY;MAAoB,CAAA,GAC3D,oBAAC,kBAAD,EAAkB,WAAU,SAAU,CAAA,CAChC;;IACL;GAEP,CAAA,CAAA,EAAA,CAAA;EAED,CAAA,CACF;;AAET"}
|
|
1
|
+
{"version":3,"file":"data-grid-pagination.js","names":[],"sources":["../../../../src/components/reui/data-grid/data-grid-pagination.tsx"],"sourcesContent":["\"use client\";\n\nimport type { JSX, ReactNode } from \"react\";\nimport { ChevronLeftIcon, ChevronRightIcon } from \"lucide-react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { Button } from \"../../ui/button\";\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"../../ui/select\";\nimport { Skeleton } from \"../../ui/skeleton\";\nimport { useDataGrid } from \"./data-grid\";\n\ninterface DataGridPaginationProps {\n sizes?: number[];\n sizesInfo?: string;\n sizesLabel?: string;\n sizesDescription?: string;\n sizesSkeleton?: ReactNode;\n more?: boolean;\n moreLimit?: number;\n info?: string;\n infoSkeleton?: ReactNode;\n className?: string;\n rowsPerPageLabel?: string;\n previousPageLabel?: string;\n nextPageLabel?: string;\n ellipsisText?: string;\n}\n\nfunction DataGridPagination(props: DataGridPaginationProps): JSX.Element {\n const { i18n, table, recordCount, isLoading } = useDataGrid();\n\n const defaultProps: Partial<DataGridPaginationProps> = {\n sizes: [5, 10, 25, 50, 100],\n sizesSkeleton: <Skeleton className=\"h-8 w-44\" />,\n moreLimit: 5,\n infoSkeleton: <Skeleton className=\"h-8 w-60\" />,\n rowsPerPageLabel: i18n.labels.rowsPerPage,\n previousPageLabel: i18n.labels.previousPage,\n nextPageLabel: i18n.labels.nextPage,\n ellipsisText: i18n.labels.paginationEllipsis,\n };\n\n const mergedProps: DataGridPaginationProps = { ...defaultProps, ...props };\n\n const btnBaseClasses = \"p-0 text-sm\";\n const btnArrowClasses = `${btnBaseClasses} rtl:transform rtl:rotate-180`;\n const pageIndex = table.state.pagination.pageIndex;\n const pageSize = table.state.pagination.pageSize;\n const from = recordCount === 0 ? 0 : pageIndex * pageSize + 1;\n const to = Math.min((pageIndex + 1) * pageSize, recordCount);\n const pageCount = table.getPageCount();\n\n // A supplied `info` keeps its placeholder-template contract; the default\n // routes through the i18n label function, where word order is free.\n const paginationInfo = mergedProps.info\n ? mergedProps.info\n .replaceAll(\"{from}\", from.toString())\n .replaceAll(\"{to}\", to.toString())\n .replaceAll(\"{count}\", recordCount.toString())\n : i18n.labels.paginationInfo({ from, to, count: recordCount });\n\n // Pagination limit logic\n const paginationMoreLimit = mergedProps.moreLimit || 5;\n\n // Determine the start and end of the pagination group\n const currentGroupStart = Math.floor(pageIndex / paginationMoreLimit) * paginationMoreLimit;\n const currentGroupEnd = Math.min(currentGroupStart + paginationMoreLimit, pageCount);\n\n // Render page buttons based on the current group\n const renderPageButtons = () => {\n const buttons = [];\n for (let i = currentGroupStart; i < currentGroupEnd; i++) {\n buttons.push(\n <Button\n key={i}\n size=\"icon-sm\"\n variant=\"ghost\"\n aria-label={i18n.labels.goToPage(i + 1)}\n aria-current={pageIndex === i ? \"page\" : undefined}\n className={cn(btnBaseClasses, \"text-muted-foreground\", {\n \"bg-accent text-accent-foreground\": pageIndex === i,\n })}\n onClick={() => {\n if (pageIndex !== i) {\n table.setPageIndex(i);\n }\n }}\n >\n {i + 1}\n </Button>,\n );\n }\n return buttons;\n };\n\n // Render a \"previous\" ellipsis button if there are previous pages to show\n const renderEllipsisPrevButton = () => {\n if (currentGroupStart > 0) {\n return (\n <Button\n size=\"icon-sm\"\n className={btnBaseClasses}\n variant=\"ghost\"\n onClick={() => table.setPageIndex(currentGroupStart - 1)}\n >\n {mergedProps.ellipsisText}\n </Button>\n );\n }\n return null;\n };\n\n // Render a \"next\" ellipsis button if there are more pages to show after the current group\n const renderEllipsisNextButton = () => {\n if (currentGroupEnd < pageCount) {\n return (\n <Button\n className={btnBaseClasses}\n variant=\"ghost\"\n size=\"icon-sm\"\n onClick={() => table.setPageIndex(currentGroupEnd)}\n >\n {mergedProps.ellipsisText}\n </Button>\n );\n }\n return null;\n };\n\n return (\n <div\n data-slot=\"data-grid-pagination\"\n className={cn(\n \"flex grow flex-col flex-wrap items-center justify-between gap-2.5 py-2.5 sm:flex-row sm:py-0\",\n mergedProps.className,\n )}\n >\n <div className=\"order-2 flex flex-wrap items-center space-x-2.5 pb-2.5 sm:order-1 sm:pb-0\">\n {isLoading ? (\n mergedProps.sizesSkeleton\n ) : (\n <>\n <div className=\"text-muted-foreground text-sm\">{mergedProps.rowsPerPageLabel}</div>\n <Select\n value={`${pageSize}`}\n onValueChange={(value) => {\n const newPageSize = Number(value);\n table.setPageSize(newPageSize);\n }}\n >\n {/* w-fit with a min, never a fixed width: a fixed w-16 clipped\n the value \"100\" by 1px at nova's paddings, while fit-content\n grows the trigger for 3-digit sizes and the min keeps the\n 1-2 digit ones from collapsing narrower than 64px. */}\n <SelectTrigger\n aria-label={mergedProps.rowsPerPageLabel}\n className=\"w-fit min-w-16\"\n size=\"sm\"\n >\n <SelectValue />\n </SelectTrigger>\n <SelectContent\n align=\"start\"\n alignItemWithTrigger={false}\n className=\"min-w-(--anchor-width)\"\n >\n {mergedProps.sizes?.map((size: number) => (\n <SelectItem key={size} value={`${size}`}>\n {size}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </>\n )}\n </div>\n <div className=\"order-1 flex flex-col items-center justify-center gap-2.5 pt-2.5 sm:order-2 sm:flex-row sm:justify-end sm:pt-0\">\n {isLoading ? (\n mergedProps.infoSkeleton\n ) : (\n <>\n <div className=\"order-2 text-nowrap text-muted-foreground text-sm sm:order-1\">\n {paginationInfo}\n </div>\n {pageCount > 1 && (\n <div className=\"order-1 flex items-center space-x-1\">\n <Button\n size=\"icon-sm\"\n variant=\"ghost\"\n className={btnArrowClasses}\n onClick={() => table.previousPage()}\n disabled={!table.getCanPreviousPage()}\n >\n <span className=\"sr-only\">{mergedProps.previousPageLabel}</span>\n <ChevronLeftIcon className=\"size-4\" />\n </Button>\n\n {renderEllipsisPrevButton()}\n\n {renderPageButtons()}\n\n {renderEllipsisNextButton()}\n\n <Button\n size=\"icon-sm\"\n variant=\"ghost\"\n className={btnArrowClasses}\n onClick={() => table.nextPage()}\n disabled={!table.getCanNextPage()}\n >\n <span className=\"sr-only\">{mergedProps.nextPageLabel}</span>\n <ChevronRightIcon className=\"size-4\" />\n </Button>\n </div>\n )}\n </>\n )}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,IAEL,CACb;IACY,CAAA,CACT;GACR,CAAA,CAAA,EAAA,CAAA;EAED,CAAA,GACL,oBAAC,OAAD;GAAK,WAAU;GACZ,UAAA,YACC,YAAY,eAEZ,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA;GACE,CAAA,GACJ,YAAY,KACX,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA;KACE,qBAAC,QAAD;MACE,MAAK;MACL,SAAQ;MACR,WAAW;MACX,eAAe,MAAM,aAAa;MAClC,UAAU,CAAC,MAAM,mBAAmB;MALtC,UAAA,CAOE,oBAAC,QAAD;OAAM,WAAU;OAAW,UAAA,YAAY;MAAwB,CAAA,GAC/D,oBAAC,iBAAD,EAAiB,WAAU,SAAU,CAAA,CAC/B;;KAEP,yBAAyB;KAEzB,kBAAkB;KAElB,yBAAyB;KAE1B,qBAAC,QAAD;MACE,MAAK;MACL,SAAQ;MACR,WAAW;MACX,eAAe,MAAM,SAAS;MAC9B,UAAU,CAAC,MAAM,eAAe;MALlC,UAAA,CAOE,oBAAC,QAAD;OAAM,WAAU;OAAW,UAAA,YAAY;MAAoB,CAAA,GAC3D,oBAAC,kBAAD,EAAkB,WAAU,SAAU,CAAA,CAChC;;IACL;GAEP,CAAA,CAAA,EAAA,CAAA;EAED,CAAA,CACF;;AAET"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useDataGrid } from "./data-grid.js";
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
-
import { cn } from "
|
|
4
|
+
import { cn } from "@kumix/utils";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { ScrollArea } from "@base-ui/react/scroll-area";
|
|
7
7
|
//#region src/components/reui/data-grid/data-grid-scroll-area.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-grid-scroll-area.js","names":["ScrollAreaPrimitive"],"sources":["../../../../src/components/reui/data-grid/data-grid-scroll-area.tsx"],"sourcesContent":["\"use client\";\n\nimport type { PointerEvent, ReactNode } from \"react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { ScrollArea as ScrollAreaPrimitive } from \"@base-ui/react/scroll-area\";\nimport { cn } from \"cn\";\n\nimport { useDataGrid } from \"./data-grid\";\n\nconst MIN_THUMB_SIZE = 24;\nconst FALLBACK_SCROLLBAR_SIZE = 12;\n\nconst INITIAL_METRICS = {\n hasVerticalOverflow: false,\n headerHeight: 0,\n horizontalScrollbarSize: 0,\n thumbHeight: 0,\n thumbTop: 0,\n trackHeight: 0,\n} as const;\n\n// Track footprint, measured: horizontal is 8px tall and vertical 6px wide, and\n// each loses 1px to its transparent border plus 2px to p-px, so the thumbs land\n// at 5px and 3px. Shrink these further and the thumb stops being a grab target.\nconst SCROLLBAR_CLASSNAME =\n \"flex touch-none p-px transition-colors select-none data-[orientation=horizontal]:h-2 data-[orientation=horizontal]:flex-col data-[orientation=horizontal]:border-t data-[orientation=horizontal]:border-t-transparent data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5 data-[orientation=vertical]:border-s data-[orientation=vertical]:border-s-transparent\";\n\nconst SCROLLBAR_THUMB_CLASSNAME = \"bg-border rounded-full relative flex-1\";\n\ntype DataGridScrollAreaOrientation = \"horizontal\" | \"vertical\" | \"both\";\n\ntype ScrollbarMetrics = {\n hasVerticalOverflow: boolean;\n headerHeight: number;\n horizontalScrollbarSize: number;\n thumbHeight: number;\n thumbTop: number;\n trackHeight: number;\n};\n\ntype ObservedElements = {\n header: HTMLElement | null;\n horizontalScrollbar: HTMLElement | null;\n table: HTMLElement | null;\n tableViewport: HTMLElement | null;\n};\n\ntype DataGridScrollAreaProps = Omit<ScrollAreaPrimitive.Root.Props, \"children\"> & {\n children: ReactNode;\n orientation?: DataGridScrollAreaOrientation;\n};\n\nfunction clamp(value: number, min: number, max: number) {\n return Math.min(max, Math.max(min, value));\n}\n\nfunction areMetricsEqual(next: ScrollbarMetrics, prev: ScrollbarMetrics) {\n return (\n next.hasVerticalOverflow === prev.hasVerticalOverflow &&\n next.headerHeight === prev.headerHeight &&\n next.horizontalScrollbarSize === prev.horizontalScrollbarSize &&\n next.thumbHeight === prev.thumbHeight &&\n next.thumbTop === prev.thumbTop &&\n next.trackHeight === prev.trackHeight\n );\n}\n\nfunction applyMetrics(element: HTMLElement, metrics: ScrollbarMetrics) {\n element.style.setProperty(\"--data-grid-scrollbar-header-height\", `${metrics.headerHeight}px`);\n element.style.setProperty(\"--data-grid-scrollbar-thumb-height\", `${metrics.thumbHeight}px`);\n element.style.setProperty(\"--data-grid-scrollbar-thumb-top\", `${metrics.thumbTop}px`);\n element.style.setProperty(\"--data-grid-scrollbar-track-height\", `${metrics.trackHeight}px`);\n}\n\nfunction DataGridScrollArea({\n children,\n className,\n orientation = \"both\",\n ...props\n}: DataGridScrollAreaProps) {\n const { props: dataGridProps, table } = useDataGrid();\n const containerRef = useRef<HTMLDivElement>(null);\n const overlayRef = useRef<HTMLDivElement | null>(null);\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const dragRef = useRef<{\n pointerId: number;\n startScrollTop: number;\n startY: number;\n } | null>(null);\n const metricsRef = useRef<ScrollbarMetrics>(INITIAL_METRICS);\n const observedElementsRef = useRef<ObservedElements>({\n header: null,\n horizontalScrollbar: null,\n table: null,\n tableViewport: null,\n });\n\n const showHorizontal = orientation !== \"vertical\";\n const showVertical = orientation !== \"horizontal\";\n const usesCustomVerticalScrollbar = showVertical && !!dataGridProps.tableLayout?.headerSticky;\n // Pinned columns are sticky and never scroll, so the horizontal scrollbar\n // track is inset to span only the scrollable center region between them.\n const isColumnsPinnable = !!dataGridProps.tableLayout?.columnsPinnable;\n const scrollbarInsetStart = isColumnsPinnable ? table.getStartTotalSize() : 0;\n const scrollbarInsetEnd = isColumnsPinnable ? table.getEndTotalSize() : 0;\n const [hasCustomVerticalOverflow, setHasCustomVerticalOverflow] = useState(false);\n\n const clearDragState = useCallback(() => {\n dragRef.current = null;\n document.body.style.userSelect = \"\";\n document.body.style.webkitUserSelect = \"\";\n }, []);\n\n // The overlay is mounted one commit after the sync that detected overflow,\n // so it misses that sync's write. Seeding it from the ref callback lands the\n // geometry during commit, before the browser paints the track.\n const setOverlayRef = useCallback((node: HTMLDivElement | null) => {\n overlayRef.current = node;\n\n if (node) applyMetrics(node, metricsRef.current);\n }, []);\n\n const resetMetrics = useCallback(() => {\n if (!areMetricsEqual(INITIAL_METRICS, metricsRef.current)) {\n metricsRef.current = INITIAL_METRICS;\n if (overlayRef.current) applyMetrics(overlayRef.current, INITIAL_METRICS);\n }\n\n setHasCustomVerticalOverflow((prev) => (prev ? false : prev));\n }, []);\n\n const syncCustomVerticalScrollbar = useCallback(() => {\n const container = containerRef.current;\n const viewport = viewportRef.current;\n\n if (!container || !viewport || !usesCustomVerticalScrollbar) {\n resetMetrics();\n return;\n }\n\n const { header, horizontalScrollbar } = observedElementsRef.current;\n const headerHeight = header?.getBoundingClientRect().height ?? 0;\n const viewportHeight = viewport.clientHeight;\n const viewportWidth = viewport.clientWidth;\n const scrollHeight = viewport.scrollHeight;\n const scrollWidth = viewport.scrollWidth;\n const hasHorizontalOverflow = showHorizontal && scrollWidth > viewportWidth + 0.5;\n const horizontalScrollbarSize = hasHorizontalOverflow\n ? horizontalScrollbar?.offsetHeight || FALLBACK_SCROLLBAR_SIZE\n : 0;\n const trackHeight = Math.max(0, viewportHeight - headerHeight - horizontalScrollbarSize);\n const maxScroll = Math.max(0, scrollHeight - viewportHeight);\n\n let nextMetrics: ScrollbarMetrics;\n\n if (trackHeight === 0 || maxScroll === 0) {\n nextMetrics = {\n hasVerticalOverflow: false,\n headerHeight,\n horizontalScrollbarSize,\n thumbHeight: trackHeight,\n thumbTop: 0,\n trackHeight,\n };\n } else {\n const bodyContentHeight = Math.max(trackHeight, scrollHeight - headerHeight);\n const thumbHeight = clamp(\n trackHeight * (trackHeight / bodyContentHeight),\n MIN_THUMB_SIZE,\n trackHeight,\n );\n const maxThumbTop = Math.max(0, trackHeight - thumbHeight);\n const thumbTop = maxThumbTop > 0 ? (viewport.scrollTop / maxScroll) * maxThumbTop : 0;\n\n nextMetrics = {\n hasVerticalOverflow: true,\n headerHeight,\n horizontalScrollbarSize,\n thumbHeight,\n thumbTop,\n trackHeight,\n };\n }\n\n if (!areMetricsEqual(nextMetrics, metricsRef.current)) {\n metricsRef.current = nextMetrics;\n // Scoped to the overlay, never to the container. These four properties\n // inherit, and thumbTop changes on essentially every scroll frame, so\n // writing them on the element that wraps the whole grid invalidates\n // computed style for every row and cell each frame. The overlay subtree\n // is their only reader.\n if (overlayRef.current) applyMetrics(overlayRef.current, nextMetrics);\n }\n\n setHasCustomVerticalOverflow((prev) =>\n prev === nextMetrics.hasVerticalOverflow ? prev : nextMetrics.hasVerticalOverflow,\n );\n }, [resetMetrics, showHorizontal, usesCustomVerticalScrollbar]);\n\n useEffect(() => {\n const container = containerRef.current;\n const viewport = viewportRef.current;\n\n if (!container || !viewport) return;\n\n if (!usesCustomVerticalScrollbar) {\n resetMetrics();\n return;\n }\n\n let frame = 0;\n\n const scheduleSync = () => {\n cancelAnimationFrame(frame);\n frame = window.requestAnimationFrame(syncCustomVerticalScrollbar);\n };\n\n const observer =\n typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(scheduleSync);\n const observed = new Set<HTMLElement>();\n\n const observeElement = (element: HTMLElement | null) => {\n if (element && observer && !observed.has(element)) {\n observer.observe(element);\n observed.add(element);\n }\n };\n\n const resolveObservedElements = () => {\n observedElementsRef.current = {\n header: container.querySelector(\n '[data-slot=\"data-grid-table\"] thead',\n ) as HTMLElement | null,\n horizontalScrollbar: container.querySelector(\n '[data-slot=\"data-grid-scrollbar\"][data-orientation=\"horizontal\"]',\n ) as HTMLElement | null,\n table: container.querySelector('[data-slot=\"data-grid-table\"]') as HTMLElement | null,\n tableViewport: container.querySelector(\n '[data-slot=\"data-grid-table-viewport\"]',\n ) as HTMLElement | null,\n };\n\n observeElement(observedElementsRef.current.header);\n observeElement(observedElementsRef.current.table);\n observeElement(observedElementsRef.current.tableViewport);\n\n return !!(observedElementsRef.current.header && observedElementsRef.current.table);\n };\n\n observeElement(viewport);\n const resolvedOnMount = resolveObservedElements();\n\n scheduleSync();\n viewport.addEventListener(\"scroll\", scheduleSync, { passive: true });\n\n // A table that mounts after this effect (empty state swapped for data)\n // would otherwise never be observed and the custom scrollbar would\n // overlap the sticky header. One-shot: disconnects once resolved.\n let mutationObserver: MutationObserver | null = null;\n if (!resolvedOnMount && typeof MutationObserver !== \"undefined\") {\n mutationObserver = new MutationObserver(() => {\n if (resolveObservedElements()) {\n mutationObserver?.disconnect();\n mutationObserver = null;\n scheduleSync();\n }\n });\n mutationObserver.observe(container, { childList: true, subtree: true });\n }\n\n return () => {\n cancelAnimationFrame(frame);\n observer?.disconnect();\n mutationObserver?.disconnect();\n viewport.removeEventListener(\"scroll\", scheduleSync);\n clearDragState();\n };\n }, [clearDragState, resetMetrics, syncCustomVerticalScrollbar, usesCustomVerticalScrollbar]);\n\n const scrollToThumbOffset = (nextThumbTop: number) => {\n const viewport = viewportRef.current;\n const { thumbHeight, trackHeight } = metricsRef.current;\n\n if (!viewport) return;\n\n const maxScroll = Math.max(0, viewport.scrollHeight - viewport.clientHeight);\n const maxThumbTop = Math.max(0, trackHeight - thumbHeight);\n\n if (maxScroll === 0 || maxThumbTop === 0) {\n viewport.scrollTop = 0;\n return;\n }\n\n const ratio = clamp(nextThumbTop, 0, maxThumbTop) / maxThumbTop;\n viewport.scrollTop = ratio * maxScroll;\n };\n\n const handleThumbPointerDown = (event: PointerEvent<HTMLDivElement>) => {\n const viewport = viewportRef.current;\n\n if (!viewport) return;\n\n event.preventDefault();\n event.stopPropagation();\n event.currentTarget.setPointerCapture(event.pointerId);\n\n dragRef.current = {\n pointerId: event.pointerId,\n startScrollTop: viewport.scrollTop,\n startY: event.clientY,\n };\n\n document.body.style.userSelect = \"none\";\n document.body.style.webkitUserSelect = \"none\";\n };\n\n const handleThumbPointerMove = (event: PointerEvent<HTMLDivElement>) => {\n const viewport = viewportRef.current;\n const dragState = dragRef.current;\n const { thumbHeight, trackHeight } = metricsRef.current;\n\n if (!viewport || !dragState || dragState.pointerId !== event.pointerId) {\n return;\n }\n\n const maxThumbTop = Math.max(0, trackHeight - thumbHeight);\n const maxScroll = Math.max(0, viewport.scrollHeight - viewport.clientHeight);\n\n if (maxThumbTop === 0 || maxScroll === 0) return;\n\n const deltaY = event.clientY - dragState.startY;\n const nextScrollTop = dragState.startScrollTop + (deltaY / maxThumbTop) * maxScroll;\n\n viewport.scrollTop = clamp(nextScrollTop, 0, maxScroll);\n };\n\n const handleThumbPointerUp = (event: PointerEvent<HTMLDivElement>) => {\n if (dragRef.current?.pointerId !== event.pointerId) return;\n clearDragState();\n };\n\n const handleTrackPointerDown = (event: PointerEvent<HTMLDivElement>) => {\n const { thumbHeight } = metricsRef.current;\n\n if (event.target !== event.currentTarget) return;\n\n event.preventDefault();\n event.stopPropagation();\n\n const rect = event.currentTarget.getBoundingClientRect();\n const offsetY = event.clientY - rect.top - thumbHeight / 2;\n\n scrollToThumbOffset(offsetY);\n };\n\n return (\n <div ref={containerRef} className=\"relative\">\n <ScrollAreaPrimitive.Root\n data-slot=\"data-grid-scroll-area\"\n // Styling hook: present while the sticky-header scroll mode detects\n // vertical overflow, so consumers can style scrollable vs short\n // grids with a plain ancestor attribute selector.\n data-overflow-vertical={hasCustomVerticalOverflow ? \"true\" : undefined}\n className={cn(\"relative\", className)}\n {...props}\n >\n <ScrollAreaPrimitive.Viewport\n ref={viewportRef}\n data-slot=\"scroll-area-viewport\"\n className=\"size-full\"\n >\n <ScrollAreaPrimitive.Content data-slot=\"scroll-area-content\">\n {children}\n </ScrollAreaPrimitive.Content>\n </ScrollAreaPrimitive.Viewport>\n\n {showHorizontal && (\n <ScrollAreaPrimitive.Scrollbar\n data-slot=\"data-grid-scrollbar\"\n data-orientation=\"horizontal\"\n orientation=\"horizontal\"\n className={SCROLLBAR_CLASSNAME}\n style={\n scrollbarInsetStart > 0 || scrollbarInsetEnd > 0\n ? {\n marginInlineStart: scrollbarInsetStart || undefined,\n marginInlineEnd: scrollbarInsetEnd || undefined,\n }\n : undefined\n }\n >\n <ScrollAreaPrimitive.Thumb\n data-slot=\"data-grid-thumb\"\n className={SCROLLBAR_THUMB_CLASSNAME}\n />\n </ScrollAreaPrimitive.Scrollbar>\n )}\n\n {showVertical && !usesCustomVerticalScrollbar && (\n <ScrollAreaPrimitive.Scrollbar\n data-slot=\"data-grid-scrollbar\"\n data-orientation=\"vertical\"\n orientation=\"vertical\"\n className={SCROLLBAR_CLASSNAME}\n >\n <ScrollAreaPrimitive.Thumb\n data-slot=\"data-grid-thumb\"\n className={SCROLLBAR_THUMB_CLASSNAME}\n />\n </ScrollAreaPrimitive.Scrollbar>\n )}\n </ScrollAreaPrimitive.Root>\n\n {usesCustomVerticalScrollbar && hasCustomVerticalOverflow && (\n <div\n ref={setOverlayRef}\n aria-hidden=\"true\"\n className=\"pointer-events-none absolute inset-e-0 top-(--data-grid-scrollbar-header-height) z-20 h-(--data-grid-scrollbar-track-height)\"\n >\n <div\n className=\"pointer-events-auto relative h-full w-1.5 touch-none p-px\"\n onPointerDown={handleTrackPointerDown}\n >\n <div\n className={cn(\n \"absolute end-px w-1.5 bg-border\",\n \"top-(--data-grid-scrollbar-thumb-top) h-(--data-grid-scrollbar-thumb-height)\",\n \"rounded-full\",\n )}\n onLostPointerCapture={clearDragState}\n onPointerCancel={handleThumbPointerUp}\n onPointerDown={handleThumbPointerDown}\n onPointerMove={handleThumbPointerMove}\n onPointerUp={handleThumbPointerUp}\n />\n </div>\n </div>\n )}\n </div>\n );\n}\n\nexport type { DataGridScrollAreaOrientation, DataGridScrollAreaProps };\nexport { DataGridScrollArea };\n"],"mappings":";;;;;;;AASA,MAAM,iBAAiB;AACvB,MAAM,0BAA0B;AAEhC,MAAM,kBAAkB;CACtB,qBAAqB;CACrB,cAAc;CACd,yBAA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ACE,sBAAsB,KAAK,oBAAoB,IAC3C;MACE,mBAAmB,uBAAuB,KAAA;MAC1C,iBAAiB,qBAAqB,KAAA;KACxC,IACA,KAAA;KAGN,UAAA,oBAACA,WAAoB,OAArB;MACE,aAAU;MACV,WAAW;KACZ,CAAA;IAC4B,CAAA;IAGhC,gBAAgB,CAAC,+BAChB,oBAACA,WAAoB,WAArB;KACE,aAAU;KACV,oBAAiB;KACjB,aAAY;KACZ,WAAW;KAEX,UAAA,oBAACA,WAAoB,OAArB;MACE,aAAU;MACV,WAAW;KACZ,CAAA;IAC4B,CAAA;GAET;EAEzB,CAAA,GAAA,+BAA+B,6BAC9B,oBAAC,OAAD;GACE,KAAK;GACL,eAAY;GACZ,WAAU;GAEV,UAAA,oBAAC,OAAD;IACE,WAAU;IACV,eAAe;IAEf,UAAA,oBAAC,OAAD;KACE,WAAW,GACT,mCACA,gFACA,cACF;KACA,sBAAsB;KACtB,iBAAiB;KACjB,eAAe;KACf,eAAe;KACf,aAAa;IACd,CAAA;GACE,CAAA;EACF,CAAA,CAEJ;;AAET"}
|
|
1
|
+
{"version":3,"file":"data-grid-scroll-area.js","names":["ScrollAreaPrimitive"],"sources":["../../../../src/components/reui/data-grid/data-grid-scroll-area.tsx"],"sourcesContent":["\"use client\";\n\nimport type { PointerEvent, ReactNode } from \"react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { ScrollArea as ScrollAreaPrimitive } from \"@base-ui/react/scroll-area\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useDataGrid } from \"./data-grid\";\n\nconst MIN_THUMB_SIZE = 24;\nconst FALLBACK_SCROLLBAR_SIZE = 12;\n\nconst INITIAL_METRICS = {\n hasVerticalOverflow: false,\n headerHeight: 0,\n horizontalScrollbarSize: 0,\n thumbHeight: 0,\n thumbTop: 0,\n trackHeight: 0,\n} as const;\n\n// Track footprint, measured: horizontal is 8px tall and vertical 6px wide, and\n// each loses 1px to its transparent border plus 2px to p-px, so the thumbs land\n// at 5px and 3px. Shrink these further and the thumb stops being a grab target.\nconst SCROLLBAR_CLASSNAME =\n \"flex touch-none p-px transition-colors select-none data-[orientation=horizontal]:h-2 data-[orientation=horizontal]:flex-col data-[orientation=horizontal]:border-t data-[orientation=horizontal]:border-t-transparent data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5 data-[orientation=vertical]:border-s data-[orientation=vertical]:border-s-transparent\";\n\nconst SCROLLBAR_THUMB_CLASSNAME = \"bg-border rounded-full relative flex-1\";\n\ntype DataGridScrollAreaOrientation = \"horizontal\" | \"vertical\" | \"both\";\n\ntype ScrollbarMetrics = {\n hasVerticalOverflow: boolean;\n headerHeight: number;\n horizontalScrollbarSize: number;\n thumbHeight: number;\n thumbTop: number;\n trackHeight: number;\n};\n\ntype ObservedElements = {\n header: HTMLElement | null;\n horizontalScrollbar: HTMLElement | null;\n table: HTMLElement | null;\n tableViewport: HTMLElement | null;\n};\n\ntype DataGridScrollAreaProps = Omit<ScrollAreaPrimitive.Root.Props, \"children\"> & {\n children: ReactNode;\n orientation?: DataGridScrollAreaOrientation;\n};\n\nfunction clamp(value: number, min: number, max: number) {\n return Math.min(max, Math.max(min, value));\n}\n\nfunction areMetricsEqual(next: ScrollbarMetrics, prev: ScrollbarMetrics) {\n return (\n next.hasVerticalOverflow === prev.hasVerticalOverflow &&\n next.headerHeight === prev.headerHeight &&\n next.horizontalScrollbarSize === prev.horizontalScrollbarSize &&\n next.thumbHeight === prev.thumbHeight &&\n next.thumbTop === prev.thumbTop &&\n next.trackHeight === prev.trackHeight\n );\n}\n\nfunction applyMetrics(element: HTMLElement, metrics: ScrollbarMetrics) {\n element.style.setProperty(\"--data-grid-scrollbar-header-height\", `${metrics.headerHeight}px`);\n element.style.setProperty(\"--data-grid-scrollbar-thumb-height\", `${metrics.thumbHeight}px`);\n element.style.setProperty(\"--data-grid-scrollbar-thumb-top\", `${metrics.thumbTop}px`);\n element.style.setProperty(\"--data-grid-scrollbar-track-height\", `${metrics.trackHeight}px`);\n}\n\nfunction DataGridScrollArea({\n children,\n className,\n orientation = \"both\",\n ...props\n}: DataGridScrollAreaProps) {\n const { props: dataGridProps, table } = useDataGrid();\n const containerRef = useRef<HTMLDivElement>(null);\n const overlayRef = useRef<HTMLDivElement | null>(null);\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const dragRef = useRef<{\n pointerId: number;\n startScrollTop: number;\n startY: number;\n } | null>(null);\n const metricsRef = useRef<ScrollbarMetrics>(INITIAL_METRICS);\n const observedElementsRef = useRef<ObservedElements>({\n header: null,\n horizontalScrollbar: null,\n table: null,\n tableViewport: null,\n });\n\n const showHorizontal = orientation !== \"vertical\";\n const showVertical = orientation !== \"horizontal\";\n const usesCustomVerticalScrollbar = showVertical && !!dataGridProps.tableLayout?.headerSticky;\n // Pinned columns are sticky and never scroll, so the horizontal scrollbar\n // track is inset to span only the scrollable center region between them.\n const isColumnsPinnable = !!dataGridProps.tableLayout?.columnsPinnable;\n const scrollbarInsetStart = isColumnsPinnable ? table.getStartTotalSize() : 0;\n const scrollbarInsetEnd = isColumnsPinnable ? table.getEndTotalSize() : 0;\n const [hasCustomVerticalOverflow, setHasCustomVerticalOverflow] = useState(false);\n\n const clearDragState = useCallback(() => {\n dragRef.current = null;\n document.body.style.userSelect = \"\";\n document.body.style.webkitUserSelect = \"\";\n }, []);\n\n // The overlay is mounted one commit after the sync that detected overflow,\n // so it misses that sync's write. Seeding it from the ref callback lands the\n // geometry during commit, before the browser paints the track.\n const setOverlayRef = useCallback((node: HTMLDivElement | null) => {\n overlayRef.current = node;\n\n if (node) applyMetrics(node, metricsRef.current);\n }, []);\n\n const resetMetrics = useCallback(() => {\n if (!areMetricsEqual(INITIAL_METRICS, metricsRef.current)) {\n metricsRef.current = INITIAL_METRICS;\n if (overlayRef.current) applyMetrics(overlayRef.current, INITIAL_METRICS);\n }\n\n setHasCustomVerticalOverflow((prev) => (prev ? false : prev));\n }, []);\n\n const syncCustomVerticalScrollbar = useCallback(() => {\n const container = containerRef.current;\n const viewport = viewportRef.current;\n\n if (!container || !viewport || !usesCustomVerticalScrollbar) {\n resetMetrics();\n return;\n }\n\n const { header, horizontalScrollbar } = observedElementsRef.current;\n const headerHeight = header?.getBoundingClientRect().height ?? 0;\n const viewportHeight = viewport.clientHeight;\n const viewportWidth = viewport.clientWidth;\n const scrollHeight = viewport.scrollHeight;\n const scrollWidth = viewport.scrollWidth;\n const hasHorizontalOverflow = showHorizontal && scrollWidth > viewportWidth + 0.5;\n const horizontalScrollbarSize = hasHorizontalOverflow\n ? horizontalScrollbar?.offsetHeight || FALLBACK_SCROLLBAR_SIZE\n : 0;\n const trackHeight = Math.max(0, viewportHeight - headerHeight - horizontalScrollbarSize);\n const maxScroll = Math.max(0, scrollHeight - viewportHeight);\n\n let nextMetrics: ScrollbarMetrics;\n\n if (trackHeight === 0 || maxScroll === 0) {\n nextMetrics = {\n hasVerticalOverflow: false,\n headerHeight,\n horizontalScrollbarSize,\n thumbHeight: trackHeight,\n thumbTop: 0,\n trackHeight,\n };\n } else {\n const bodyContentHeight = Math.max(trackHeight, scrollHeight - headerHeight);\n const thumbHeight = clamp(\n trackHeight * (trackHeight / bodyContentHeight),\n MIN_THUMB_SIZE,\n trackHeight,\n );\n const maxThumbTop = Math.max(0, trackHeight - thumbHeight);\n const thumbTop = maxThumbTop > 0 ? (viewport.scrollTop / maxScroll) * maxThumbTop : 0;\n\n nextMetrics = {\n hasVerticalOverflow: true,\n headerHeight,\n horizontalScrollbarSize,\n thumbHeight,\n thumbTop,\n trackHeight,\n };\n }\n\n if (!areMetricsEqual(nextMetrics, metricsRef.current)) {\n metricsRef.current = nextMetrics;\n // Scoped to the overlay, never to the container. These four properties\n // inherit, and thumbTop changes on essentially every scroll frame, so\n // writing them on the element that wraps the whole grid invalidates\n // computed style for every row and cell each frame. The overlay subtree\n // is their only reader.\n if (overlayRef.current) applyMetrics(overlayRef.current, nextMetrics);\n }\n\n setHasCustomVerticalOverflow((prev) =>\n prev === nextMetrics.hasVerticalOverflow ? prev : nextMetrics.hasVerticalOverflow,\n );\n }, [resetMetrics, showHorizontal, usesCustomVerticalScrollbar]);\n\n useEffect(() => {\n const container = containerRef.current;\n const viewport = viewportRef.current;\n\n if (!container || !viewport) return;\n\n if (!usesCustomVerticalScrollbar) {\n resetMetrics();\n return;\n }\n\n let frame = 0;\n\n const scheduleSync = () => {\n cancelAnimationFrame(frame);\n frame = window.requestAnimationFrame(syncCustomVerticalScrollbar);\n };\n\n const observer =\n typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(scheduleSync);\n const observed = new Set<HTMLElement>();\n\n const observeElement = (element: HTMLElement | null) => {\n if (element && observer && !observed.has(element)) {\n observer.observe(element);\n observed.add(element);\n }\n };\n\n const resolveObservedElements = () => {\n observedElementsRef.current = {\n header: container.querySelector(\n '[data-slot=\"data-grid-table\"] thead',\n ) as HTMLElement | null,\n horizontalScrollbar: container.querySelector(\n '[data-slot=\"data-grid-scrollbar\"][data-orientation=\"horizontal\"]',\n ) as HTMLElement | null,\n table: container.querySelector('[data-slot=\"data-grid-table\"]') as HTMLElement | null,\n tableViewport: container.querySelector(\n '[data-slot=\"data-grid-table-viewport\"]',\n ) as HTMLElement | null,\n };\n\n observeElement(observedElementsRef.current.header);\n observeElement(observedElementsRef.current.table);\n observeElement(observedElementsRef.current.tableViewport);\n\n return !!(observedElementsRef.current.header && observedElementsRef.current.table);\n };\n\n observeElement(viewport);\n const resolvedOnMount = resolveObservedElements();\n\n scheduleSync();\n viewport.addEventListener(\"scroll\", scheduleSync, { passive: true });\n\n // A table that mounts after this effect (empty state swapped for data)\n // would otherwise never be observed and the custom scrollbar would\n // overlap the sticky header. One-shot: disconnects once resolved.\n let mutationObserver: MutationObserver | null = null;\n if (!resolvedOnMount && typeof MutationObserver !== \"undefined\") {\n mutationObserver = new MutationObserver(() => {\n if (resolveObservedElements()) {\n mutationObserver?.disconnect();\n mutationObserver = null;\n scheduleSync();\n }\n });\n mutationObserver.observe(container, { childList: true, subtree: true });\n }\n\n return () => {\n cancelAnimationFrame(frame);\n observer?.disconnect();\n mutationObserver?.disconnect();\n viewport.removeEventListener(\"scroll\", scheduleSync);\n clearDragState();\n };\n }, [clearDragState, resetMetrics, syncCustomVerticalScrollbar, usesCustomVerticalScrollbar]);\n\n const scrollToThumbOffset = (nextThumbTop: number) => {\n const viewport = viewportRef.current;\n const { thumbHeight, trackHeight } = metricsRef.current;\n\n if (!viewport) return;\n\n const maxScroll = Math.max(0, viewport.scrollHeight - viewport.clientHeight);\n const maxThumbTop = Math.max(0, trackHeight - thumbHeight);\n\n if (maxScroll === 0 || maxThumbTop === 0) {\n viewport.scrollTop = 0;\n return;\n }\n\n const ratio = clamp(nextThumbTop, 0, maxThumbTop) / maxThumbTop;\n viewport.scrollTop = ratio * maxScroll;\n };\n\n const handleThumbPointerDown = (event: PointerEvent<HTMLDivElement>) => {\n const viewport = viewportRef.current;\n\n if (!viewport) return;\n\n event.preventDefault();\n event.stopPropagation();\n event.currentTarget.setPointerCapture(event.pointerId);\n\n dragRef.current = {\n pointerId: event.pointerId,\n startScrollTop: viewport.scrollTop,\n startY: event.clientY,\n };\n\n document.body.style.userSelect = \"none\";\n document.body.style.webkitUserSelect = \"none\";\n };\n\n const handleThumbPointerMove = (event: PointerEvent<HTMLDivElement>) => {\n const viewport = viewportRef.current;\n const dragState = dragRef.current;\n const { thumbHeight, trackHeight } = metricsRef.current;\n\n if (!viewport || !dragState || dragState.pointerId !== event.pointerId) {\n return;\n }\n\n const maxThumbTop = Math.max(0, trackHeight - thumbHeight);\n const maxScroll = Math.max(0, viewport.scrollHeight - viewport.clientHeight);\n\n if (maxThumbTop === 0 || maxScroll === 0) return;\n\n const deltaY = event.clientY - dragState.startY;\n const nextScrollTop = dragState.startScrollTop + (deltaY / maxThumbTop) * maxScroll;\n\n viewport.scrollTop = clamp(nextScrollTop, 0, maxScroll);\n };\n\n const handleThumbPointerUp = (event: PointerEvent<HTMLDivElement>) => {\n if (dragRef.current?.pointerId !== event.pointerId) return;\n clearDragState();\n };\n\n const handleTrackPointerDown = (event: PointerEvent<HTMLDivElement>) => {\n const { thumbHeight } = metricsRef.current;\n\n if (event.target !== event.currentTarget) return;\n\n event.preventDefault();\n event.stopPropagation();\n\n const rect = event.currentTarget.getBoundingClientRect();\n const offsetY = event.clientY - rect.top - thumbHeight / 2;\n\n scrollToThumbOffset(offsetY);\n };\n\n return (\n <div ref={containerRef} className=\"relative\">\n <ScrollAreaPrimitive.Root\n data-slot=\"data-grid-scroll-area\"\n // Styling hook: present while the sticky-header scroll mode detects\n // vertical overflow, so consumers can style scrollable vs short\n // grids with a plain ancestor attribute selector.\n data-overflow-vertical={hasCustomVerticalOverflow ? \"true\" : undefined}\n className={cn(\"relative\", className)}\n {...props}\n >\n <ScrollAreaPrimitive.Viewport\n ref={viewportRef}\n data-slot=\"scroll-area-viewport\"\n className=\"size-full\"\n >\n <ScrollAreaPrimitive.Content data-slot=\"scroll-area-content\">\n {children}\n </ScrollAreaPrimitive.Content>\n </ScrollAreaPrimitive.Viewport>\n\n {showHorizontal && (\n <ScrollAreaPrimitive.Scrollbar\n data-slot=\"data-grid-scrollbar\"\n data-orientation=\"horizontal\"\n orientation=\"horizontal\"\n className={SCROLLBAR_CLASSNAME}\n style={\n scrollbarInsetStart > 0 || scrollbarInsetEnd > 0\n ? {\n marginInlineStart: scrollbarInsetStart || undefined,\n marginInlineEnd: scrollbarInsetEnd || undefined,\n }\n : undefined\n }\n >\n <ScrollAreaPrimitive.Thumb\n data-slot=\"data-grid-thumb\"\n className={SCROLLBAR_THUMB_CLASSNAME}\n />\n </ScrollAreaPrimitive.Scrollbar>\n )}\n\n {showVertical && !usesCustomVerticalScrollbar && (\n <ScrollAreaPrimitive.Scrollbar\n data-slot=\"data-grid-scrollbar\"\n data-orientation=\"vertical\"\n orientation=\"vertical\"\n className={SCROLLBAR_CLASSNAME}\n >\n <ScrollAreaPrimitive.Thumb\n data-slot=\"data-grid-thumb\"\n className={SCROLLBAR_THUMB_CLASSNAME}\n />\n </ScrollAreaPrimitive.Scrollbar>\n )}\n </ScrollAreaPrimitive.Root>\n\n {usesCustomVerticalScrollbar && hasCustomVerticalOverflow && (\n <div\n ref={setOverlayRef}\n aria-hidden=\"true\"\n className=\"pointer-events-none absolute inset-e-0 top-(--data-grid-scrollbar-header-height) z-20 h-(--data-grid-scrollbar-track-height)\"\n >\n <div\n className=\"pointer-events-auto relative h-full w-1.5 touch-none p-px\"\n onPointerDown={handleTrackPointerDown}\n >\n <div\n className={cn(\n \"absolute end-px w-1.5 bg-border\",\n \"top-(--data-grid-scrollbar-thumb-top) h-(--data-grid-scrollbar-thumb-height)\",\n \"rounded-full\",\n )}\n onLostPointerCapture={clearDragState}\n onPointerCancel={handleThumbPointerUp}\n onPointerDown={handleThumbPointerDown}\n onPointerMove={handleThumbPointerMove}\n onPointerUp={handleThumbPointerUp}\n />\n </div>\n </div>\n )}\n </div>\n );\n}\n\nexport type { DataGridScrollAreaOrientation, DataGridScrollAreaProps };\nexport { DataGridScrollArea };\n"],"mappings":";;;;;;;AASA,MAAM,iBAAiB;AACvB,MAAM,0BAA0B;AAEhC,MAAM,kBAAkB;CACtB,qBAAqB;CACrB,cAAc;CACd,yBAAyB;CACzB,aAAa;CACb,UAAU;CACV,aAAa;AACf;AAKA,MAAM,sBACJ;AAEF,MAAM,4BAA4B;AAyBlC,SAAS,MAAM,OAAe,KAAa,KAAa;CACtD,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC;AAC3C;AAEA,SAAS,gBAAgB,MAAwB,MAAwB;CACvE,OACE,KAAK,wBAAwB,KAAK,uBAClC,KAAK,iBAAiB,KAAK,gBAC3B,KAAK,4BAA4B,KAAK,2BACtC,KAAK,gBAAgB,KAAK,eAC1B,KAAK,aAAa,KAAK,YACvB,KAAK,gBAAgB,KAAK;AAE9B;AAEA,SAAS,aAAa,SAAsB,SAA2B;CACrE,QAAQ,MAAM,YAAY,uCAAuC,GAAG,QAAQ,aAAa,GAAG;CAC5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eAAe;IAEf,UAAA,oBAAC,OAAD;KACE,WAAW,GACT,mCACA,gFACA,cACF;KACA,sBAAsB;KACtB,iBAAiB;KACjB,eAAe;KACf,eAAe;KACf,aAAa;IACd,CAAA;GACE,CAAA;EACF,CAAA,CAEJ;;AAET"}
|
|
@@ -3,7 +3,7 @@ import { Button } from "../../ui/button.js";
|
|
|
3
3
|
import { useDataGrid } from "./data-grid.js";
|
|
4
4
|
import { DataGridTableBase, DataGridTableBody, DataGridTableBodyRow, DataGridTableBodyRowCell, DataGridTableBodyRowExpandded, DataGridTableBodyRowSkeleton, DataGridTableBodyRowSkeletonCell, DataGridTableEmpty, DataGridTableFillBodyCell, DataGridTableFillHeadCell, DataGridTableFoot, DataGridTableHead, DataGridTableHeadRow, DataGridTableHeadRowCell, DataGridTableHeadRowCellResize, DataGridTableRowSpacer, DataGridTableViewport } from "./data-grid-table.js";
|
|
5
5
|
import { createContext, memo, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
6
|
-
import { cn } from "
|
|
6
|
+
import { cn } from "@kumix/utils";
|
|
7
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { GripHorizontalIcon } from "lucide-react";
|
|
9
9
|
import { createPortal } from "react-dom";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-grid-table-dnd-rows.js","names":[],"sources":["../../../../src/components/reui/data-grid/data-grid-table-dnd-rows.tsx"],"sourcesContent":["\"use client\";\n\nimport type { CSSProperties, ReactNode } from \"react\";\nimport {\n createContext,\n memo,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n type CollisionDetection,\n closestCenter,\n DndContext,\n type DragCancelEvent,\n type DragEndEvent,\n type DragMoveEvent,\n type DragOverEvent,\n DragOverlay,\n type DragStartEvent,\n KeyboardSensor,\n type Modifier,\n MouseSensor,\n TouchSensor,\n type UniqueIdentifier,\n useSensor,\n useSensors,\n} from \"@dnd-kit/core\";\nimport { restrictToVerticalAxis } from \"@dnd-kit/modifiers\";\nimport {\n SortableContext,\n type SortingStrategy,\n sortableKeyboardCoordinates,\n useSortable,\n} from \"@dnd-kit/sortable\";\nimport { CSS } from \"@dnd-kit/utilities\";\nimport type { Cell, HeaderGroup, Row } from \"@tanstack/react-table\";\nimport { flexRender } from \"@tanstack/react-table\";\nimport { cn } from \"cn\";\nimport { GripHorizontalIcon } from \"lucide-react\";\nimport { createPortal } from \"react-dom\";\n\nimport { Button } from \"../../ui/button\";\nimport type { DataGridFeatures, DataGridTableInstance } from \"./data-grid\";\nimport { useDataGrid } from \"./data-grid\";\nimport {\n DataGridTableBase,\n DataGridTableBody,\n DataGridTableBodyRow,\n DataGridTableBodyRowCell,\n DataGridTableBodyRowExpandded,\n DataGridTableBodyRowSkeleton,\n DataGridTableBodyRowSkeletonCell,\n DataGridTableEmpty,\n DataGridTableFillBodyCell,\n DataGridTableFillHeadCell,\n DataGridTableFoot,\n DataGridTableHead,\n DataGridTableHeadRow,\n DataGridTableHeadRowCell,\n DataGridTableHeadRowCellResize,\n DataGridTableRowSpacer,\n DataGridTableViewport,\n} from \"./data-grid-table\";\n\n// Context to share sortable listeners from row to handle\ntype SortableContextValue = ReturnType<typeof useSortable>;\nconst SortableRowContext = createContext<Pick<\n SortableContextValue,\n \"attributes\" | \"listeners\"\n> | null>(null);\n\n/**\n * Tree metadata attached to every sortable row, readable from\n * `active.data.current` / `over.data.current` in any drag event. Cross-parent\n * drops can be resolved from it without re-deriving the shape of the table.\n */\ntype DataGridTableDndRowData = {\n type: \"data-grid-row\";\n /** Tree depth, 0 for root rows. */\n depth: number;\n /** Index within the parent's children, or within the root rows. */\n index: number;\n /** Parent row id, or null for root rows. */\n parentId: string | null;\n};\n\n/**\n * Per-row render slot for drop indicators and depth guides. The returned node\n * is positioned over the row, so it never adds a column, shifts striping, or\n * gets clipped by a truncating resizable cell.\n */\ntype DataGridTableDndRowDecoration<TData extends object> = (context: {\n row: Row<DataGridFeatures, TData>;\n isDragging: boolean;\n isOver: boolean;\n}) => ReactNode;\n\nfunction DataGridTableDndRowHandle({\n className,\n disabled,\n disabledLabel,\n}: {\n className?: string;\n /**\n * Renders the grip inert instead of withdrawing it. A grid that reorders on\n * one truth (manual order) and sorts on another cannot honour both at once,\n * but dropping the handle entirely collapses the gutter and reads as broken\n * rather than as unavailable. Keep the column's shape, mute the control.\n */\n disabled?: boolean;\n /** Announced and shown on hover in place of the drag affordance. */\n disabledLabel?: string;\n}) {\n const { i18n } = useDataGrid();\n const context = useContext(SortableRowContext);\n const resolvedDisabledLabel = disabledLabel ?? i18n.labels.reorderingUnavailable;\n\n if (!context || disabled) {\n return (\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n className={cn(\n \"size-7 cursor-grab opacity-70 hover:bg-transparent hover:opacity-100 active:cursor-grabbing\",\n // The Button's own disabled treatment supplies the muting; only the\n // cursor needs saying, so the grip reads as unavailable rather than\n // merely unresponsive.\n disabled && \"cursor-not-allowed\",\n className,\n )}\n aria-label={disabled ? resolvedDisabledLabel : i18n.labels.dragToReorderRow}\n title={disabled ? resolvedDisabledLabel : undefined}\n disabled\n >\n <GripHorizontalIcon aria-hidden=\"true\" />\n </Button>\n );\n }\n\n return (\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n className={cn(\n \"size-7 cursor-grab opacity-70 hover:bg-transparent hover:opacity-100 active:cursor-grabbing\",\n className,\n )}\n aria-label={i18n.labels.dragToReorderRow}\n {...context.attributes}\n {...context.listeners}\n >\n <GripHorizontalIcon aria-hidden=\"true\" />\n </Button>\n );\n}\n\n/**\n * The rows do not move while one is being carried.\n *\n * Sliding the siblings apart opens a gap the carried row could go into, which\n * reads well in a list of identical rows and badly in a table: the gap is the\n * height of the row you are holding, so with rows of unequal height it never\n * matches the slot it claims to be, and the row you picked up slides away from\n * where it started - which is exactly the position you need to remember if you\n * decide not to drop it.\n *\n * Holding everything still keeps the origin legible, and nothing is lost: the\n * DragOverlay clone follows the pointer and the drop indicator names the seam.\n * Pass `verticalListSortingStrategy` as `sortingStrategy` for the old feel.\n */\nconst holdRowsInPlaceStrategy: SortingStrategy = () => null;\n\nfunction DataGridTableDndRow<TData extends object>({\n row,\n renderRowDecoration,\n dropIndicator = true,\n}: {\n row: Row<DataGridFeatures, TData>;\n renderRowDecoration?: DataGridTableDndRowDecoration<TData>;\n dropIndicator?: boolean;\n}) {\n const rowData: DataGridTableDndRowData = {\n type: \"data-grid-row\",\n depth: row.depth,\n index: row.index,\n parentId: row.getParentRow()?.id ?? null,\n };\n\n const {\n transform,\n setNodeRef,\n isDragging,\n isOver,\n attributes,\n listeners,\n index,\n activeIndex,\n overIndex,\n } = useSortable({\n id: row.id,\n data: rowData,\n });\n\n // Which edge of THIS row the carried row would land on, or null when it is\n // not the drop target. Nothing slides apart any more, so the bar is the only\n // thing that says where the drop goes: it marks the row at the destination\n // index, on the side the carried row comes to rest.\n //\n // Dragging down it lands after the target, dragging up before it, so the\n // edge follows the direction of travel.\n const dropEdge =\n dropIndicator && activeIndex !== -1 && index === overIndex && !isDragging\n ? activeIndex < overIndex\n ? \"bottom\"\n : \"top\"\n : null;\n\n const style: CSSProperties = {\n transform: CSS.Transform.toString(transform),\n // dnd-kit's transition is deliberately dropped. A transition on a transform\n // property of a `tr` does not merely fail to animate in Chrome, it stops the\n // transform applying at all: the element sits at the start value forever.\n // The drag source escapes it because dnd-kit disables its own transition\n // while it is being dragged, which is why the carried row used to be the\n // ONLY one that moved and every other row silently refused to open a gap.\n // Displacement therefore lands in one step, which is what a table wants.\n zIndex: isDragging ? 1 : 0,\n position: \"relative\",\n cursor: isDragging ? \"grabbing\" : undefined,\n // The row you are holding is drawn by the DragOverlay, so the one left\n // behind is not a second copy of it - it is the slot you came from, and it\n // stays exactly where it was. Fading alone read as \"this row is busy\";\n // the outline says \"this is the space you are moving out of\", which is the\n // thing you need if you change your mind mid-drag.\n ...(isDragging && {\n opacity: 0.4,\n // Inset so the dashes sit inside the row box and cannot be clipped by\n // the neighbouring row's border.\n outline: \"1px dashed var(--border)\",\n outlineOffset: \"-1px\",\n }),\n };\n\n const decoration = renderRowDecoration?.({ row, isDragging, isOver });\n\n return (\n <SortableRowContext.Provider value={{ attributes, listeners }}>\n <DataGridTableBodyRow row={row} dndRef={setNodeRef} dndStyle={style}>\n {row.getVisibleCells().map((cell: Cell<DataGridFeatures, TData, unknown>, index, cells) => {\n return (\n <DataGridTableBodyRowCell cell={cell} key={cell.id}>\n {flexRender(cell.column.columnDef.cell, cell.getContext())}\n {decoration && index === cells.length - 1 ? (\n // Rides inside the last cell rather than in a `td` of its own.\n // An absolutely positioned `td` is still a cell as far as table\n // layout is concerned, so it added a NINTH column with no width\n // of its own, and under `table-layout: fixed` that new column\n // swallowed the whole surplus the real columns had been sharing\n // — every column snapped back to its declared size and the row's\n // content visibly narrowed the moment a drag began. A plain\n // element adds no column. It still anchors to the ROW, because\n // the row is the nearest positioned ancestor, so the decoration\n // spans the full width and is not clipped by the cell.\n <div\n aria-hidden=\"true\"\n data-slot=\"data-grid-table-row-decoration\"\n className=\"pointer-events-none absolute inset-0\"\n >\n {decoration}\n </div>\n ) : null}\n {dropEdge && index === cells.length - 1 ? (\n // Same anchoring trick as the decoration above: a plain\n // element inside the last cell, so it adds no column and\n // cannot disturb `table-layout: fixed`. It spans the row\n // because the row is the nearest positioned ancestor.\n <div\n aria-hidden=\"true\"\n data-slot=\"data-grid-table-row-drop-indicator\"\n data-edge={dropEdge}\n className=\"pointer-events-none absolute inset-0 z-20\"\n >\n {/* Two solid pixels down the leading edge, the same marker\n the tree drag uses for its drop target. A wash across\n the row has to stay faint enough not to read as a\n selected row, and in the achromatic styles primary\n carries no chroma at all, so faint plus colourless is\n just grey. The bar reads at any weight and leaves the\n row's own background to hover and selection.\n\n The bar is the whole indicator: the gap the rows have\n already opened says which side, so a rule across the\n seam as well only competes with the row borders it sits\n between. `data-edge` still carries the direction for\n anyone styling their own. */}\n <span className=\"absolute inset-y-0 start-0 w-0.5 bg-primary\" />\n </div>\n ) : null}\n </DataGridTableBodyRowCell>\n );\n })}\n <DataGridTableFillBodyCell />\n </DataGridTableBodyRow>\n {row.getIsExpanded() && <DataGridTableBodyRowExpandded row={row} />}\n </SortableRowContext.Provider>\n );\n}\n\nfunction DataGridTableDndRowsBody<TData extends object>({\n table,\n dataIds,\n renderRowDecoration,\n dropIndicator,\n sortingStrategy,\n}: {\n table: DataGridTableInstance<TData>;\n dataIds: UniqueIdentifier[];\n renderRowDecoration?: DataGridTableDndRowDecoration<TData>;\n dropIndicator?: boolean;\n sortingStrategy: SortingStrategy;\n}) {\n const { isLoading, props } = useDataGrid();\n const pagination = table.state.pagination;\n\n if (props.loadingMode === \"skeleton\" && isLoading && pagination?.pageSize) {\n return (\n <>\n {Array.from({ length: pagination.pageSize }).map((_, rowIndex) => (\n <DataGridTableBodyRowSkeleton key={rowIndex}>\n {table.getVisibleFlatColumns().map((column, colIndex) => {\n return (\n <DataGridTableBodyRowSkeletonCell column={column} key={colIndex}>\n {column.columnDef.meta?.skeleton}\n </DataGridTableBodyRowSkeletonCell>\n );\n })}\n <DataGridTableFillBodyCell />\n </DataGridTableBodyRowSkeleton>\n ))}\n </>\n );\n }\n\n if (!table.getRowModel().rows.length) return <DataGridTableEmpty />;\n\n return (\n <SortableContext items={dataIds} strategy={sortingStrategy}>\n {table.getRowModel().rows.map((row: Row<DataGridFeatures, TData>) => {\n return (\n <DataGridTableDndRow\n row={row}\n renderRowDecoration={renderRowDecoration}\n dropIndicator={dropIndicator}\n key={row.id}\n />\n );\n })}\n </SortableContext>\n );\n}\n\n/**\n * Memoized body rows: skip re-renders during active column resize.\n * Column widths update via CSS variables on the <table> element,\n * so the browser handles width changes without React re-renders.\n */\nconst MemoizedDataGridTableDndRowsBody = memo(\n DataGridTableDndRowsBody,\n (_prev, next) => !!next.table.state.columnResizing.isResizingColumn,\n) as typeof DataGridTableDndRowsBody;\n\nfunction DataGridTableDndRows<TData extends object>({\n handleDragEnd,\n dataIds,\n footerContent,\n collisionDetection = closestCenter,\n modifiers,\n sortingStrategy = holdRowsInPlaceStrategy,\n renderRowDecoration,\n dropIndicator = true,\n onDragStart,\n onDragMove,\n onDragOver,\n onDragCancel,\n}: {\n handleDragEnd: (event: DragEndEvent) => void;\n dataIds: UniqueIdentifier[];\n footerContent?: ReactNode;\n /** Overrides the default `closestCenter` strategy. */\n collisionDetection?: CollisionDetection;\n /**\n * Replaces the default axis restriction, e.g. drop `restrictToVerticalAxis`\n * to allow the horizontal gesture that tree re-parenting relies on. The\n * table container clamp is always applied after these, so a dragged row\n * cannot leave the grid.\n */\n modifiers?: Modifier[];\n /**\n * Replaces the default `verticalListSortingStrategy`. Return null from a\n * strategy to leave every row exactly where it is. A tree needs that: its drop\n * is either INTO the hovered row or BETWEEN two rows, and which one it is\n * flips as the pointer crosses a single row, so a gap that opens for one and\n * shuts for the other flickers the whole surface. Such a caller draws its own\n * insertion line instead, and pairs this with a modifier that holds the\n * carried row still, since a gap nothing moves into is just a hole.\n */\n sortingStrategy?: SortingStrategy;\n /** Per-row slot for drop indicators and depth guides. */\n renderRowDecoration?: DataGridTableDndRowDecoration<TData>;\n /**\n * Draws a line on the seam the carried row would land on. On by default;\n * pass `false` when `renderRowDecoration` paints its own insertion affordance\n * and the two would compete.\n */\n dropIndicator?: boolean;\n onDragStart?: (event: DragStartEvent) => void;\n onDragMove?: (event: DragMoveEvent) => void;\n onDragOver?: (event: DragOverEvent) => void;\n onDragCancel?: (event: DragCancelEvent) => void;\n}) {\n const { table, props } = useDataGrid<TData>();\n const tableContainerRef = useRef<HTMLDivElement>(null);\n const [isDraggingRow, setIsDraggingRow] = useState(false);\n // The overlay is portalled to the document body. dnd-kit renders DragOverlay\n // in place, and it positions with `position: fixed` against viewport\n // coordinates - so any ancestor that establishes a containing block for fixed\n // descendants silently re-anchors it. `content-visibility`, `contain`,\n // `transform`, `filter` and `will-change` all do that, and the first two are\n // exactly what a card grid uses to defer off-screen work. The clone then\n // lands offset by that ancestor's own top/left, and the container clamp\n // below mis-clamps too, because its rects are measured in viewport space.\n //\n // Resolved in an effect rather than read at render so the server and the\n // first client render agree. A drag cannot start before hydration, so the\n // overlay being absent for one frame costs nothing.\n const [portalTarget, setPortalTarget] = useState<HTMLElement | null>(null);\n\n useEffect(() => {\n setPortalTarget(document.body);\n }, []);\n // The row being carried, plus the column widths measured off the header the\n // moment the drag starts. The clone lives outside the table, so it has no\n // columns of its own and has to be told what they are.\n const [carried, setCarried] = useState<{\n id: UniqueIdentifier;\n width: number;\n height: number;\n columns: number[];\n } | null>(null);\n\n const pickUpRow = useCallback((id: UniqueIdentifier) => {\n const container = tableContainerRef.current;\n const head = container?.querySelector(\"thead tr\");\n if (!container || !head) {\n setCarried(null);\n return;\n }\n\n // The clone has to be exactly as tall as the row it was lifted from.\n // A fixed height reads as the grid growing under the pointer the moment\n // you pick a row up, and it is wrong in both directions: rows whose\n // content wraps are taller than any constant, and dense rows are shorter.\n const source = Array.from(\n container.querySelectorAll<HTMLElement>(\"tbody tr[data-row-id]\"),\n ).find((candidate) => candidate.dataset.rowId === String(id));\n const height = source?.getBoundingClientRect().height ?? 0;\n\n // The fill cell is a header-only spacer that soaks up the surplus a column\n // resize leaves behind, and the clone renders data cells only. Measuring it\n // in would make the clone's table wider than the cells it actually holds,\n // and `table-fixed` hands that orphaned width back out across every column\n // -- the carried row comes out visibly wider than the row it was lifted\n // from. So the width is the sum of what we render, never the header's own.\n const columns = Array.from(head.children)\n .filter((cell) => cell.getAttribute(\"data-slot\") !== \"data-grid-table-fill-head-cell\")\n .map((cell) => cell.getBoundingClientRect().width);\n\n setCarried({\n id,\n width: columns.reduce((total, width) => total + width, 0),\n height,\n columns,\n });\n }, []);\n\n const carriedRow = carried\n ? table.getRowModel().rows.find((row: Row<DataGridFeatures, TData>) => row.id === carried.id)\n : undefined;\n\n const sensors = useSensors(\n useSensor(MouseSensor, {}),\n useSensor(TouchSensor, {}),\n // Keyboard reordering moves one sortable position per keypress instead\n // of the sensor's raw 25px default.\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n }),\n );\n\n useEffect(() => {\n if (!isDraggingRow) return;\n\n const { body, documentElement } = document;\n const previousBodyCursor = body.style.cursor;\n const previousDocumentCursor = documentElement.style.cursor;\n\n body.style.cursor = \"grabbing\";\n documentElement.style.cursor = \"grabbing\";\n\n return () => {\n body.style.cursor = previousBodyCursor;\n documentElement.style.cursor = previousDocumentCursor;\n };\n }, [isDraggingRow]);\n\n const resolvedModifiers = useMemo(() => {\n const restrictToTableContainer: Modifier = ({ transform, draggingNodeRect }) => {\n if (!tableContainerRef.current || !draggingNodeRect) {\n return transform;\n }\n\n const containerRect = tableContainerRef.current.getBoundingClientRect();\n const { x, y } = transform;\n\n const minX = containerRect.left - draggingNodeRect.left;\n const maxX = containerRect.right - draggingNodeRect.right;\n const minY = containerRect.top - draggingNodeRect.top;\n const maxY = containerRect.bottom - draggingNodeRect.bottom;\n\n return {\n ...transform,\n // The horizontal rail only engages while the default axis restriction\n // is in force. A row is exactly as wide as the viewport, so minX and\n // maxX both collapse to 0 and clamping x erases it entirely: harmless\n // under restrictToVerticalAxis, which zeroes x anyway, but fatal for a\n // caller that replaced the restriction precisely to READ x, as a tree\n // does to resolve drop depth. Vertical is railed either way, which is\n // what actually keeps a dragged row inside the grid.\n x: modifiers ? x : Math.max(minX, Math.min(maxX, x)),\n y: Math.max(minY, Math.min(maxY, y)),\n };\n };\n\n // The container clamp is a safety rail rather than a policy, so it stays\n // applied even when the caller replaces the axis restriction.\n return [...(modifiers ?? [restrictToVerticalAxis]), restrictToTableContainer];\n }, [modifiers]);\n\n return (\n <DndContext\n id={useId()}\n collisionDetection={collisionDetection}\n modifiers={resolvedModifiers}\n onDragCancel={(event) => {\n setIsDraggingRow(false);\n setCarried(null);\n onDragCancel?.(event);\n }}\n onDragEnd={(event) => {\n setIsDraggingRow(false);\n setCarried(null);\n handleDragEnd(event);\n }}\n onDragMove={onDragMove}\n onDragOver={onDragOver}\n onDragStart={(event) => {\n setIsDraggingRow(true);\n pickUpRow(event.active.id);\n onDragStart?.(event);\n }}\n sensors={sensors}\n >\n <DataGridTableViewport\n viewportRef={tableContainerRef}\n className={isDraggingRow ? \"relative cursor-grabbing **:cursor-grabbing!\" : \"relative\"}\n >\n <DataGridTableBase>\n <DataGridTableHead>\n {table\n .getHeaderGroups()\n .map((headerGroup: HeaderGroup<DataGridFeatures, TData>, index) => {\n return (\n <DataGridTableHeadRow key={index} rowId={headerGroup.id}>\n {headerGroup.headers.map((header, index) => {\n const { column } = header;\n\n return (\n <DataGridTableHeadRowCell header={header} key={index}>\n {header.isPlaceholder\n ? null\n : props.tableLayout?.columnsResizable && column.getCanResize()\n ? flexRender(header.column.columnDef.header, header.getContext())\n : flexRender(header.column.columnDef.header, header.getContext())}\n {props.tableLayout?.columnsResizable && column.getCanResize() && (\n <DataGridTableHeadRowCellResize header={header} />\n )}\n </DataGridTableHeadRowCell>\n );\n })}\n <DataGridTableFillHeadCell />\n </DataGridTableHeadRow>\n );\n })}\n </DataGridTableHead>\n\n {(props.tableLayout?.stripped || !props.tableLayout?.rowBorder) && (\n <DataGridTableRowSpacer />\n )}\n\n <DataGridTableBody>\n <MemoizedDataGridTableDndRowsBody\n table={table}\n dataIds={dataIds}\n renderRowDecoration={renderRowDecoration}\n dropIndicator={dropIndicator}\n sortingStrategy={sortingStrategy}\n />\n </DataGridTableBody>\n\n {footerContent && <DataGridTableFoot>{footerContent}</DataGridTableFoot>}\n </DataGridTableBase>\n </DataGridTableViewport>\n\n {/* The row you are actually holding. It is a real clone rendered outside\n the table, which is the only way a dragged row can follow the pointer\n without disturbing the grid: it adds no cell, so it cannot alter the\n column widths, and it floats above the rows rather than through them.\n Its presence also tells dnd-kit to stop translating the source row, so\n the row left behind simply dims in place.\n\n Portalled to the body so the fixed positioning resolves against the\n viewport wherever the grid is mounted. React context crosses a portal,\n so DndContext still reaches it. */}\n {portalTarget\n ? createPortal(\n <DragOverlay dropAnimation={null}>\n {carried && carriedRow ? (\n <table\n aria-hidden=\"true\"\n style={{ width: carried.width, tableLayout: \"fixed\" }}\n className=\"pointer-events-none cursor-grabbing rounded-md border border-border bg-background shadow-lg\"\n >\n <tbody>\n {/* Padding rides on the inner element, not the cell. A `td` can\n never render narrower than its own horizontal padding, so a\n column resized below that would silently widen here and the\n clone would stop matching the row it came from. Height comes\n from the measured source row for the same reason the widths\n do: the clone has no row of its own to inherit it from. */}\n <tr\n style={{ height: carried.height || undefined }}\n className=\"[&>td]:p-0 [&>td]:align-middle\"\n >\n {carriedRow\n .getVisibleCells()\n .map((cell: Cell<DataGridFeatures, TData, unknown>, index: number) => (\n <td\n key={cell.id}\n // Falls back to the column's own size so an unforeseen\n // header/cell count mismatch degrades to a real width\n // rather than to `auto`.\n style={{\n width: carried.columns[index] ?? cell.column.getSize(),\n }}\n >\n <div className=\"truncate px-3\">\n {flexRender(cell.column.columnDef.cell, cell.getContext())}\n </div>\n </td>\n ))}\n </tr>\n </tbody>\n </table>\n ) : null}\n </DragOverlay>,\n portalTarget,\n )\n : null}\n </DndContext>\n );\n}\n\nexport type { DataGridTableDndRowData, DataGridTableDndRowDecoration };\nexport { DataGridTableDndRowHandle, DataGridTableDndRows };\n"],"mappings":";;;;;;;;;;;;;;;AAuEA,MAAM,qBAAqB,cAGjB,IAAI;AA4Bd,SAAS,0BAA0B,EACjC,WACA,UACA,iBAYC;CACD,MAAM,EAAE,SAAS,YAAY;CAC7B,MAAM,UAAU,WAAW,kBAAkB;CAC7C,MAAM,wBAAwB,iBAAiB,KAAK,OAAO;CAE3D,IAAI,CAAC,WAAW,UACd,OACE,oBAAC,QAAD;EACE,SAAQ;EACR,MAAK;EACL,WAAW,GACT,+FAIA,YAAY,sBACZ,SACF;EACA,cAAY,WAAW,wBAAwB,KAAK,OAAO;EAC3D,OAAO,WAAW,wBAAwB,KAAA;EAC1C,UAAA;EAEA,UAAA,oBAAC,oBAAD,EAAoB,eAAY,OAAQ,CAAA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AA,EAAU;KAC7C,WAAU;KAET,UAAA,WACE,gBAAgB,CAAC,CACjB,KAAK,MAA8C,UAClD,oBAAC,MAAD;MAKE,OAAO,EACL,OAAO,QAAQ,QAAQ,UAAU,KAAK,OAAO,QAAQ,EACvD;MAEA,UAAA,oBAAC,OAAD;OAAK,WAAU;OACZ,UAAA,WAAW,KAAK,OAAO,UAAU,MAAM,KAAK,WAAW,CAAC;MACtD,CAAA;KACH,GAXG,KAAK,EAWR,CACL;IACD,CAAA,EACC,CAAA;GACF,CAAA,IACL;EACO,CAAA,GACb,YACF,IACA,IACM;;AAEhB"}
|
|
1
|
+
{"version":3,"file":"data-grid-table-dnd-rows.js","names":[],"sources":["../../../../src/components/reui/data-grid/data-grid-table-dnd-rows.tsx"],"sourcesContent":["\"use client\";\n\nimport type { CSSProperties, ReactNode } from \"react\";\nimport {\n createContext,\n memo,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n type CollisionDetection,\n closestCenter,\n DndContext,\n type DragCancelEvent,\n type DragEndEvent,\n type DragMoveEvent,\n type DragOverEvent,\n DragOverlay,\n type DragStartEvent,\n KeyboardSensor,\n type Modifier,\n MouseSensor,\n TouchSensor,\n type UniqueIdentifier,\n useSensor,\n useSensors,\n} from \"@dnd-kit/core\";\nimport { restrictToVerticalAxis } from \"@dnd-kit/modifiers\";\nimport {\n SortableContext,\n type SortingStrategy,\n sortableKeyboardCoordinates,\n useSortable,\n} from \"@dnd-kit/sortable\";\nimport { CSS } from \"@dnd-kit/utilities\";\nimport type { Cell, HeaderGroup, Row } from \"@tanstack/react-table\";\nimport { flexRender } from \"@tanstack/react-table\";\nimport { GripHorizontalIcon } from \"lucide-react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { Button } from \"../../ui/button\";\nimport type { DataGridFeatures, DataGridTableInstance } from \"./data-grid\";\nimport { useDataGrid } from \"./data-grid\";\nimport {\n DataGridTableBase,\n DataGridTableBody,\n DataGridTableBodyRow,\n DataGridTableBodyRowCell,\n DataGridTableBodyRowExpandded,\n DataGridTableBodyRowSkeleton,\n DataGridTableBodyRowSkeletonCell,\n DataGridTableEmpty,\n DataGridTableFillBodyCell,\n DataGridTableFillHeadCell,\n DataGridTableFoot,\n DataGridTableHead,\n DataGridTableHeadRow,\n DataGridTableHeadRowCell,\n DataGridTableHeadRowCellResize,\n DataGridTableRowSpacer,\n DataGridTableViewport,\n} from \"./data-grid-table\";\n\n// Context to share sortable listeners from row to handle\ntype SortableContextValue = ReturnType<typeof useSortable>;\nconst SortableRowContext = createContext<Pick<\n SortableContextValue,\n \"attributes\" | \"listeners\"\n> | null>(null);\n\n/**\n * Tree metadata attached to every sortable row, readable from\n * `active.data.current` / `over.data.current` in any drag event. Cross-parent\n * drops can be resolved from it without re-deriving the shape of the table.\n */\ntype DataGridTableDndRowData = {\n type: \"data-grid-row\";\n /** Tree depth, 0 for root rows. */\n depth: number;\n /** Index within the parent's children, or within the root rows. */\n index: number;\n /** Parent row id, or null for root rows. */\n parentId: string | null;\n};\n\n/**\n * Per-row render slot for drop indicators and depth guides. The returned node\n * is positioned over the row, so it never adds a column, shifts striping, or\n * gets clipped by a truncating resizable cell.\n */\ntype DataGridTableDndRowDecoration<TData extends object> = (context: {\n row: Row<DataGridFeatures, TData>;\n isDragging: boolean;\n isOver: boolean;\n}) => ReactNode;\n\nfunction DataGridTableDndRowHandle({\n className,\n disabled,\n disabledLabel,\n}: {\n className?: string;\n /**\n * Renders the grip inert instead of withdrawing it. A grid that reorders on\n * one truth (manual order) and sorts on another cannot honour both at once,\n * but dropping the handle entirely collapses the gutter and reads as broken\n * rather than as unavailable. Keep the column's shape, mute the control.\n */\n disabled?: boolean;\n /** Announced and shown on hover in place of the drag affordance. */\n disabledLabel?: string;\n}) {\n const { i18n } = useDataGrid();\n const context = useContext(SortableRowContext);\n const resolvedDisabledLabel = disabledLabel ?? i18n.labels.reorderingUnavailable;\n\n if (!context || disabled) {\n return (\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n className={cn(\n \"size-7 cursor-grab opacity-70 hover:bg-transparent hover:opacity-100 active:cursor-grabbing\",\n // The Button's own disabled treatment supplies the muting; only the\n // cursor needs saying, so the grip reads as unavailable rather than\n // merely unresponsive.\n disabled && \"cursor-not-allowed\",\n className,\n )}\n aria-label={disabled ? resolvedDisabledLabel : i18n.labels.dragToReorderRow}\n title={disabled ? resolvedDisabledLabel : undefined}\n disabled\n >\n <GripHorizontalIcon aria-hidden=\"true\" />\n </Button>\n );\n }\n\n return (\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n className={cn(\n \"size-7 cursor-grab opacity-70 hover:bg-transparent hover:opacity-100 active:cursor-grabbing\",\n className,\n )}\n aria-label={i18n.labels.dragToReorderRow}\n {...context.attributes}\n {...context.listeners}\n >\n <GripHorizontalIcon aria-hidden=\"true\" />\n </Button>\n );\n}\n\n/**\n * The rows do not move while one is being carried.\n *\n * Sliding the siblings apart opens a gap the carried row could go into, which\n * reads well in a list of identical rows and badly in a table: the gap is the\n * height of the row you are holding, so with rows of unequal height it never\n * matches the slot it claims to be, and the row you picked up slides away from\n * where it started - which is exactly the position you need to remember if you\n * decide not to drop it.\n *\n * Holding everything still keeps the origin legible, and nothing is lost: the\n * DragOverlay clone follows the pointer and the drop indicator names the seam.\n * Pass `verticalListSortingStrategy` as `sortingStrategy` for the old feel.\n */\nconst holdRowsInPlaceStrategy: SortingStrategy = () => null;\n\nfunction DataGridTableDndRow<TData extends object>({\n row,\n renderRowDecoration,\n dropIndicator = true,\n}: {\n row: Row<DataGridFeatures, TData>;\n renderRowDecoration?: DataGridTableDndRowDecoration<TData>;\n dropIndicator?: boolean;\n}) {\n const rowData: DataGridTableDndRowData = {\n type: \"data-grid-row\",\n depth: row.depth,\n index: row.index,\n parentId: row.getParentRow()?.id ?? null,\n };\n\n const {\n transform,\n setNodeRef,\n isDragging,\n isOver,\n attributes,\n listeners,\n index,\n activeIndex,\n overIndex,\n } = useSortable({\n id: row.id,\n data: rowData,\n });\n\n // Which edge of THIS row the carried row would land on, or null when it is\n // not the drop target. Nothing slides apart any more, so the bar is the only\n // thing that says where the drop goes: it marks the row at the destination\n // index, on the side the carried row comes to rest.\n //\n // Dragging down it lands after the target, dragging up before it, so the\n // edge follows the direction of travel.\n const dropEdge =\n dropIndicator && activeIndex !== -1 && index === overIndex && !isDragging\n ? activeIndex < overIndex\n ? \"bottom\"\n : \"top\"\n : null;\n\n const style: CSSProperties = {\n transform: CSS.Transform.toString(transform),\n // dnd-kit's transition is deliberately dropped. A transition on a transform\n // property of a `tr` does not merely fail to animate in Chrome, it stops the\n // transform applying at all: the element sits at the start value forever.\n // The drag source escapes it because dnd-kit disables its own transition\n // while it is being dragged, which is why the carried row used to be the\n // ONLY one that moved and every other row silently refused to open a gap.\n // Displacement therefore lands in one step, which is what a table wants.\n zIndex: isDragging ? 1 : 0,\n position: \"relative\",\n cursor: isDragging ? \"grabbing\" : undefined,\n // The row you are holding is drawn by the DragOverlay, so the one left\n // behind is not a second copy of it - it is the slot you came from, and it\n // stays exactly where it was. Fading alone read as \"this row is busy\";\n // the outline says \"this is the space you are moving out of\", which is the\n // thing you need if you change your mind mid-drag.\n ...(isDragging && {\n opacity: 0.4,\n // Inset so the dashes sit inside the row box and cannot be clipped by\n // the neighbouring row's border.\n outline: \"1px dashed var(--border)\",\n outlineOffset: \"-1px\",\n }),\n };\n\n const decoration = renderRowDecoration?.({ row, isDragging, isOver });\n\n return (\n <SortableRowContext.Provider value={{ attributes, listeners }}>\n <DataGridTableBodyRow row={row} dndRef={setNodeRef} dndStyle={style}>\n {row.getVisibleCells().map((cell: Cell<DataGridFeatures, TData, unknown>, index, cells) => {\n return (\n <DataGridTableBodyRowCell cell={cell} key={cell.id}>\n {flexRender(cell.column.columnDef.cell, cell.getContext())}\n {decoration && index === cells.length - 1 ? (\n // Rides inside the last cell rather than in a `td` of its own.\n // An absolutely positioned `td` is still a cell as far as table\n // layout is concerned, so it added a NINTH column with no width\n // of its own, and under `table-layout: fixed` that new column\n // swallowed the whole surplus the real columns had been sharing\n // — every column snapped back to its declared size and the row's\n // content visibly narrowed the moment a drag began. A plain\n // element adds no column. It still anchors to the ROW, because\n // the row is the nearest positioned ancestor, so the decoration\n // spans the full width and is not clipped by the cell.\n <div\n aria-hidden=\"true\"\n data-slot=\"data-grid-table-row-decoration\"\n className=\"pointer-events-none absolute inset-0\"\n >\n {decoration}\n </div>\n ) : null}\n {dropEdge && index === cells.length - 1 ? (\n // Same anchoring trick as the decoration above: a plain\n // element inside the last cell, so it adds no column and\n // cannot disturb `table-layout: fixed`. It spans the row\n // because the row is the nearest positioned ancestor.\n <div\n aria-hidden=\"true\"\n data-slot=\"data-grid-table-row-drop-indicator\"\n data-edge={dropEdge}\n className=\"pointer-events-none absolute inset-0 z-20\"\n >\n {/* Two solid pixels down the leading edge, the same marker\n the tree drag uses for its drop target. A wash across\n the row has to stay faint enough not to read as a\n selected row, and in the achromatic styles primary\n carries no chroma at all, so faint plus colourless is\n just grey. The bar reads at any weight and leaves the\n row's own background to hover and selection.\n\n The bar is the whole indicator: the gap the rows have\n already opened says which side, so a rule across the\n seam as well only competes with the row borders it sits\n between. `data-edge` still carries the direction for\n anyone styling their own. */}\n <span className=\"absolute inset-y-0 start-0 w-0.5 bg-primary\" />\n </div>\n ) : null}\n </DataGridTableBodyRowCell>\n );\n })}\n <DataGridTableFillBodyCell />\n </DataGridTableBodyRow>\n {row.getIsExpanded() && <DataGridTableBodyRowExpandded row={row} />}\n </SortableRowContext.Provider>\n );\n}\n\nfunction DataGridTableDndRowsBody<TData extends object>({\n table,\n dataIds,\n renderRowDecoration,\n dropIndicator,\n sortingStrategy,\n}: {\n table: DataGridTableInstance<TData>;\n dataIds: UniqueIdentifier[];\n renderRowDecoration?: DataGridTableDndRowDecoration<TData>;\n dropIndicator?: boolean;\n sortingStrategy: SortingStrategy;\n}) {\n const { isLoading, props } = useDataGrid();\n const pagination = table.state.pagination;\n\n if (props.loadingMode === \"skeleton\" && isLoading && pagination?.pageSize) {\n return (\n <>\n {Array.from({ length: pagination.pageSize }).map((_, rowIndex) => (\n <DataGridTableBodyRowSkeleton key={rowIndex}>\n {table.getVisibleFlatColumns().map((column, colIndex) => {\n return (\n <DataGridTableBodyRowSkeletonCell column={column} key={colIndex}>\n {column.columnDef.meta?.skeleton}\n </DataGridTableBodyRowSkeletonCell>\n );\n })}\n <DataGridTableFillBodyCell />\n </DataGridTableBodyRowSkeleton>\n ))}\n </>\n );\n }\n\n if (!table.getRowModel().rows.length) return <DataGridTableEmpty />;\n\n return (\n <SortableContext items={dataIds} strategy={sortingStrategy}>\n {table.getRowModel().rows.map((row: Row<DataGridFeatures, TData>) => {\n return (\n <DataGridTableDndRow\n row={row}\n renderRowDecoration={renderRowDecoration}\n dropIndicator={dropIndicator}\n key={row.id}\n />\n );\n })}\n </SortableContext>\n );\n}\n\n/**\n * Memoized body rows: skip re-renders during active column resize.\n * Column widths update via CSS variables on the <table> element,\n * so the browser handles width changes without React re-renders.\n */\nconst MemoizedDataGridTableDndRowsBody = memo(\n DataGridTableDndRowsBody,\n (_prev, next) => !!next.table.state.columnResizing.isResizingColumn,\n) as typeof DataGridTableDndRowsBody;\n\nfunction DataGridTableDndRows<TData extends object>({\n handleDragEnd,\n dataIds,\n footerContent,\n collisionDetection = closestCenter,\n modifiers,\n sortingStrategy = holdRowsInPlaceStrategy,\n renderRowDecoration,\n dropIndicator = true,\n onDragStart,\n onDragMove,\n onDragOver,\n onDragCancel,\n}: {\n handleDragEnd: (event: DragEndEvent) => void;\n dataIds: UniqueIdentifier[];\n footerContent?: ReactNode;\n /** Overrides the default `closestCenter` strategy. */\n collisionDetection?: CollisionDetection;\n /**\n * Replaces the default axis restriction, e.g. drop `restrictToVerticalAxis`\n * to allow the horizontal gesture that tree re-parenting relies on. The\n * table container clamp is always applied after these, so a dragged row\n * cannot leave the grid.\n */\n modifiers?: Modifier[];\n /**\n * Replaces the default `verticalListSortingStrategy`. Return null from a\n * strategy to leave every row exactly where it is. A tree needs that: its drop\n * is either INTO the hovered row or BETWEEN two rows, and which one it is\n * flips as the pointer crosses a single row, so a gap that opens for one and\n * shuts for the other flickers the whole surface. Such a caller draws its own\n * insertion line instead, and pairs this with a modifier that holds the\n * carried row still, since a gap nothing moves into is just a hole.\n */\n sortingStrategy?: SortingStrategy;\n /** Per-row slot for drop indicators and depth guides. */\n renderRowDecoration?: DataGridTableDndRowDecoration<TData>;\n /**\n * Draws a line on the seam the carried row would land on. On by default;\n * pass `false` when `renderRowDecoration` paints its own insertion affordance\n * and the two would compete.\n */\n dropIndicator?: boolean;\n onDragStart?: (event: DragStartEvent) => void;\n onDragMove?: (event: DragMoveEvent) => void;\n onDragOver?: (event: DragOverEvent) => void;\n onDragCancel?: (event: DragCancelEvent) => void;\n}) {\n const { table, props } = useDataGrid<TData>();\n const tableContainerRef = useRef<HTMLDivElement>(null);\n const [isDraggingRow, setIsDraggingRow] = useState(false);\n // The overlay is portalled to the document body. dnd-kit renders DragOverlay\n // in place, and it positions with `position: fixed` against viewport\n // coordinates - so any ancestor that establishes a containing block for fixed\n // descendants silently re-anchors it. `content-visibility`, `contain`,\n // `transform`, `filter` and `will-change` all do that, and the first two are\n // exactly what a card grid uses to defer off-screen work. The clone then\n // lands offset by that ancestor's own top/left, and the container clamp\n // below mis-clamps too, because its rects are measured in viewport space.\n //\n // Resolved in an effect rather than read at render so the server and the\n // first client render agree. A drag cannot start before hydration, so the\n // overlay being absent for one frame costs nothing.\n const [portalTarget, setPortalTarget] = useState<HTMLElement | null>(null);\n\n useEffect(() => {\n setPortalTarget(document.body);\n }, []);\n // The row being carried, plus the column widths measured off the header the\n // moment the drag starts. The clone lives outside the table, so it has no\n // columns of its own and has to be told what they are.\n const [carried, setCarried] = useState<{\n id: UniqueIdentifier;\n width: number;\n height: number;\n columns: number[];\n } | null>(null);\n\n const pickUpRow = useCallback((id: UniqueIdentifier) => {\n const container = tableContainerRef.current;\n const head = container?.querySelector(\"thead tr\");\n if (!container || !head) {\n setCarried(null);\n return;\n }\n\n // The clone has to be exactly as tall as the row it was lifted from.\n // A fixed height reads as the grid growing under the pointer the moment\n // you pick a row up, and it is wrong in both directions: rows whose\n // content wraps are taller than any constant, and dense rows are shorter.\n const source = Array.from(\n container.querySelectorAll<HTMLElement>(\"tbody tr[data-row-id]\"),\n ).find((candidate) => candidate.dataset.rowId === String(id));\n const height = source?.getBoundingClientRect().height ?? 0;\n\n // The fill cell is a header-only spacer that soaks up the surplus a column\n // resize leaves behind, and the clone renders data cells only. Measuring it\n // in would make the clone's table wider than the cells it actually holds,\n // and `table-fixed` hands that orphaned width back out across every column\n // -- the carried row comes out visibly wider than the row it was lifted\n // from. So the width is the sum of what we render, never the header's own.\n const columns = Array.from(head.children)\n .filter((cell) => cell.getAttribute(\"data-slot\") !== \"data-grid-table-fill-head-cell\")\n .map((cell) => cell.getBoundingClientRect().width);\n\n setCarried({\n id,\n width: columns.reduce((total, width) => total + width, 0),\n height,\n columns,\n });\n }, []);\n\n const carriedRow = carried\n ? table.getRowModel().rows.find((row: Row<DataGridFeatures, TData>) => row.id === carried.id)\n : undefined;\n\n const sensors = useSensors(\n useSensor(MouseSensor, {}),\n useSensor(TouchSensor, {}),\n // Keyboard reordering moves one sortable position per keypress instead\n // of the sensor's raw 25px default.\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n }),\n );\n\n useEffect(() => {\n if (!isDraggingRow) return;\n\n const { body, documentElement } = document;\n const previousBodyCursor = body.style.cursor;\n const previousDocumentCursor = documentElement.style.cursor;\n\n body.style.cursor = \"grabbing\";\n documentElement.style.cursor = \"grabbing\";\n\n return () => {\n body.style.cursor = previousBodyCursor;\n documentElement.style.cursor = previousDocumentCursor;\n };\n }, [isDraggingRow]);\n\n const resolvedModifiers = useMemo(() => {\n const restrictToTableContainer: Modifier = ({ transform, draggingNodeRect }) => {\n if (!tableContainerRef.current || !draggingNodeRect) {\n return transform;\n }\n\n const containerRect = tableContainerRef.current.getBoundingClientRect();\n const { x, y } = transform;\n\n const minX = containerRect.left - draggingNodeRect.left;\n const maxX = containerRect.right - draggingNodeRect.right;\n const minY = containerRect.top - draggingNodeRect.top;\n const maxY = containerRect.bottom - draggingNodeRect.bottom;\n\n return {\n ...transform,\n // The horizontal rail only engages while the default axis restriction\n // is in force. A row is exactly as wide as the viewport, so minX and\n // maxX both collapse to 0 and clamping x erases it entirely: harmless\n // under restrictToVerticalAxis, which zeroes x anyway, but fatal for a\n // caller that replaced the restriction precisely to READ x, as a tree\n // does to resolve drop depth. Vertical is railed either way, which is\n // what actually keeps a dragged row inside the grid.\n x: modifiers ? x : Math.max(minX, Math.min(maxX, x)),\n y: Math.max(minY, Math.min(maxY, y)),\n };\n };\n\n // The container clamp is a safety rail rather than a policy, so it stays\n // applied even when the caller replaces the axis restriction.\n return [...(modifiers ?? [restrictToVerticalAxis]), restrictToTableContainer];\n }, [modifiers]);\n\n return (\n <DndContext\n id={useId()}\n collisionDetection={collisionDetection}\n modifiers={resolvedModifiers}\n onDragCancel={(event) => {\n setIsDraggingRow(false);\n setCarried(null);\n onDragCancel?.(event);\n }}\n onDragEnd={(event) => {\n setIsDraggingRow(false);\n setCarried(null);\n handleDragEnd(event);\n }}\n onDragMove={onDragMove}\n onDragOver={onDragOver}\n onDragStart={(event) => {\n setIsDraggingRow(true);\n pickUpRow(event.active.id);\n onDragStart?.(event);\n }}\n sensors={sensors}\n >\n <DataGridTableViewport\n viewportRef={tableContainerRef}\n className={isDraggingRow ? \"relative cursor-grabbing **:cursor-grabbing!\" : \"relative\"}\n >\n <DataGridTableBase>\n <DataGridTableHead>\n {table\n .getHeaderGroups()\n .map((headerGroup: HeaderGroup<DataGridFeatures, TData>, index) => {\n return (\n <DataGridTableHeadRow key={index} rowId={headerGroup.id}>\n {headerGroup.headers.map((header, index) => {\n const { column } = header;\n\n return (\n <DataGridTableHeadRowCell header={header} key={index}>\n {header.isPlaceholder\n ? null\n : props.tableLayout?.columnsResizable && column.getCanResize()\n ? flexRender(header.column.columnDef.header, header.getContext())\n : flexRender(header.column.columnDef.header, header.getContext())}\n {props.tableLayout?.columnsResizable && column.getCanResize() && (\n <DataGridTableHeadRowCellResize header={header} />\n )}\n </DataGridTableHeadRowCell>\n );\n })}\n <DataGridTableFillHeadCell />\n </DataGridTableHeadRow>\n );\n })}\n </DataGridTableHead>\n\n {(props.tableLayout?.stripped || !props.tableLayout?.rowBorder) && (\n <DataGridTableRowSpacer />\n )}\n\n <DataGridTableBody>\n <MemoizedDataGridTableDndRowsBody\n table={table}\n dataIds={dataIds}\n renderRowDecoration={renderRowDecoration}\n dropIndicator={dropIndicator}\n sortingStrategy={sortingStrategy}\n />\n </DataGridTableBody>\n\n {footerContent && <DataGridTableFoot>{footerContent}</DataGridTableFoot>}\n </DataGridTableBase>\n </DataGridTableViewport>\n\n {/* The row you are actually holding. It is a real clone rendered outside\n the table, which is the only way a dragged row can follow the pointer\n without disturbing the grid: it adds no cell, so it cannot alter the\n column widths, and it floats above the rows rather than through them.\n Its presence also tells dnd-kit to stop translating the source row, so\n the row left behind simply dims in place.\n\n Portalled to the body so the fixed positioning resolves against the\n viewport wherever the grid is mounted. React context crosses a portal,\n so DndContext still reaches it. */}\n {portalTarget\n ? createPortal(\n <DragOverlay dropAnimation={null}>\n {carried && carriedRow ? (\n <table\n aria-hidden=\"true\"\n style={{ width: carried.width, tableLayout: \"fixed\" }}\n className=\"pointer-events-none cursor-grabbing rounded-md border border-border bg-background shadow-lg\"\n >\n <tbody>\n {/* Padding rides on the inner element, not the cell. A `td` can\n never render narrower than its own horizontal padding, so a\n column resized below that would silently widen here and the\n clone would stop matching the row it came from. Height comes\n from the measured source row for the same reason the widths\n do: the clone has no row of its own to inherit it from. */}\n <tr\n style={{ height: carried.height || undefined }}\n className=\"[&>td]:p-0 [&>td]:align-middle\"\n >\n {carriedRow\n .getVisibleCells()\n .map((cell: Cell<DataGridFeatures, TData, unknown>, index: number) => (\n <td\n key={cell.id}\n // Falls back to the column's own size so an unforeseen\n // header/cell count mismatch degrades to a real width\n // rather than to `auto`.\n style={{\n width: carried.columns[index] ?? cell.column.getSize(),\n }}\n >\n <div className=\"truncate px-3\">\n {flexRender(cell.column.columnDef.cell, cell.getContext())}\n </div>\n </td>\n ))}\n </tr>\n </tbody>\n </table>\n ) : null}\n </DragOverlay>,\n portalTarget,\n )\n : null}\n </DndContext>\n );\n}\n\nexport type { DataGridTableDndRowData, DataGridTableDndRowDecoration };\nexport { DataGridTableDndRowHandle, DataGridTableDndRows };\n"],"mappings":";;;;;;;;;;;;;;;AAuEA,MAAM,qBAAqB,cAGjB,IAAI;AA4Bd,SAAS,0BAA0B,EACjC,WACA,UACA,iBAYC;CACD,MAAM,EAAE,SAAS,YAAY;CAC7B,MAAM,UAAU,WAAW,kBAAkB;CAC7C,MAAM,wBAAwB,iBAAiB,KAAK,OAAO;CAE3D,IAAI,CAAC,WAAW,UACd,OACE,oBAAC,QAAD;EACE,SAAQ;EACR,MAAK;EACL,WAAW,GACT,+FAIA,YAAY,sBACZ,SACF;EACA,cAAY,WAAW,wBAAwB,KAAK,OAAO;EAC3D,OAAO,WAAW,wBAAwB,KAAA;EAC1C,UAAA;EAEA,UAAA,oBAAC,oBAAD,EAAoB,eAAY,OAAQ,CAAA;CAClC,CAAA;CAIZ,OACE,oBAAC,QAAD;EACE,SAAQ;EACR,MAAK;EACL,WAAW,GACT,+FACA,SACF;EACA,cAAY,KAAK,OAAO;EACxB,GAAI,QAAQ;EACZ,GAAI,QAAQ;EAEZ,UAAA,oBAAC,oBAAD,EAAoB,eAAY,OAAQ,CAAA;CAClC,CAAA;AAEZ;;;;;;;;;;;;;;;AAgBA,MAAM,gCAAiD;AAEvD,SAAS,oBAA0C,EACjD,KACA,qBACA,gBAAgB,QAKf;CACD,MAAM,UAAmC;EACvC,MAAM;EACN,OAAO,IAAI;EACX,OAAO,IAAI;EACX,UAAU,IAAI,aAAa,CAAC,EAAE,MAAM;CACtC;CAEA,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
3
3
|
import { useDataGrid } from "./data-grid.js";
|
|
4
4
|
import { DataGridTableAddRow, DataGridTableBase, DataGridTableBody, DataGridTableEmpty, DataGridTableFillBodyCell, DataGridTableFillHeadCell, DataGridTableFoot, DataGridTableHead, DataGridTableHeadRow, DataGridTableHeadRowCell, DataGridTableHeadRowCellResize, DataGridTableRenderedRow, DataGridTableRowSpacer, DataGridTableViewport, getDataGridScrollAreaViewport, getDataGridTableMergedHeaderGroups, getDataGridTableRowSections, getPinningStyles, hasDataGridTableRightPinnedColumns } from "./data-grid-table.js";
|
|
5
5
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
-
import { cn } from "
|
|
6
|
+
import { cn } from "@kumix/utils";
|
|
7
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
9
9
|
import { flexRender } from "@tanstack/react-table";
|