@espressif/dashboard-ui-components 1.10.0 → 1.11.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/CHANGELOG.md +65 -0
- package/dist/_vendor/@radix-ui/primitive/dist/index.js +9 -0
- package/dist/_vendor/@radix-ui/react-checkbox/dist/index.js +185 -0
- package/dist/_vendor/@radix-ui/react-compose-refs/dist/index.js +28 -0
- package/dist/_vendor/@radix-ui/react-context/dist/index.js +68 -0
- package/dist/_vendor/@radix-ui/react-presence/dist/index.js +127 -0
- package/dist/_vendor/@radix-ui/react-primitive/dist/index.js +42 -0
- package/dist/_vendor/@radix-ui/react-use-controllable-state/dist/index.js +55 -0
- package/dist/_vendor/@radix-ui/react-use-layout-effect/dist/index.js +5 -0
- package/dist/_vendor/@radix-ui/react-use-previous/dist/index.js +17 -0
- package/dist/_vendor/@radix-ui/react-use-size/dist/index.js +39 -0
- package/dist/_vendor/lottie-react/build/index.es.js +537 -0
- package/dist/_vendor/lottie-web/build/player/lottie.js +14149 -0
- package/dist/_virtual/_rolldown/runtime.js +24 -0
- package/dist/assets/illustrations/bulb-cloud-drawing.js +4 -0
- package/dist/assets/illustrations/rm-dashboard-update.js +4 -0
- package/dist/assets/illustrations/rm-data-download.js +4 -0
- package/dist/assets/logos/espressif/espressif-no-text.js +4 -0
- package/dist/assets/logos/espressif/espressif-with-text-dm.js +4 -0
- package/dist/assets/logos/espressif/espressif-with-text.js +4 -0
- package/dist/assets/logos/insights/insights-no-text.js +4 -0
- package/dist/assets/logos/insights/insights-with-text-dm.js +4 -0
- package/dist/assets/logos/insights/insights-with-text.js +4 -0
- package/dist/assets/logos/launchpad/launchpad-no-text-dm.js +4 -0
- package/dist/assets/logos/launchpad/launchpad-no-text.js +4 -0
- package/dist/assets/logos/launchpad/launchpad-with-text-dm.js +4 -0
- package/dist/assets/logos/launchpad/launchpad-with-text.js +4 -0
- package/dist/assets/logos/private-agents/private-agents-no-text.js +4 -0
- package/dist/assets/logos/private-agents/private-agents-with-text-dm.js +4 -0
- package/dist/assets/logos/private-agents/private-agents-with-text.js +4 -0
- package/dist/assets/logos/rainmaker/rainmaker-no-text.js +4 -0
- package/dist/assets/logos/rainmaker/rainmaker-with-text-dm.js +4 -0
- package/dist/assets/logos/rainmaker/rainmaker-with-text.js +4 -0
- package/dist/assets/logos/rainmaker-classic/rainmaker-classic-no-text-dm.js +4 -0
- package/dist/assets/logos/rainmaker-classic/rainmaker-classic-no-text.js +4 -0
- package/dist/assets/logos/rainmaker-classic/rainmaker-classic-with-text-dm.js +4 -0
- package/dist/assets/logos/rainmaker-classic/rainmaker-classic-with-text.js +4 -0
- package/dist/assets/logos/rainmaker-neo/rainmaker-neo-no-text.js +4 -0
- package/dist/assets/logos/rainmaker-neo/rainmaker-neo-with-text-dm.js +4 -0
- package/dist/assets/logos/rainmaker-neo/rainmaker-neo-with-text.js +4 -0
- package/dist/assets/logos/ui-components/ui-components-no-text.js +4 -0
- package/dist/assets/logos/ui-components/ui-components-with-text-dm.js +4 -0
- package/dist/assets/logos/ui-components/ui-components-with-text.js +4 -0
- package/dist/assets/logos/zerocode/zerocode-no-text.js +4 -0
- package/dist/assets/logos/zerocode/zerocode-with-text-dm.js +4 -0
- package/dist/assets/logos/zerocode/zerocode-with-text.js +4 -0
- package/dist/assets/logos/zerocode-ai/zerocode-ai-no-text.js +4 -0
- package/dist/assets/logos/zerocode-ai/zerocode-ai-with-text-dm.js +4 -0
- package/dist/assets/logos/zerocode-ai/zerocode-ai-with-text.js +4 -0
- package/dist/common/animated-rainmaker-logo/animated-rainmaker-logo.constants.js +18 -0
- package/dist/common/animated-rainmaker-logo/animated-rainmaker-logo.js +24 -0
- package/dist/common/animated-rainmaker-logo/rainmaker-c-logo.js +50 -0
- package/dist/common/animated-rainmaker-logo/use-animated-rainmaker-logo-animation.js +85 -0
- package/dist/common/app-logo/app-logo.js +59 -0
- package/dist/common/app-logo/logo-config.js +297 -0
- package/dist/common/copyright-card/copyright-card.js +39 -0
- package/dist/common/footer-card/footer-card.js +22 -0
- package/dist/common/index.js +8 -8
- package/dist/common/my-account-menu/my-account-menu.js +32 -0
- package/dist/common/page-loader/page-loader.js +21 -0
- package/dist/common/profile-card/profile-card.js +26 -0
- package/dist/components/accordion/accordion.js +52 -0
- package/dist/components/advanced-search-box/advanced-search-box.js +106 -0
- package/dist/components/alert/alert.js +85 -0
- package/dist/components/animated-containers/pop-collection-item.js +28 -0
- package/dist/components/async-multi-select/async-multi-select.js +199 -0
- package/dist/components/avatar/avatar.js +41 -0
- package/dist/components/button/button.js +191 -0
- package/dist/components/button/flash-button.js +110 -0
- package/dist/components/button/invert-button.js +13 -0
- package/dist/components/calendar/calendar.js +105 -0
- package/dist/components/cards/animated-card/animated-card-animations.js +57 -0
- package/dist/components/cards/animated-card/animated-card.js +42 -0
- package/dist/components/cards/basic-details-card.js +46 -0
- package/dist/components/cards/collapsible-card.js +48 -0
- package/dist/components/cards/no-data-card/no-data-card.js +30 -0
- package/dist/components/cards/section-card.js +265 -0
- package/dist/components/cards/simple-card.js +24 -0
- package/dist/components/carousel/carousel.js +158 -0
- package/dist/components/chart/area-chart.js +135 -0
- package/dist/components/chart/bar-chart.js +151 -0
- package/dist/components/chart/chart-colors.js +85 -0
- package/dist/components/chart/chart-series-data.js +53 -0
- package/dist/components/chart/chart.js +147 -0
- package/dist/components/chart/chart.types.js +7 -0
- package/dist/components/chart/composed-chart.js +182 -0
- package/dist/components/chart/donut-chart.js +177 -0
- package/dist/components/chart/line-chart.js +137 -0
- package/dist/components/chart/treemap-chart.js +294 -0
- package/dist/components/circular-progress/circular-progress.js +125 -0
- package/dist/components/code-editor/code-editor.js +235 -0
- package/dist/components/code-editor/code-editor.utils.js +122 -0
- package/dist/components/code-editor/use-code-editor-keys.js +79 -0
- package/dist/components/code-editor/use-highlighted-html.js +102 -0
- package/dist/components/confirmation-dialog/confirmation-dialog.js +72 -0
- package/dist/components/content-container/content-container.js +20 -0
- package/dist/components/copiable-text/copiable-text.js +46 -0
- package/dist/components/data-table/data-table.js +186 -0
- package/dist/components/data-table/responsive-columns.js +65 -0
- package/dist/components/data-table/row-actions.js +27 -0
- package/dist/components/data-table/sticky-columns.js +71 -0
- package/dist/components/data-table/table-body.js +57 -0
- package/dist/components/data-table/table-header.js +21 -0
- package/dist/components/date-picker/date-picker.js +95 -0
- package/dist/components/date-range-picker/date-range-picker.js +301 -0
- package/dist/components/date-range-picker/presets.js +174 -0
- package/dist/components/date-time-picker/date-time-picker.js +144 -0
- package/dist/components/date-time-picker/date-time-picker.utils.js +32 -0
- package/dist/components/device-icon/device-icon.config.js +194 -0
- package/dist/components/device-icon/device-icon.js +17 -0
- package/dist/components/device-icon/icons/air-conditioner.js +22 -0
- package/dist/components/device-icon/icons/blind.js +24 -0
- package/dist/components/device-icon/icons/dimmer.js +14 -0
- package/dist/components/device-icon/icons/extension-board.js +42 -0
- package/dist/components/device-icon/icons/fan.js +14 -0
- package/dist/components/device-icon/icons/knob.js +14 -0
- package/dist/components/device-icon/icons/led-strip.js +22 -0
- package/dist/components/device-icon/icons/light.js +14 -0
- package/dist/components/device-icon/icons/refrigerator.js +18 -0
- package/dist/components/device-icon/icons/retro-switch.js +18 -0
- package/dist/components/device-icon/icons/router.js +20 -0
- package/dist/components/device-icon/icons/sensor.js +20 -0
- package/dist/components/device-icon/icons/socket.js +19 -0
- package/dist/components/device-icon/icons/switch.js +19 -0
- package/dist/components/device-icon/icons/thermostat.js +21 -0
- package/dist/components/device-icon/icons/washing-machine.js +22 -0
- package/dist/components/device-icon/match-device.js +61 -0
- package/dist/components/dynamic-list/dynamic-list.js +445 -0
- package/dist/components/error-display/full-size-error/full-size-error.js +20 -0
- package/dist/components/error-display/inline-error/inline-error.js +12 -0
- package/dist/components/file-input/file-input.js +318 -0
- package/dist/components/file-upload/file-upload.js +317 -0
- package/dist/components/filters-bar/filters-bar.js +36 -0
- package/dist/components/fullscreen-dialog/fullscreen-dialog.js +68 -0
- package/dist/components/icon-avatar/icon-avatar.js +130 -0
- package/dist/components/icon-text-action-card/icon-text-action-card.js +190 -0
- package/dist/components/illustration/illustration-registry.js +37 -0
- package/dist/components/illustration/illustration-variants.js +21 -0
- package/dist/components/illustration/illustration.js +68 -0
- package/dist/components/index.d.ts +0 -20
- package/dist/components/index.js +134 -6
- package/dist/components/key-value-manager/key-value-manager-add-popover.js +126 -0
- package/dist/components/key-value-manager/key-value-manager-field.js +47 -0
- package/dist/components/key-value-manager/key-value-manager-table.js +188 -0
- package/dist/components/key-value-manager/key-value-manager.js +111 -0
- package/dist/components/key-value-manager/key-value-manager.props.js +28 -0
- package/dist/components/key-value-manager/key-value-manager.utils.js +21 -0
- package/dist/components/link/link.js +67 -0
- package/dist/components/list/dropdown-list-item.js +60 -0
- package/dist/components/list/list-item.utils.js +76 -0
- package/dist/components/list/list.js +49 -0
- package/dist/components/list/list.props.js +27 -0
- package/dist/components/list/standard-list-item.js +66 -0
- package/dist/components/list-details/list-details-item-button.js +46 -0
- package/dist/components/list-details/list-details-item-dropdown.js +112 -0
- package/dist/components/list-details/list-details-item-strip.js +125 -0
- package/dist/components/list-details/list-details.js +148 -0
- package/dist/components/lottie-animation-container/lottie-animation-container.js +31 -0
- package/dist/components/lottie-animations/animation-data/access-denied.js +3980 -0
- package/dist/components/lottie-animations/animation-data/active.js +825 -0
- package/dist/components/lottie-animations/animation-data/bar-chart.js +610 -0
- package/dist/components/lottie-animations/animation-data/chart-loading.js +5368 -0
- package/dist/components/lottie-animations/animation-data/cloud-download.js +1660 -0
- package/dist/components/lottie-animations/animation-data/cloud-sync.js +932 -0
- package/dist/components/lottie-animations/animation-data/coud-upload.js +7060 -0
- package/dist/components/lottie-animations/animation-data/cross-throb.js +1506 -0
- package/dist/components/lottie-animations/animation-data/dashboard-loading.js +14330 -0
- package/dist/components/lottie-animations/animation-data/error-spread-out.js +5567 -0
- package/dist/components/lottie-animations/animation-data/error.js +1211 -0
- package/dist/components/lottie-animations/animation-data/green-success.js +14826 -0
- package/dist/components/lottie-animations/animation-data/inactive.js +723 -0
- package/dist/components/lottie-animations/animation-data/light.js +2678 -0
- package/dist/components/lottie-animations/animation-data/lock.js +900 -0
- package/dist/components/lottie-animations/animation-data/lock2.js +1686 -0
- package/dist/components/lottie-animations/animation-data/locked.js +641 -0
- package/dist/components/lottie-animations/animation-data/search-error.js +954 -0
- package/dist/components/lottie-animations/animation-data/security.js +4121 -0
- package/dist/components/lottie-animations/animation-data/success.js +404 -0
- package/dist/components/lottie-animations/animation-data/verification-in-progress.js +10138 -0
- package/dist/components/lottie-animations/animation-data/warning.js +843 -0
- package/dist/components/lottie-animations/verification-in-progress/verification-in-progress.js +19 -0
- package/dist/components/markdown-content/markdown-content.components.js +114 -0
- package/dist/components/markdown-content/markdown-content.js +39 -0
- package/dist/components/menu/menu.js +19 -0
- package/dist/components/monospace-content/monospace-content.js +80 -0
- package/dist/components/nav-bar/nav-bar-details-panel.js +51 -0
- package/dist/components/nav-bar/nav-bar-mobile-menu.js +105 -0
- package/dist/components/nav-bar/nav-bar.js +449 -0
- package/dist/components/nav-bar/use-nav-bar-overflow.js +74 -0
- package/dist/components/nav-bar/use-nav-bar-scroll.js +42 -0
- package/dist/components/overflow-badge-list/overflow-badge-list.js +58 -0
- package/dist/components/page-container/page-container-skeleton.js +72 -0
- package/dist/components/page-container/page-container.js +93 -0
- package/dist/components/pagination/pagination.js +96 -0
- package/dist/components/pagination/pagination.props.js +16 -0
- package/dist/components/progress-bar/progress-bar.js +106 -0
- package/dist/components/radio-group/radio-group.js +41 -0
- package/dist/components/requirement-list/requirement-list.js +83 -0
- package/dist/components/scrollable-sections/scrollable-sections.js +270 -0
- package/dist/components/search-box/search-box.js +54 -0
- package/dist/components/search-field-shell.js +24 -0
- package/dist/components/selectable-card-list/checkbox-card-list.js +85 -0
- package/dist/components/selectable-card-list/radio-card-list.js +99 -0
- package/dist/components/selectable-card-list/selectable-card-list-shared.js +135 -0
- package/dist/components/selectable-card-list/selectable-card-list.js +34 -0
- package/dist/components/sidebar/sidebar.js +344 -0
- package/dist/components/sidebar/types.js +6 -0
- package/dist/components/simple-clickable-card/simple-clickable-card-shared.js +309 -0
- package/dist/components/simple-clickable-card/simple-clickable-card.js +106 -0
- package/dist/components/simple-info-card/simple-info-card.js +154 -0
- package/dist/components/simple-list/simple-list.js +146 -0
- package/dist/components/simple-paginated-list/simple-paginated-list.js +178 -0
- package/dist/components/simplified-date/simplified-date.js +56 -0
- package/dist/components/skeletons/table-skeleton.js +16 -0
- package/dist/components/spinner/spinner.js +25 -0
- package/dist/components/stat-card/stat-card.js +206 -0
- package/dist/components/status-badge/status-badge.js +108 -0
- package/dist/components/status-card-list/status-card-list.js +282 -0
- package/dist/components/tag/tag.js +144 -0
- package/dist/components/tag-input/tag-input.js +161 -0
- package/dist/components/text-effects/glitch-effect/glitch-text.js +115 -0
- package/dist/components/text-effects/gradient-text/gradient-text.js +32 -0
- package/dist/components/text-effects/highlight-text/highlight-text.js +35 -0
- package/dist/components/text-effects/parse-text-markup.js +53 -0
- package/dist/components/text-effects/shimmer-text/shimmer-text.js +67 -0
- package/dist/components/time-picker/time-picker.js +23 -0
- package/dist/components/toast/toast.js +126 -0
- package/dist/components/togglable-items-list/togglable-items-list.js +28 -0
- package/dist/components/tooltip/tooltip.js +21 -0
- package/dist/components/transfer-list/transfer-list.js +413 -0
- package/dist/components/truncated-line-with-tooltip/truncated-line-with-tooltip.js +61 -0
- package/dist/components/typography/typography-variants.js +41 -0
- package/dist/components/typography/typography.js +15 -0
- package/dist/components/user-type-badge/user-type-badge.js +40 -0
- package/dist/components/user-type-badge/user-type-badge.registry.js +17 -0
- package/dist/components/vertical-stepper/vertical-stepper.js +171 -0
- package/dist/core/alert.js +33 -0
- package/dist/core/animate-ui/components/animate/code-header.js +30 -0
- package/dist/core/animate-ui/components/animate/code.js +35 -0
- package/dist/core/animate-ui/components/animate/tabs.js +188 -0
- package/dist/core/animate-ui/components/animate/tooltip.js +39 -0
- package/dist/core/animate-ui/components/base/preview-card.js +29 -0
- package/dist/core/animate-ui/components/base/progress.js +32 -0
- package/dist/core/animate-ui/components/base/radio.js +24 -0
- package/dist/core/animate-ui/components/buttons/copy.js +95 -0
- package/dist/core/animate-ui/components/radix/accordion.js +36 -0
- package/dist/core/animate-ui/components/radix/dialog.js +60 -0
- package/dist/core/animate-ui/components/radix/dropdown-menu.js +129 -0
- package/dist/core/animate-ui/components/radix/sheet.js +110 -0
- package/dist/core/animate-ui/components/radix/sidebar.js +416 -0
- package/dist/core/animate-ui/components/radix/switch.js +34 -0
- package/dist/core/animate-ui/components/radix/toggle-group.js +115 -0
- package/dist/core/animate-ui/components/radix/toggle.js +24 -0
- package/dist/core/animate-ui/primitives/animate/code-block.js +131 -0
- package/dist/core/animate-ui/primitives/animate/escape-html.js +7 -0
- package/dist/core/animate-ui/primitives/animate/shiki-highlighter.js +64 -0
- package/dist/core/animate-ui/primitives/animate/slot.js +39 -0
- package/dist/core/animate-ui/primitives/animate/tabs.js +202 -0
- package/dist/core/animate-ui/primitives/animate/tooltip.js +351 -0
- package/dist/core/animate-ui/primitives/base/preview-card.js +107 -0
- package/dist/core/animate-ui/primitives/base/progress.js +60 -0
- package/dist/core/animate-ui/primitives/base/radio.js +83 -0
- package/dist/core/animate-ui/primitives/buttons/button.js +15 -0
- package/dist/core/animate-ui/primitives/effects/highlight.js +407 -0
- package/dist/core/animate-ui/primitives/radix/accordion.js +76 -0
- package/dist/core/animate-ui/primitives/radix/dialog.js +136 -0
- package/dist/core/animate-ui/primitives/radix/dropdown-menu.js +305 -0
- package/dist/core/animate-ui/primitives/radix/sheet.js +165 -0
- package/dist/core/animate-ui/primitives/radix/switch.js +86 -0
- package/dist/core/animate-ui/primitives/radix/toggle-group.js +100 -0
- package/dist/core/animate-ui/primitives/texts/counting-number.js +75 -0
- package/dist/core/avatar.js +32 -0
- package/dist/core/badge.js +27 -0
- package/dist/core/breadcrumb.js +62 -0
- package/dist/core/button/button.js +43 -0
- package/dist/core/button/craft-button.js +78 -0
- package/dist/core/button-group.js +38 -0
- package/dist/core/button.js +40 -0
- package/dist/core/card.js +42 -0
- package/dist/core/carousel/carousel.js +149 -0
- package/dist/core/checkbox/motion-checkbox.js +103 -0
- package/dist/core/collapsible.js +54 -0
- package/dist/core/combobox/combobox.js +85 -0
- package/dist/core/command.js +61 -0
- package/dist/core/field-end-icons.js +36 -0
- package/dist/core/field-label-row.js +33 -0
- package/dist/core/form.js +92 -0
- package/dist/core/hooks/use-controlled-state.js +27 -0
- package/dist/core/hooks/use-data-state.js +39 -0
- package/dist/core/hooks/use-is-in-view.js +18 -0
- package/dist/core/hooks/use-mobile.js +19 -0
- package/dist/core/hooks/use-reveal-on-scroll-up.js +141 -0
- package/dist/core/hooks/use-scroll-overflow.js +50 -0
- package/dist/core/index.js +18 -52
- package/dist/core/input/input-password.js +30 -0
- package/dist/core/input/input.js +147 -0
- package/dist/core/input-otp/input-otp.js +183 -0
- package/dist/core/label.js +15 -0
- package/dist/core/popover.js +31 -0
- package/dist/core/scroll-area.js +42 -0
- package/dist/core/select.js +121 -0
- package/dist/core/separator.js +40 -0
- package/dist/core/skeleton.js +11 -0
- package/dist/core/table.js +59 -0
- package/dist/core/textarea/textarea.js +97 -0
- package/dist/core/utils/get-strict-context.js +18 -0
- package/dist/index.js +148 -9
- package/dist/layouts/entry-layout/entry-layout-bg.js +4 -0
- package/dist/layouts/entry-layout/entry-layout.js +52 -0
- package/dist/layouts/index.js +7 -6
- package/dist/layouts/workspace-layout/account-menu/account-menu.js +108 -0
- package/dist/layouts/workspace-layout/breadcrumbs/derive-breadcrumbs.js +37 -0
- package/dist/layouts/workspace-layout/breadcrumbs/workspace-breadcrumbs.js +22 -0
- package/dist/layouts/workspace-layout/footer/footer.js +15 -0
- package/dist/layouts/workspace-layout/header/header.js +54 -0
- package/dist/layouts/workspace-layout/workspace-layout.js +157 -0
- package/dist/tailwind-preset.js +3 -4
- package/dist/utils/cn.js +8 -0
- package/dist/utils/color.js +72 -0
- package/dist/utils/index.js +3 -2
- package/dist/utils/path-match.js +17 -0
- package/dist/utils/silver-shine.js +63 -0
- package/dist/utils/variant-gradient-underlay.js +45 -0
- package/dist/utils/variant.js +426 -0
- package/package.json +7 -4
- package/dist/chunk-2GDYZAKR.js +0 -505
- package/dist/chunk-ALCWXFUC.js +0 -733
- package/dist/chunk-CDHBLANU.js +0 -59
- package/dist/chunk-LUESSJAF.js +0 -70068
- package/dist/chunk-TMORRNEB.js +0 -323
- package/dist/chunk-TRTQSARU.js +0 -31
- package/dist/chunk-VU4CZ76T.js +0 -43
- package/dist/chunk-XNLCVHBC.js +0 -364
- package/dist/chunk-Z4776NRY.js +0 -4347
- package/src/assets/illustrations/add-to-group.svg +0 -32
- package/src/assets/illustrations/chip.svg +0 -51
- package/src/assets/illustrations/create-new-group.svg +0 -27
- package/src/assets/illustrations/new-ota.svg +0 -61
- package/src/assets/illustrations/secured-key.svg +0 -48
- /package/dist/assets/{entry-layout-bg-JPI7GJ42.webp → entry-layout-bg-DUM0UhT3.webp} +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
//#region src/components/code-editor/code-editor.utils.ts
|
|
2
|
+
/** Offset of the first character of the line containing `pos`. */
|
|
3
|
+
function getLineStart(value, pos) {
|
|
4
|
+
return value.lastIndexOf("\n", pos - 1) + 1;
|
|
5
|
+
}
|
|
6
|
+
/** Offset just past the last character of the line containing `pos` (before its `\n`). */
|
|
7
|
+
function getLineEnd(value, pos) {
|
|
8
|
+
const next = value.indexOf("\n", pos);
|
|
9
|
+
return next === -1 ? value.length : next;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Leading spaces and tabs of the line containing `pos`, counting only the
|
|
13
|
+
* part before `pos`, so a caret inside the indentation never carries more
|
|
14
|
+
* indentation than sits to its left.
|
|
15
|
+
*/
|
|
16
|
+
function getLineIndent(value, pos) {
|
|
17
|
+
const lineStart = getLineStart(value, pos);
|
|
18
|
+
return /^[ \t]*/.exec(value.slice(lineStart, pos))[0];
|
|
19
|
+
}
|
|
20
|
+
/** True when the selection touches more than one line. */
|
|
21
|
+
function isMultiLineSelection(value, start, end) {
|
|
22
|
+
return value.slice(start, end).includes("\n");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Start offsets of every line the selection covers. A selection that ends
|
|
26
|
+
* at the very start of a line (after its `\n`) does not include that line,
|
|
27
|
+
* matching how editors treat a full-line selection.
|
|
28
|
+
*/
|
|
29
|
+
function getSelectedLineStarts(value, start, end) {
|
|
30
|
+
const lastPos = end > start && value[end - 1] === "\n" ? end - 1 : end;
|
|
31
|
+
const starts = [getLineStart(value, start)];
|
|
32
|
+
for (let i = value.indexOf("\n", starts[0]); i !== -1 && i < lastPos; i = value.indexOf("\n", i + 1)) starts.push(i + 1);
|
|
33
|
+
return starts;
|
|
34
|
+
}
|
|
35
|
+
/** Tab with a caret or a single-line selection: spaces up to the next tab stop. */
|
|
36
|
+
function insertTab(value, start, end, tabSize) {
|
|
37
|
+
const column = start - getLineStart(value, start);
|
|
38
|
+
const text = " ".repeat(tabSize - column % tabSize);
|
|
39
|
+
const caret = start + text.length;
|
|
40
|
+
return {
|
|
41
|
+
start,
|
|
42
|
+
end,
|
|
43
|
+
text,
|
|
44
|
+
selectionStart: caret,
|
|
45
|
+
selectionEnd: caret
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Tab with a multi-line selection: prefix every selected non-empty line with `tabSize` spaces. */
|
|
49
|
+
function indentLines(value, start, end, tabSize) {
|
|
50
|
+
const lineStarts = getSelectedLineStarts(value, start, end);
|
|
51
|
+
const blockStart = lineStarts[0];
|
|
52
|
+
const blockEnd = getLineEnd(value, lineStarts[lineStarts.length - 1]);
|
|
53
|
+
const indent = " ".repeat(tabSize);
|
|
54
|
+
const added = lineStarts.map((lineStart) => lineStart === getLineEnd(value, lineStart) ? 0 : tabSize);
|
|
55
|
+
const text = value.slice(blockStart, blockEnd).split("\n").map((line, i) => added[i] ? indent + line : line).join("\n");
|
|
56
|
+
const mapOffset = (pos, keepAtLineStart) => {
|
|
57
|
+
let shift = 0;
|
|
58
|
+
lineStarts.forEach((lineStart, i) => {
|
|
59
|
+
if (lineStart < pos || lineStart === pos && !keepAtLineStart) shift += added[i];
|
|
60
|
+
});
|
|
61
|
+
return pos + shift;
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
start: blockStart,
|
|
65
|
+
end: blockEnd,
|
|
66
|
+
text,
|
|
67
|
+
selectionStart: mapOffset(start, true),
|
|
68
|
+
selectionEnd: mapOffset(end, false)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Shift+Tab: remove up to `tabSize` leading spaces (or one leading tab) from
|
|
73
|
+
* every selected line; with a caret, from the caret's line.
|
|
74
|
+
*/
|
|
75
|
+
function outdentLines(value, start, end, tabSize) {
|
|
76
|
+
const lineStarts = getSelectedLineStarts(value, start, end);
|
|
77
|
+
const blockStart = lineStarts[0];
|
|
78
|
+
const blockEnd = getLineEnd(value, lineStarts[lineStarts.length - 1]);
|
|
79
|
+
const lines = value.slice(blockStart, blockEnd).split("\n");
|
|
80
|
+
const removed = lines.map((line) => line.startsWith(" ") ? 1 : Math.min(tabSize, /^ */.exec(line)[0].length));
|
|
81
|
+
const text = lines.map((line, i) => line.slice(removed[i])).join("\n");
|
|
82
|
+
const mapOffset = (pos) => {
|
|
83
|
+
let shift = 0;
|
|
84
|
+
lineStarts.forEach((lineStart, i) => {
|
|
85
|
+
if (lineStart <= pos) shift += Math.min(removed[i], pos - lineStart);
|
|
86
|
+
});
|
|
87
|
+
return pos - shift;
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
start: blockStart,
|
|
91
|
+
end: blockEnd,
|
|
92
|
+
text,
|
|
93
|
+
selectionStart: mapOffset(start),
|
|
94
|
+
selectionEnd: mapOffset(end)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Enter: a line break followed by the current line's indentation. */
|
|
98
|
+
function insertNewline(value, start, end) {
|
|
99
|
+
const text = "\n" + getLineIndent(value, start);
|
|
100
|
+
const caret = start + text.length;
|
|
101
|
+
return {
|
|
102
|
+
start,
|
|
103
|
+
end,
|
|
104
|
+
text,
|
|
105
|
+
selectionStart: caret,
|
|
106
|
+
selectionEnd: caret
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** Applies a `TextEdit` to a string. Used by tests and the non-`execCommand` fallback check. */
|
|
110
|
+
function applyTextEdit(value, edit) {
|
|
111
|
+
return value.slice(0, edit.start) + edit.text + value.slice(edit.end);
|
|
112
|
+
}
|
|
113
|
+
/** Pretty-prints JSON with `tabSize`-space indentation. Throws on invalid JSON. */
|
|
114
|
+
function formatJson(value, tabSize) {
|
|
115
|
+
return JSON.stringify(JSON.parse(value), null, tabSize);
|
|
116
|
+
}
|
|
117
|
+
/** Built-in formatter for `lang`, or `undefined` when there is none (only JSON has one). */
|
|
118
|
+
function getBuiltInFormatter(lang) {
|
|
119
|
+
return lang.toLowerCase() === "json" ? formatJson : void 0;
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
export { applyTextEdit, formatJson, getBuiltInFormatter, getLineEnd, getLineIndent, getLineStart, indentLines, insertNewline, insertTab, isMultiLineSelection, outdentLines };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { applyTextEdit, indentLines, insertNewline, insertTab, isMultiLineSelection, outdentLines } from "./code-editor.utils.js";
|
|
2
|
+
import * as React$1 from "react";
|
|
3
|
+
//#region src/components/code-editor/use-code-editor-keys.ts
|
|
4
|
+
/**
|
|
5
|
+
* Replaces a range of the textarea through the browser's editing pipeline so
|
|
6
|
+
* the change lands on the native undo stack (Cmd/Ctrl+Z undoes a Tab, an
|
|
7
|
+
* auto-indent or a Format like any typed text).
|
|
8
|
+
*
|
|
9
|
+
* `document.execCommand` is deprecated, but it is still the only standard way
|
|
10
|
+
* to make a programmatic edit undoable; `setRangeText` and assigning `value`
|
|
11
|
+
* both clear the undo history. When `execCommand` is missing or refuses the
|
|
12
|
+
* edit, fall back to `setRangeText` plus a synthetic `input` event, which
|
|
13
|
+
* edits correctly (and fires React's `onChange`) but is not undoable.
|
|
14
|
+
*/
|
|
15
|
+
function applyEdit(el, edit) {
|
|
16
|
+
const current = el.value;
|
|
17
|
+
const expected = applyTextEdit(current, edit);
|
|
18
|
+
if (expected === current) {
|
|
19
|
+
el.setSelectionRange(edit.selectionStart, edit.selectionEnd);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (el.ownerDocument.activeElement !== el) el.focus({ preventScroll: true });
|
|
23
|
+
el.setSelectionRange(edit.start, edit.end);
|
|
24
|
+
let applied = false;
|
|
25
|
+
try {
|
|
26
|
+
applied = typeof document.execCommand === "function" && document.execCommand(edit.text ? "insertText" : "delete", false, edit.text);
|
|
27
|
+
} catch {
|
|
28
|
+
applied = false;
|
|
29
|
+
}
|
|
30
|
+
if (!applied || el.value !== expected) {
|
|
31
|
+
if (el.value !== current) el.value = current;
|
|
32
|
+
el.setRangeText(edit.text, edit.start, edit.end, "end");
|
|
33
|
+
el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
34
|
+
}
|
|
35
|
+
el.setSelectionRange(edit.selectionStart, edit.selectionEnd);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Editor keys for the `CodeEditor` textarea: Tab / Shift+Tab indent and
|
|
39
|
+
* outdent, Enter keeps the current indentation, and Esc releases Tab so the
|
|
40
|
+
* next Tab moves focus (WCAG 2.1.2, no keyboard trap).
|
|
41
|
+
*/
|
|
42
|
+
function useCodeEditorKeys({ tabSize, onKeyDown, onBlur }) {
|
|
43
|
+
const tabReleasedRef = React$1.useRef(false);
|
|
44
|
+
return {
|
|
45
|
+
onKeyDown: React$1.useCallback((event) => {
|
|
46
|
+
onKeyDown?.(event);
|
|
47
|
+
if (event.defaultPrevented) return;
|
|
48
|
+
if (event.nativeEvent.isComposing || event.keyCode === 229) return;
|
|
49
|
+
const el = event.currentTarget;
|
|
50
|
+
if (el.readOnly || el.disabled) return;
|
|
51
|
+
if (event.key === "Escape") {
|
|
52
|
+
tabReleasedRef.current = true;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (event.key === "Shift") return;
|
|
56
|
+
const released = tabReleasedRef.current;
|
|
57
|
+
tabReleasedRef.current = false;
|
|
58
|
+
const { value, selectionStart: start, selectionEnd: end } = el;
|
|
59
|
+
if (event.key === "Tab") {
|
|
60
|
+
if (released || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
if (event.shiftKey) applyEdit(el, outdentLines(value, start, end, tabSize));
|
|
63
|
+
else if (isMultiLineSelection(value, start, end)) applyEdit(el, indentLines(value, start, end, tabSize));
|
|
64
|
+
else applyEdit(el, insertTab(value, start, end, tabSize));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (event.key === "Enter" && !event.shiftKey && !event.altKey && !event.ctrlKey && !event.metaKey) {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
applyEdit(el, insertNewline(value, start, end));
|
|
70
|
+
}
|
|
71
|
+
}, [onKeyDown, tabSize]),
|
|
72
|
+
onBlur: React$1.useCallback((event) => {
|
|
73
|
+
tabReleasedRef.current = false;
|
|
74
|
+
onBlur?.(event);
|
|
75
|
+
}, [onBlur])
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { applyEdit, useCodeEditorKeys };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getHighlighter, normalizeLang } from "../../core/animate-ui/primitives/animate/shiki-highlighter.js";
|
|
2
|
+
import { escapeHtml } from "../../core/animate-ui/primitives/animate/escape-html.js";
|
|
3
|
+
import * as React$1 from "react";
|
|
4
|
+
//#region src/components/code-editor/use-highlighted-html.ts
|
|
5
|
+
var DEFAULT_CODE_EDITOR_THEMES = {
|
|
6
|
+
light: "everforest-light",
|
|
7
|
+
dark: "everforest-dark"
|
|
8
|
+
};
|
|
9
|
+
/** Shiki's grammar-less languages; they need no bundled grammar. */
|
|
10
|
+
var PLAIN_LANGS = /* @__PURE__ */ new Set([
|
|
11
|
+
"text",
|
|
12
|
+
"plaintext",
|
|
13
|
+
"txt",
|
|
14
|
+
"plain"
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* A zero-width space after the last character. A `<pre>` collapses a
|
|
18
|
+
* trailing `\n` while the textarea shows an empty last line for it; the
|
|
19
|
+
* extra character gives that line a box so both layers keep the same height.
|
|
20
|
+
*/
|
|
21
|
+
var TRAILING_LINE = "";
|
|
22
|
+
var transformer = {
|
|
23
|
+
pre(node) {
|
|
24
|
+
delete node.properties.tabindex;
|
|
25
|
+
},
|
|
26
|
+
code(node) {
|
|
27
|
+
node.children.push({
|
|
28
|
+
type: "text",
|
|
29
|
+
value: TRAILING_LINE
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
function plainHtml(value) {
|
|
34
|
+
return `<pre><code>${escapeHtml(value)}${TRAILING_LINE}</code></pre>`;
|
|
35
|
+
}
|
|
36
|
+
var warned = /* @__PURE__ */ new Set();
|
|
37
|
+
function warnOnce(key, message, error) {
|
|
38
|
+
if (warned.has(key)) return;
|
|
39
|
+
warned.add(key);
|
|
40
|
+
console.warn(`[dashboard-ui-components] ${message}`, ...error ? [error] : []);
|
|
41
|
+
}
|
|
42
|
+
var resolved = /* @__PURE__ */ new WeakMap();
|
|
43
|
+
/**
|
|
44
|
+
* HTML for the `CodeEditor` highlight layer. The highlighter loads once;
|
|
45
|
+
* after that each value is highlighted synchronously, so results can never
|
|
46
|
+
* arrive out of order. Highlighting follows `useDeferredValue(value)` so
|
|
47
|
+
* React can let a keystroke render before the colours catch up. Falls back
|
|
48
|
+
* to escaped plain text while loading, for languages or themes outside the
|
|
49
|
+
* curated bundle, and above `maxHighlightLength`.
|
|
50
|
+
*/
|
|
51
|
+
function useHighlightedHtml(value, { lang, theme, themes, maxHighlightLength }) {
|
|
52
|
+
const [highlighter, setHighlighter] = React$1.useState(() => {
|
|
53
|
+
const promise = getHighlighter();
|
|
54
|
+
return resolved.get(promise) ?? null;
|
|
55
|
+
});
|
|
56
|
+
React$1.useEffect(() => {
|
|
57
|
+
if (highlighter) return;
|
|
58
|
+
let active = true;
|
|
59
|
+
const promise = getHighlighter();
|
|
60
|
+
promise.then((loaded) => {
|
|
61
|
+
resolved.set(promise, loaded);
|
|
62
|
+
if (active) setHighlighter(loaded);
|
|
63
|
+
}, (error) => warnOnce("load", "Syntax highlighter failed to load; showing plain text.", error));
|
|
64
|
+
return () => {
|
|
65
|
+
active = false;
|
|
66
|
+
};
|
|
67
|
+
}, [highlighter]);
|
|
68
|
+
const deferredValue = React$1.useDeferredValue(value);
|
|
69
|
+
const { light, dark } = themes;
|
|
70
|
+
return React$1.useMemo(() => {
|
|
71
|
+
if (!highlighter || deferredValue.length > maxHighlightLength) return plainHtml(deferredValue);
|
|
72
|
+
const normalizedLang = normalizeLang(lang);
|
|
73
|
+
if (!PLAIN_LANGS.has(normalizedLang) && !highlighter.getLoadedLanguages().includes(normalizedLang)) {
|
|
74
|
+
warnOnce(`lang:${lang}`, `Falling back to plain text for lang="${lang}"; not in the curated Shiki bundle.`);
|
|
75
|
+
return plainHtml(deferredValue);
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
return highlighter.codeToHtml(deferredValue, {
|
|
79
|
+
lang: normalizedLang,
|
|
80
|
+
themes: {
|
|
81
|
+
light,
|
|
82
|
+
dark
|
|
83
|
+
},
|
|
84
|
+
defaultColor: theme,
|
|
85
|
+
transformers: [transformer]
|
|
86
|
+
});
|
|
87
|
+
} catch (error) {
|
|
88
|
+
warnOnce(`theme:${light}:${dark}:${lang}`, `Falling back to plain text for themes "${light}" / "${dark}" with lang="${lang}".`, error);
|
|
89
|
+
return plainHtml(deferredValue);
|
|
90
|
+
}
|
|
91
|
+
}, [
|
|
92
|
+
highlighter,
|
|
93
|
+
deferredValue,
|
|
94
|
+
lang,
|
|
95
|
+
theme,
|
|
96
|
+
light,
|
|
97
|
+
dark,
|
|
98
|
+
maxHighlightLength
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
export { DEFAULT_CODE_EDITOR_THEMES, useHighlightedHtml };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Button } from "../button/button.js";
|
|
2
|
+
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "../../core/animate-ui/components/radix/dialog.js";
|
|
3
|
+
import { Alert } from "../alert/alert.js";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region src/components/confirmation-dialog/confirmation-dialog.tsx
|
|
7
|
+
function ConfirmationDialog({ title, description, onConfirm, onCancel, children, cancelButtonText = "Cancel", confirmButtonText = "Confirm", cancelButtonVariant = "ghost", confirmButtonVariant = "default", cancelButtonColor, confirmButtonColor = "error", cancelButtonStartIcon, confirmButtonEndIcon, isLoading = false, error = null, open, onOpenChange }) {
|
|
8
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
9
|
+
const isOpen = open ?? uncontrolledOpen;
|
|
10
|
+
const setOpen = (next) => {
|
|
11
|
+
setUncontrolledOpen(next);
|
|
12
|
+
onOpenChange?.(next);
|
|
13
|
+
};
|
|
14
|
+
const handleConfirm = async () => {
|
|
15
|
+
try {
|
|
16
|
+
await onConfirm();
|
|
17
|
+
setOpen(false);
|
|
18
|
+
} catch {}
|
|
19
|
+
};
|
|
20
|
+
return /* @__PURE__ */ jsxs(Dialog, {
|
|
21
|
+
open: isOpen,
|
|
22
|
+
onOpenChange: setOpen,
|
|
23
|
+
children: [children != null && /* @__PURE__ */ jsx(DialogTrigger, {
|
|
24
|
+
asChild: true,
|
|
25
|
+
children
|
|
26
|
+
}), /* @__PURE__ */ jsxs(DialogContent, {
|
|
27
|
+
showCloseButton: false,
|
|
28
|
+
children: [/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
29
|
+
/* @__PURE__ */ jsx(DialogTitle, {
|
|
30
|
+
className: "leading-relaxed",
|
|
31
|
+
children: title
|
|
32
|
+
}),
|
|
33
|
+
/* @__PURE__ */ jsx(DialogDescription, {
|
|
34
|
+
className: "leading-relaxed",
|
|
35
|
+
children: description
|
|
36
|
+
}),
|
|
37
|
+
error != null && error !== "" && /* @__PURE__ */ jsx(Alert, {
|
|
38
|
+
color: "error",
|
|
39
|
+
className: "mt-3",
|
|
40
|
+
children: error
|
|
41
|
+
})
|
|
42
|
+
] }), /* @__PURE__ */ jsxs(DialogFooter, {
|
|
43
|
+
className: "gap-3 flex",
|
|
44
|
+
children: [/* @__PURE__ */ jsx(DialogClose, {
|
|
45
|
+
asChild: true,
|
|
46
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
47
|
+
type: "button",
|
|
48
|
+
variant: cancelButtonVariant,
|
|
49
|
+
color: cancelButtonColor,
|
|
50
|
+
onClick: onCancel,
|
|
51
|
+
fullWidth: false,
|
|
52
|
+
className: "text-foreground",
|
|
53
|
+
disabled: isLoading,
|
|
54
|
+
startIcon: cancelButtonStartIcon,
|
|
55
|
+
children: cancelButtonText
|
|
56
|
+
})
|
|
57
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
58
|
+
type: "button",
|
|
59
|
+
fullWidth: false,
|
|
60
|
+
variant: confirmButtonVariant,
|
|
61
|
+
color: confirmButtonColor,
|
|
62
|
+
onClick: handleConfirm,
|
|
63
|
+
loading: isLoading,
|
|
64
|
+
endIcon: confirmButtonEndIcon,
|
|
65
|
+
children: confirmButtonText
|
|
66
|
+
})]
|
|
67
|
+
})]
|
|
68
|
+
})]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { ConfirmationDialog };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import * as React$1 from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/components/content-container/content-container.tsx
|
|
5
|
+
var maxWidthClasses = {
|
|
6
|
+
sm: "max-w-2xl",
|
|
7
|
+
md: "max-w-4xl",
|
|
8
|
+
lg: "max-w-5xl",
|
|
9
|
+
xl: "max-w-7xl"
|
|
10
|
+
};
|
|
11
|
+
var ContentContainer = React$1.forwardRef(function ContentContainer({ maxWidth, children, className, noGutters = false }, ref) {
|
|
12
|
+
return /* @__PURE__ */ jsx("div", {
|
|
13
|
+
ref,
|
|
14
|
+
className: cn("w-full", !noGutters && "mt-[72px]", maxWidth != null && maxWidthClasses[maxWidth], "mx-auto", "p-3 md:p-6", className),
|
|
15
|
+
children
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
ContentContainer.displayName = "ContentContainer";
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ContentContainer };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { CopyButton } from "../../core/animate-ui/components/buttons/copy.js";
|
|
3
|
+
import { buttonGroupVariants } from "../../core/button-group.js";
|
|
4
|
+
import "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region src/components/copiable-text/copiable-text.tsx
|
|
7
|
+
/** Row height and action-button size per scale; both must move together or the group tears. */
|
|
8
|
+
var COPIABLE_TEXT_SIZE_STYLES = {
|
|
9
|
+
sm: {
|
|
10
|
+
row: "min-h-6",
|
|
11
|
+
action: "size-5"
|
|
12
|
+
},
|
|
13
|
+
default: {
|
|
14
|
+
row: "min-h-7",
|
|
15
|
+
action: "size-6"
|
|
16
|
+
},
|
|
17
|
+
lg: {
|
|
18
|
+
row: "min-h-8",
|
|
19
|
+
action: "size-7"
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
function CopiableText({ text, actions, alwaysShowActions = false, hideActionsOnTouch = false, size = "default", className }) {
|
|
23
|
+
const content = typeof text === "number" ? String(text) : text;
|
|
24
|
+
const sizeStyles = COPIABLE_TEXT_SIZE_STYLES[size];
|
|
25
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
26
|
+
className: cn("relative inline-flex min-w-0 max-w-full items-center overflow-hidden group/copiable-text", sizeStyles.row, className),
|
|
27
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
28
|
+
className: "block min-w-0 flex-1 truncate",
|
|
29
|
+
children: content
|
|
30
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
31
|
+
role: actions != null ? "group" : void 0,
|
|
32
|
+
className: cn(buttonGroupVariants(), "ml-2 shrink-0", !alwaysShowActions && "[@media(hover:hover)]:absolute [@media(hover:hover)]:right-0 [@media(hover:hover)]:top-1/2 [@media(hover:hover)]:ml-0 [@media(hover:hover)]:-translate-y-1/2 [@media(hover:hover)]:opacity-0 transition-opacity group-hover/copiable-text:opacity-100 group-focus-within/copiable-text:opacity-100", hideActionsOnTouch && "[@media(hover:none)]:hidden"),
|
|
33
|
+
onClick: (e) => e.stopPropagation(),
|
|
34
|
+
children: [actions, /* @__PURE__ */ jsx(CopyButton, {
|
|
35
|
+
content,
|
|
36
|
+
className: sizeStyles.action,
|
|
37
|
+
variant: "outline",
|
|
38
|
+
size: "sm",
|
|
39
|
+
hoverScale: 1,
|
|
40
|
+
tapScale: .9
|
|
41
|
+
})]
|
|
42
|
+
})]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { CopiableText };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { useScrollOverflow } from "../../core/hooks/use-scroll-overflow.js";
|
|
3
|
+
import { Checkbox } from "../../core/checkbox/motion-checkbox.js";
|
|
4
|
+
import { Table } from "../../core/table.js";
|
|
5
|
+
import { TogglableItemsList } from "../togglable-items-list/togglable-items-list.js";
|
|
6
|
+
import { Pagination } from "../pagination/pagination.js";
|
|
7
|
+
import { DEFAULT_PAGE_SIZE_OPTIONS } from "../pagination/pagination.props.js";
|
|
8
|
+
import { SELECT_COLUMN_ID, buildStickyColumns, countStickyColumns, useStickyOffsets } from "./sticky-columns.js";
|
|
9
|
+
import { DataTableHeader } from "./table-header.js";
|
|
10
|
+
import { DataTableBody } from "./table-body.js";
|
|
11
|
+
import { useResponsiveColumnVisibility } from "./responsive-columns.js";
|
|
12
|
+
import { useMemo, useRef, useState } from "react";
|
|
13
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { Columns2 } from "lucide-react";
|
|
15
|
+
import { getCoreRowModel, getPaginationRowModel, useReactTable } from "@tanstack/react-table";
|
|
16
|
+
//#region src/components/data-table/data-table.tsx
|
|
17
|
+
var edgeShadowClass = "pointer-events-none absolute inset-y-0 z-[3] w-4 from-black/10 to-transparent opacity-0 transition-opacity dark:from-black/40";
|
|
18
|
+
function DataTable({ columns, data, tableActionsContent, isFetching, pageIndex = 0, hasNextPage = false, hasPrevPage = false, onNextPage, onPrevPage, pageSize = 5, onPageSizeChange, pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS, showColumnVisibilitySelector = true, columnVisibilityLabel = "Columns", noResultsHeading = "No results", noResultsDescription = "No results found. Try adjusting your search or filter to find what you're looking for.", noResultsAction, noResultsIllustration, hideNoResultsIllustration, pageLabel, previousLabel = "Previous", nextLabel = "Next", pageSizeOptionLabel, onRowClick, showBorder = false, rowSelection, onRowSelectionChange, getRowId, enableMultiRowSelection = true, enableRowSelection = false, tableRowClassName, getRowClassName, className, hidePaginationControls = false }) {
|
|
19
|
+
const [columnVisibility, setColumnVisibility] = useState(() => {
|
|
20
|
+
const initial = {};
|
|
21
|
+
for (const col of columns) {
|
|
22
|
+
const meta = col.meta;
|
|
23
|
+
const id = col.id ?? col.accessorKey;
|
|
24
|
+
if (id && meta?.defaultHidden) initial[id] = false;
|
|
25
|
+
}
|
|
26
|
+
return initial;
|
|
27
|
+
});
|
|
28
|
+
const selectColumn = useMemo(() => ({
|
|
29
|
+
id: SELECT_COLUMN_ID,
|
|
30
|
+
enableHiding: false,
|
|
31
|
+
enableSorting: false,
|
|
32
|
+
size: 40,
|
|
33
|
+
header: enableMultiRowSelection ? ({ table: t }) => /* @__PURE__ */ jsx(Checkbox, {
|
|
34
|
+
checked: t.getIsAllPageRowsSelected() ? true : t.getIsSomePageRowsSelected() ? "indeterminate" : false,
|
|
35
|
+
onCheckedChange: (value) => t.toggleAllPageRowsSelected(!!value),
|
|
36
|
+
"aria-label": "Select all"
|
|
37
|
+
}) : void 0,
|
|
38
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(Checkbox, {
|
|
39
|
+
checked: row.getIsSelected(),
|
|
40
|
+
disabled: !row.getCanSelect(),
|
|
41
|
+
onCheckedChange: (value) => row.toggleSelected(!!value),
|
|
42
|
+
onClick: (e) => e.stopPropagation(),
|
|
43
|
+
"aria-label": "Select row"
|
|
44
|
+
})
|
|
45
|
+
}), [enableMultiRowSelection]);
|
|
46
|
+
const tableColumns = useMemo(() => enableRowSelection ? [selectColumn, ...columns] : columns, [
|
|
47
|
+
enableRowSelection,
|
|
48
|
+
selectColumn,
|
|
49
|
+
columns
|
|
50
|
+
]);
|
|
51
|
+
const table = useReactTable({
|
|
52
|
+
data,
|
|
53
|
+
columns: tableColumns,
|
|
54
|
+
state: {
|
|
55
|
+
columnVisibility,
|
|
56
|
+
pagination: useMemo(() => ({
|
|
57
|
+
pageIndex: 0,
|
|
58
|
+
pageSize
|
|
59
|
+
}), [pageSize]),
|
|
60
|
+
...rowSelection !== void 0 && { rowSelection }
|
|
61
|
+
},
|
|
62
|
+
autoResetPageIndex: false,
|
|
63
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
64
|
+
enableRowSelection,
|
|
65
|
+
enableMultiRowSelection,
|
|
66
|
+
onRowSelectionChange,
|
|
67
|
+
getRowId,
|
|
68
|
+
getCoreRowModel: getCoreRowModel(),
|
|
69
|
+
getPaginationRowModel: getPaginationRowModel()
|
|
70
|
+
});
|
|
71
|
+
const rootRef = useRef(null);
|
|
72
|
+
useResponsiveColumnVisibility(rootRef, table.getAllLeafColumns(), setColumnVisibility);
|
|
73
|
+
const tableRef = useRef(null);
|
|
74
|
+
const scrollerRef = useRef(null);
|
|
75
|
+
const overflow = useScrollOverflow(scrollerRef, { getContent: (scroller) => scroller.querySelector("table") });
|
|
76
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
|
77
|
+
const stickyOffsets = useStickyOffsets(tableRef, countStickyColumns(visibleColumns));
|
|
78
|
+
const stickyColumns = useMemo(() => buildStickyColumns(visibleColumns, stickyOffsets), [visibleColumns, stickyOffsets]);
|
|
79
|
+
const hasStickyColumns = stickyColumns.size > 0;
|
|
80
|
+
const { columnVisibilityItems, columnVisibilityCheckedState } = useMemo(() => {
|
|
81
|
+
const def = (c) => c;
|
|
82
|
+
const items = columns.filter((col) => def(col).enableHiding !== false).map((col, i) => {
|
|
83
|
+
const d = def(col);
|
|
84
|
+
const id = d.id ?? (typeof d.accessorKey === "string" ? d.accessorKey : void 0) ?? String(i);
|
|
85
|
+
return {
|
|
86
|
+
id,
|
|
87
|
+
label: typeof d.header === "string" ? d.header : id
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
columnVisibilityItems: items,
|
|
92
|
+
columnVisibilityCheckedState: Object.fromEntries(items.map(({ id }) => [id, columnVisibility[id] ?? true]))
|
|
93
|
+
};
|
|
94
|
+
}, [columns, columnVisibility]);
|
|
95
|
+
const canChangePageSize = Boolean(onPageSizeChange);
|
|
96
|
+
const resolvedPageSizeOptions = useMemo(() => {
|
|
97
|
+
if (!canChangePageSize || pageSizeOptions.length === 0) return [];
|
|
98
|
+
return pageSizeOptions.includes(pageSize) ? pageSizeOptions : [...pageSizeOptions, pageSize].sort((a, b) => a - b);
|
|
99
|
+
}, [
|
|
100
|
+
canChangePageSize,
|
|
101
|
+
pageSizeOptions,
|
|
102
|
+
pageSize
|
|
103
|
+
]);
|
|
104
|
+
const showToolbar = tableActionsContent || showColumnVisibilitySelector;
|
|
105
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
106
|
+
ref: rootRef,
|
|
107
|
+
className: cn("space-y-3", className),
|
|
108
|
+
children: [
|
|
109
|
+
showToolbar && /* @__PURE__ */ jsxs("div", {
|
|
110
|
+
className: "flex flex-wrap items-center gap-3 data-table-toolbar",
|
|
111
|
+
children: [tableActionsContent && /* @__PURE__ */ jsx("div", {
|
|
112
|
+
className: "min-w-0 flex-[1_1_16rem]",
|
|
113
|
+
children: tableActionsContent
|
|
114
|
+
}), showColumnVisibilitySelector && /* @__PURE__ */ jsx("div", {
|
|
115
|
+
className: "ml-auto",
|
|
116
|
+
children: /* @__PURE__ */ jsx(TogglableItemsList, {
|
|
117
|
+
items: columnVisibilityItems,
|
|
118
|
+
checkedState: columnVisibilityCheckedState,
|
|
119
|
+
onToggle: (id, checked) => setColumnVisibility((prev) => ({
|
|
120
|
+
...prev,
|
|
121
|
+
[id]: checked
|
|
122
|
+
})),
|
|
123
|
+
label: columnVisibilityLabel,
|
|
124
|
+
icon: /* @__PURE__ */ jsx(Columns2, {}),
|
|
125
|
+
triggerButtonColor: "gray"
|
|
126
|
+
})
|
|
127
|
+
})]
|
|
128
|
+
}),
|
|
129
|
+
/* @__PURE__ */ jsxs("div", {
|
|
130
|
+
"data-overflow-start": overflow.start || void 0,
|
|
131
|
+
"data-overflow-end": overflow.end || void 0,
|
|
132
|
+
className: cn("group/data-table relative overflow-hidden rounded-md data-table-container", showToolbar && "mt-6", showBorder && "border border-border/50"),
|
|
133
|
+
children: [
|
|
134
|
+
/* @__PURE__ */ jsxs(Table, {
|
|
135
|
+
ref: tableRef,
|
|
136
|
+
containerRef: scrollerRef,
|
|
137
|
+
children: [/* @__PURE__ */ jsx(DataTableHeader, {
|
|
138
|
+
headerGroups: table.getHeaderGroups(),
|
|
139
|
+
showBorder,
|
|
140
|
+
stickyColumns
|
|
141
|
+
}), /* @__PURE__ */ jsx(DataTableBody, {
|
|
142
|
+
rows: table.getRowModel().rows,
|
|
143
|
+
columnCount: tableColumns.length,
|
|
144
|
+
isFetching,
|
|
145
|
+
pageSize,
|
|
146
|
+
noResultsHeading,
|
|
147
|
+
noResultsDescription,
|
|
148
|
+
noResultsAction,
|
|
149
|
+
noResultsIllustration,
|
|
150
|
+
hideNoResultsIllustration,
|
|
151
|
+
onRowClick,
|
|
152
|
+
showBorder,
|
|
153
|
+
tableRowClassName,
|
|
154
|
+
getRowClassName,
|
|
155
|
+
stickyColumns
|
|
156
|
+
})]
|
|
157
|
+
}),
|
|
158
|
+
/* @__PURE__ */ jsx("div", {
|
|
159
|
+
"aria-hidden": true,
|
|
160
|
+
className: cn(edgeShadowClass, "left-0 bg-linear-to-r", overflow.start && !hasStickyColumns && "opacity-100")
|
|
161
|
+
}),
|
|
162
|
+
/* @__PURE__ */ jsx("div", {
|
|
163
|
+
"aria-hidden": true,
|
|
164
|
+
className: cn(edgeShadowClass, "right-0 bg-linear-to-l", overflow.end && "opacity-100")
|
|
165
|
+
})
|
|
166
|
+
]
|
|
167
|
+
}),
|
|
168
|
+
!hidePaginationControls && /* @__PURE__ */ jsx(Pagination, {
|
|
169
|
+
pageLabel: pageLabel ?? `Page ${pageIndex + 1}`,
|
|
170
|
+
previousLabel,
|
|
171
|
+
nextLabel,
|
|
172
|
+
onPrevPage: onPrevPage ?? (() => {}),
|
|
173
|
+
onNextPage: onNextPage ?? (() => {}),
|
|
174
|
+
hasPrevPage,
|
|
175
|
+
hasNextPage,
|
|
176
|
+
disabled: isFetching,
|
|
177
|
+
currentPageSize: pageSize,
|
|
178
|
+
pageSizeOptions: resolvedPageSizeOptions,
|
|
179
|
+
pageSizeOptionLabel,
|
|
180
|
+
onPageSizeChange: (size) => onPageSizeChange?.(size)
|
|
181
|
+
})
|
|
182
|
+
]
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
export { DataTable };
|