@vamos-ui/react 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -2
- package/dist/blocks/block-heading.d.ts +29 -0
- package/dist/blocks/block-heading.js +39 -0
- package/dist/blocks/block-image.d.ts +52 -0
- package/dist/blocks/block-image.js +48 -0
- package/dist/blocks/block-link.d.ts +30 -0
- package/dist/blocks/block-link.js +36 -0
- package/dist/blocks/create-blocks.d.ts +54 -0
- package/dist/blocks/create-blocks.js +52 -0
- package/dist/blocks/index.d.ts +55 -0
- package/dist/blocks/index.js +59 -0
- package/dist/blocks/json-ld.d.ts +18 -0
- package/dist/blocks/json-ld.js +44 -0
- package/dist/blocks/labels.d.ts +20 -0
- package/dist/blocks/labels.js +43 -0
- package/dist/blocks/rich-text.d.ts +36 -0
- package/dist/blocks/rich-text.js +106 -0
- package/dist/blocks/schema/define-block.d.ts +151 -0
- package/dist/blocks/schema/define-block.js +120 -0
- package/dist/blocks/schema/emphasis.d.ts +17 -0
- package/dist/blocks/schema/emphasis.js +69 -0
- package/dist/blocks/schema/fields.d.ts +497 -0
- package/dist/blocks/schema/fields.js +240 -0
- package/dist/blocks/schema/icons.d.ts +2 -0
- package/dist/blocks/schema/icons.js +26 -0
- package/dist/blocks/schema/index.d.ts +18 -0
- package/dist/blocks/schema/index.js +21 -0
- package/dist/blocks/schema/lint-types.d.ts +16 -0
- package/dist/blocks/schema/lint-types.js +2 -0
- package/dist/blocks/schema/lint.d.ts +32 -0
- package/dist/blocks/schema/lint.js +164 -0
- package/dist/blocks/schema/localize.d.ts +20 -0
- package/dist/blocks/schema/localize.js +29 -0
- package/dist/blocks/schema/localized.d.ts +25 -0
- package/dist/blocks/schema/localized.js +53 -0
- package/dist/blocks/schema/migrate.d.ts +24 -0
- package/dist/blocks/schema/migrate.js +75 -0
- package/dist/blocks/schema/nodes.d.ts +196 -0
- package/dist/blocks/schema/nodes.js +78 -0
- package/dist/blocks/schema/rich-doc-schema.d.ts +32 -0
- package/dist/blocks/schema/rich-doc-schema.js +66 -0
- package/dist/blocks/schema/rich-doc.d.ts +90 -0
- package/dist/blocks/schema/rich-doc.js +62 -0
- package/dist/blocks/schema/safety.d.ts +20 -0
- package/dist/blocks/schema/safety.js +49 -0
- package/dist/blocks/schema/types.d.ts +172 -0
- package/dist/blocks/schema/types.js +3 -0
- package/dist/blocks/schema/validate.d.ts +17 -0
- package/dist/blocks/schema/validate.js +32 -0
- package/dist/blocks/schema/walk.d.ts +22 -0
- package/dist/blocks/schema/walk.js +60 -0
- package/dist/blocks/section-header.d.ts +38 -0
- package/dist/blocks/section-header.js +22 -0
- package/dist/blocks/section.d.ts +59 -0
- package/dist/blocks/section.js +66 -0
- package/dist/blocks/site/_kit-1.d.ts +101 -0
- package/dist/blocks/site/_kit-1.js +137 -0
- package/dist/blocks/site/_site-icon-1.d.ts +6 -0
- package/dist/blocks/site/_site-icon-1.js +15 -0
- package/dist/blocks/site/announcement-bar.d.ts +42 -0
- package/dist/blocks/site/announcement-bar.js +38 -0
- package/dist/blocks/site/announcement-dismiss.d.ts +18 -0
- package/dist/blocks/site/announcement-dismiss.js +28 -0
- package/dist/blocks/site/article-layout.d.ts +65 -0
- package/dist/blocks/site/article-layout.js +88 -0
- package/dist/blocks/site/blog-list.d.ts +79 -0
- package/dist/blocks/site/blog-list.js +78 -0
- package/dist/blocks/site/comparison-table.d.ts +54 -0
- package/dist/blocks/site/comparison-table.js +38 -0
- package/dist/blocks/site/consent-banner.d.ts +52 -0
- package/dist/blocks/site/consent-banner.js +33 -0
- package/dist/blocks/site/contact-dock.d.ts +52 -0
- package/dist/blocks/site/contact-dock.js +55 -0
- package/dist/blocks/site/contact-form.d.ts +60 -0
- package/dist/blocks/site/contact-form.js +45 -0
- package/dist/blocks/site/cta-booking.d.ts +43 -0
- package/dist/blocks/site/cta-booking.js +69 -0
- package/dist/blocks/site/cta.d.ts +74 -0
- package/dist/blocks/site/cta.js +113 -0
- package/dist/blocks/site/embed-facade.d.ts +20 -0
- package/dist/blocks/site/embed-facade.js +21 -0
- package/dist/blocks/site/faq.d.ts +48 -0
- package/dist/blocks/site/faq.js +52 -0
- package/dist/blocks/site/feature-grid.d.ts +46 -0
- package/dist/blocks/site/feature-grid.js +50 -0
- package/dist/blocks/site/feature-tabs.d.ts +22 -0
- package/dist/blocks/site/feature-tabs.js +11 -0
- package/dist/blocks/site/footer.d.ts +68 -0
- package/dist/blocks/site/footer.js +61 -0
- package/dist/blocks/site/gallery-section.d.ts +42 -0
- package/dist/blocks/site/gallery-section.js +48 -0
- package/dist/blocks/site/hero-video.d.ts +15 -0
- package/dist/blocks/site/hero-video.js +31 -0
- package/dist/blocks/site/hero.d.ts +64 -0
- package/dist/blocks/site/hero.js +73 -0
- package/dist/blocks/site/logo-strip.d.ts +44 -0
- package/dist/blocks/site/logo-strip.js +27 -0
- package/dist/blocks/site/map-hours.d.ts +83 -0
- package/dist/blocks/site/map-hours.js +125 -0
- package/dist/blocks/site/media-text.d.ts +45 -0
- package/dist/blocks/site/media-text.js +56 -0
- package/dist/blocks/site/menu-list.d.ts +74 -0
- package/dist/blocks/site/menu-list.js +84 -0
- package/dist/blocks/site/navbar-submenu.d.ts +18 -0
- package/dist/blocks/site/navbar-submenu.js +51 -0
- package/dist/blocks/site/navbar.d.ts +67 -0
- package/dist/blocks/site/navbar.js +64 -0
- package/dist/blocks/site/not-found.d.ts +40 -0
- package/dist/blocks/site/not-found.js +38 -0
- package/dist/blocks/site/page-intro.d.ts +46 -0
- package/dist/blocks/site/page-intro.js +44 -0
- package/dist/blocks/site/pricing-table.d.ts +67 -0
- package/dist/blocks/site/pricing-table.js +83 -0
- package/dist/blocks/site/process.d.ts +36 -0
- package/dist/blocks/site/process.js +42 -0
- package/dist/blocks/site/registry-1.d.ts +720 -0
- package/dist/blocks/site/registry-1.js +783 -0
- package/dist/blocks/site/registry-2.d.ts +914 -0
- package/dist/blocks/site/registry-2.js +563 -0
- package/dist/blocks/site/rich-text-section.d.ts +34 -0
- package/dist/blocks/site/rich-text-section.js +32 -0
- package/dist/blocks/site/shared/brand-icons.d.ts +21 -0
- package/dist/blocks/site/shared/brand-icons.js +56 -0
- package/dist/blocks/site/shared/consent-gate.d.ts +41 -0
- package/dist/blocks/site/shared/consent-gate.js +43 -0
- package/dist/blocks/site/shared/consent-island.d.ts +38 -0
- package/dist/blocks/site/shared/consent-island.js +63 -0
- package/dist/blocks/site/shared/consent.d.ts +49 -0
- package/dist/blocks/site/shared/consent.js +130 -0
- package/dist/blocks/site/shared/contact-form-island.d.ts +41 -0
- package/dist/blocks/site/shared/contact-form-island.js +100 -0
- package/dist/blocks/site/shared/copy-link.d.ts +10 -0
- package/dist/blocks/site/shared/copy-link.js +25 -0
- package/dist/blocks/site/shared/dock-avoid.d.ts +15 -0
- package/dist/blocks/site/shared/dock-avoid.js +107 -0
- package/dist/blocks/site/shared/dock-hours.d.ts +13 -0
- package/dist/blocks/site/shared/dock-hours.js +25 -0
- package/dist/blocks/site/shared/gallery-lightbox.d.ts +12 -0
- package/dist/blocks/site/shared/gallery-lightbox.js +10 -0
- package/dist/blocks/site/shared/island-keys.d.ts +10 -0
- package/dist/blocks/site/shared/island-keys.js +44 -0
- package/dist/blocks/site/shared/kit-2.d.ts +55 -0
- package/dist/blocks/site/shared/kit-2.js +84 -0
- package/dist/blocks/site/shared/labels-2.d.ts +209 -0
- package/dist/blocks/site/shared/labels-2.js +427 -0
- package/dist/blocks/site/shared/open-now.d.ts +22 -0
- package/dist/blocks/site/shared/open-now.js +27 -0
- package/dist/blocks/site/shared/opening-hours.d.ts +117 -0
- package/dist/blocks/site/shared/opening-hours.js +245 -0
- package/dist/blocks/site/shared/site-accent.d.ts +48 -0
- package/dist/blocks/site/shared/site-accent.js +249 -0
- package/dist/blocks/site/shared/site-form.d.ts +79 -0
- package/dist/blocks/site/shared/site-form.js +111 -0
- package/dist/blocks/site/shared/site-routing.d.ts +54 -0
- package/dist/blocks/site/shared/site-routing.js +86 -0
- package/dist/blocks/site/shared/testimonials-carousel.d.ts +17 -0
- package/dist/blocks/site/shared/testimonials-carousel.js +64 -0
- package/dist/blocks/site/site-shell.d.ts +108 -0
- package/dist/blocks/site/site-shell.js +254 -0
- package/dist/blocks/site/stats-band.d.ts +42 -0
- package/dist/blocks/site/stats-band.js +45 -0
- package/dist/blocks/site/team.d.ts +44 -0
- package/dist/blocks/site/team.js +48 -0
- package/dist/blocks/site/testimonials.d.ts +68 -0
- package/dist/blocks/site/testimonials.js +66 -0
- package/dist/blocks/types.d.ts +63 -0
- package/dist/blocks/types.js +2 -0
- package/dist/business/approval-flow.d.ts +152 -0
- package/dist/business/approval-flow.js +221 -0
- package/dist/business/export-core.d.ts +55 -0
- package/dist/business/export-core.js +101 -0
- package/dist/business/export.d.ts +148 -0
- package/dist/business/export.js +264 -0
- package/dist/business/import-core.d.ts +104 -0
- package/dist/business/import-core.js +281 -0
- package/dist/business/import-wizard.d.ts +186 -0
- package/dist/business/import-wizard.js +401 -0
- package/dist/business/index.d.ts +12 -0
- package/dist/business/index.js +22 -0
- package/dist/business/line-items-core.d.ts +129 -0
- package/dist/business/line-items-core.js +183 -0
- package/dist/business/line-items.d.ts +119 -0
- package/dist/business/line-items.js +299 -0
- package/dist/business/multi-step-form.d.ts +131 -0
- package/dist/business/multi-step-form.js +337 -0
- package/dist/business/permission-core.d.ts +59 -0
- package/dist/business/permission-core.js +99 -0
- package/dist/business/permission-matrix.d.ts +158 -0
- package/dist/business/permission-matrix.js +341 -0
- package/dist/business/setup-checklist.d.ts +80 -0
- package/dist/business/setup-checklist.js +92 -0
- package/dist/business/signer-status.d.ts +53 -0
- package/dist/business/signer-status.js +76 -0
- package/dist/charts/area-chart.d.ts +35 -0
- package/dist/charts/area-chart.js +33 -0
- package/dist/charts/bar-chart.d.ts +27 -0
- package/dist/charts/bar-chart.js +46 -0
- package/dist/charts/bar-list.d.ts +47 -0
- package/dist/charts/bar-list.js +60 -0
- package/dist/charts/chart-shell.d.ts +173 -0
- package/dist/charts/chart-shell.js +205 -0
- package/dist/charts/chart.d.ts +73 -0
- package/dist/charts/chart.js +106 -0
- package/dist/charts/combo-chart.d.ts +29 -0
- package/dist/charts/combo-chart.js +47 -0
- package/dist/charts/donut-chart.d.ts +33 -0
- package/dist/charts/donut-chart.js +113 -0
- package/dist/charts/funnel.d.ts +51 -0
- package/dist/charts/funnel.js +69 -0
- package/dist/charts/gauge.d.ts +62 -0
- package/dist/charts/gauge.js +104 -0
- package/dist/charts/heatmap.d.ts +81 -0
- package/dist/charts/heatmap.js +338 -0
- package/dist/charts/index.d.ts +12 -0
- package/dist/charts/index.js +14 -0
- package/dist/charts/line-chart.d.ts +21 -0
- package/dist/charts/line-chart.js +36 -0
- package/dist/charts/test-utils.d.ts +2 -0
- package/dist/charts/test-utils.js +38 -0
- package/dist/charts/utils.d.ts +130 -0
- package/dist/charts/utils.js +262 -0
- package/dist/components/_qr-core.d.ts +26 -0
- package/dist/components/_qr-core.js +376 -0
- package/dist/components/accordion.d.ts +47 -0
- package/dist/components/accordion.js +70 -0
- package/dist/components/activity-timeline.d.ts +149 -0
- package/dist/components/activity-timeline.js +122 -0
- package/dist/components/address-field.d.ts +116 -0
- package/dist/components/address-field.js +219 -0
- package/dist/components/alert-dialog.d.ts +99 -0
- package/dist/components/alert-dialog.js +192 -0
- package/dist/components/alert.d.ts +42 -0
- package/dist/components/alert.js +82 -0
- package/dist/components/app-shell.d.ts +159 -0
- package/dist/components/app-shell.js +289 -0
- package/dist/components/attachment-list.d.ts +96 -0
- package/dist/components/attachment-list.js +196 -0
- package/dist/components/audit-log.d.ts +150 -0
- package/dist/components/audit-log.js +205 -0
- package/dist/components/avatar.d.ts +87 -0
- package/dist/components/avatar.js +126 -0
- package/dist/components/backup-codes.d.ts +42 -0
- package/dist/components/backup-codes.js +67 -0
- package/dist/components/badge.d.ts +41 -0
- package/dist/components/badge.js +68 -0
- package/dist/components/breadcrumb.d.ts +78 -0
- package/dist/components/breadcrumb.js +106 -0
- package/dist/components/button-group.d.ts +52 -0
- package/dist/components/button-group.js +77 -0
- package/dist/components/button.d.ts +58 -0
- package/dist/components/button.js +107 -0
- package/dist/components/calendar.d.ts +240 -0
- package/dist/components/calendar.js +483 -0
- package/dist/components/card.d.ts +66 -0
- package/dist/components/card.js +76 -0
- package/dist/components/carousel.d.ts +170 -0
- package/dist/components/carousel.js +348 -0
- package/dist/components/checkbox.d.ts +78 -0
- package/dist/components/checkbox.js +138 -0
- package/dist/components/color-picker.d.ts +112 -0
- package/dist/components/color-picker.js +235 -0
- package/dist/components/combobox.d.ts +136 -0
- package/dist/components/combobox.js +294 -0
- package/dist/components/command.d.ts +281 -0
- package/dist/components/command.js +498 -0
- package/dist/components/comment-thread.d.ts +252 -0
- package/dist/components/comment-thread.js +449 -0
- package/dist/components/context-menu.d.ts +77 -0
- package/dist/components/context-menu.js +82 -0
- package/dist/components/currency-input.d.ts +43 -0
- package/dist/components/currency-input.js +85 -0
- package/dist/components/date-picker.d.ts +141 -0
- package/dist/components/date-picker.js +241 -0
- package/dist/components/date-range-picker.d.ts +91 -0
- package/dist/components/date-range-picker.js +251 -0
- package/dist/components/description-list.d.ts +92 -0
- package/dist/components/description-list.js +42 -0
- package/dist/components/dialog.d.ts +139 -0
- package/dist/components/dialog.js +185 -0
- package/dist/components/dropdown-menu.d.ts +100 -0
- package/dist/components/dropdown-menu.js +102 -0
- package/dist/components/editor-layout.d.ts +166 -0
- package/dist/components/editor-layout.js +237 -0
- package/dist/components/empty-state.d.ts +49 -0
- package/dist/components/empty-state.js +68 -0
- package/dist/components/entity-card.d.ts +83 -0
- package/dist/components/entity-card.js +92 -0
- package/dist/components/file-upload.d.ts +256 -0
- package/dist/components/file-upload.js +490 -0
- package/dist/components/formatted-input.d.ts +177 -0
- package/dist/components/formatted-input.js +399 -0
- package/dist/components/hierarchy-chart.d.ts +190 -0
- package/dist/components/hierarchy-chart.js +890 -0
- package/dist/components/hover-card.d.ts +21 -0
- package/dist/components/hover-card.js +32 -0
- package/dist/components/iban-input.d.ts +38 -0
- package/dist/components/iban-input.js +112 -0
- package/dist/components/id-input.d.ts +65 -0
- package/dist/components/id-input.js +130 -0
- package/dist/components/image.d.ts +130 -0
- package/dist/components/image.js +168 -0
- package/dist/components/input-otp.d.ts +62 -0
- package/dist/components/input-otp.js +73 -0
- package/dist/components/input.d.ts +141 -0
- package/dist/components/input.js +187 -0
- package/dist/components/item.d.ts +96 -0
- package/dist/components/item.js +113 -0
- package/dist/components/kbd.d.ts +64 -0
- package/dist/components/kbd.js +119 -0
- package/dist/components/list-layout.d.ts +144 -0
- package/dist/components/list-layout.js +210 -0
- package/dist/components/native-select.d.ts +33 -0
- package/dist/components/native-select.js +48 -0
- package/dist/components/navigation-menu.d.ts +127 -0
- package/dist/components/navigation-menu.js +129 -0
- package/dist/components/notification-center.d.ts +164 -0
- package/dist/components/notification-center.js +399 -0
- package/dist/components/page-header.d.ts +60 -0
- package/dist/components/page-header.js +60 -0
- package/dist/components/pagination.d.ts +121 -0
- package/dist/components/pagination.js +174 -0
- package/dist/components/phone-input.d.ts +49 -0
- package/dist/components/phone-input.js +266 -0
- package/dist/components/pin-map.d.ts +58 -0
- package/dist/components/pin-map.js +167 -0
- package/dist/components/popover.d.ts +38 -0
- package/dist/components/popover.js +69 -0
- package/dist/components/progress.d.ts +79 -0
- package/dist/components/progress.js +97 -0
- package/dist/components/qr-code.d.ts +36 -0
- package/dist/components/qr-code.js +27 -0
- package/dist/components/radio-group.d.ts +43 -0
- package/dist/components/radio-group.js +81 -0
- package/dist/components/record-detail-layout.d.ts +167 -0
- package/dist/components/record-detail-layout.js +233 -0
- package/dist/components/record-picker.d.ts +199 -0
- package/dist/components/record-picker.js +650 -0
- package/dist/components/resizable.d.ts +50 -0
- package/dist/components/resizable.js +88 -0
- package/dist/components/scroll-area.d.ts +40 -0
- package/dist/components/scroll-area.js +56 -0
- package/dist/components/select.d.ts +126 -0
- package/dist/components/select.js +137 -0
- package/dist/components/separator.d.ts +31 -0
- package/dist/components/separator.js +41 -0
- package/dist/components/settings-layout.d.ts +134 -0
- package/dist/components/settings-layout.js +180 -0
- package/dist/components/sheet.d.ts +103 -0
- package/dist/components/sheet.js +165 -0
- package/dist/components/sidebar.d.ts +171 -0
- package/dist/components/sidebar.js +421 -0
- package/dist/components/signature-pad.d.ts +85 -0
- package/dist/components/signature-pad.js +283 -0
- package/dist/components/skeleton.d.ts +64 -0
- package/dist/components/skeleton.js +53 -0
- package/dist/components/sla-timer.d.ts +75 -0
- package/dist/components/sla-timer.js +142 -0
- package/dist/components/slider.d.ts +57 -0
- package/dist/components/slider.js +133 -0
- package/dist/components/slug-input.d.ts +69 -0
- package/dist/components/slug-input.js +201 -0
- package/dist/components/sparkline.d.ts +54 -0
- package/dist/components/sparkline.js +122 -0
- package/dist/components/spinner.d.ts +34 -0
- package/dist/components/spinner.js +34 -0
- package/dist/components/stat.d.ts +135 -0
- package/dist/components/stat.js +130 -0
- package/dist/components/status-picker.d.ts +107 -0
- package/dist/components/status-picker.js +175 -0
- package/dist/components/stepper.d.ts +86 -0
- package/dist/components/stepper.js +103 -0
- package/dist/components/switch.d.ts +34 -0
- package/dist/components/switch.js +70 -0
- package/dist/components/table.d.ts +101 -0
- package/dist/components/table.js +72 -0
- package/dist/components/tabs.d.ts +103 -0
- package/dist/components/tabs.js +173 -0
- package/dist/components/tag-input.d.ts +77 -0
- package/dist/components/tag-input.js +305 -0
- package/dist/components/task-list.d.ts +89 -0
- package/dist/components/task-list.js +238 -0
- package/dist/components/time-picker.d.ts +119 -0
- package/dist/components/time-picker.js +399 -0
- package/dist/components/toast.d.ts +87 -0
- package/dist/components/toast.js +142 -0
- package/dist/components/toggle.d.ts +77 -0
- package/dist/components/toggle.js +109 -0
- package/dist/components/tooltip.d.ts +69 -0
- package/dist/components/tooltip.js +105 -0
- package/dist/components/top-bar.d.ts +87 -0
- package/dist/components/top-bar.js +99 -0
- package/dist/components/tour.d.ts +60 -0
- package/dist/components/tour.js +139 -0
- package/dist/components/tree-select.d.ts +89 -0
- package/dist/components/tree-select.js +243 -0
- package/dist/components/tree-view.d.ts +109 -0
- package/dist/components/tree-view.js +170 -0
- package/dist/components/typography.d.ts +107 -0
- package/dist/components/typography.js +128 -0
- package/dist/components/user-picker.d.ts +89 -0
- package/dist/components/user-picker.js +162 -0
- package/dist/components/version-history.d.ts +191 -0
- package/dist/components/version-history.js +431 -0
- package/dist/data-table/csv.d.ts +27 -0
- package/dist/data-table/csv.js +68 -0
- package/dist/data-table/data-table.d.ts +423 -0
- package/dist/data-table/data-table.js +1259 -0
- package/dist/data-table/filter-bar.d.ts +146 -0
- package/dist/data-table/filter-bar.js +569 -0
- package/dist/data-table/filter-fns.d.ts +65 -0
- package/dist/data-table/filter-fns.js +382 -0
- package/dist/data-table/index.d.ts +8 -0
- package/dist/data-table/index.js +9 -0
- package/dist/data-table/saved-views.d.ts +100 -0
- package/dist/data-table/saved-views.js +251 -0
- package/dist/data-table/types.d.ts +168 -0
- package/dist/data-table/types.js +87 -0
- package/dist/data-table/url-state.d.ts +94 -0
- package/dist/data-table/url-state.js +303 -0
- package/dist/data-table/view-state.d.ts +16 -0
- package/dist/data-table/view-state.js +81 -0
- package/dist/editor/_test-setup.d.ts +1 -0
- package/dist/editor/_test-setup.js +33 -0
- package/dist/editor/block-editor.d.ts +137 -0
- package/dist/editor/block-editor.js +280 -0
- package/dist/editor/commands.d.ts +31 -0
- package/dist/editor/commands.js +150 -0
- package/dist/editor/context.d.ts +108 -0
- package/dist/editor/context.js +30 -0
- package/dist/editor/convert.d.ts +66 -0
- package/dist/editor/convert.js +567 -0
- package/dist/editor/drag-handle.d.ts +10 -0
- package/dist/editor/drag-handle.js +69 -0
- package/dist/editor/extensions.d.ts +34 -0
- package/dist/editor/extensions.js +239 -0
- package/dist/editor/index.d.ts +14 -0
- package/dist/editor/index.js +17 -0
- package/dist/editor/inserter.d.ts +12 -0
- package/dist/editor/inserter.js +88 -0
- package/dist/editor/inspector.d.ts +17 -0
- package/dist/editor/inspector.js +65 -0
- package/dist/editor/items.d.ts +62 -0
- package/dist/editor/items.js +195 -0
- package/dist/editor/labels.d.ts +119 -0
- package/dist/editor/labels.js +130 -0
- package/dist/editor/markdown.d.ts +14 -0
- package/dist/editor/markdown.js +209 -0
- package/dist/editor/menus.d.ts +20 -0
- package/dist/editor/menus.js +236 -0
- package/dist/editor/nodes.d.ts +14 -0
- package/dist/editor/nodes.js +201 -0
- package/dist/editor/outline.d.ts +11 -0
- package/dist/editor/outline.js +52 -0
- package/dist/editor/schema-form.d.ts +64 -0
- package/dist/editor/schema-form.js +290 -0
- package/dist/editor/slash-menu.d.ts +15 -0
- package/dist/editor/slash-menu.js +119 -0
- package/dist/fonts/catalog.d.ts +53 -0
- package/dist/fonts/catalog.js +121 -0
- package/dist/fonts/font-picker.d.ts +70 -0
- package/dist/fonts/font-picker.js +225 -0
- package/dist/fonts/index.d.ts +6 -0
- package/dist/fonts/index.js +7 -0
- package/dist/fonts/loader.d.ts +66 -0
- package/dist/fonts/loader.js +161 -0
- package/dist/fonts/pairing-picker.d.ts +31 -0
- package/dist/fonts/pairing-picker.js +81 -0
- package/dist/fonts/pairings.d.ts +84 -0
- package/dist/fonts/pairings.js +149 -0
- package/dist/fonts/provider.d.ts +34 -0
- package/dist/fonts/provider.js +51 -0
- package/dist/form/index.d.ts +1 -0
- package/dist/form/index.js +1 -0
- package/dist/format/core.d.ts +149 -0
- package/dist/format/core.js +357 -0
- package/dist/format/index.d.ts +4 -0
- package/dist/format/index.js +5 -0
- package/dist/format/use-format.d.ts +1 -0
- package/dist/format/use-format.js +3 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +92 -0
- package/dist/lib/cn.d.ts +3 -0
- package/dist/lib/cn.js +16 -0
- package/dist/lib/color.d.ts +64 -0
- package/dist/lib/color.js +177 -0
- package/dist/lib/compose-refs.d.ts +24 -0
- package/dist/lib/compose-refs.js +45 -0
- package/dist/lib/data-islands.d.ts +194 -0
- package/dist/lib/data-islands.js +368 -0
- package/dist/lib/date.d.ts +129 -0
- package/dist/lib/date.js +386 -0
- package/dist/lib/field-context.d.ts +64 -0
- package/dist/lib/field-context.js +62 -0
- package/dist/lib/floating-arrow.d.ts +18 -0
- package/dist/lib/floating-arrow.js +15 -0
- package/dist/lib/islands.d.ts +38 -0
- package/dist/lib/islands.js +40 -0
- package/dist/lib/labels.d.ts +51 -0
- package/dist/lib/labels.js +56 -0
- package/dist/lib/layer.d.ts +36 -0
- package/dist/lib/layer.js +42 -0
- package/dist/lib/locale.d.ts +85 -0
- package/dist/lib/locale.js +105 -0
- package/dist/lib/menu.d.ts +58 -0
- package/dist/lib/menu.js +99 -0
- package/dist/lib/message-format.d.ts +20 -0
- package/dist/lib/message-format.js +116 -0
- package/dist/lib/nav.d.ts +132 -0
- package/dist/lib/nav.js +178 -0
- package/dist/lib/provider.d.ts +100 -0
- package/dist/lib/provider.js +105 -0
- package/dist/lib/public.d.ts +23 -0
- package/dist/lib/public.js +34 -0
- package/dist/lib/sr-name.d.ts +18 -0
- package/dist/lib/sr-name.js +17 -0
- package/dist/lib/text.d.ts +100 -0
- package/dist/lib/text.js +233 -0
- package/dist/lib/theme-scope.d.ts +58 -0
- package/dist/lib/theme-scope.js +59 -0
- package/dist/lib/use-async-list.d.ts +60 -0
- package/dist/lib/use-async-list.js +119 -0
- package/dist/lib/use-container-width.d.ts +19 -0
- package/dist/lib/use-container-width.js +39 -0
- package/dist/lib/use-controllable-state.d.ts +33 -0
- package/dist/lib/use-controllable-state.js +56 -0
- package/dist/lib/use-edge-fade.d.ts +13 -0
- package/dist/lib/use-edge-fade.js +43 -0
- package/dist/lib/use-formatted-input.d.ts +69 -0
- package/dist/lib/use-formatted-input.js +152 -0
- package/dist/lib/use-hotkeys.d.ts +80 -0
- package/dist/lib/use-hotkeys.js +221 -0
- package/dist/lib/use-hover-intent.d.ts +44 -0
- package/dist/lib/use-hover-intent.js +119 -0
- package/dist/lib/use-media-query.d.ts +21 -0
- package/dist/lib/use-media-query.js +28 -0
- package/dist/lib/use-reduced-motion.d.ts +8 -0
- package/dist/lib/use-reduced-motion.js +13 -0
- package/dist/lib/use-tree.d.ts +153 -0
- package/dist/lib/use-tree.js +534 -0
- package/dist/lib/value-format.d.ts +25 -0
- package/dist/lib/value-format.js +56 -0
- package/dist/lib/variants.d.ts +131 -0
- package/dist/lib/variants.js +109 -0
- package/dist/locale-data/core/date.d.ts +24 -0
- package/dist/locale-data/core/date.js +68 -0
- package/dist/locale-data/core/decimal.d.ts +19 -0
- package/dist/locale-data/core/decimal.js +79 -0
- package/dist/locale-data/core/holidays.d.ts +30 -0
- package/dist/locale-data/core/holidays.js +79 -0
- package/dist/locale-data/core/iban.d.ts +29 -0
- package/dist/locale-data/core/iban.js +74 -0
- package/dist/locale-data/core/index.d.ts +7 -0
- package/dist/locale-data/core/index.js +6 -0
- package/dist/locale-data/core/types.d.ts +173 -0
- package/dist/locale-data/core/types.js +6 -0
- package/dist/locale-data/core/week-info.d.ts +23 -0
- package/dist/locale-data/core/week-info.js +85 -0
- package/dist/locale-data/core/working-days.d.ts +27 -0
- package/dist/locale-data/core/working-days.js +133 -0
- package/dist/locale-data/index.d.ts +2 -0
- package/dist/locale-data/index.js +4 -0
- package/dist/locale-data/tr/address-tr.json +1 -0
- package/dist/locale-data/tr/address.d.ts +23 -0
- package/dist/locale-data/tr/address.js +52 -0
- package/dist/locale-data/tr/holidays.d.ts +31 -0
- package/dist/locale-data/tr/holidays.js +81 -0
- package/dist/locale-data/tr/iban.d.ts +21 -0
- package/dist/locale-data/tr/iban.js +45 -0
- package/dist/locale-data/tr/id.d.ts +36 -0
- package/dist/locale-data/tr/id.js +120 -0
- package/dist/locale-data/tr/index.d.ts +12 -0
- package/dist/locale-data/tr/index.js +33 -0
- package/dist/locale-data/tr/kdv.d.ts +91 -0
- package/dist/locale-data/tr/kdv.js +222 -0
- package/dist/locales/en.d.ts +2102 -0
- package/dist/locales/en.js +2088 -0
- package/dist/locales/tr.d.ts +2086 -0
- package/dist/locales/tr.js +2087 -0
- package/dist/media/focal-point.d.ts +42 -0
- package/dist/media/focal-point.js +96 -0
- package/dist/media/gallery-layout.d.ts +19 -0
- package/dist/media/gallery-layout.js +61 -0
- package/dist/media/gallery.d.ts +64 -0
- package/dist/media/gallery.js +140 -0
- package/dist/media/image-cropper.d.ts +86 -0
- package/dist/media/image-cropper.js +170 -0
- package/dist/media/image-field.d.ts +115 -0
- package/dist/media/image-field.js +212 -0
- package/dist/media/index.d.ts +19 -0
- package/dist/media/index.js +23 -0
- package/dist/media/lightbox.d.ts +82 -0
- package/dist/media/lightbox.js +171 -0
- package/dist/media/link-preview.d.ts +97 -0
- package/dist/media/link-preview.js +177 -0
- package/dist/media/media-library.d.ts +244 -0
- package/dist/media/media-library.js +776 -0
- package/dist/media/media-picker.d.ts +96 -0
- package/dist/media/media-picker.js +209 -0
- package/dist/media/media-provider.d.ts +23 -0
- package/dist/media/media-provider.js +44 -0
- package/dist/media/media-utils.d.ts +39 -0
- package/dist/media/media-utils.js +145 -0
- package/dist/media/memory-adapter.d.ts +22 -0
- package/dist/media/memory-adapter.js +162 -0
- package/dist/media/rest-adapter.d.ts +90 -0
- package/dist/media/rest-adapter.js +208 -0
- package/dist/media/serp.d.ts +62 -0
- package/dist/media/serp.js +108 -0
- package/dist/media/test-fixtures.d.ts +3 -0
- package/dist/media/test-fixtures.js +37 -0
- package/dist/media/types.d.ts +183 -0
- package/dist/media/types.js +3 -0
- package/dist/media/use-pan-zoom.d.ts +51 -0
- package/dist/media/use-pan-zoom.js +156 -0
- package/dist/media/use-upload-queue.d.ts +64 -0
- package/dist/media/use-upload-queue.js +115 -0
- package/dist/media/video-player.d.ts +135 -0
- package/dist/media/video-player.js +319 -0
- package/dist/motion/core.d.ts +32 -0
- package/dist/motion/core.js +77 -0
- package/dist/motion/count-up.d.ts +29 -0
- package/dist/motion/count-up.js +92 -0
- package/dist/motion/index.d.ts +11 -0
- package/dist/motion/index.js +13 -0
- package/dist/motion/motion-scope.d.ts +17 -0
- package/dist/motion/motion-scope.js +16 -0
- package/dist/motion/page-transition.d.ts +33 -0
- package/dist/motion/page-transition.js +61 -0
- package/dist/motion/parallax.d.ts +37 -0
- package/dist/motion/parallax.js +90 -0
- package/dist/motion/pointer.d.ts +38 -0
- package/dist/motion/pointer.js +117 -0
- package/dist/motion/reveal.d.ts +72 -0
- package/dist/motion/reveal.js +133 -0
- package/dist/motion/scroll-shrink.d.ts +18 -0
- package/dist/motion/scroll-shrink.js +47 -0
- package/dist/motion/skeleton-swap.d.ts +17 -0
- package/dist/motion/skeleton-swap.js +43 -0
- package/dist/motion/text-reveal.d.ts +30 -0
- package/dist/motion/text-reveal.js +29 -0
- package/dist/motion/ticker.d.ts +35 -0
- package/dist/motion/ticker.js +16 -0
- package/dist/next/index.d.ts +42 -0
- package/dist/next/index.js +36 -0
- package/dist/render/block-renderer.d.ts +56 -0
- package/dist/render/block-renderer.js +137 -0
- package/dist/render/index.d.ts +6 -0
- package/dist/render/index.js +7 -0
- package/dist/render/prepare.d.ts +61 -0
- package/dist/render/prepare.js +119 -0
- package/dist/scheduler/core/duration.d.ts +83 -0
- package/dist/scheduler/core/duration.js +174 -0
- package/dist/scheduler/core/gantt.d.ts +63 -0
- package/dist/scheduler/core/gantt.js +226 -0
- package/dist/scheduler/core/index.d.ts +6 -0
- package/dist/scheduler/core/index.js +7 -0
- package/dist/scheduler/core/layout.d.ts +97 -0
- package/dist/scheduler/core/layout.js +249 -0
- package/dist/scheduler/core/time-scale.d.ts +89 -0
- package/dist/scheduler/core/time-scale.js +173 -0
- package/dist/scheduler/gantt.d.ts +125 -0
- package/dist/scheduler/gantt.js +532 -0
- package/dist/scheduler/index.d.ts +6 -0
- package/dist/scheduler/index.js +7 -0
- package/dist/scheduler/resource-calendar.d.ts +218 -0
- package/dist/scheduler/resource-calendar.js +661 -0
- package/dist/scheduler/scheduler.d.ts +168 -0
- package/dist/scheduler/scheduler.js +768 -0
- package/dist/scheduler/shared.d.ts +63 -0
- package/dist/scheduler/shared.js +145 -0
- package/dist/scheduler/time-tracker.d.ts +138 -0
- package/dist/scheduler/time-tracker.js +403 -0
- package/dist/sortable/core.d.ts +67 -0
- package/dist/sortable/core.js +167 -0
- package/dist/sortable/index.d.ts +8 -0
- package/dist/sortable/index.js +10 -0
- package/dist/sortable/kanban-core.d.ts +70 -0
- package/dist/sortable/kanban-core.js +67 -0
- package/dist/sortable/kanban.d.ts +147 -0
- package/dist/sortable/kanban.js +472 -0
- package/dist/sortable/sortable-list.d.ts +71 -0
- package/dist/sortable/sortable-list.js +76 -0
- package/dist/sortable/sortable-tree.d.ts +105 -0
- package/dist/sortable/sortable-tree.js +462 -0
- package/dist/sortable/sortable.d.ts +188 -0
- package/dist/sortable/sortable.js +485 -0
- package/dist/sortable/use-pointer-drag.d.ts +75 -0
- package/dist/sortable/use-pointer-drag.js +173 -0
- package/dist/sortable/use-time-scale.d.ts +11 -0
- package/dist/sortable/use-time-scale.js +19 -0
- package/dist/styles/base.css +51 -0
- package/dist/styles/blocks.css +949 -0
- package/dist/styles/calendar.css +642 -0
- package/dist/styles/charts.css +264 -0
- package/dist/styles/data.css +474 -0
- package/dist/styles/editors.css +1022 -0
- package/dist/styles/forms.css +406 -0
- package/dist/styles/media.css +515 -0
- package/dist/styles/motion.css +389 -0
- package/dist/styles/navigation.css +293 -0
- package/dist/styles/overlays.css +244 -0
- package/dist/styles.css +743 -0
- package/package.json +160 -4
|
@@ -0,0 +1,1259 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { columnOrderingFeature, columnPinningFeature, columnResizingFeature, columnSizingFeature, columnVisibilityFeature, createPaginatedRowModel, createSortedRowModel, functionalUpdate, rowPaginationFeature, rowSortingFeature, tableFeatures, useTable, } from "@tanstack/react-table";
|
|
5
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
6
|
+
import { ArrowDown, ArrowDownToLine, ArrowUp, ChevronDown, ChevronUp, ChevronsUpDown, Columns3, Download, EyeOff, ListFilter, MoreHorizontal, Pin, PinOff, RotateCcw, Search, X, } from "lucide-react";
|
|
7
|
+
import { cn } from "../lib/cn.js";
|
|
8
|
+
import { useLabels } from "../lib/labels.js";
|
|
9
|
+
import { useFormat, useLocale } from "../lib/locale.js";
|
|
10
|
+
import { useLink } from "../lib/provider.js";
|
|
11
|
+
import { getCollator } from "../lib/text.js";
|
|
12
|
+
import { useControllableState, useIsomorphicLayoutEffect } from "../lib/use-controllable-state.js";
|
|
13
|
+
import { useContainerWidth } from "../lib/use-container-width.js";
|
|
14
|
+
import { controlVariants } from "../lib/variants.js";
|
|
15
|
+
import { Alert } from "../components/alert.js";
|
|
16
|
+
import { ConfirmDialog } from "../components/alert-dialog.js";
|
|
17
|
+
import { Avatar } from "../components/avatar.js";
|
|
18
|
+
import { Badge } from "../components/badge.js";
|
|
19
|
+
import { Button } from "../components/button.js";
|
|
20
|
+
import { Checkbox } from "../components/checkbox.js";
|
|
21
|
+
import { ActionMenu, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "../components/dropdown-menu.js";
|
|
22
|
+
import { EmptyState } from "../components/empty-state.js";
|
|
23
|
+
import { Input } from "../components/input.js";
|
|
24
|
+
import { CursorPagination, PaginationBar } from "../components/pagination.js";
|
|
25
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../components/popover.js";
|
|
26
|
+
import { Skeleton } from "../components/skeleton.js";
|
|
27
|
+
import { Spinner } from "../components/spinner.js";
|
|
28
|
+
import { Switch } from "../components/switch.js";
|
|
29
|
+
import { Table, TableBody, TableCaption, TableCell, TableContainer, TableHead, TableHeader, TableRow } from "../components/table.js";
|
|
30
|
+
import { toast } from "../components/toast.js";
|
|
31
|
+
import { FilterBar } from "./filter-bar.js";
|
|
32
|
+
import { applyFilters, hasActiveFilters, searchRows } from "./filter-fns.js";
|
|
33
|
+
import { SavedViews } from "./saved-views.js";
|
|
34
|
+
import { csvDelimiter, downloadCsv, toCsv } from "./csv.js";
|
|
35
|
+
import { applyViewState, toViewState } from "./view-state.js";
|
|
36
|
+
import { createHistoryAdapter, mergeListStateIntoSearch, parseListState } from "./url-state.js";
|
|
37
|
+
import { createListState, emptyFilterGroup, emptySelection, isCursorPage, isRowSelected, selectionCount, } from "./types.js";
|
|
38
|
+
/* ------------------------------------------------------------------ */
|
|
39
|
+
/* Labels */
|
|
40
|
+
/* ------------------------------------------------------------------ */
|
|
41
|
+
export const dataTableLabels = {
|
|
42
|
+
search: "Search",
|
|
43
|
+
searchPlaceholder: "Search…",
|
|
44
|
+
selectPageRows: "Select all rows on this page",
|
|
45
|
+
selectRow: "Select {name}",
|
|
46
|
+
selectedCount: "{count} selected",
|
|
47
|
+
selectedOnPage: "{count} on this page",
|
|
48
|
+
selectPage: "Select all {count} on this page",
|
|
49
|
+
selectAllMatching: "Select all {count}",
|
|
50
|
+
allSelected: "All {count} selected",
|
|
51
|
+
clearSelection: "Clear selection",
|
|
52
|
+
clear: "Clear",
|
|
53
|
+
selectionReset: "Selection cleared because the filters changed.",
|
|
54
|
+
bulkActions: "Bulk actions",
|
|
55
|
+
moreActions: "More actions",
|
|
56
|
+
rowActions: "Actions for {name}",
|
|
57
|
+
view: "View",
|
|
58
|
+
viewOptions: "View options",
|
|
59
|
+
columns: "Columns",
|
|
60
|
+
findColumn: "Find a column",
|
|
61
|
+
density: "Density",
|
|
62
|
+
compact: "Compact",
|
|
63
|
+
comfortable: "Comfortable",
|
|
64
|
+
spacious: "Spacious",
|
|
65
|
+
resetColumns: "Reset to default",
|
|
66
|
+
moveUp: "Move {name} up",
|
|
67
|
+
moveDown: "Move {name} down",
|
|
68
|
+
sortAsc: "Sort ascending",
|
|
69
|
+
sortDesc: "Sort descending",
|
|
70
|
+
clearSort: "Clear sort",
|
|
71
|
+
sortBy: "Sort by {name}",
|
|
72
|
+
sortOrder: "sort {index}",
|
|
73
|
+
pinStart: "Pin to start",
|
|
74
|
+
pinEnd: "Pin to end",
|
|
75
|
+
unpin: "Unpin",
|
|
76
|
+
hide: "Hide column",
|
|
77
|
+
filterBy: "Filter by this column",
|
|
78
|
+
columnMenu: "{name} column options",
|
|
79
|
+
resize: "Resize {name} column",
|
|
80
|
+
export: "Export",
|
|
81
|
+
exportPage: "Rows on this page",
|
|
82
|
+
exportSelected: "Selected rows",
|
|
83
|
+
exportAll: "All rows",
|
|
84
|
+
exportAllServer: "All matching rows",
|
|
85
|
+
exportStarted: "Export started — you’ll get the file shortly.",
|
|
86
|
+
exported: "{count, plural, one {# row exported} other {# rows exported}}",
|
|
87
|
+
emptyTitle: "Nothing here yet",
|
|
88
|
+
emptyDescription: "Records you add will show up here.",
|
|
89
|
+
noResultsTitle: "No results for these filters",
|
|
90
|
+
noResultsDescription: "Try a different search or remove a filter.",
|
|
91
|
+
clearFilters: "Clear filters",
|
|
92
|
+
errorTitle: "Couldn’t load the list",
|
|
93
|
+
retry: "Try again",
|
|
94
|
+
loading: "Loading…",
|
|
95
|
+
refreshing: "Updating the list",
|
|
96
|
+
loadMore: "Load more",
|
|
97
|
+
noMore: "You’ve reached the end.",
|
|
98
|
+
edit: "{column}: {value}. Edit",
|
|
99
|
+
editHint: "Press Enter to save, Escape to cancel.",
|
|
100
|
+
saving: "Saving…",
|
|
101
|
+
saveFailed: "Couldn’t save {column}. The previous value is back.",
|
|
102
|
+
invalid: "Invalid value",
|
|
103
|
+
yes: "Yes",
|
|
104
|
+
no: "No",
|
|
105
|
+
none: "—",
|
|
106
|
+
cancel: "Cancel",
|
|
107
|
+
bulkDone: "{action}: {count, plural, one {# record} other {# records}}",
|
|
108
|
+
bulkFailed: "{action} failed. Nothing was changed.",
|
|
109
|
+
undo: "Undo",
|
|
110
|
+
undone: "Undone",
|
|
111
|
+
rowCount: "{count, plural, one {# row} other {# rows}}",
|
|
112
|
+
};
|
|
113
|
+
/* ------------------------------------------------------------------ */
|
|
114
|
+
/* Column helpers */
|
|
115
|
+
/* ------------------------------------------------------------------ */
|
|
116
|
+
const SELECT = "__select";
|
|
117
|
+
const ACTIONS = "__actions";
|
|
118
|
+
const DEFAULT_SIZE = { text: 220, number: 120, currency: 140, percent: 110, date: 140, datetime: 180, enum: 150, boolean: 110, user: 200, tags: 220 };
|
|
119
|
+
const END_TYPES = new Set(["number", "currency", "percent"]);
|
|
120
|
+
export function readColumnValue(col, row) {
|
|
121
|
+
if (!col.accessor)
|
|
122
|
+
return undefined;
|
|
123
|
+
return typeof col.accessor === "function" ? col.accessor(row) : row[col.accessor];
|
|
124
|
+
}
|
|
125
|
+
const columnAlign = (col) => col.align ?? (END_TYPES.has(col.type ?? "text") ? "end" : "start");
|
|
126
|
+
/** Filter bar fields from Data Table columns (`filter: false` opts out; display-only columns are skipped). */
|
|
127
|
+
export function filterFieldsFromColumns(cols) {
|
|
128
|
+
return cols
|
|
129
|
+
.filter((c) => c.accessor && c.filter !== false)
|
|
130
|
+
.map((c) => ({
|
|
131
|
+
field: c.id,
|
|
132
|
+
label: c.header,
|
|
133
|
+
type: c.type ?? "text",
|
|
134
|
+
options: c.options,
|
|
135
|
+
currency: c.currency,
|
|
136
|
+
accessor: (row) => readColumnValue(c, row),
|
|
137
|
+
...(c.filter || {}),
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
const textOf = (v) => {
|
|
141
|
+
if (v === null || v === undefined)
|
|
142
|
+
return "";
|
|
143
|
+
if (Array.isArray(v))
|
|
144
|
+
return v.map(textOf).join(" ");
|
|
145
|
+
if (typeof v === "object") {
|
|
146
|
+
const o = v;
|
|
147
|
+
return String(o.name ?? o.label ?? o.title ?? o.id ?? "");
|
|
148
|
+
}
|
|
149
|
+
return String(v);
|
|
150
|
+
};
|
|
151
|
+
/* ------------------------------------------------------------------ */
|
|
152
|
+
/* TanStack v9 setup (isolated here) */
|
|
153
|
+
/* ------------------------------------------------------------------ */
|
|
154
|
+
const features = tableFeatures({
|
|
155
|
+
rowSortingFeature,
|
|
156
|
+
rowPaginationFeature,
|
|
157
|
+
columnVisibilityFeature,
|
|
158
|
+
columnOrderingFeature,
|
|
159
|
+
columnSizingFeature,
|
|
160
|
+
columnResizingFeature,
|
|
161
|
+
columnPinningFeature,
|
|
162
|
+
sortedRowModel: createSortedRowModel(),
|
|
163
|
+
paginatedRowModel: createPaginatedRowModel(),
|
|
164
|
+
});
|
|
165
|
+
const DataTableContext = React.createContext(null);
|
|
166
|
+
/**
|
|
167
|
+
* The table's state and helpers, for custom layouts and bindings inside `<DataTable>`.
|
|
168
|
+
*
|
|
169
|
+
* ```tsx
|
|
170
|
+
* const { state, selection, exportCsv, filterBarProps } = useDataTable<Contact>();
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export function useDataTable() {
|
|
174
|
+
const ctx = React.useContext(DataTableContext);
|
|
175
|
+
if (!ctx)
|
|
176
|
+
throw new Error("useDataTable must be used inside <DataTable>.");
|
|
177
|
+
return ctx;
|
|
178
|
+
}
|
|
179
|
+
/* ------------------------------------------------------------------ */
|
|
180
|
+
/* Storage */
|
|
181
|
+
/* ------------------------------------------------------------------ */
|
|
182
|
+
function readPrefs(key) {
|
|
183
|
+
try {
|
|
184
|
+
const raw = window.localStorage.getItem(`vamos-ui:dt:${key}`);
|
|
185
|
+
return raw ? JSON.parse(raw) : null;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function writePrefs(key, v) {
|
|
192
|
+
try {
|
|
193
|
+
window.localStorage.setItem(`vamos-ui:dt:${key}`, JSON.stringify(v));
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
/* storage blocked */
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/* ------------------------------------------------------------------ */
|
|
200
|
+
/* DataTable */
|
|
201
|
+
/* ------------------------------------------------------------------ */
|
|
202
|
+
const sameJSON = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
203
|
+
/**
|
|
204
|
+
* The backbone of every list screen: sorting, search, filters, column management, selection and
|
|
205
|
+
* bulk actions, inline editing, pagination, server mode, URL state, mobile cards and CSV.
|
|
206
|
+
* Built on TanStack Table v9 — `useDataTable().table` is the escape hatch.
|
|
207
|
+
*
|
|
208
|
+
* ```tsx
|
|
209
|
+
* <DataTable caption="Contacts" columns={columns} data={contacts} getRowId={(c) => c.id} selectable bulkActions={actions} />
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export function DataTable(props) {
|
|
213
|
+
const { columns, data, getRowId, mode = "client", rowCount, state: stateProp, defaultState, onStateChange, urlState, storageKey, pagination = "pages", pageSizes = [25, 50, 100], selectable, selection: selectionProp, defaultSelection, onSelectionChange, rowSelectable, onCellEdit, getRowLabel, mobile = "cards", density = "inherit", variant = "card", shortcuts = true, labels, me, children, className, caption: _caption, showCaption: _showCaption, loading: _loading, error: _error, onLoadMore: _onLoadMore, hasMore: _hasMore, cursors: _cursors, virtual: _virtual, bulkActions: _bulk, onRowClick: _orc, rowHref: _rh, rowActions: _ra, readOnly: _ro, navigation: _nav, empty: _empty, noResults: _nr, export: _export, toolbar, ...rest } = props;
|
|
214
|
+
const t = useLabels("dataTable", dataTableLabels, labels);
|
|
215
|
+
const { locale, timeZone, dir } = useLocale();
|
|
216
|
+
const server = mode === "server";
|
|
217
|
+
/* ---- columns ---- */
|
|
218
|
+
const defaultColumns = React.useMemo(() => {
|
|
219
|
+
const visible = {};
|
|
220
|
+
for (const c of columns)
|
|
221
|
+
if (c.defaultVisible === false)
|
|
222
|
+
visible[c.id] = false;
|
|
223
|
+
return { visible, order: columns.map((c) => c.id), sizing: {}, pinned: { start: [], end: [] }, ...defaultState?.columns };
|
|
224
|
+
}, [columns, defaultState?.columns]);
|
|
225
|
+
const titleColumn = columns.find((c) => c.mobile === "title") ?? columns.find((c) => c.accessor) ?? columns[0];
|
|
226
|
+
const fields = React.useMemo(() => filterFieldsFromColumns(columns), [columns]);
|
|
227
|
+
/* ---- list state (any subset can be controlled) ---- */
|
|
228
|
+
const base = React.useMemo(() => createListState({ ...defaultState, columns: defaultColumns }, pageSizes[0] ?? 25), [defaultState, defaultColumns, pageSizes]);
|
|
229
|
+
const [internal, setInternal] = React.useState(base);
|
|
230
|
+
const state = React.useMemo(() => ({ ...internal, ...stateProp }), [internal, stateProp]);
|
|
231
|
+
const stateRef = React.useRef(state);
|
|
232
|
+
stateRef.current = state;
|
|
233
|
+
const requestId = React.useRef(0);
|
|
234
|
+
const onStateChangeRef = React.useRef(onStateChange);
|
|
235
|
+
onStateChangeRef.current = onStateChange;
|
|
236
|
+
const setState = React.useCallback((patch, reason = "reset") => {
|
|
237
|
+
const prev = stateRef.current;
|
|
238
|
+
let next = { ...prev, ...patch };
|
|
239
|
+
// A new query starts at the first page.
|
|
240
|
+
if ((reason === "search" || reason === "filters" || reason === "sort" || reason === "pageSize") && !("page" in patch && reason === "pageSize")) {
|
|
241
|
+
next = { ...next, page: isCursorPage(next.page) ? { cursor: null, size: next.page.size } : { index: 0, size: next.page.size } };
|
|
242
|
+
}
|
|
243
|
+
if (sameJSON(prev, next))
|
|
244
|
+
return;
|
|
245
|
+
stateRef.current = next;
|
|
246
|
+
setInternal(next);
|
|
247
|
+
requestId.current += 1;
|
|
248
|
+
onStateChangeRef.current?.(next, reason, requestId.current);
|
|
249
|
+
}, []);
|
|
250
|
+
/* ---- URL state ---- */
|
|
251
|
+
const urlOptions = urlState ? (urlState === true ? {} : urlState) : null;
|
|
252
|
+
const adapter = React.useMemo(() => (urlOptions ? (urlOptions.adapter ?? createHistoryAdapter()) : null), [urlOptions?.adapter, Boolean(urlOptions)]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
253
|
+
// "pending": the URL was just read; skip one write so the pre-parse state never overwrites it.
|
|
254
|
+
const urlReady = React.useRef(false);
|
|
255
|
+
React.useEffect(() => {
|
|
256
|
+
if (!adapter || !urlOptions)
|
|
257
|
+
return;
|
|
258
|
+
const load = () => {
|
|
259
|
+
const parsed = parseListState(adapter.read(), { ...urlOptions, fields, defaults: { ...base, columns: stateRef.current.columns }, pageSizes });
|
|
260
|
+
setState({ q: parsed.q, filters: parsed.filters, sort: parsed.sort, page: parsed.page, view: parsed.view, ...(urlOptions.density ? { density: parsed.density } : {}) }, "reset");
|
|
261
|
+
};
|
|
262
|
+
load();
|
|
263
|
+
urlReady.current = "pending";
|
|
264
|
+
return adapter.subscribe(load);
|
|
265
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
266
|
+
}, [adapter]);
|
|
267
|
+
React.useEffect(() => {
|
|
268
|
+
if (!adapter || !urlOptions || !urlReady.current)
|
|
269
|
+
return;
|
|
270
|
+
if (urlReady.current === "pending") {
|
|
271
|
+
urlReady.current = true;
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
adapter.write(mergeListStateIntoSearch(adapter.read(), state, { ...urlOptions, defaults: base }), urlOptions.history ?? "replace");
|
|
275
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
276
|
+
}, [adapter, state.q, JSON.stringify(state.filters), JSON.stringify(state.sort), JSON.stringify(state.page), state.view, state.density]);
|
|
277
|
+
/* ---- column prefs in localStorage ---- */
|
|
278
|
+
const prefsLoaded = React.useRef(false);
|
|
279
|
+
React.useEffect(() => {
|
|
280
|
+
if (!storageKey)
|
|
281
|
+
return;
|
|
282
|
+
const prefs = readPrefs(storageKey);
|
|
283
|
+
prefsLoaded.current = true;
|
|
284
|
+
if (prefs && !stateRef.current.view)
|
|
285
|
+
setState({ columns: { ...stateRef.current.columns, ...prefs.columns }, density: prefs.density ?? stateRef.current.density }, "columns");
|
|
286
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
287
|
+
}, [storageKey]);
|
|
288
|
+
React.useEffect(() => {
|
|
289
|
+
if (storageKey && prefsLoaded.current)
|
|
290
|
+
writePrefs(storageKey, { columns: state.columns, density: state.density });
|
|
291
|
+
}, [storageKey, state.columns, state.density]);
|
|
292
|
+
/* ---- selection ---- */
|
|
293
|
+
const [selection, setSelectionRaw] = useControllableState({ value: selectionProp, defaultValue: defaultSelection ?? emptySelection(), onChange: onSelectionChange, name: "DataTable" });
|
|
294
|
+
const [announcement, setAnnouncement] = React.useState("");
|
|
295
|
+
const announce = React.useCallback((msg) => setAnnouncement((prev) => (prev === msg ? `${msg} ` : msg)), []);
|
|
296
|
+
const queryKey = JSON.stringify([state.q, state.filters]);
|
|
297
|
+
const lastQueryKey = React.useRef(queryKey);
|
|
298
|
+
React.useEffect(() => {
|
|
299
|
+
if (lastQueryKey.current === queryKey)
|
|
300
|
+
return;
|
|
301
|
+
lastQueryKey.current = queryKey;
|
|
302
|
+
if (selection.mode === "all") {
|
|
303
|
+
setSelectionRaw(emptySelection());
|
|
304
|
+
announce(t("selectionReset"));
|
|
305
|
+
}
|
|
306
|
+
}, [queryKey, selection.mode, setSelectionRaw, announce, t]);
|
|
307
|
+
/* ---- client pipeline: search → filters ---- */
|
|
308
|
+
const colById = React.useMemo(() => new Map(columns.map((c) => [c.id, c])), [columns]);
|
|
309
|
+
const searchable = React.useMemo(() => columns.filter((c) => c.accessor && (c.searchable ?? ["text", "enum", "user", "tags", undefined].includes(c.type))), [columns]);
|
|
310
|
+
const optionLabel = React.useCallback((c, v) => (c.options ? (c.options.find((o) => o.value === v)?.label ?? textOf(v)) : textOf(v)), []);
|
|
311
|
+
const filteredRows = React.useMemo(() => {
|
|
312
|
+
if (server)
|
|
313
|
+
return data;
|
|
314
|
+
const searched = searchRows(data, state.q, (row) => searchable.map((c) => optionLabel(c, readColumnValue(c, row))).join(" "), locale);
|
|
315
|
+
return applyFilters(searched, state.filters, fields, { locale, timeZone, me: me?.id });
|
|
316
|
+
}, [server, data, state.q, state.filters, searchable, fields, locale, timeZone, me?.id, optionLabel]);
|
|
317
|
+
/* ---- TanStack ---- */
|
|
318
|
+
const collator = React.useMemo(() => getCollator(locale, { numeric: true, sensitivity: "base" }), [locale]);
|
|
319
|
+
const tsColumns = React.useMemo(() => {
|
|
320
|
+
const out = [];
|
|
321
|
+
if (selectable)
|
|
322
|
+
out.push({ id: SELECT, header: "", size: 44, minSize: 44, maxSize: 44, enableSorting: false, enableHiding: false, enableResizing: false, enablePinning: false });
|
|
323
|
+
for (const c of columns) {
|
|
324
|
+
const type = c.type ?? "text";
|
|
325
|
+
const optionIndex = c.options ? new Map(c.options.map((o, i) => [o.value, i])) : null;
|
|
326
|
+
const sortKey = (row) => {
|
|
327
|
+
if (c.sortValue)
|
|
328
|
+
return c.sortValue(row) ?? null;
|
|
329
|
+
const v = readColumnValue(c, row);
|
|
330
|
+
if (v === null || v === undefined || v === "")
|
|
331
|
+
return null;
|
|
332
|
+
if (END_TYPES.has(type))
|
|
333
|
+
return Number(v);
|
|
334
|
+
if (type === "boolean")
|
|
335
|
+
return v ? 1 : 0;
|
|
336
|
+
if (type === "enum" && optionIndex)
|
|
337
|
+
return optionIndex.get(String(v)) ?? Number.MAX_SAFE_INTEGER;
|
|
338
|
+
if (type === "date" || type === "datetime")
|
|
339
|
+
return typeof v === "string" && /^\d{4}-\d{2}-\d{2}$/.test(v) ? v : new Date(v).getTime();
|
|
340
|
+
return textOf(v);
|
|
341
|
+
};
|
|
342
|
+
out.push({
|
|
343
|
+
id: c.id,
|
|
344
|
+
header: c.header,
|
|
345
|
+
accessorFn: (row) => readColumnValue(c, row),
|
|
346
|
+
size: c.size ?? DEFAULT_SIZE[type],
|
|
347
|
+
minSize: c.minSize ?? 72,
|
|
348
|
+
maxSize: c.maxSize ?? 640,
|
|
349
|
+
enableSorting: c.sortable ?? Boolean(c.accessor || c.sortValue),
|
|
350
|
+
enableHiding: c.hideable ?? c !== titleColumn,
|
|
351
|
+
enableResizing: c.resizable ?? true,
|
|
352
|
+
enablePinning: c.pinnable ?? true,
|
|
353
|
+
sortUndefined: "last",
|
|
354
|
+
sortFn: (a, b) => {
|
|
355
|
+
const x = sortKey(a.original);
|
|
356
|
+
const y = sortKey(b.original);
|
|
357
|
+
if (x === null && y === null)
|
|
358
|
+
return 0;
|
|
359
|
+
if (x === null)
|
|
360
|
+
return 1;
|
|
361
|
+
if (y === null)
|
|
362
|
+
return -1;
|
|
363
|
+
if (typeof x === "number" && typeof y === "number")
|
|
364
|
+
return x - y;
|
|
365
|
+
return collator.compare(String(x), String(y));
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
if (props.rowActions)
|
|
370
|
+
out.push({ id: ACTIONS, header: "", size: 52, minSize: 52, maxSize: 52, enableSorting: false, enableHiding: false, enableResizing: false, enablePinning: false });
|
|
371
|
+
return out;
|
|
372
|
+
}, [columns, selectable, props.rowActions, collator, titleColumn]);
|
|
373
|
+
const order = React.useMemo(() => {
|
|
374
|
+
const known = state.columns.order.filter((id) => colById.has(id));
|
|
375
|
+
const rest = columns.map((c) => c.id).filter((id) => !known.includes(id));
|
|
376
|
+
return [...(selectable ? [SELECT] : []), ...known, ...rest, ...(props.rowActions ? [ACTIONS] : [])];
|
|
377
|
+
}, [state.columns.order, colById, columns, selectable, props.rowActions]);
|
|
378
|
+
const pinning = React.useMemo(() => {
|
|
379
|
+
const start = state.columns.pinned.start.filter((id) => colById.has(id));
|
|
380
|
+
const end = state.columns.pinned.end.filter((id) => colById.has(id));
|
|
381
|
+
return { start: start.length && selectable ? [SELECT, ...start] : start, end: props.rowActions ? [...end, ACTIONS] : end };
|
|
382
|
+
}, [state.columns.pinned, colById, selectable, props.rowActions]);
|
|
383
|
+
const manualPaging = server || pagination !== "pages" || isCursorPage(state.page);
|
|
384
|
+
const pageState = { pageIndex: isCursorPage(state.page) ? 0 : state.page.index, pageSize: state.page.size };
|
|
385
|
+
const update = (current, updater) => functionalUpdate(updater, current);
|
|
386
|
+
const table = useTable({
|
|
387
|
+
features,
|
|
388
|
+
columns: tsColumns,
|
|
389
|
+
data: filteredRows,
|
|
390
|
+
getRowId: (row) => getRowId(row),
|
|
391
|
+
state: {
|
|
392
|
+
sorting: state.sort,
|
|
393
|
+
pagination: pageState,
|
|
394
|
+
columnVisibility: state.columns.visible,
|
|
395
|
+
columnOrder: order,
|
|
396
|
+
columnSizing: state.columns.sizing,
|
|
397
|
+
columnPinning: pinning,
|
|
398
|
+
},
|
|
399
|
+
onSortingChange: (u) => setState({ sort: update(stateRef.current.sort, u) }, "sort"),
|
|
400
|
+
onPaginationChange: (u) => {
|
|
401
|
+
const s = stateRef.current;
|
|
402
|
+
const prev = { pageIndex: isCursorPage(s.page) ? 0 : s.page.index, pageSize: s.page.size };
|
|
403
|
+
const next = update(prev, u);
|
|
404
|
+
setState({ page: { index: next.pageIndex, size: next.pageSize } }, next.pageSize !== prev.pageSize ? "pageSize" : "page");
|
|
405
|
+
},
|
|
406
|
+
onColumnVisibilityChange: (u) => setState({ columns: { ...stateRef.current.columns, visible: update(stateRef.current.columns.visible, u) } }, "columns"),
|
|
407
|
+
onColumnOrderChange: (u) => {
|
|
408
|
+
const next = update(order, u).filter((id) => id !== SELECT && id !== ACTIONS);
|
|
409
|
+
setState({ columns: { ...stateRef.current.columns, order: next } }, "columns");
|
|
410
|
+
},
|
|
411
|
+
onColumnSizingChange: (u) => setState({ columns: { ...stateRef.current.columns, sizing: update(stateRef.current.columns.sizing, u) } }, "columns"),
|
|
412
|
+
onColumnPinningChange: (u) => {
|
|
413
|
+
const next = update(pinning, u);
|
|
414
|
+
setState({ columns: { ...stateRef.current.columns, pinned: { start: next.start.filter((id) => id !== SELECT), end: next.end.filter((id) => id !== ACTIONS) } } }, "columns");
|
|
415
|
+
},
|
|
416
|
+
manualSorting: server,
|
|
417
|
+
manualPagination: manualPaging,
|
|
418
|
+
rowCount: server ? (rowCount ?? data.length) : undefined,
|
|
419
|
+
autoResetPageIndex: false,
|
|
420
|
+
enableSortingRemoval: true,
|
|
421
|
+
enableMultiSort: true,
|
|
422
|
+
sortDescFirst: false,
|
|
423
|
+
columnResizeMode: "onChange",
|
|
424
|
+
columnResizeDirection: dir,
|
|
425
|
+
});
|
|
426
|
+
const pageRowModels = table.getRowModel().rows;
|
|
427
|
+
const pageRows = React.useMemo(() => pageRowModels.map((r) => r.original), [pageRowModels]);
|
|
428
|
+
const total = server ? (rowCount ?? data.length) : filteredRows.length;
|
|
429
|
+
// Clamp the page when the list shrinks (client).
|
|
430
|
+
React.useEffect(() => {
|
|
431
|
+
if (server || manualPaging || isCursorPage(state.page))
|
|
432
|
+
return;
|
|
433
|
+
const pages = Math.max(1, Math.ceil(total / state.page.size));
|
|
434
|
+
if (state.page.index > pages - 1)
|
|
435
|
+
setState({ page: { index: pages - 1, size: state.page.size } }, "page");
|
|
436
|
+
}, [server, manualPaging, total, state.page, setState]);
|
|
437
|
+
/* ---- width / layout ---- */
|
|
438
|
+
const { ref: measureRef, width } = useContainerWidth();
|
|
439
|
+
const narrow = width !== undefined && width < 640;
|
|
440
|
+
const cards = narrow && mobile === "cards";
|
|
441
|
+
/* ---- inline edit ---- */
|
|
442
|
+
const [editing, setEditing] = React.useState(null);
|
|
443
|
+
const [cellStatus, setCellStatus] = React.useState({});
|
|
444
|
+
React.useEffect(() => {
|
|
445
|
+
// New data from the parent replaces optimistic values that were saved.
|
|
446
|
+
setCellStatus((prev) => {
|
|
447
|
+
const next = {};
|
|
448
|
+
let changed = false;
|
|
449
|
+
for (const [k, v] of Object.entries(prev)) {
|
|
450
|
+
if (v.status === "saved")
|
|
451
|
+
changed = true;
|
|
452
|
+
else
|
|
453
|
+
next[k] = v;
|
|
454
|
+
}
|
|
455
|
+
return changed ? next : prev;
|
|
456
|
+
});
|
|
457
|
+
}, [data]);
|
|
458
|
+
const rowLabel = React.useCallback((row) => (getRowLabel ? getRowLabel(row) : titleColumn ? textOf(readColumnValue(titleColumn, row)) : getRowId(row)), [getRowLabel, titleColumn, getRowId]);
|
|
459
|
+
const commitEdit = React.useCallback((row, rowId, col, value) => {
|
|
460
|
+
const key = `${rowId}:${col.id}`;
|
|
461
|
+
setEditing(null);
|
|
462
|
+
if (sameJSON(value, readColumnValue(col, row)))
|
|
463
|
+
return;
|
|
464
|
+
setCellStatus((s) => ({ ...s, [key]: { value, status: "saving" } }));
|
|
465
|
+
Promise.resolve(onCellEdit?.({ row, rowId, columnId: col.id, value })).then(() => setCellStatus((s) => ({ ...s, [key]: { value, status: "saved" } })), (err) => {
|
|
466
|
+
const message = err instanceof Error && err.message ? err.message : t("saveFailed", { column: col.header });
|
|
467
|
+
setCellStatus((s) => ({ ...s, [key]: { value, status: "error", error: message } }));
|
|
468
|
+
announce(message);
|
|
469
|
+
});
|
|
470
|
+
}, [onCellEdit, t, announce]);
|
|
471
|
+
/* ---- misc ---- */
|
|
472
|
+
const searchRef = React.useRef(null);
|
|
473
|
+
const [filterBound, setFilterBound] = React.useState(false);
|
|
474
|
+
const [filterRequest, setFilterRequest] = React.useState(null);
|
|
475
|
+
const lastClicked = React.useRef(null);
|
|
476
|
+
const isSelectable = React.useCallback((row) => (rowSelectable ? rowSelectable(row) : true), [rowSelectable]);
|
|
477
|
+
const hasQuery = state.q.trim() !== "" || hasActiveFilters(state.filters);
|
|
478
|
+
const orderedColumns = [...table.getStartVisibleLeafColumns(), ...table.getCenterVisibleLeafColumns(), ...table.getEndVisibleLeafColumns()].filter((c) => {
|
|
479
|
+
if (!(narrow && mobile === "priority"))
|
|
480
|
+
return true;
|
|
481
|
+
const p = colById.get(c.id)?.priority;
|
|
482
|
+
return !(p === 3 || (p === 2 && width !== undefined && width < 480));
|
|
483
|
+
});
|
|
484
|
+
if (process.env.NODE_ENV !== "production" && !props.virtual && pageRows.length > 300) {
|
|
485
|
+
warnOnce("[vamos-ui] DataTable is rendering more than 300 rows without `virtual`. Turn on `virtual` or paginate.");
|
|
486
|
+
}
|
|
487
|
+
const exportCsv = (o = {}) => {
|
|
488
|
+
const scope = o.scope ?? "all";
|
|
489
|
+
const formatted = o.formatted ?? props.export?.formatted ?? false;
|
|
490
|
+
const filename = o.filename ?? props.export?.filename ?? "export";
|
|
491
|
+
let rows;
|
|
492
|
+
if (scope === "page")
|
|
493
|
+
rows = pageRows;
|
|
494
|
+
else if (scope === "selected")
|
|
495
|
+
rows = (server ? data : filteredRows).filter((r) => isRowSelected(selection, getRowId(r)));
|
|
496
|
+
else {
|
|
497
|
+
if (server && props.export?.onServerExport) {
|
|
498
|
+
void props.export.onServerExport(stateRef.current);
|
|
499
|
+
toast.info(t("exportStarted"));
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
rows = server ? data : table.getPrePaginatedRowModel().rows.map((r) => r.original);
|
|
503
|
+
}
|
|
504
|
+
const cols = orderedColumns.map((c) => colById.get(c.id)).filter((c) => Boolean(c && c.accessor));
|
|
505
|
+
const matrix = [cols.map((c) => c.header)];
|
|
506
|
+
for (const row of rows)
|
|
507
|
+
matrix.push(cols.map((c) => exportCell(c, row, formatted, formatRef.current)));
|
|
508
|
+
downloadCsv(filename, toCsv(matrix, { locale, delimiter: csvDelimiter(locale) }));
|
|
509
|
+
announce(t("exported", { count: rows.length }));
|
|
510
|
+
};
|
|
511
|
+
const format = useFormat();
|
|
512
|
+
const formatRef = React.useRef(format);
|
|
513
|
+
formatRef.current = format;
|
|
514
|
+
const ctx = {
|
|
515
|
+
table,
|
|
516
|
+
state,
|
|
517
|
+
setState,
|
|
518
|
+
selection,
|
|
519
|
+
setSelection: setSelectionRaw,
|
|
520
|
+
columns,
|
|
521
|
+
fields,
|
|
522
|
+
pageRows,
|
|
523
|
+
filteredRows,
|
|
524
|
+
total,
|
|
525
|
+
filterBarProps: {
|
|
526
|
+
fields,
|
|
527
|
+
value: state.filters,
|
|
528
|
+
onChange: (g) => setState({ filters: g }, "filters"),
|
|
529
|
+
q: state.q,
|
|
530
|
+
onQChange: (q) => setState({ q }, "search"),
|
|
531
|
+
addRequest: filterRequest,
|
|
532
|
+
resultCount: total,
|
|
533
|
+
me,
|
|
534
|
+
},
|
|
535
|
+
savedViewsBinding: (views) => ({
|
|
536
|
+
activeId: state.view ?? null,
|
|
537
|
+
current: toViewState(state),
|
|
538
|
+
onSelect: (id) => setState(applyViewState(stateRef.current, views.find((v) => v.id === id)?.state, id, { ...defaultState, columns: defaultColumns }), "view"),
|
|
539
|
+
onReset: () => {
|
|
540
|
+
const id = stateRef.current.view ?? null;
|
|
541
|
+
setState(applyViewState(stateRef.current, views.find((v) => v.id === id)?.state, id, { ...defaultState, columns: defaultColumns }), "view");
|
|
542
|
+
},
|
|
543
|
+
}),
|
|
544
|
+
exportCsv,
|
|
545
|
+
requestFilter: (field) => setFilterRequest({ field, key: Date.now() }),
|
|
546
|
+
props,
|
|
547
|
+
internal: {
|
|
548
|
+
t,
|
|
549
|
+
width,
|
|
550
|
+
narrow,
|
|
551
|
+
cards,
|
|
552
|
+
searchRef,
|
|
553
|
+
filterBound,
|
|
554
|
+
setFilterBound,
|
|
555
|
+
editing,
|
|
556
|
+
setEditing,
|
|
557
|
+
cellStatus,
|
|
558
|
+
commitEdit,
|
|
559
|
+
announce,
|
|
560
|
+
rowLabel,
|
|
561
|
+
titleColumn,
|
|
562
|
+
orderedColumns,
|
|
563
|
+
defaultColumns,
|
|
564
|
+
lastClicked,
|
|
565
|
+
isSelectable,
|
|
566
|
+
hasQuery,
|
|
567
|
+
requestId,
|
|
568
|
+
filterRequest,
|
|
569
|
+
},
|
|
570
|
+
};
|
|
571
|
+
const onKeyDown = (e) => {
|
|
572
|
+
if (!shortcuts || e.defaultPrevented)
|
|
573
|
+
return;
|
|
574
|
+
const target = e.target;
|
|
575
|
+
const typing = target.closest("input, textarea, select, [contenteditable=true], [role=dialog], [role=menu], [role=listbox]");
|
|
576
|
+
if (e.key === "Escape" && selectionCount(selection) > 0 && !typing) {
|
|
577
|
+
e.preventDefault();
|
|
578
|
+
setSelectionRaw(emptySelection());
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
if (typing || e.metaKey || e.ctrlKey || e.altKey)
|
|
582
|
+
return;
|
|
583
|
+
if (e.key === "/" && searchRef.current) {
|
|
584
|
+
e.preventDefault();
|
|
585
|
+
searchRef.current.focus();
|
|
586
|
+
}
|
|
587
|
+
else if ((e.key === "x" || e.key === "X") && selectable) {
|
|
588
|
+
const tr = target.closest("[data-row-id]");
|
|
589
|
+
const id = tr?.dataset.rowId;
|
|
590
|
+
const row = id ? pageRows.find((r) => getRowId(r) === id) : undefined;
|
|
591
|
+
if (row && isSelectable(row) === true) {
|
|
592
|
+
e.preventDefault();
|
|
593
|
+
setSelectionRaw(toggleId(selection, id, selectable === "single"));
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
return (_jsx(DataTableContext.Provider, { value: ctx, children: _jsxs("div", { ref: measureRef, "data-slot": "data-table", "data-variant": variant, "data-density": density === "inherit" ? (state.density ?? undefined) : density, "data-layout": cards ? "cards" : "table", className: cn("ui-dt relative flex min-w-0 flex-col text-fg", variant === "card" && "surface overflow-hidden rounded-ui-lg", className), onKeyDown: onKeyDown, ...rest, children: [children ?? (_jsxs(_Fragment, { children: [_jsxs(DataTableToolbar, { children: [_jsx(DataTableSearch, {}), toolbar, _jsxs("div", { className: "ms-auto flex items-center gap-1.5", children: [_jsx(DataTableViewOptions, {}), props.export ? _jsx(DataTableExport, {}) : null] })] }), _jsx(DataTableContent, {}), _jsx(DataTableFooter, {})] })), _jsx("div", { "aria-live": "polite", className: "sr-only", "data-slot": "data-table-live", children: announcement })] }) }));
|
|
598
|
+
}
|
|
599
|
+
const warned = new Set();
|
|
600
|
+
function warnOnce(msg) {
|
|
601
|
+
if (warned.has(msg))
|
|
602
|
+
return;
|
|
603
|
+
warned.add(msg);
|
|
604
|
+
console.warn(msg);
|
|
605
|
+
}
|
|
606
|
+
function toggleId(s, id, single) {
|
|
607
|
+
if (s.mode === "all")
|
|
608
|
+
return { ...s, except: s.except.includes(id) ? s.except.filter((x) => x !== id) : [...s.except, id] };
|
|
609
|
+
if (single)
|
|
610
|
+
return { mode: "ids", ids: s.ids.includes(id) ? [] : [id] };
|
|
611
|
+
return { mode: "ids", ids: s.ids.includes(id) ? s.ids.filter((x) => x !== id) : [...s.ids, id] };
|
|
612
|
+
}
|
|
613
|
+
function exportCell(c, row, formatted, f) {
|
|
614
|
+
if (c.exportValue)
|
|
615
|
+
return c.exportValue(row);
|
|
616
|
+
const v = readColumnValue(c, row);
|
|
617
|
+
if (v === null || v === undefined)
|
|
618
|
+
return null;
|
|
619
|
+
const type = c.type ?? "text";
|
|
620
|
+
if (formatted)
|
|
621
|
+
return formatPlain(c, v, f);
|
|
622
|
+
if (type === "enum")
|
|
623
|
+
return String(v);
|
|
624
|
+
if (type === "boolean")
|
|
625
|
+
return Boolean(v);
|
|
626
|
+
if (type === "number" || type === "percent")
|
|
627
|
+
return typeof v === "number" ? v : Number(v);
|
|
628
|
+
if (type === "currency")
|
|
629
|
+
return typeof v === "number" ? v : Number(v);
|
|
630
|
+
if (Array.isArray(v))
|
|
631
|
+
return v.map(textOf).join(", ");
|
|
632
|
+
if (typeof v === "object" && !(v instanceof Date))
|
|
633
|
+
return textOf(v);
|
|
634
|
+
return v;
|
|
635
|
+
}
|
|
636
|
+
function formatPlain(c, v, f) {
|
|
637
|
+
if (v === null || v === undefined || v === "")
|
|
638
|
+
return "";
|
|
639
|
+
switch (c.type ?? "text") {
|
|
640
|
+
case "currency":
|
|
641
|
+
return f.currency(v, c.currency);
|
|
642
|
+
case "number":
|
|
643
|
+
return f.number(v);
|
|
644
|
+
case "percent":
|
|
645
|
+
return f.percent(Number(v));
|
|
646
|
+
case "date":
|
|
647
|
+
return f.date(v);
|
|
648
|
+
case "datetime":
|
|
649
|
+
return f.dateTime(v);
|
|
650
|
+
case "enum":
|
|
651
|
+
return c.options?.find((o) => o.value === v)?.label ?? String(v);
|
|
652
|
+
case "boolean":
|
|
653
|
+
return v ? "Yes" : "No";
|
|
654
|
+
default:
|
|
655
|
+
return textOf(v);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
/* ------------------------------------------------------------------ */
|
|
659
|
+
/* Toolbar, search, bulk bar */
|
|
660
|
+
/* ------------------------------------------------------------------ */
|
|
661
|
+
/**
|
|
662
|
+
* The bar above the table. While rows are selected it shows the bulk bar in the same place
|
|
663
|
+
* (same height, no layout jump).
|
|
664
|
+
*/
|
|
665
|
+
export function DataTableToolbar({ className, children, ...props }) {
|
|
666
|
+
const { selection, props: p } = useDataTable();
|
|
667
|
+
const bulk = Boolean(p.selectable) && selectionCount(selection) > 0;
|
|
668
|
+
return (_jsx("div", { "data-slot": "data-table-toolbar", className: cn("ui-dt-toolbar flex min-h-[calc(var(--control-h)+1.5rem)] flex-wrap items-center gap-2 px-(--cell-px) py-3", p.variant !== "flush" && "border-b border-line", className), ...props, children: bulk ? _jsx(DataTableBulkBar, {}) : children }));
|
|
669
|
+
}
|
|
670
|
+
/** Global search across the searchable columns. `/` focuses it. */
|
|
671
|
+
export function DataTableSearch({ debounce = 300, className, placeholder, ...props }) {
|
|
672
|
+
const { state, setState, internal } = useDataTable();
|
|
673
|
+
const { t, searchRef } = internal;
|
|
674
|
+
const [value, setValue] = React.useState(state.q);
|
|
675
|
+
const timer = React.useRef(undefined);
|
|
676
|
+
React.useEffect(() => setValue(state.q), [state.q]);
|
|
677
|
+
React.useEffect(() => () => clearTimeout(timer.current), []);
|
|
678
|
+
const push = (q, wait) => {
|
|
679
|
+
clearTimeout(timer.current);
|
|
680
|
+
if (wait === 0)
|
|
681
|
+
setState({ q }, "search");
|
|
682
|
+
else
|
|
683
|
+
timer.current = setTimeout(() => setState({ q }, "search"), wait);
|
|
684
|
+
};
|
|
685
|
+
return (_jsx(Input, { ref: searchRef, type: "search", size: "sm", "aria-label": t("search"), placeholder: placeholder ?? t("searchPlaceholder"), value: value, leading: _jsx(Search, {}), clearable: true, onClear: () => push("", 0), onChange: (e) => {
|
|
686
|
+
setValue(e.target.value);
|
|
687
|
+
push(e.target.value, debounce);
|
|
688
|
+
}, onKeyDown: (e) => {
|
|
689
|
+
if (e.key === "Enter")
|
|
690
|
+
push(value, 0);
|
|
691
|
+
}, className: cn("w-full sm:w-64", className), "data-slot": "data-table-search", ...props }));
|
|
692
|
+
}
|
|
693
|
+
/** A Filter bar bound to the table (fields from the columns, "Filter by this column" opens it). */
|
|
694
|
+
export function DataTableFilterBar(props) {
|
|
695
|
+
const { filterBarProps, internal } = useDataTable();
|
|
696
|
+
const { setFilterBound } = internal;
|
|
697
|
+
React.useEffect(() => {
|
|
698
|
+
setFilterBound(true);
|
|
699
|
+
return () => setFilterBound(false);
|
|
700
|
+
}, [setFilterBound]);
|
|
701
|
+
const { q: _q, onQChange: _oq, ...bound } = filterBarProps;
|
|
702
|
+
return _jsx(FilterBar, { ...bound, ...props, className: cn("min-w-0 flex-1", props.className) });
|
|
703
|
+
}
|
|
704
|
+
/** Saved views bound to the table: switching applies the view, edits mark it modified. */
|
|
705
|
+
export function DataTableSavedViews(props) {
|
|
706
|
+
const { savedViewsBinding } = useDataTable();
|
|
707
|
+
return _jsx(SavedViews, { ...savedViewsBinding(props.views), ...props });
|
|
708
|
+
}
|
|
709
|
+
/** Replaces the toolbar while rows are selected: count, select-all across pages, actions. */
|
|
710
|
+
export function DataTableBulkBar({ className }) {
|
|
711
|
+
const { selection, setSelection, pageRows, filteredRows, total, state, props: p, internal } = useDataTable();
|
|
712
|
+
const { t } = internal;
|
|
713
|
+
const f = useFormat();
|
|
714
|
+
const [busy, setBusy] = React.useState(null);
|
|
715
|
+
const [confirming, setConfirming] = React.useState(null);
|
|
716
|
+
const count = selectionCount(selection);
|
|
717
|
+
const pageIds = pageRows.map((r) => p.getRowId(r));
|
|
718
|
+
const onPage = pageIds.filter((id) => isRowSelected(selection, id)).length;
|
|
719
|
+
const allPage = pageIds.length > 0 && onPage === pageIds.length;
|
|
720
|
+
const server = p.mode === "server";
|
|
721
|
+
const allMatching = selection.mode === "all" || count >= total;
|
|
722
|
+
const selectedRows = (server ? p.data : filteredRows).filter((r) => isRowSelected(selection, p.getRowId(r)));
|
|
723
|
+
const selectAll = () => {
|
|
724
|
+
if (server)
|
|
725
|
+
setSelection({ mode: "all", except: [], filters: state.filters, q: state.q, total });
|
|
726
|
+
else
|
|
727
|
+
setSelection({ mode: "ids", ids: filteredRows.filter((r) => internal.isSelectable(r) === true).map((r) => p.getRowId(r)) });
|
|
728
|
+
};
|
|
729
|
+
const selectPage = () => {
|
|
730
|
+
const add = pageRows.filter((r) => internal.isSelectable(r) === true).map((r) => p.getRowId(r));
|
|
731
|
+
if (selection.mode === "all")
|
|
732
|
+
setSelection({ ...selection, except: selection.except.filter((id) => !add.includes(id)) });
|
|
733
|
+
else
|
|
734
|
+
setSelection({ mode: "ids", ids: Array.from(new Set([...selection.ids, ...add])) });
|
|
735
|
+
};
|
|
736
|
+
const run = async (action) => {
|
|
737
|
+
setBusy(action.id);
|
|
738
|
+
try {
|
|
739
|
+
const result = await action.run(selection, selectedRows);
|
|
740
|
+
const n = count;
|
|
741
|
+
setSelection(emptySelection());
|
|
742
|
+
const undo = result && typeof result === "object" && "undo" in result ? result.undo : undefined;
|
|
743
|
+
toast.success(t("bulkDone", { action: action.label, count: n }), undo ? { action: { label: t("undo"), onClick: () => void Promise.resolve(undo()).then(() => toast(t("undone"))) } } : undefined);
|
|
744
|
+
}
|
|
745
|
+
catch {
|
|
746
|
+
toast.danger(t("bulkFailed", { action: action.label }));
|
|
747
|
+
}
|
|
748
|
+
finally {
|
|
749
|
+
setBusy(null);
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
const actions = p.bulkActions ?? [];
|
|
753
|
+
const inline = actions.slice(0, 3);
|
|
754
|
+
const extra = actions.slice(3);
|
|
755
|
+
const disabledReason = (a) => {
|
|
756
|
+
const r = a.disabled?.(selection, selectedRows);
|
|
757
|
+
return r === true ? "" : typeof r === "string" ? r : null;
|
|
758
|
+
};
|
|
759
|
+
return (_jsxs("div", { role: "toolbar", "aria-label": t("bulkActions"), "data-slot": "data-table-bulk-bar", className: cn("ui-dt-bulk ui-fade flex w-full flex-wrap items-center gap-x-1 gap-y-2 text-[13px]", className), children: [_jsxs("span", { className: "inline-flex items-center gap-2 pe-2 font-medium text-fg tabular", children: [_jsx("span", { "aria-hidden": true, className: "inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-accent px-1.5 text-[11px] font-semibold text-accent-fg", children: f.count(count, 9999) }), allMatching && selection.mode === "all" ? t("allSelected", { count: f.number(count) }) : t("selectedCount", { count: f.number(count) }), selection.mode === "ids" && onPage !== count && onPage > 0 ? _jsxs("span", { className: "font-normal text-fg-muted", children: ["(", t("selectedOnPage", { count: f.number(onPage) }), ")"] }) : null] }), !allPage && pageIds.length > 1 && p.selectable !== "single" ? (_jsx(Button, { size: "xs", variant: "ghost", onClick: selectPage, children: t("selectPage", { count: f.number(pageIds.length) }) })) : null, !allMatching && allPage && p.selectable !== "single" ? (_jsx(Button, { size: "xs", variant: "ghost", className: "text-accent-ink", onClick: selectAll, children: t("selectAllMatching", { count: f.number(total) }) })) : null, _jsx(Button, { size: "xs", variant: "ghost", className: "text-fg-muted", onClick: () => setSelection(emptySelection()), children: t("clear") }), _jsx("span", { "aria-hidden": true, className: "mx-1 hidden h-4 w-px bg-line sm:block" }), _jsxs("div", { className: "ms-auto flex flex-wrap items-center gap-1.5", children: [inline.map((a) => {
|
|
760
|
+
const reason = disabledReason(a);
|
|
761
|
+
return (_jsxs(Button, { size: "sm", variant: a.tone === "danger" ? "danger-ghost" : "secondary", disabled: reason !== null, title: reason || undefined, loading: busy === a.id, onClick: () => (a.confirm ? setConfirming(a) : run(a)), children: [a.icon, a.label] }, a.id));
|
|
762
|
+
}), extra.length ? (_jsx(ActionMenu, { triggerLabel: t("moreActions"), items: extra.map((a) => ({ id: a.id, label: a.label, icon: a.icon, tone: a.tone, disabled: disabledReason(a) !== null, onSelect: () => (a.confirm ? setConfirming(a) : run(a)) })) })) : null] }), _jsx(ConfirmDialog, { open: confirming !== null, tone: confirming?.tone === "danger" ? "danger" : "default", title: confirming?.confirm?.title ?? "", description: confirming?.confirm?.description?.(count), confirmLabel: confirming?.confirm?.confirmLabel ?? confirming?.label, onResult: (ok) => {
|
|
763
|
+
const a = confirming;
|
|
764
|
+
setConfirming(null);
|
|
765
|
+
if (ok && a)
|
|
766
|
+
void run(a);
|
|
767
|
+
} })] }));
|
|
768
|
+
}
|
|
769
|
+
/* ------------------------------------------------------------------ */
|
|
770
|
+
/* View options */
|
|
771
|
+
/* ------------------------------------------------------------------ */
|
|
772
|
+
/** "View" popover: show/hide and reorder columns, density, reset. */
|
|
773
|
+
export function DataTableViewOptions({ className }) {
|
|
774
|
+
const { state, setState, columns, internal } = useDataTable();
|
|
775
|
+
const { t, defaultColumns } = internal;
|
|
776
|
+
const { locale } = useLocale();
|
|
777
|
+
const [query, setQuery] = React.useState("");
|
|
778
|
+
const order = [...state.columns.order.filter((id) => columns.some((c) => c.id === id)), ...columns.map((c) => c.id).filter((id) => !state.columns.order.includes(id))];
|
|
779
|
+
const list = order.map((id) => columns.find((c) => c.id === id)).filter((c) => !query || c.header.toLocaleLowerCase(locale).includes(query.toLocaleLowerCase(locale)));
|
|
780
|
+
const move = (id, by) => {
|
|
781
|
+
const next = [...order];
|
|
782
|
+
const i = next.indexOf(id);
|
|
783
|
+
const j = i + by;
|
|
784
|
+
if (j < 0 || j >= next.length)
|
|
785
|
+
return;
|
|
786
|
+
[next[i], next[j]] = [next[j], next[i]];
|
|
787
|
+
setState({ columns: { ...state.columns, order: next } }, "columns");
|
|
788
|
+
};
|
|
789
|
+
const densities = ["compact", "comfortable", "spacious"];
|
|
790
|
+
const current = state.density ?? "comfortable";
|
|
791
|
+
return (_jsxs(Popover, { children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { size: "sm", variant: "ghost", className: cn("text-fg-muted", className), "aria-label": t("viewOptions"), children: [_jsx(Columns3, { "aria-hidden": true }), _jsx("span", { className: "max-sm:sr-only", children: t("view") })] }) }), _jsxs(PopoverContent, { align: "end", size: "sm", padded: false, "aria-label": t("viewOptions"), className: "w-72", children: [_jsxs("div", { className: "border-b border-line p-2", children: [_jsx("p", { className: "px-1 pb-1.5 text-[11px] font-medium tracking-[0.04em] text-fg-subtle", children: t("columns") }), columns.length > 7 ? _jsx(Input, { size: "sm", type: "search", "aria-label": t("findColumn"), placeholder: t("findColumn"), value: query, onChange: (e) => setQuery(e.target.value), leading: _jsx(Search, {}) }) : null] }), _jsx("ul", { className: "max-h-64 overflow-y-auto p-1", "aria-label": t("columns"), children: list.map((c) => {
|
|
792
|
+
const hideable = c.hideable ?? c !== internal.titleColumn;
|
|
793
|
+
const visible = state.columns.visible[c.id] !== false;
|
|
794
|
+
const i = order.indexOf(c.id);
|
|
795
|
+
return (_jsxs("li", { className: "group/col flex items-center gap-1 rounded-ui-sm py-0.5 ps-2 pe-1 hover:bg-hover", children: [_jsx(Checkbox, { size: "sm", label: c.header, checked: visible, disabled: !hideable, onCheckedChange: (v) => setState({ columns: { ...state.columns, visible: { ...state.columns.visible, [c.id]: v === true } } }, "columns"), className: "min-w-0 flex-1 py-1 text-[13px]" }), _jsx("button", { type: "button", "aria-label": t("moveUp", { name: c.header }), disabled: i === 0 || Boolean(query), onClick: () => move(c.id, -1), className: "inline-flex size-6 items-center justify-center rounded-ui-sm text-fg-subtle hover:bg-selected hover:text-fg focus-ring disabled:opacity-30", children: _jsx(ChevronUp, { "aria-hidden": true, className: "size-3.5" }) }), _jsx("button", { type: "button", "aria-label": t("moveDown", { name: c.header }), disabled: i === order.length - 1 || Boolean(query), onClick: () => move(c.id, 1), className: "inline-flex size-6 items-center justify-center rounded-ui-sm text-fg-subtle hover:bg-selected hover:text-fg focus-ring disabled:opacity-30", children: _jsx(ChevronDown, { "aria-hidden": true, className: "size-3.5" }) })] }, c.id));
|
|
796
|
+
}) }), _jsxs("div", { className: "border-t border-line p-2", children: [_jsx("p", { id: "dt-density-label", className: "px-1 pb-1.5 text-[11px] font-medium tracking-[0.04em] text-fg-subtle", children: t("density") }), _jsx("div", { role: "radiogroup", "aria-label": t("density"), className: "grid grid-cols-3 gap-0.5 rounded-ui-sm bg-selected p-0.5", children: densities.map((d) => (_jsx("button", { type: "button", role: "radio", "aria-checked": current === d, onClick: () => setState({ density: d }, "density"), className: cn("h-7 rounded-[calc(var(--radius)-6px)] text-xs font-medium transition-colors focus-ring", current === d ? "bg-surface text-fg shadow-[0_1px_2px_rgb(0_0_0/0.08)]" : "text-fg-muted hover:text-fg"), children: t(d) }, d))) })] }), _jsx("div", { className: "border-t border-line p-1", children: _jsxs("button", { type: "button", onClick: () => setState({ columns: defaultColumns, density: undefined }, "columns"), className: "flex h-8 w-full items-center gap-2 rounded-ui-sm px-2 text-[13px] text-fg-muted hover:bg-hover hover:text-fg focus-ring", children: [_jsx(RotateCcw, { "aria-hidden": true, className: "size-3.5" }), t("resetColumns")] }) })] })] }));
|
|
797
|
+
}
|
|
798
|
+
/** "Export" menu: rows on this page, selected rows, all rows (or your server export). */
|
|
799
|
+
export function DataTableExport({ className }) {
|
|
800
|
+
const { exportCsv, selection, pageRows, total, props: p, internal } = useDataTable();
|
|
801
|
+
const { t } = internal;
|
|
802
|
+
const f = useFormat();
|
|
803
|
+
const selected = selectionCount(selection);
|
|
804
|
+
return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsxs(Button, { size: "sm", variant: "ghost", className: cn("text-fg-muted", className), "aria-label": t("export"), children: [_jsx(Download, { "aria-hidden": true }), _jsx("span", { className: "max-sm:sr-only", children: t("export") })] }) }), _jsxs(DropdownMenuContent, { align: "end", size: "md", children: [_jsx(DropdownMenuLabel, { children: "CSV" }), _jsx(DropdownMenuItem, { icon: _jsx(ArrowDownToLine, {}), badge: f.number(pageRows.length), onSelect: () => exportCsv({ scope: "page" }), children: t("exportPage") }), _jsx(DropdownMenuItem, { icon: _jsx(ArrowDownToLine, {}), badge: f.number(selected), disabled: selected === 0, onSelect: () => exportCsv({ scope: "selected" }), children: t("exportSelected") }), _jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuItem, { icon: _jsx(Download, {}), badge: p.mode === "server" && p.export?.onServerExport ? undefined : f.number(total), onSelect: () => exportCsv({ scope: "all" }), children: p.mode === "server" && p.export?.onServerExport ? t("exportAllServer") : t("exportAll") })] })] }));
|
|
805
|
+
}
|
|
806
|
+
/* ------------------------------------------------------------------ */
|
|
807
|
+
/* Header cell */
|
|
808
|
+
/* ------------------------------------------------------------------ */
|
|
809
|
+
function pinStyle(col, header) {
|
|
810
|
+
const pinned = col.getIsPinned();
|
|
811
|
+
if (!pinned)
|
|
812
|
+
return undefined;
|
|
813
|
+
return pinned === "start"
|
|
814
|
+
? { position: "sticky", insetInlineStart: col.getStart("start"), zIndex: header ? 4 : 1 }
|
|
815
|
+
: { position: "sticky", insetInlineEnd: col.getAfter("end"), zIndex: header ? 4 : 1 };
|
|
816
|
+
}
|
|
817
|
+
function pinAttrs(col) {
|
|
818
|
+
const pinned = col.getIsPinned();
|
|
819
|
+
if (!pinned)
|
|
820
|
+
return {};
|
|
821
|
+
const edge = pinned === "start" ? col.getIsLastColumn("start") : col.getIsFirstColumn("end");
|
|
822
|
+
return { "data-pinned": pinned, "data-pin-edge": edge ? "" : undefined };
|
|
823
|
+
}
|
|
824
|
+
function HeaderCell({ header, def }) {
|
|
825
|
+
const { state, setState, internal, requestFilter, fields } = useDataTable();
|
|
826
|
+
const { t } = internal;
|
|
827
|
+
const col = header.column;
|
|
828
|
+
const sorted = col.getIsSorted();
|
|
829
|
+
const sortIndex = state.sort.length > 1 ? col.getSortIndex() : -1;
|
|
830
|
+
const align = columnAlign(def);
|
|
831
|
+
const canSort = col.getCanSort();
|
|
832
|
+
const canPin = col.getCanPin();
|
|
833
|
+
const canHide = col.getCanHide();
|
|
834
|
+
const pinned = col.getIsPinned();
|
|
835
|
+
const filterable = internal.filterBound && fields.some((f) => f.field === def.id);
|
|
836
|
+
const size = header.getSize();
|
|
837
|
+
const resizeHandler = header.getResizeHandler();
|
|
838
|
+
const thRef = React.useRef(null);
|
|
839
|
+
const setSize = (px) => setState({ columns: { ...state.columns, sizing: { ...state.columns.sizing, [def.id]: Math.round(Math.min(col.columnDef.maxSize ?? 640, Math.max(col.columnDef.minSize ?? 72, px))) } } }, "columns");
|
|
840
|
+
const autofit = () => {
|
|
841
|
+
const table = thRef.current?.closest("table");
|
|
842
|
+
if (!table)
|
|
843
|
+
return;
|
|
844
|
+
let max = 0;
|
|
845
|
+
table.querySelectorAll(`[data-col="${CSS.escape(def.id)}"] > [data-fit]`).forEach((el) => {
|
|
846
|
+
max = Math.max(max, el.scrollWidth);
|
|
847
|
+
});
|
|
848
|
+
if (max)
|
|
849
|
+
setSize(max + 36);
|
|
850
|
+
};
|
|
851
|
+
return (_jsxs(TableHead, { ref: thRef, "data-col": def.id, align: align, "aria-sort": canSort ? (sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : "none") : undefined, style: { width: size, ...pinStyle(col, true) }, ...pinAttrs(col), className: "group/th relative", children: [_jsxs("div", { "data-fit": true, className: cn("flex min-w-0 items-center gap-0.5", align === "end" && "flex-row-reverse", align === "center" && "justify-center"), children: [canSort ? (_jsxs("button", { type: "button", onClick: col.getToggleSortingHandler(), "aria-label": t("sortBy", { name: def.header }), className: cn("-mx-1.5 inline-flex min-w-0 items-center gap-1 rounded-ui-sm px-1.5 py-1 font-medium transition-colors hover:bg-hover hover:text-fg focus-ring", sorted && "text-fg", align === "end" && "flex-row-reverse"), children: [_jsx("span", { className: "truncate", children: def.header }), sorted === "asc" ? _jsx(ArrowUp, { "aria-hidden": true, className: "size-3.5 shrink-0" }) : sorted === "desc" ? _jsx(ArrowDown, { "aria-hidden": true, className: "size-3.5 shrink-0" }) : _jsx(ChevronsUpDown, { "aria-hidden": true, className: "size-3.5 shrink-0 text-fg-subtle opacity-0 transition-opacity group-hover/th:opacity-100" }), sortIndex >= 0 ? (_jsx("span", { className: "inline-flex size-4 items-center justify-center rounded-full bg-accent-soft font-mono text-[10px] text-accent-ink", "aria-label": t("sortOrder", { index: sortIndex + 1 }), children: sortIndex + 1 })) : null] })) : (_jsx("span", { className: "truncate", children: def.header })), canSort || canPin || canHide || filterable ? (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { type: "button", "aria-label": t("columnMenu", { name: def.header }), className: "inline-flex size-6 shrink-0 items-center justify-center rounded-ui-sm text-fg-subtle opacity-0 transition-opacity group-hover/th:opacity-100 hover:bg-hover hover:text-fg focus-visible:opacity-100 focus-ring data-[state=open]:opacity-100 pointer-coarse:opacity-100", children: _jsx(MoreHorizontal, { "aria-hidden": true, className: "size-3.5" }) }) }), _jsxs(DropdownMenuContent, { align: align === "end" ? "end" : "start", size: "sm", children: [canSort ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuItem, { icon: _jsx(ArrowUp, {}), onSelect: () => col.toggleSorting(false), children: t("sortAsc") }), _jsx(DropdownMenuItem, { icon: _jsx(ArrowDown, {}), onSelect: () => col.toggleSorting(true), children: t("sortDesc") }), sorted ? (_jsx(DropdownMenuItem, { icon: _jsx(X, {}), onSelect: () => col.clearSorting(), children: t("clearSort") })) : null] })) : null, filterable ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuItem, { icon: _jsx(ListFilter, {}), onSelect: () => requestFilter(def.id), children: t("filterBy") })] })) : null, canPin || canHide ? _jsx(DropdownMenuSeparator, {}) : null, canPin && pinned !== "start" ? (_jsx(DropdownMenuItem, { icon: _jsx(Pin, {}), onSelect: () => col.pin("start"), children: t("pinStart") })) : null, canPin && pinned !== "end" ? (_jsx(DropdownMenuItem, { icon: _jsx(Pin, { className: "rotate-90" }), onSelect: () => col.pin("end"), children: t("pinEnd") })) : null, canPin && pinned ? (_jsx(DropdownMenuItem, { icon: _jsx(PinOff, {}), onSelect: () => col.pin(false), children: t("unpin") })) : null, canHide ? (_jsx(DropdownMenuItem, { icon: _jsx(EyeOff, {}), onSelect: () => col.toggleVisibility(false), children: t("hide") })) : null] })] })) : null] }), col.getCanResize() ? (_jsx("div", { role: "separator", "aria-orientation": "vertical", "aria-label": t("resize", { name: def.header }), "aria-valuenow": Math.round(size), "aria-valuemin": col.columnDef.minSize ?? 72, "aria-valuemax": col.columnDef.maxSize ?? 640, tabIndex: 0, "data-resizing": col.getIsResizing() ? "" : undefined, onMouseDown: resizeHandler, onTouchStart: resizeHandler, onDoubleClick: autofit, onKeyDown: (e) => {
|
|
852
|
+
const step = e.shiftKey ? 64 : 16;
|
|
853
|
+
const rtl = getComputedStyle(e.currentTarget).direction === "rtl";
|
|
854
|
+
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
|
|
855
|
+
e.preventDefault();
|
|
856
|
+
const grow = (e.key === "ArrowRight") !== rtl;
|
|
857
|
+
setSize(size + (grow ? step : -step));
|
|
858
|
+
}
|
|
859
|
+
else if (e.key === "Enter") {
|
|
860
|
+
e.preventDefault();
|
|
861
|
+
autofit();
|
|
862
|
+
}
|
|
863
|
+
}, className: "ui-dt-resize" })) : null] }));
|
|
864
|
+
}
|
|
865
|
+
/* ------------------------------------------------------------------ */
|
|
866
|
+
/* Cells */
|
|
867
|
+
/* ------------------------------------------------------------------ */
|
|
868
|
+
/** Default rendering of a value by column type. */
|
|
869
|
+
export function DataTableValue({ column, value }) {
|
|
870
|
+
const f = useFormat();
|
|
871
|
+
const t = useLabels("dataTable", dataTableLabels);
|
|
872
|
+
if (value === null || value === undefined || value === "" || (Array.isArray(value) && value.length === 0)) {
|
|
873
|
+
return _jsx("span", { className: "text-fg-subtle", children: t("none") });
|
|
874
|
+
}
|
|
875
|
+
switch (column.type ?? "text") {
|
|
876
|
+
case "currency":
|
|
877
|
+
return _jsx(_Fragment, { children: f.currency(value, column.currency) });
|
|
878
|
+
case "number":
|
|
879
|
+
return _jsx(_Fragment, { children: f.number(value) });
|
|
880
|
+
case "percent":
|
|
881
|
+
return _jsx(_Fragment, { children: f.percent(Number(value)) });
|
|
882
|
+
case "date":
|
|
883
|
+
return _jsx("time", { dateTime: String(value), children: f.date(value) });
|
|
884
|
+
case "datetime":
|
|
885
|
+
return _jsx("time", { dateTime: String(value), children: f.dateTime(value) });
|
|
886
|
+
case "boolean":
|
|
887
|
+
return value ? _jsx("span", { className: "text-fg", children: t("yes") }) : _jsx("span", { className: "text-fg-subtle", children: t("no") });
|
|
888
|
+
case "enum": {
|
|
889
|
+
const o = column.options?.find((x) => x.value === value);
|
|
890
|
+
return (_jsx(Badge, { tone: o?.tone ?? "neutral", dot: Boolean(o?.tone && o.tone !== "neutral"), children: o?.label ?? String(value) }));
|
|
891
|
+
}
|
|
892
|
+
case "user": {
|
|
893
|
+
const name = textOf(value);
|
|
894
|
+
const src = typeof value === "object" && value ? (value.avatar ?? value.image) : undefined;
|
|
895
|
+
return (_jsxs("span", { className: "inline-flex min-w-0 items-center gap-2", children: [_jsx(Avatar, { name: name, src: src, size: "xs" }), _jsx("span", { className: "truncate", children: name })] }));
|
|
896
|
+
}
|
|
897
|
+
case "tags": {
|
|
898
|
+
const list = (Array.isArray(value) ? value : [value]).map(textOf);
|
|
899
|
+
return (_jsxs("span", { className: "inline-flex min-w-0 items-center gap-1", children: [list.slice(0, 2).map((x) => (_jsx(Badge, { tone: "outline", children: x }, x))), list.length > 2 ? _jsxs("span", { className: "text-xs text-fg-subtle tabular", children: ["+", list.length - 2] }) : null] }));
|
|
900
|
+
}
|
|
901
|
+
default:
|
|
902
|
+
return _jsx(_Fragment, { children: textOf(value) });
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
function CellEditorInput({ def, row, value, onCommit, onCancel }) {
|
|
906
|
+
const { internal } = useDataTable();
|
|
907
|
+
const { t } = internal;
|
|
908
|
+
const editor = def.edit;
|
|
909
|
+
const [draft, setDraft] = React.useState(() => (value === null || value === undefined ? "" : String(value)));
|
|
910
|
+
const [error, setError] = React.useState(null);
|
|
911
|
+
const errorId = React.useId();
|
|
912
|
+
const parse = (s) => {
|
|
913
|
+
if (editor.type === "number")
|
|
914
|
+
return s === "" ? null : Number(s.replace(",", "."));
|
|
915
|
+
if (editor.type === "currency")
|
|
916
|
+
return s === "" ? null : s.replace(",", ".").replace(/[^\d.-]/g, "");
|
|
917
|
+
return s;
|
|
918
|
+
};
|
|
919
|
+
const commit = () => {
|
|
920
|
+
const v = parse(draft);
|
|
921
|
+
if ((editor.type === "number" || editor.type === "currency") && v !== null && !Number.isFinite(Number(v))) {
|
|
922
|
+
setError(t("invalid"));
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
const msg = editor.validate?.(v, row) ?? null;
|
|
926
|
+
if (msg) {
|
|
927
|
+
setError(msg);
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
onCommit(v);
|
|
931
|
+
};
|
|
932
|
+
const keys = (e) => {
|
|
933
|
+
if (e.key === "Enter" || e.key === "Tab") {
|
|
934
|
+
if (e.key === "Enter")
|
|
935
|
+
e.preventDefault();
|
|
936
|
+
commit();
|
|
937
|
+
}
|
|
938
|
+
else if (e.key === "Escape") {
|
|
939
|
+
e.preventDefault();
|
|
940
|
+
e.stopPropagation();
|
|
941
|
+
onCancel();
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
if (editor.type === "select") {
|
|
945
|
+
return (_jsxs("div", { className: "relative", children: [_jsx("select", { autoFocus: true, "aria-label": def.header, value: draft, onChange: (e) => {
|
|
946
|
+
setDraft(e.target.value);
|
|
947
|
+
onCommit(e.target.value);
|
|
948
|
+
}, onKeyDown: keys, onBlur: onCancel, className: cn(controlVariants({ size: "sm" }), "h-[calc(var(--row-h)-0.75rem)] w-full appearance-none py-0 ps-2 pe-7 text-[13px]"), children: (editor.options ?? def.options ?? []).map((o) => (_jsx("option", { value: o.value, children: o.label }, o.value))) }), _jsx(ChevronDown, { "aria-hidden": true, className: "pointer-events-none absolute end-2 top-1/2 size-3.5 -translate-y-1/2 text-fg-subtle" })] }));
|
|
949
|
+
}
|
|
950
|
+
return (_jsxs("div", { className: "relative", children: [_jsx(Input, { autoFocus: true, size: "sm", "aria-label": def.header, type: editor.type === "date" ? "date" : "text", inputMode: editor.type === "number" || editor.type === "currency" ? "decimal" : undefined, value: draft, invalid: Boolean(error), "aria-describedby": error ? errorId : undefined, onChange: (e) => {
|
|
951
|
+
setDraft(e.target.value);
|
|
952
|
+
setError(null);
|
|
953
|
+
}, onKeyDown: keys, onBlur: commit, onFocus: (e) => e.currentTarget.select(), className: "h-[calc(var(--row-h)-0.75rem)] w-full", inputClassName: cn("text-[13px]", END_TYPES.has(def.type ?? "text") && "text-end tabular") }), error ? (_jsx("p", { id: errorId, role: "alert", className: "surface-popover absolute start-0 top-full z-(--z-popover) mt-1 rounded-ui-sm px-2 py-1 text-xs whitespace-nowrap text-danger", children: error })) : null] }));
|
|
954
|
+
}
|
|
955
|
+
function BodyCell({ row, rowId, col, def, index, gridPos }) {
|
|
956
|
+
const { internal, props: p } = useDataTable();
|
|
957
|
+
const { t, editing, setEditing, cellStatus, commitEdit } = internal;
|
|
958
|
+
const Link = useLink();
|
|
959
|
+
const key = `${rowId}:${def.id}`;
|
|
960
|
+
const status = cellStatus[key];
|
|
961
|
+
const raw = readColumnValue(def, row);
|
|
962
|
+
const value = status && status.status !== "error" ? status.value : raw;
|
|
963
|
+
const editable = Boolean(def.edit && !p.readOnly && p.onCellEdit);
|
|
964
|
+
const isEditing = editing?.rowId === rowId && editing.columnId === def.id;
|
|
965
|
+
const align = columnAlign(def);
|
|
966
|
+
const isTitle = def === internal.titleColumn;
|
|
967
|
+
const content = def.cell ? def.cell({ row, value, rowId, index, column: def }) : _jsx(DataTableValue, { column: def, value: value });
|
|
968
|
+
const grid = p.navigation === "grid";
|
|
969
|
+
const f = useFormat();
|
|
970
|
+
// The edit button's name carries the value as the cell shows it ("$72,500.00", not "72500"),
|
|
971
|
+
// or it fails WCAG 2.5.3 label in name. A custom cell renderer falls back to the raw text.
|
|
972
|
+
const label = (def.cell ? textOf(raw) : formatPlain(def, value, f)) || t("none");
|
|
973
|
+
let body = content;
|
|
974
|
+
if (isEditing && def.edit && def.edit.type === "custom") {
|
|
975
|
+
body = def.edit.render({ value: raw, row, commit: (v) => commitEdit(row, rowId, def, v), cancel: () => setEditing(null) });
|
|
976
|
+
}
|
|
977
|
+
else if (isEditing) {
|
|
978
|
+
body = _jsx(CellEditorInput, { def: def, row: row, value: raw, onCommit: (v) => commitEdit(row, rowId, def, v), onCancel: () => setEditing(null) });
|
|
979
|
+
}
|
|
980
|
+
else if (editable && def.edit && def.edit.type === "boolean") {
|
|
981
|
+
body = _jsx(Switch, { size: "sm", checked: Boolean(value), "aria-label": `${def.header}, ${internal.rowLabel(row)}`, onCheckedChange: (c) => commitEdit(row, rowId, def, c) });
|
|
982
|
+
}
|
|
983
|
+
else if (editable && !grid) {
|
|
984
|
+
body = (_jsx("button", { type: "button", "data-no-row-click": "", onClick: () => setEditing({ rowId, columnId: def.id }), "aria-label": t("edit", { column: def.header, value: label }), className: cn("ui-dt-editable -mx-2 flex w-[calc(100%+1rem)] min-w-0 items-center rounded-ui-sm px-2 py-1 text-start focus-ring", align === "end" && "justify-end text-end"), children: _jsx("span", { className: "min-w-0 truncate", children: content }) }));
|
|
985
|
+
}
|
|
986
|
+
else if (isTitle && p.rowHref) {
|
|
987
|
+
body = (_jsx(Link, { href: p.rowHref(row), className: "min-w-0 truncate font-medium text-fg underline-offset-4 hover:underline focus-ring rounded-ui-sm", children: content }));
|
|
988
|
+
}
|
|
989
|
+
const rowHeader = def.rowHeader ?? isTitle;
|
|
990
|
+
return (_jsx(TableCell, { rowHeader: rowHeader && !grid, "data-col": def.id, align: align, numeric: END_TYPES.has(def.type ?? "text") && !def.cell, role: grid ? "gridcell" : undefined, tabIndex: grid ? -1 : undefined, "data-r": gridPos?.r, "data-c": gridPos?.c, "aria-readonly": grid && !editable ? true : undefined, "data-editable": editable ? "" : undefined, "data-editing": isEditing ? "" : undefined, "data-status": status?.status, title: status?.status === "error" ? status.error : undefined, "aria-invalid": status?.status === "error" || undefined, style: pinStyle(col), ...pinAttrs(col), className: cn("relative", isEditing ? "py-1" : "truncate", rowHeader && "font-medium"), children: _jsxs("div", { "data-fit": true, className: cn("flex min-w-0 items-center gap-2", align === "end" && "justify-end", align === "center" && "justify-center"), children: [body, status?.status === "saving" ? _jsx(Spinner, { size: "xs", tone: "muted", "aria-label": t("saving"), className: "shrink-0" }) : null] }) }));
|
|
991
|
+
}
|
|
992
|
+
/* ------------------------------------------------------------------ */
|
|
993
|
+
/* Rows */
|
|
994
|
+
/* ------------------------------------------------------------------ */
|
|
995
|
+
function SelectCell({ row, rowId, index, col }) {
|
|
996
|
+
const { selection, setSelection, pageRows, internal, props: p } = useDataTable();
|
|
997
|
+
const selected = isRowSelected(selection, rowId);
|
|
998
|
+
const can = internal.isSelectable(row);
|
|
999
|
+
return (_jsx(TableCell, { style: pinStyle(col), ...pinAttrs(col), className: "w-11 pe-0", "data-no-row-click": "", children: _jsx("span", { className: "flex items-center", title: typeof can === "string" ? can : undefined, children: _jsx(Checkbox, { size: "sm", checked: selected, disabled: can !== true, "aria-label": internal.t("selectRow", { name: internal.rowLabel(row) }), onClick: (e) => {
|
|
1000
|
+
if (e.shiftKey && internal.lastClicked.current !== null && p.selectable !== "single") {
|
|
1001
|
+
e.preventDefault();
|
|
1002
|
+
const [a, b] = [internal.lastClicked.current, index].sort((x, y) => x - y);
|
|
1003
|
+
const ids = pageRows.slice(a, b + 1).filter((r) => internal.isSelectable(r) === true).map((r) => p.getRowId(r));
|
|
1004
|
+
if (selection.mode === "all")
|
|
1005
|
+
setSelection({ ...selection, except: selection.except.filter((x) => !ids.includes(x)) });
|
|
1006
|
+
else
|
|
1007
|
+
setSelection({ mode: "ids", ids: Array.from(new Set([...selection.ids, ...ids])) });
|
|
1008
|
+
}
|
|
1009
|
+
internal.lastClicked.current = index;
|
|
1010
|
+
}, onCheckedChange: () => setSelection(toggleId(selection, rowId, p.selectable === "single")) }) }) }));
|
|
1011
|
+
}
|
|
1012
|
+
function ActionsCell({ row, col }) {
|
|
1013
|
+
const { props: p, internal } = useDataTable();
|
|
1014
|
+
const items = p.rowActions?.(row) ?? [];
|
|
1015
|
+
return (_jsx(TableCell, { style: pinStyle(col), ...pinAttrs(col), align: "end", className: "w-[52px] ps-0", "data-no-row-click": "", children: _jsx(ActionMenu, { items: items, triggerLabel: internal.t("rowActions", { name: internal.rowLabel(row) }), triggerSize: "xs" }) }));
|
|
1016
|
+
}
|
|
1017
|
+
const INTERACTIVE = "a, button, input, select, textarea, label, [role=checkbox], [role=switch], [role=menuitem], [data-no-row-click]";
|
|
1018
|
+
function DataRow({ row, index, measureRef, virtualIndex }) {
|
|
1019
|
+
const { selection, internal, props: p } = useDataTable();
|
|
1020
|
+
const navigate = useNavigateRow();
|
|
1021
|
+
const rowId = row.id;
|
|
1022
|
+
const selected = p.selectable ? isRowSelected(selection, rowId) : undefined;
|
|
1023
|
+
const can = internal.isSelectable(row.original);
|
|
1024
|
+
const clickable = Boolean(p.onRowClick || p.rowHref);
|
|
1025
|
+
const grid = p.navigation === "grid";
|
|
1026
|
+
return (_jsx(TableRow, { ref: measureRef, "data-index": virtualIndex, "data-row-id": rowId, selected: selected, "aria-selected": p.selectable ? selected : undefined, "aria-rowindex": virtualIndex !== undefined ? virtualIndex + 2 : undefined, disabled: p.selectable ? can !== true : undefined, className: cn(clickable && "cursor-pointer"), onClick: (e) => {
|
|
1027
|
+
if (!clickable || e.target.closest(INTERACTIVE))
|
|
1028
|
+
return;
|
|
1029
|
+
navigate(row.original);
|
|
1030
|
+
}, children: internal.orderedColumns.map((col, c) => {
|
|
1031
|
+
if (col.id === SELECT)
|
|
1032
|
+
return _jsx(SelectCell, { row: row.original, rowId: rowId, index: index, col: col }, col.id);
|
|
1033
|
+
if (col.id === ACTIONS)
|
|
1034
|
+
return _jsx(ActionsCell, { row: row.original, col: col }, col.id);
|
|
1035
|
+
const def = p.columns.find((x) => x.id === col.id);
|
|
1036
|
+
return _jsx(BodyCell, { row: row.original, rowId: rowId, col: col, def: def, index: index, gridPos: grid ? { r: index, c } : undefined }, col.id);
|
|
1037
|
+
}) }));
|
|
1038
|
+
}
|
|
1039
|
+
function useNavigateRow() {
|
|
1040
|
+
const { props: p } = useDataTable();
|
|
1041
|
+
return (row) => {
|
|
1042
|
+
if (p.onRowClick)
|
|
1043
|
+
p.onRowClick(row);
|
|
1044
|
+
else if (p.rowHref && typeof window !== "undefined") {
|
|
1045
|
+
const href = p.rowHref(row);
|
|
1046
|
+
const a = document.querySelector(`a[href="${CSS.escape(href)}"]`);
|
|
1047
|
+
if (a)
|
|
1048
|
+
a.click();
|
|
1049
|
+
else
|
|
1050
|
+
window.location.assign(href);
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
function SkeletonRows({ count }) {
|
|
1055
|
+
const { internal, props: p } = useDataTable();
|
|
1056
|
+
const widths = ["72%", "54%", "64%", "48%", "80%"];
|
|
1057
|
+
return (_jsx(_Fragment, { children: Array.from({ length: count }, (_, r) => (_jsx(TableRow, { "aria-hidden": true, "data-slot": "data-table-skeleton", children: internal.orderedColumns.map((col, c) => {
|
|
1058
|
+
if (col.id === SELECT || col.id === ACTIONS)
|
|
1059
|
+
return _jsx(TableCell, { className: "w-11" }, col.id);
|
|
1060
|
+
const def = p.columns.find((x) => x.id === col.id);
|
|
1061
|
+
const type = def.type ?? "text";
|
|
1062
|
+
return (_jsx(TableCell, { align: columnAlign(def), children: type === "user" ? (_jsxs("span", { className: "flex items-center gap-2", children: [_jsx(Skeleton, { shape: "circle", className: "size-5" }), _jsx(Skeleton, { className: "h-3 rounded-full", style: { width: widths[(r + c) % 5] } })] })) : type === "enum" || type === "tags" ? (_jsx(Skeleton, { className: "h-5 w-16 rounded-full" })) : (_jsx(Skeleton, { className: cn("h-3 rounded-full", END_TYPES.has(type) && "ms-auto"), style: { width: END_TYPES.has(type) ? "46%" : widths[(r + c) % 5] } })) }, col.id));
|
|
1063
|
+
}) }, r))) }));
|
|
1064
|
+
}
|
|
1065
|
+
/* ------------------------------------------------------------------ */
|
|
1066
|
+
/* Content */
|
|
1067
|
+
/* ------------------------------------------------------------------ */
|
|
1068
|
+
function StatusRow({ colSpan, children }) {
|
|
1069
|
+
return (_jsx("tr", { "data-slot": "table-empty", children: _jsx("td", { colSpan: colSpan, className: "px-(--cell-px) py-10", children: children }) }));
|
|
1070
|
+
}
|
|
1071
|
+
/** The table (or the mobile cards) with loading, empty, no-results and error states. */
|
|
1072
|
+
export function DataTableContent({ className }) {
|
|
1073
|
+
const ctx = useDataTable();
|
|
1074
|
+
const { table, selection, setSelection, pageRows, setState, internal, props: p } = ctx;
|
|
1075
|
+
const { t, orderedColumns } = internal;
|
|
1076
|
+
const scrollRef = React.useRef(null);
|
|
1077
|
+
const rows = table.getRowModel().rows;
|
|
1078
|
+
const virtual = p.virtual ? (p.virtual === true ? {} : p.virtual) : null;
|
|
1079
|
+
const virtualizer = useVirtualizer({
|
|
1080
|
+
count: virtual ? rows.length : 0,
|
|
1081
|
+
getScrollElement: () => scrollRef.current,
|
|
1082
|
+
estimateSize: () => virtual?.estimateRowHeight ?? 48,
|
|
1083
|
+
overscan: virtual?.overscan ?? 8,
|
|
1084
|
+
getItemKey: (i) => rows[i]?.id ?? i,
|
|
1085
|
+
initialRect: { width: 960, height: 600 },
|
|
1086
|
+
});
|
|
1087
|
+
const grid = p.navigation === "grid";
|
|
1088
|
+
const firstLoad = Boolean(p.loading) && p.data.length === 0;
|
|
1089
|
+
const refreshing = Boolean(p.loading) && p.data.length > 0;
|
|
1090
|
+
const noData = !p.loading && p.data.length === 0 && !internal.hasQuery;
|
|
1091
|
+
const noResults = !p.loading && rows.length === 0 && !noData;
|
|
1092
|
+
const pageIds = pageRows.map((r) => p.getRowId(r));
|
|
1093
|
+
const selectablePage = pageRows.filter((r) => internal.isSelectable(r) === true).map((r) => p.getRowId(r));
|
|
1094
|
+
const onPage = pageIds.filter((id) => isRowSelected(selection, id)).length;
|
|
1095
|
+
const headerChecked = onPage === 0 ? false : onPage === pageIds.length ? true : "indeterminate";
|
|
1096
|
+
const toggleAllPage = () => {
|
|
1097
|
+
if (headerChecked === true) {
|
|
1098
|
+
if (selection.mode === "all")
|
|
1099
|
+
setSelection({ ...selection, except: Array.from(new Set([...selection.except, ...pageIds])) });
|
|
1100
|
+
else
|
|
1101
|
+
setSelection({ mode: "ids", ids: selection.ids.filter((id) => !pageIds.includes(id)) });
|
|
1102
|
+
}
|
|
1103
|
+
else if (selection.mode === "all")
|
|
1104
|
+
setSelection({ ...selection, except: selection.except.filter((id) => !selectablePage.includes(id)) });
|
|
1105
|
+
else
|
|
1106
|
+
setSelection({ mode: "ids", ids: Array.from(new Set([...selection.ids, ...selectablePage])) });
|
|
1107
|
+
};
|
|
1108
|
+
// Grid navigation (WAI-ARIA data grid): roving cell focus.
|
|
1109
|
+
const [active, setActive] = React.useState({ r: 0, c: 0 });
|
|
1110
|
+
useIsomorphicLayoutEffect(() => {
|
|
1111
|
+
if (!grid)
|
|
1112
|
+
return;
|
|
1113
|
+
const root = scrollRef.current;
|
|
1114
|
+
if (!root)
|
|
1115
|
+
return;
|
|
1116
|
+
root.querySelectorAll("[data-r]").forEach((el) => {
|
|
1117
|
+
el.tabIndex = Number(el.dataset.r) === active.r && Number(el.dataset.c) === active.c ? 0 : -1;
|
|
1118
|
+
});
|
|
1119
|
+
});
|
|
1120
|
+
const onGridKeyDown = (e) => {
|
|
1121
|
+
if (!grid)
|
|
1122
|
+
return;
|
|
1123
|
+
const cell = e.target.closest("[data-r]");
|
|
1124
|
+
if (!cell || cell !== e.target)
|
|
1125
|
+
return;
|
|
1126
|
+
const r = Number(cell.dataset.r);
|
|
1127
|
+
const c = Number(cell.dataset.c);
|
|
1128
|
+
const maxR = rows.length - 1;
|
|
1129
|
+
const maxC = orderedColumns.length - 1;
|
|
1130
|
+
let next = null;
|
|
1131
|
+
if (e.key === "ArrowDown")
|
|
1132
|
+
next = { r: Math.min(maxR, r + 1), c };
|
|
1133
|
+
else if (e.key === "ArrowUp")
|
|
1134
|
+
next = { r: Math.max(0, r - 1), c };
|
|
1135
|
+
else if (e.key === "ArrowRight")
|
|
1136
|
+
next = { r, c: Math.min(maxC, c + 1) };
|
|
1137
|
+
else if (e.key === "ArrowLeft")
|
|
1138
|
+
next = { r, c: Math.max(0, c - 1) };
|
|
1139
|
+
else if (e.key === "Home")
|
|
1140
|
+
next = e.ctrlKey || e.metaKey ? { r: 0, c: 0 } : { r, c: 0 };
|
|
1141
|
+
else if (e.key === "End")
|
|
1142
|
+
next = e.ctrlKey || e.metaKey ? { r: maxR, c: maxC } : { r, c: maxC };
|
|
1143
|
+
else if (e.key === "PageDown")
|
|
1144
|
+
next = { r: Math.min(maxR, r + 10), c };
|
|
1145
|
+
else if (e.key === "PageUp")
|
|
1146
|
+
next = { r: Math.max(0, r - 10), c };
|
|
1147
|
+
else if (e.key === "Enter" || e.key === "F2") {
|
|
1148
|
+
const colId = orderedColumns[c]?.id;
|
|
1149
|
+
const def = p.columns.find((x) => x.id === colId);
|
|
1150
|
+
if (def?.edit && !p.readOnly && p.onCellEdit) {
|
|
1151
|
+
e.preventDefault();
|
|
1152
|
+
internal.setEditing({ rowId: rows[r].id, columnId: def.id });
|
|
1153
|
+
}
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
if (!next)
|
|
1157
|
+
return;
|
|
1158
|
+
e.preventDefault();
|
|
1159
|
+
setActive(next);
|
|
1160
|
+
const target = scrollRef.current?.querySelector(`[data-r="${next.r}"][data-c="${next.c}"]`);
|
|
1161
|
+
target?.focus();
|
|
1162
|
+
};
|
|
1163
|
+
if (internal.cards)
|
|
1164
|
+
return _jsx(DataTableCards, { className: className });
|
|
1165
|
+
const visibleCount = orderedColumns.length;
|
|
1166
|
+
const items = virtual ? virtualizer.getVirtualItems() : [];
|
|
1167
|
+
const padTop = virtual && items.length ? items[0].start : 0;
|
|
1168
|
+
const padBottom = virtual && items.length ? virtualizer.getTotalSize() - items[items.length - 1].end : 0;
|
|
1169
|
+
return (_jsxs("div", { className: cn("relative min-w-0", className), "data-slot": "data-table-content", children: [p.error ? (_jsx("div", { className: "px-(--cell-px) pt-3", children: _jsx(Alert, { tone: "danger", live: "assertive", title: t("errorTitle"), actions: p.error.onRetry ? (_jsx(Button, { size: "sm", variant: "secondary", onClick: p.error.onRetry, children: t("retry") })) : undefined, children: p.error.message }) })) : null, refreshing ? _jsx("div", { className: "ui-dt-refresh", role: "progressbar", "aria-label": t("refreshing") }) : null, _jsx(TableContainer, { ref: scrollRef, "aria-label": p.caption, maxHeight: virtual ? (virtual.height ?? "32rem") : undefined, onKeyDown: onGridKeyDown, children: _jsxs(Table, { role: grid ? "grid" : undefined, "aria-busy": p.loading || undefined, "aria-rowcount": virtual ? rows.length + 1 : undefined, "aria-multiselectable": grid && p.selectable === true ? true : undefined, layout: "fixed", stickyHeader: Boolean(virtual), stickyFirstColumn: internal.narrow && p.mobile === "scroll", density: "inherit", style: { width: table.getTotalSize(), minWidth: "100%" }, className: "ui-dt-table", children: [_jsx(TableCaption, { visuallyHidden: !p.showCaption, side: "top", children: p.caption }), _jsx(TableHeader, { children: _jsx(TableRow, { "aria-rowindex": virtual ? 1 : undefined, children: orderedColumns.map((col) => {
|
|
1170
|
+
if (col.id === SELECT) {
|
|
1171
|
+
return (_jsx(TableHead, { style: { width: 44, ...pinStyle(col, true) }, ...pinAttrs(col), className: "pe-0", children: p.selectable === true ? (_jsx("span", { className: "flex items-center", children: _jsx(Checkbox, { size: "sm", checked: headerChecked, disabled: selectablePage.length === 0, onCheckedChange: toggleAllPage, "aria-label": t("selectPageRows") }) })) : (_jsx("span", { className: "sr-only", children: t("selectPageRows") })) }, col.id));
|
|
1172
|
+
}
|
|
1173
|
+
if (col.id === ACTIONS)
|
|
1174
|
+
return (_jsx(TableHead, { style: { width: 52, ...pinStyle(col, true) }, ...pinAttrs(col), children: _jsx("span", { className: "sr-only", children: t("moreActions") }) }, col.id));
|
|
1175
|
+
const header = table.getFlatHeaders().find((h) => h.column.id === col.id);
|
|
1176
|
+
const def = p.columns.find((x) => x.id === col.id);
|
|
1177
|
+
return _jsx(HeaderCell, { header: header, def: def }, col.id);
|
|
1178
|
+
}) }) }), _jsx(TableBody, { children: firstLoad ? (_jsx(SkeletonRows, { count: Math.min(10, isCursorPage(ctx.state.page) ? 10 : ctx.state.page.size) })) : noData ? (_jsx(StatusRow, { colSpan: visibleCount, children: p.empty ?? _jsx(EmptyState, { kind: "first-use", size: "sm", title: t("emptyTitle"), description: t("emptyDescription") }) })) : noResults ? (_jsx(StatusRow, { colSpan: visibleCount, children: p.noResults ?? (_jsx(EmptyState, { kind: "no-results", size: "sm", title: t("noResultsTitle"), description: t("noResultsDescription"), actions: _jsx(Button, { size: "sm", variant: "secondary", onClick: () => setState({ q: "", filters: emptyFilterGroup() }, "filters"), children: t("clearFilters") }) })) })) : virtual ? (_jsxs(_Fragment, { children: [padTop > 0 ? (_jsx("tr", { "aria-hidden": true, style: { height: padTop }, children: _jsx("td", { colSpan: visibleCount }) })) : null, items.map((item) => {
|
|
1179
|
+
const row = rows[item.index];
|
|
1180
|
+
return _jsx(DataRow, { row: row, index: item.index, virtualIndex: item.index, measureRef: virtualizer.measureElement }, row.id);
|
|
1181
|
+
}), padBottom > 0 ? (_jsx("tr", { "aria-hidden": true, style: { height: padBottom }, children: _jsx("td", { colSpan: visibleCount }) })) : null] })) : (rows.map((row, i) => _jsx(DataRow, { row: row, index: i }, row.id))) })] }) })] }));
|
|
1182
|
+
}
|
|
1183
|
+
/** Mobile layout: every row a card (title, subtitle, badge, label:value meta, checkbox, actions). */
|
|
1184
|
+
export function DataTableCards({ className }) {
|
|
1185
|
+
const { table, selection, setSelection, internal, props: p, setState } = useDataTable();
|
|
1186
|
+
const { t } = internal;
|
|
1187
|
+
const navigate = useNavigateRow();
|
|
1188
|
+
const rows = table.getRowModel().rows;
|
|
1189
|
+
const visibleIds = new Set(internal.orderedColumns.map((c) => c.id));
|
|
1190
|
+
const defs = p.columns.filter((c) => visibleIds.has(c.id) && c.mobile !== "hidden");
|
|
1191
|
+
const title = internal.titleColumn;
|
|
1192
|
+
const subtitle = defs.find((c) => c.mobile === "subtitle");
|
|
1193
|
+
const badge = defs.find((c) => c.mobile === "badge") ?? defs.find((c) => c !== title && c.type === "enum" && !c.mobile);
|
|
1194
|
+
const avatar = defs.find((c) => c.mobile === "avatar");
|
|
1195
|
+
const meta = defs.filter((c) => c !== title && c !== subtitle && c !== badge && c !== avatar && (c.mobile === "meta" || !c.mobile)).slice(0, 4);
|
|
1196
|
+
const Link = useLink();
|
|
1197
|
+
if (p.loading && p.data.length === 0) {
|
|
1198
|
+
return (_jsx("ul", { "aria-label": p.caption, "aria-busy": true, className: cn("grid gap-2 p-3", className), children: Array.from({ length: 4 }, (_, i) => (_jsxs("li", { className: "surface-2 grid gap-2 rounded-ui p-3", children: [_jsx(Skeleton, { className: "h-3.5 w-2/3 rounded-full" }), _jsx(Skeleton, { className: "h-3 w-1/2 rounded-full" })] }, i))) }));
|
|
1199
|
+
}
|
|
1200
|
+
if (rows.length === 0) {
|
|
1201
|
+
return (_jsx("div", { className: cn("px-4 py-10", className), children: internal.hasQuery
|
|
1202
|
+
? (p.noResults ?? (_jsx(EmptyState, { kind: "no-results", size: "sm", title: t("noResultsTitle"), description: t("noResultsDescription"), actions: _jsx(Button, { size: "sm", variant: "secondary", onClick: () => setState({ q: "", filters: emptyFilterGroup() }, "filters"), children: t("clearFilters") }) })))
|
|
1203
|
+
: (p.empty ?? _jsx(EmptyState, { kind: "first-use", size: "sm", title: t("emptyTitle"), description: t("emptyDescription") })) }));
|
|
1204
|
+
}
|
|
1205
|
+
return (_jsx("ul", { "aria-label": p.caption, "aria-busy": p.loading || undefined, "data-slot": "data-table-cards", className: cn("grid gap-2 p-3", className), children: rows.map((row) => {
|
|
1206
|
+
const r = row.original;
|
|
1207
|
+
const selected = isRowSelected(selection, row.id);
|
|
1208
|
+
const titleValue = title ? readColumnValue(title, r) : row.id;
|
|
1209
|
+
const titleNode = title?.cell ? title.cell({ row: r, value: titleValue, rowId: row.id, index: row.index, column: title }) : textOf(titleValue);
|
|
1210
|
+
return (_jsxs("li", { "data-row-id": row.id, "data-state": selected ? "selected" : undefined, className: cn("ui-dt-card surface-2 relative flex gap-3 rounded-ui p-3 transition-colors", selected && "bg-selected", (p.onRowClick || p.rowHref) && "cursor-pointer"), onClick: (e) => {
|
|
1211
|
+
if (!(p.onRowClick || p.rowHref) || e.target.closest(INTERACTIVE))
|
|
1212
|
+
return;
|
|
1213
|
+
navigate(r);
|
|
1214
|
+
}, children: [p.selectable ? (_jsx("span", { className: "pt-0.5", "data-no-row-click": "", children: _jsx(Checkbox, { size: "sm", checked: selected, disabled: internal.isSelectable(r) !== true, "aria-label": t("selectRow", { name: internal.rowLabel(r) }), onCheckedChange: () => setSelection(toggleId(selection, row.id, p.selectable === "single")) }) })) : null, avatar ? _jsx(DataTableValue, { column: { ...avatar, type: "user" }, value: readColumnValue(avatar, r) }) : null, _jsxs("div", { className: "min-w-0 flex-1", children: [_jsxs("div", { className: "flex items-start gap-2", children: [_jsx("p", { className: "min-w-0 flex-1 truncate text-sm font-medium text-fg", children: p.rowHref ? (_jsx(Link, { href: p.rowHref(r), className: "rounded-ui-sm underline-offset-4 hover:underline focus-ring", children: titleNode })) : (titleNode) }), badge ? _jsx("span", { className: "shrink-0", children: badge.cell ? badge.cell({ row: r, value: readColumnValue(badge, r), rowId: row.id, index: row.index, column: badge }) : _jsx(DataTableValue, { column: badge, value: readColumnValue(badge, r) }) }) : null] }), subtitle ? _jsx("p", { className: "mt-0.5 truncate text-[13px] text-fg-muted", children: subtitle.cell ? subtitle.cell({ row: r, value: readColumnValue(subtitle, r), rowId: row.id, index: row.index, column: subtitle }) : _jsx(DataTableValue, { column: subtitle, value: readColumnValue(subtitle, r) }) }) : null, meta.length ? (_jsx("dl", { className: "mt-2 grid grid-cols-2 gap-x-3 gap-y-1 text-xs", children: meta.map((c) => (_jsxs("div", { className: "min-w-0", children: [_jsx("dt", { className: "text-fg-subtle", children: c.header }), _jsx("dd", { className: cn("truncate text-fg", END_TYPES.has(c.type ?? "text") && "tabular"), children: c.cell ? c.cell({ row: r, value: readColumnValue(c, r), rowId: row.id, index: row.index, column: c }) : _jsx(DataTableValue, { column: c, value: readColumnValue(c, r) }) })] }, c.id))) })) : null] }), p.rowActions ? (_jsx("span", { "data-no-row-click": "", className: "-me-1 -mt-1", children: _jsx(ActionMenu, { items: p.rowActions(r), triggerLabel: t("rowActions", { name: internal.rowLabel(r) }), triggerSize: "xs" }) })) : null] }, row.id));
|
|
1215
|
+
}) }));
|
|
1216
|
+
}
|
|
1217
|
+
/* ------------------------------------------------------------------ */
|
|
1218
|
+
/* Footer */
|
|
1219
|
+
/* ------------------------------------------------------------------ */
|
|
1220
|
+
/** Pagination (pages, cursor), "Load more" or the infinite-scroll sentinel. */
|
|
1221
|
+
export function DataTableFooter({ className }) {
|
|
1222
|
+
const { state, setState, total, internal, props: p } = useDataTable();
|
|
1223
|
+
const { t } = internal;
|
|
1224
|
+
const sentinel = React.useRef(null);
|
|
1225
|
+
const [loadingMore, setLoadingMore] = React.useState(false);
|
|
1226
|
+
const loadMore = React.useCallback(async () => {
|
|
1227
|
+
if (!p.onLoadMore || loadingMore)
|
|
1228
|
+
return;
|
|
1229
|
+
setLoadingMore(true);
|
|
1230
|
+
try {
|
|
1231
|
+
await p.onLoadMore();
|
|
1232
|
+
}
|
|
1233
|
+
finally {
|
|
1234
|
+
setLoadingMore(false);
|
|
1235
|
+
}
|
|
1236
|
+
}, [p, loadingMore]);
|
|
1237
|
+
React.useEffect(() => {
|
|
1238
|
+
if (p.pagination !== "infinite" || !p.hasMore || typeof IntersectionObserver === "undefined" || !sentinel.current)
|
|
1239
|
+
return;
|
|
1240
|
+
const io = new IntersectionObserver((entries) => {
|
|
1241
|
+
if (entries.some((e) => e.isIntersecting))
|
|
1242
|
+
void loadMore();
|
|
1243
|
+
}, { rootMargin: "240px" });
|
|
1244
|
+
io.observe(sentinel.current);
|
|
1245
|
+
return () => io.disconnect();
|
|
1246
|
+
}, [p.pagination, p.hasMore, loadMore]);
|
|
1247
|
+
const pagination = p.pagination ?? "pages";
|
|
1248
|
+
if (pagination === "none" || (p.data.length === 0 && !p.loading && total === 0))
|
|
1249
|
+
return null;
|
|
1250
|
+
const frame = cn("flex items-center gap-3 px-(--cell-px) py-3", p.variant !== "flush" && "border-t border-line", className);
|
|
1251
|
+
if (pagination === "load-more" || pagination === "infinite") {
|
|
1252
|
+
return (_jsxs("div", { className: cn(frame, "justify-center"), "data-slot": "data-table-footer", children: [pagination === "infinite" ? _jsx("div", { ref: sentinel, "aria-hidden": true, className: "h-px w-px" }) : null, p.hasMore ? (_jsx(Button, { size: "sm", variant: "secondary", loading: loadingMore || (Boolean(p.loading) && p.data.length > 0), onClick: () => void loadMore(), children: t("loadMore") })) : (_jsx("p", { className: "text-[13px] text-fg-subtle", children: t("noMore") }))] }));
|
|
1253
|
+
}
|
|
1254
|
+
if (isCursorPage(state.page)) {
|
|
1255
|
+
const size = state.page.size;
|
|
1256
|
+
return (_jsx("div", { className: cn(frame, "justify-end"), "data-slot": "data-table-footer", children: _jsx(CursorPagination, { hasPrev: Boolean(p.cursors?.prev), hasNext: Boolean(p.cursors?.next), loading: p.loading, size: "sm", onPrev: () => setState({ page: { cursor: p.cursors?.prev ?? null, size } }, "page"), onNext: () => setState({ page: { cursor: p.cursors?.next ?? null, size } }, "page") }) }));
|
|
1257
|
+
}
|
|
1258
|
+
return (_jsx("div", { className: frame, "data-slot": "data-table-footer", children: _jsx(PaginationBar, { className: "w-full", size: "sm", total: total, page: state.page.index + 1, pageSize: state.page.size, pageSizeOptions: p.pageSizes ?? [25, 50, 100], loading: Boolean(p.loading) && p.data.length > 0, onPageChange: (page) => setState({ page: { index: page - 1, size: state.page.size } }, "page"), onPageSizeChange: (size) => setState({ page: { index: 0, size } }, "pageSize") }) }));
|
|
1259
|
+
}
|