@zonsh/ui 0.0.0 → 0.4.1
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 +43 -0
- package/README.md +81 -1
- package/assets/illustrations/drawing/bracket-construction-dark.svg +77 -0
- package/assets/illustrations/drawing/bracket-construction-filled-dark.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction-filled.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction.svg +77 -0
- package/assets/illustrations/drawing/crescent-dark.svg +28 -0
- package/assets/illustrations/drawing/crescent-guides-dark.svg +33 -0
- package/assets/illustrations/drawing/crescent-guides.svg +33 -0
- package/assets/illustrations/drawing/crescent.svg +28 -0
- package/assets/illustrations/drawing/eclipse-dark.svg +187 -0
- package/assets/illustrations/drawing/eclipse-guides-dark.svg +191 -0
- package/assets/illustrations/drawing/eclipse-guides.svg +191 -0
- package/assets/illustrations/drawing/eclipse.svg +187 -0
- package/assets/illustrations/drawing/elevation-guides-dark.svg +31 -0
- package/assets/illustrations/drawing/elevation-guides-plain-dark.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides-plain.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides.svg +31 -0
- package/assets/illustrations/drawing/horizon-dark.svg +30 -0
- package/assets/illustrations/drawing/horizon.svg +30 -0
- package/assets/illustrations/drawing/nib-study-dark.svg +107 -0
- package/assets/illustrations/drawing/nib-study-plain-dark.svg +93 -0
- package/assets/illustrations/drawing/nib-study-plain.svg +93 -0
- package/assets/illustrations/drawing/nib-study.svg +107 -0
- package/assets/illustrations/editorial/assistant-640.webp +0 -0
- package/assets/illustrations/editorial/assistant.webp +0 -0
- package/assets/illustrations/editorial/automation-640.webp +0 -0
- package/assets/illustrations/editorial/automation.webp +0 -0
- package/assets/illustrations/editorial/bracket-left-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-left.webp +0 -0
- package/assets/illustrations/editorial/bracket-right-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-right.webp +0 -0
- package/assets/illustrations/editorial/custom-software-640.webp +0 -0
- package/assets/illustrations/editorial/custom-software.webp +0 -0
- package/assets/illustrations/editorial/digitalization-640.webp +0 -0
- package/assets/illustrations/editorial/digitalization.webp +0 -0
- package/assets/illustrations/editorial/integration-640.webp +0 -0
- package/assets/illustrations/editorial/integration.webp +0 -0
- package/assets/illustrations/editorial/problem-640.webp +0 -0
- package/assets/illustrations/editorial/problem.webp +0 -0
- package/assets/illustrations/editorial/process-analysis-640.webp +0 -0
- package/assets/illustrations/editorial/process-analysis.webp +0 -0
- package/assets/illustrations/editorial/process-concept-640.webp +0 -0
- package/assets/illustrations/editorial/process-concept.webp +0 -0
- package/assets/illustrations/editorial/process-development-640.webp +0 -0
- package/assets/illustrations/editorial/process-development.webp +0 -0
- package/assets/illustrations/editorial/process-discovery-640.webp +0 -0
- package/assets/illustrations/editorial/process-discovery.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance-640.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance.webp +0 -0
- package/assets/illustrations/editorial/process-prototype-640.webp +0 -0
- package/assets/illustrations/editorial/process-prototype.webp +0 -0
- package/assets/illustrations/editorial/process-testing-640.webp +0 -0
- package/assets/illustrations/editorial/process-testing.webp +0 -0
- package/assets/illustrations/iso/automation-dark.svg +6 -0
- package/assets/illustrations/iso/automation.svg +6 -0
- package/assets/illustrations/iso/bar-chart-dark.svg +6 -0
- package/assets/illustrations/iso/bar-chart.svg +6 -0
- package/assets/illustrations/iso/brackets-classic-dark.svg +6 -0
- package/assets/illustrations/iso/brackets-classic.svg +6 -0
- package/assets/illustrations/iso/brackets-dark.svg +6 -0
- package/assets/illustrations/iso/brackets.svg +6 -0
- package/assets/illustrations/iso/city-dark.svg +6 -0
- package/assets/illustrations/iso/city.svg +6 -0
- package/assets/illustrations/iso/conveyor-dark.svg +6 -0
- package/assets/illustrations/iso/conveyor.svg +6 -0
- package/assets/illustrations/iso/database-dark.svg +6 -0
- package/assets/illustrations/iso/database.svg +6 -0
- package/assets/illustrations/iso/documents-dark.svg +6 -0
- package/assets/illustrations/iso/documents.svg +6 -0
- package/assets/illustrations/iso/inbox-dark.svg +6 -0
- package/assets/illustrations/iso/inbox.svg +6 -0
- package/assets/illustrations/iso/laptop-dark.svg +6 -0
- package/assets/illustrations/iso/laptop.svg +6 -0
- package/assets/illustrations/iso/monitor-dark.svg +6 -0
- package/assets/illustrations/iso/monitor.svg +6 -0
- package/assets/illustrations/iso/pipeline-dark.svg +6 -0
- package/assets/illustrations/iso/pipeline.svg +6 -0
- package/assets/illustrations/iso/platform-dark.svg +6 -0
- package/assets/illustrations/iso/platform.svg +6 -0
- package/assets/illustrations/iso/server-dark.svg +6 -0
- package/assets/illustrations/iso/server.svg +6 -0
- package/assets/illustrations/iso/spreadsheet-dark.svg +6 -0
- package/assets/illustrations/iso/spreadsheet.svg +6 -0
- package/assets/illustrations/iso/timeline-dark.svg +6 -0
- package/assets/illustrations/iso/timeline.svg +6 -0
- package/assets/illustrations/sheet/construction.svg +115 -0
- package/assets/illustrations/sheet/crescent.svg +40 -0
- package/assets/illustrations/sheet/limb.svg +42 -0
- package/assets/illustrations/sheet/stress-axis.svg +119 -0
- package/assets/illustrations/sheet/totality.svg +215 -0
- package/assets/illustrations/sheet/vertical-metrics.svg +43 -0
- package/assets/logo-left.svg +1 -0
- package/assets/logo-right.svg +1 -0
- package/assets/logo.svg +1 -0
- package/dist/components/_overlay.d.ts +47 -0
- package/dist/components/_overlay.js +59 -0
- package/dist/components/accordion.d.ts +32 -0
- package/dist/components/accordion.js +39 -0
- package/dist/components/alert-dialog.d.ts +45 -0
- package/dist/components/alert-dialog.js +56 -0
- package/dist/components/alert.d.ts +35 -0
- package/dist/components/alert.js +42 -0
- package/dist/components/ascii-field.d.ts +34 -0
- package/dist/components/ascii-field.js +410 -0
- package/dist/components/aspect-ratio.d.ts +14 -0
- package/dist/components/aspect-ratio.js +17 -0
- package/dist/components/avatar.d.ts +42 -0
- package/dist/components/avatar.js +55 -0
- package/dist/components/badge.d.ts +70 -0
- package/dist/components/badge.js +62 -0
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +31 -0
- package/dist/components/breadcrumb.js +37 -0
- package/dist/components/button-group.d.ts +30 -0
- package/dist/components/button-group.js +47 -0
- package/dist/components/button.d.ts +53 -0
- package/dist/components/button.js +130 -0
- package/dist/components/calendar.d.ts +26 -0
- package/dist/components/calendar.js +179 -0
- package/dist/components/card.d.ts +42 -0
- package/dist/components/card.js +76 -0
- package/dist/components/carousel.d.ts +109 -0
- package/dist/components/carousel.js +231 -0
- package/dist/components/chart.d.ts +189 -0
- package/dist/components/chart.js +323 -0
- package/dist/components/checkbox.d.ts +23 -0
- package/dist/components/checkbox.js +43 -0
- package/dist/components/code-block.d.ts +55 -0
- package/dist/components/code-block.js +100 -0
- package/dist/components/collapsible.d.ts +20 -0
- package/dist/components/collapsible.js +32 -0
- package/dist/components/color-picker.d.ts +107 -0
- package/dist/components/color-picker.js +428 -0
- package/dist/components/combobox.d.ts +99 -0
- package/dist/components/combobox.js +172 -0
- package/dist/components/command.d.ts +132 -0
- package/dist/components/command.js +257 -0
- package/dist/components/context-menu.d.ts +29 -0
- package/dist/components/context-menu.js +35 -0
- package/dist/components/conversation.d.ts +36 -0
- package/dist/components/conversation.js +303 -0
- package/dist/components/copy-button.d.ts +55 -0
- package/dist/components/copy-button.js +133 -0
- package/dist/components/data-table.d.ts +235 -0
- package/dist/components/data-table.js +655 -0
- package/dist/components/date-picker.d.ts +160 -0
- package/dist/components/date-picker.js +338 -0
- package/dist/components/dialog.d.ts +57 -0
- package/dist/components/dialog.js +95 -0
- package/dist/components/direction.d.ts +16 -0
- package/dist/components/direction.js +18 -0
- package/dist/components/drawer.d.ts +69 -0
- package/dist/components/drawer.js +79 -0
- package/dist/components/empty.d.ts +31 -0
- package/dist/components/empty.js +50 -0
- package/dist/components/feature-list.d.ts +54 -0
- package/dist/components/feature-list.js +43 -0
- package/dist/components/field.d.ts +34 -0
- package/dist/components/field.js +81 -0
- package/dist/components/file-drop.d.ts +77 -0
- package/dist/components/file-drop.js +258 -0
- package/dist/components/filter-bar.d.ts +153 -0
- package/dist/components/filter-bar.js +334 -0
- package/dist/components/form.d.ts +35 -0
- package/dist/components/form.js +56 -0
- package/dist/components/graph.d.ts +146 -0
- package/dist/components/graph.js +825 -0
- package/dist/components/illustration.d.ts +85 -0
- package/dist/components/illustration.js +165 -0
- package/dist/components/input-group.d.ts +138 -0
- package/dist/components/input-group.js +312 -0
- package/dist/components/input.d.ts +16 -0
- package/dist/components/input.js +25 -0
- package/dist/components/item.d.ts +64 -0
- package/dist/components/item.js +116 -0
- package/dist/components/kbd.d.ts +50 -0
- package/dist/components/kbd.js +45 -0
- package/dist/components/label.d.ts +12 -0
- package/dist/components/label.js +24 -0
- package/dist/components/layout.d.ts +136 -0
- package/dist/components/layout.js +162 -0
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +439 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.d.ts +54 -0
- package/dist/components/logo.js +96 -0
- package/dist/components/menu.d.ts +60 -0
- package/dist/components/menu.js +140 -0
- package/dist/components/menubar.d.ts +62 -0
- package/dist/components/menubar.js +223 -0
- package/dist/components/message.d.ts +42 -0
- package/dist/components/message.js +59 -0
- package/dist/components/meter.d.ts +31 -0
- package/dist/components/meter.js +27 -0
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/native-select.d.ts +26 -0
- package/dist/components/native-select.js +35 -0
- package/dist/components/navigation-menu.d.ts +42 -0
- package/dist/components/navigation-menu.js +97 -0
- package/dist/components/number-field.d.ts +55 -0
- package/dist/components/number-field.js +164 -0
- package/dist/components/otp-field.d.ts +48 -0
- package/dist/components/otp-field.js +102 -0
- package/dist/components/pagination.d.ts +37 -0
- package/dist/components/pagination.js +81 -0
- package/dist/components/pdf-viewer.d.ts +134 -0
- package/dist/components/pdf-viewer.js +996 -0
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.d.ts +33 -0
- package/dist/components/popover.js +48 -0
- package/dist/components/preview-card.d.ts +25 -0
- package/dist/components/preview-card.js +22 -0
- package/dist/components/progress.d.ts +27 -0
- package/dist/components/progress.js +25 -0
- package/dist/components/prompt-input.d.ts +156 -0
- package/dist/components/prompt-input.js +415 -0
- package/dist/components/quote.d.ts +22 -0
- package/dist/components/quote.js +15 -0
- package/dist/components/radio-group.d.ts +18 -0
- package/dist/components/radio-group.js +34 -0
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +46 -0
- package/dist/components/reasoning.js +73 -0
- package/dist/components/resizable.d.ts +47 -0
- package/dist/components/resizable.js +44 -0
- package/dist/components/response.d.ts +41 -0
- package/dist/components/response.js +566 -0
- package/dist/components/scroll-area.d.ts +33 -0
- package/dist/components/scroll-area.js +31 -0
- package/dist/components/select.d.ts +35 -0
- package/dist/components/select.js +71 -0
- package/dist/components/separator.d.ts +14 -0
- package/dist/components/separator.js +17 -0
- package/dist/components/sidebar.d.ts +163 -0
- package/dist/components/sidebar.js +505 -0
- package/dist/components/site-header.d.ts +93 -0
- package/dist/components/site-header.js +121 -0
- package/dist/components/skeleton.d.ts +31 -0
- package/dist/components/skeleton.js +29 -0
- package/dist/components/slider.d.ts +24 -0
- package/dist/components/slider.js +131 -0
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1258 -0
- package/dist/components/sources.d.ts +40 -0
- package/dist/components/sources.js +42 -0
- package/dist/components/spinner.d.ts +48 -0
- package/dist/components/spinner.js +75 -0
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/suggestions.d.ts +20 -0
- package/dist/components/suggestions.js +18 -0
- package/dist/components/switch.d.ts +14 -0
- package/dist/components/switch.js +26 -0
- package/dist/components/table.d.ts +172 -0
- package/dist/components/table.js +895 -0
- package/dist/components/tabs.d.ts +25 -0
- package/dist/components/tabs.js +162 -0
- package/dist/components/tag.d.ts +41 -0
- package/dist/components/tag.js +88 -0
- package/dist/components/tags-input.d.ts +56 -0
- package/dist/components/tags-input.js +271 -0
- package/dist/components/textarea.d.ts +13 -0
- package/dist/components/textarea.js +16 -0
- package/dist/components/theme.d.ts +55 -0
- package/dist/components/theme.js +120 -0
- package/dist/components/time-field.d.ts +70 -0
- package/dist/components/time-field.js +450 -0
- package/dist/components/timeline.d.ts +92 -0
- package/dist/components/timeline.js +108 -0
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +88 -0
- package/dist/components/toast.js +205 -0
- package/dist/components/toggle-group.d.ts +41 -0
- package/dist/components/toggle-group.js +140 -0
- package/dist/components/toggle.d.ts +23 -0
- package/dist/components/toggle.js +35 -0
- package/dist/components/tool-call.d.ts +63 -0
- package/dist/components/tool-call.js +68 -0
- package/dist/components/toolbar.d.ts +17 -0
- package/dist/components/toolbar.js +39 -0
- package/dist/components/tooltip.d.ts +42 -0
- package/dist/components/tooltip.js +47 -0
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +648 -0
- package/dist/components/tree.d.ts +75 -0
- package/dist/components/tree.js +649 -0
- package/dist/components/typography.d.ts +134 -0
- package/dist/components/typography.js +176 -0
- package/dist/components/video-player.d.ts +284 -0
- package/dist/components/video-player.js +1392 -0
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +94 -0
- package/dist/lib/cn.d.ts +20 -0
- package/dist/lib/cn.js +38 -0
- package/dist/lib/code-highlight.d.ts +18 -0
- package/dist/lib/code-highlight.js +174 -0
- package/dist/lib/code-theme.d.ts +19 -0
- package/dist/lib/code-theme.js +140 -0
- package/dist/lib/collapse-row.d.ts +9 -0
- package/dist/lib/collapse-row.js +129 -0
- package/dist/lib/digit-roll.d.ts +21 -0
- package/dist/lib/digit-roll.js +31 -0
- package/dist/lib/editorial-assets.d.ts +16 -0
- package/dist/lib/editorial-assets.js +56 -0
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/figure/catalog.d.ts +127 -0
- package/dist/lib/figure/catalog.js +130 -0
- package/dist/lib/figure/figures/automation.d.ts +7 -0
- package/dist/lib/figure/figures/automation.js +143 -0
- package/dist/lib/figure/figures/bar-chart.d.ts +7 -0
- package/dist/lib/figure/figures/bar-chart.js +99 -0
- package/dist/lib/figure/figures/brackets-classic.d.ts +11 -0
- package/dist/lib/figure/figures/brackets-classic.js +170 -0
- package/dist/lib/figure/figures/brackets.d.ts +8 -0
- package/dist/lib/figure/figures/brackets.js +84 -0
- package/dist/lib/figure/figures/city.d.ts +7 -0
- package/dist/lib/figure/figures/city.js +93 -0
- package/dist/lib/figure/figures/conveyor.d.ts +7 -0
- package/dist/lib/figure/figures/conveyor.js +97 -0
- package/dist/lib/figure/figures/database.d.ts +7 -0
- package/dist/lib/figure/figures/database.js +65 -0
- package/dist/lib/figure/figures/documents.d.ts +7 -0
- package/dist/lib/figure/figures/documents.js +83 -0
- package/dist/lib/figure/figures/inbox.d.ts +7 -0
- package/dist/lib/figure/figures/inbox.js +92 -0
- package/dist/lib/figure/figures/laptop.d.ts +7 -0
- package/dist/lib/figure/figures/laptop.js +67 -0
- package/dist/lib/figure/figures/monitor.d.ts +7 -0
- package/dist/lib/figure/figures/monitor.js +59 -0
- package/dist/lib/figure/figures/pipeline.d.ts +8 -0
- package/dist/lib/figure/figures/pipeline.js +117 -0
- package/dist/lib/figure/figures/platform.d.ts +7 -0
- package/dist/lib/figure/figures/platform.js +117 -0
- package/dist/lib/figure/figures/server.d.ts +7 -0
- package/dist/lib/figure/figures/server.js +115 -0
- package/dist/lib/figure/figures/spreadsheet.d.ts +7 -0
- package/dist/lib/figure/figures/spreadsheet.js +87 -0
- package/dist/lib/figure/figures/timeline.d.ts +7 -0
- package/dist/lib/figure/figures/timeline.js +65 -0
- package/dist/lib/figure/kernel.d.ts +152 -0
- package/dist/lib/figure/kernel.js +576 -0
- package/dist/lib/figure/parts.d.ts +42 -0
- package/dist/lib/figure/parts.js +126 -0
- package/dist/lib/form-reset.d.ts +11 -0
- package/dist/lib/form-reset.js +22 -0
- package/dist/lib/glide.d.ts +53 -0
- package/dist/lib/glide.js +138 -0
- package/dist/lib/graph-layout.d.ts +58 -0
- package/dist/lib/graph-layout.js +209 -0
- package/dist/lib/illustration-drawings.d.ts +89 -0
- package/dist/lib/illustration-drawings.js +539 -0
- package/dist/lib/illustration-info.d.ts +37 -0
- package/dist/lib/illustration-info.js +22 -0
- package/dist/lib/illustration-library.d.ts +87 -0
- package/dist/lib/illustration-library.js +352 -0
- package/dist/lib/logo-geometry.d.ts +29 -0
- package/dist/lib/logo-geometry.js +67 -0
- package/dist/lib/markdown-guard.d.ts +16 -0
- package/dist/lib/markdown-guard.js +123 -0
- package/dist/lib/merge-refs.d.ts +10 -0
- package/dist/lib/merge-refs.js +26 -0
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/motion.d.ts +6 -0
- package/dist/lib/motion.js +12 -0
- package/dist/lib/pdf-worker.d.ts +1 -0
- package/dist/lib/pdf-worker.js +6 -0
- package/dist/lib/pdf.d.ts +19 -0
- package/dist/lib/pdf.js +58 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +38 -0
- package/dist/lib/platform.js +75 -0
- package/dist/lib/room.d.ts +25 -0
- package/dist/lib/room.js +46 -0
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +143 -0
- package/dist/lib/table-fit.js +596 -0
- package/dist/lib/theme-script.d.ts +31 -0
- package/dist/lib/theme-script.js +49 -0
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +203 -0
- package/dist/styles/fonts.css +145 -0
- package/dist/styles/index.css +207 -0
- package/dist/styles/material.css +317 -0
- package/dist/styles/parts/ai.css +361 -0
- package/dist/styles/parts/brand.css +75 -0
- package/dist/styles/parts/controls.css +774 -0
- package/dist/styles/parts/data.css +222 -0
- package/dist/styles/parts/editorial.css +120 -0
- package/dist/styles/parts/feedback.css +340 -0
- package/dist/styles/parts/foundations.css +166 -0
- package/dist/styles/parts/graph.css +214 -0
- package/dist/styles/parts/inputs.css +261 -0
- package/dist/styles/parts/isometric.css +124 -0
- package/dist/styles/parts/navigation.css +424 -0
- package/dist/styles/parts/overlays.css +250 -0
- package/dist/styles/parts/pdf.css +154 -0
- package/dist/styles/parts/react-flow.css +519 -0
- package/dist/styles/tokens.css +299 -0
- package/dist/vite.d.ts +66 -0
- package/dist/vite.js +29 -0
- package/package.json +183 -5
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { defaultRangeExtractor, useVirtualizer, } from "@tanstack/react-virtual";
|
|
4
|
+
import { ChevronRightIcon } from "lucide-react";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { cn } from "../lib/cn.js";
|
|
7
|
+
import { mergeRefs } from "../lib/merge-refs.js";
|
|
8
|
+
import { isApple, modPressed } from "../lib/platform.js";
|
|
9
|
+
/** Trees of more nodes than this render only the rows in view, unless `virtualized` says otherwise. */
|
|
10
|
+
const VIRTUALIZE_FROM = 500;
|
|
11
|
+
/* Each `items` array is warned about once, also when StrictMode indexes it twice. */
|
|
12
|
+
const warned = new WeakSet();
|
|
13
|
+
/** Every node by id, with its level and parent, so keys can walk up and Left can find the parent. */
|
|
14
|
+
function indexTree(items) {
|
|
15
|
+
const map = new Map();
|
|
16
|
+
const shared = new Set();
|
|
17
|
+
const walk = (nodes, level, parent) => {
|
|
18
|
+
nodes.forEach((node, i) => {
|
|
19
|
+
if (map.has(node.id))
|
|
20
|
+
shared.add(node.id);
|
|
21
|
+
map.set(node.id, { node, level, parent, posinset: i + 1, setsize: nodes.length });
|
|
22
|
+
if (node.children)
|
|
23
|
+
walk(node.children, level + 1, node.id);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
walk(items, 1, null);
|
|
27
|
+
if (process.env.NODE_ENV !== "production" && shared.size && !warned.has(items)) {
|
|
28
|
+
warned.add(items);
|
|
29
|
+
const ids = [...shared].slice(0, 5).map((id) => `"${id}"`);
|
|
30
|
+
console.warn(`Tree: more than one node has the id ${ids.join(", ")}${shared.size > 5 ? " (and more)" : ""}. ` +
|
|
31
|
+
"Ids must be unique across the whole tree: selection, expansion and focus are kept by id, " +
|
|
32
|
+
"and the arrow keys loop between nodes that share one.");
|
|
33
|
+
}
|
|
34
|
+
return map;
|
|
35
|
+
}
|
|
36
|
+
/** The ids a person can reach right now: every node whose ancestors are all expanded, in order. */
|
|
37
|
+
function visibleOrder(items, expanded) {
|
|
38
|
+
const out = [];
|
|
39
|
+
const walk = (nodes) => {
|
|
40
|
+
for (const node of nodes) {
|
|
41
|
+
out.push(node.id);
|
|
42
|
+
if (node.children && expanded.has(node.id))
|
|
43
|
+
walk(node.children);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
walk(items);
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
function textOf(node) {
|
|
50
|
+
if (typeof node === "string" || typeof node === "number")
|
|
51
|
+
return String(node);
|
|
52
|
+
if (Array.isArray(node))
|
|
53
|
+
return node.map(textOf).join("");
|
|
54
|
+
if (React.isValidElement(node))
|
|
55
|
+
return textOf(node.props.children);
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
function useControllable(value, defaultValue, onChange) {
|
|
59
|
+
const [inner, setInner] = React.useState(defaultValue);
|
|
60
|
+
const controlled = value !== undefined;
|
|
61
|
+
const current = controlled ? value : inner;
|
|
62
|
+
const set = React.useCallback((next) => {
|
|
63
|
+
if (!controlled)
|
|
64
|
+
setInner(next);
|
|
65
|
+
onChange?.(next);
|
|
66
|
+
}, [controlled, onChange]);
|
|
67
|
+
return [current, set];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The rows that must render again: those whose state differs from the last render, and every
|
|
71
|
+
* ancestor of each — a nested row renders its children — so a key press re-renders the path
|
|
72
|
+
* down to the rows it changed and no other row.
|
|
73
|
+
*/
|
|
74
|
+
function changedRows(prev, next, index) {
|
|
75
|
+
const out = new Set();
|
|
76
|
+
if (!prev)
|
|
77
|
+
return out;
|
|
78
|
+
const mark = (id) => {
|
|
79
|
+
for (let at = id; at !== null && !out.has(at); at = index.get(at)?.parent ?? null)
|
|
80
|
+
out.add(at);
|
|
81
|
+
};
|
|
82
|
+
for (const [a, b] of [
|
|
83
|
+
[prev.expanded, next.expanded],
|
|
84
|
+
[prev.selected, next.selected],
|
|
85
|
+
]) {
|
|
86
|
+
for (const id of a)
|
|
87
|
+
if (!b.has(id))
|
|
88
|
+
mark(id);
|
|
89
|
+
for (const id of b)
|
|
90
|
+
if (!a.has(id))
|
|
91
|
+
mark(id);
|
|
92
|
+
}
|
|
93
|
+
if (prev.focusId !== next.focusId) {
|
|
94
|
+
mark(prev.focusId);
|
|
95
|
+
mark(next.focusId);
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
/* ── Rows ──────────────────────────────────────────────────────────────────── */
|
|
100
|
+
const sizes = {
|
|
101
|
+
default: {
|
|
102
|
+
row: "min-h-(--control-h) gap-2 px-2.5 text-sm",
|
|
103
|
+
// The group's hairline runs under the parent's chevron (10px padding + half of 16px); the
|
|
104
|
+
// 5px after it brings each child's chevron in line with its parent's icon.
|
|
105
|
+
group: "ms-[18px] ps-[5px]",
|
|
106
|
+
// The same geometry for a virtual tree's flat rows: each level indents 18 + 1 + 5px, and its
|
|
107
|
+
// guide sits 18px in from its parent's start.
|
|
108
|
+
indent: 24,
|
|
109
|
+
guide: 18,
|
|
110
|
+
estimate: 38,
|
|
111
|
+
},
|
|
112
|
+
sm: {
|
|
113
|
+
row: "min-h-(--control-h-sm) gap-1.5 px-2 text-[13px]",
|
|
114
|
+
group: "ms-4 ps-[5px]",
|
|
115
|
+
indent: 22,
|
|
116
|
+
guide: 16,
|
|
117
|
+
estimate: 30,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
/* Stable for the tree's life (handlers go through a ref): rows re-render for their own state only. */
|
|
121
|
+
const TreeContext = React.createContext(null);
|
|
122
|
+
/** The `treeitem`'s attributes: the same for a nested and a flat row. */
|
|
123
|
+
function itemProps(ctx, node, level, posinset, setsize, state) {
|
|
124
|
+
return {
|
|
125
|
+
role: "treeitem",
|
|
126
|
+
"data-slot": "tree-item",
|
|
127
|
+
"data-tree-id": node.id,
|
|
128
|
+
"aria-level": level,
|
|
129
|
+
"aria-posinset": posinset,
|
|
130
|
+
"aria-setsize": setsize,
|
|
131
|
+
"aria-expanded": node.children !== undefined ? state.expanded : undefined,
|
|
132
|
+
"aria-selected": ctx.selectionMode === "none" ? undefined : state.selected,
|
|
133
|
+
"aria-disabled": node.disabled || undefined,
|
|
134
|
+
tabIndex: state.focused ? 0 : -1,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The row inside a `treeitem`: chevron, icon, label and meta. Memoised: a nested branch renders
|
|
139
|
+
* again to reach a changed child, and its own row need not.
|
|
140
|
+
*/
|
|
141
|
+
const TreeRow = React.memo(function TreeRow({ node, level, expanded, selected, }) {
|
|
142
|
+
const ctx = React.useContext(TreeContext);
|
|
143
|
+
const branch = node.children !== undefined;
|
|
144
|
+
const state = { expanded, selected, level };
|
|
145
|
+
const icon = typeof node.icon === "function" ? node.icon(state) : node.icon;
|
|
146
|
+
const Row = node.href ? "a" : "div";
|
|
147
|
+
return (_jsxs(Row, { "data-slot": "tree-row", "data-selected": selected ? "" : undefined, "data-current": selected ? "" : undefined, "data-disabled": node.disabled ? "" : undefined, href: node.href, tabIndex: node.href ? -1 : undefined, "aria-current": node.href && selected && ctx.selectionMode === "single" ? "page" : undefined, onClick: (event) => ctx.onRowClick(node, event), className: cn("flex w-full cursor-pointer items-center rounded-item material-row leading-none no-underline select-none",
|
|
148
|
+
// Hover lifts like a highlighted menu item; the full raised row (outer edge) is the selection.
|
|
149
|
+
"hover:not-data-current:border-control-inner-edge! hover:not-data-current:bg-none! hover:not-data-current:shadow-highlight!",
|
|
150
|
+
// The treeitem holds the focus; its own row draws the ring, never the whole subtree.
|
|
151
|
+
"[li:focus-visible>&]:outline-2 [li:focus-visible>&]:outline-offset-0 [li:focus-visible>&]:outline-control-focus [li:focus-visible>&]:outline-solid", "data-disabled:cursor-default data-disabled:opacity-50", "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", sizes[ctx.size].row), children: [branch ? (_jsx("span", { "data-slot": "tree-chevron", "aria-hidden": true, onClick: (event) => ctx.onChevronClick(node, event), className: "-my-1 flex shrink-0 items-center self-stretch text-muted-foreground", children: _jsx(ChevronRightIcon, { className: cn("transition-[rotate] duration-(--duration) ease-(--ease) rtl:-scale-x-100", expanded && "rotate-90 rtl:-rotate-90") }) })) : (_jsx("span", { "data-slot": "tree-chevron-space", "aria-hidden": true, className: "size-4 shrink-0" })), icon != null && (_jsx("span", { "data-slot": "tree-icon", "aria-hidden": true, className: cn("flex shrink-0", selected ? "text-foreground" : "text-muted-foreground"), children: icon })), _jsx("span", { "data-slot": "tree-label", className: "min-w-0 flex-1 truncate py-1 leading-5", children: node.label }), node.meta != null && (_jsx("span", { "data-slot": "tree-meta", className: "ms-auto shrink-0 ps-2 font-mono text-xs leading-none text-muted-foreground tabular-nums", children: node.meta }))] }));
|
|
152
|
+
});
|
|
153
|
+
/**
|
|
154
|
+
* One `treeitem`: the row, and below it — once first opened — its children in a `group`. The
|
|
155
|
+
* group stays mounted after it closes, so closing animates too: its grid row eases from 1fr to 0fr,
|
|
156
|
+
* then `visibility` hides it from the keyboard and assistive tech. It renders again only when
|
|
157
|
+
* its own state changed or a descendant's did (`view.changed`).
|
|
158
|
+
*/
|
|
159
|
+
const TreeItem = React.memo(
|
|
160
|
+
// Not named TreeItem: its children must be the memoised component, not this function.
|
|
161
|
+
function NestedTreeItem({ node, level, posinset, setsize, view }) {
|
|
162
|
+
const ctx = React.useContext(TreeContext);
|
|
163
|
+
const branch = node.children !== undefined;
|
|
164
|
+
const expanded = branch && view.expanded.has(node.id);
|
|
165
|
+
const selected = view.selected.has(node.id);
|
|
166
|
+
// Open on first render: in place. Opened later: the group grows in from 0fr.
|
|
167
|
+
const [mounted, setMounted] = React.useState(expanded && "initial");
|
|
168
|
+
if (expanded && !mounted)
|
|
169
|
+
setMounted("later");
|
|
170
|
+
const register = ctx.register;
|
|
171
|
+
const ref = React.useCallback((el) => register(node.id, el), [register, node.id]);
|
|
172
|
+
return (_jsxs("li", { ref: ref, ...itemProps(ctx, node, level, posinset, setsize, {
|
|
173
|
+
expanded,
|
|
174
|
+
selected,
|
|
175
|
+
focused: view.focusId === node.id,
|
|
176
|
+
}), className: "flex flex-col outline-none", children: [_jsx(TreeRow, { node: node, level: level, expanded: expanded, selected: selected }), branch && mounted && (_jsx("div", { "data-slot": "tree-group-frame", "data-open": expanded ? "" : undefined, className: cn("grid transition-[grid-template-rows,visibility] duration-(--duration) ease-(--ease)", expanded ? "visible grid-rows-[1fr]" : "invisible grid-rows-[0fr]", expanded && mounted === "later" && "starting:grid-rows-[0fr]"), children: _jsx("ul", { role: "group", "data-slot": "tree-group", className: cn(
|
|
177
|
+
// Clipped for the open and close, but 2px out: the focus ring and the selection's
|
|
178
|
+
// outer edge on the group's last row and at its end stay whole. Not a scroll
|
|
179
|
+
// container, so it takes min-w-0 to let long labels truncate. The 2px above the
|
|
180
|
+
// first child is its margin, not the group's padding, so a closed or empty group
|
|
181
|
+
// is 0px.
|
|
182
|
+
"m-0 flex min-h-0 min-w-0 list-none flex-col gap-0.5 overflow-clip border-s pe-0 pb-0 [overflow-clip-margin:2px] [&>:first-child]:mt-0.5", ctx.guides ? "border-border/60" : "border-transparent", sizes[ctx.size].group), children: node.children.map((child, i) => (_jsx(TreeItem, { node: child, level: level + 1, posinset: i + 1, setsize: node.children.length, view: view }, child.id))) }) }))] }));
|
|
183
|
+
}, (a, b) => a.node === b.node &&
|
|
184
|
+
a.level === b.level &&
|
|
185
|
+
a.posinset === b.posinset &&
|
|
186
|
+
a.setsize === b.setsize &&
|
|
187
|
+
!b.view.changed.has(b.node.id));
|
|
188
|
+
/**
|
|
189
|
+
* One row of a virtual tree, flat under the `tree`: the level lives in `aria-level`, the
|
|
190
|
+
* indentation in its start padding, and each open ancestor's guide is a hairline at the place the
|
|
191
|
+
* nested group's edge would be. It carries the 2px gap above it, so its guides meet the next row's.
|
|
192
|
+
*/
|
|
193
|
+
const TreeFlatItem = React.memo(function TreeFlatItem({ node, level, posinset, setsize, index, expanded, selected, focused, measure, }) {
|
|
194
|
+
const ctx = React.useContext(TreeContext);
|
|
195
|
+
const { indent, guide } = sizes[ctx.size];
|
|
196
|
+
const register = ctx.register;
|
|
197
|
+
const ref = React.useCallback((el) => {
|
|
198
|
+
register(node.id, el);
|
|
199
|
+
measure(el);
|
|
200
|
+
}, [register, measure, node.id]);
|
|
201
|
+
return (_jsxs("li", { ref: ref, "data-index": index, ...itemProps(ctx, node, level, posinset, setsize, { expanded, selected, focused }),
|
|
202
|
+
// scroll-my-2: a row the keyboard brings into view stops short of the edge, ring and all.
|
|
203
|
+
className: cn("relative flex scroll-my-2 flex-col outline-none", index > 0 && "pt-0.5"), style: level > 1 ? { paddingInlineStart: indent * (level - 1) } : undefined, children: [ctx.guides &&
|
|
204
|
+
Array.from({ length: level - 1 }, (_, k) => (_jsx("span", { "data-slot": "tree-guide", "aria-hidden": true,
|
|
205
|
+
// A border, as the nested group's edge is, so forced colours keep it.
|
|
206
|
+
className: "pointer-events-none absolute inset-y-0 border-s border-border/60", style: { insetInlineStart: guide + indent * k } }, k))), _jsx(TreeRow, { node: node, level: level, expanded: expanded, selected: selected })] }));
|
|
207
|
+
});
|
|
208
|
+
/**
|
|
209
|
+
* The part of a virtual tree that is on screen: the viewport, narrowed by every box around the
|
|
210
|
+
* tree that clips — the tree itself when it scrolls, a `ScrollArea`, a panel with `overflow-auto`.
|
|
211
|
+
* So it follows whichever of them scrolls, and the page, without being told which.
|
|
212
|
+
*/
|
|
213
|
+
function visibleSpan(tree, win) {
|
|
214
|
+
let top = 0;
|
|
215
|
+
let bottom = win.innerHeight;
|
|
216
|
+
// Inside an absolutely placed box, only its containing block and the boxes around that clip it.
|
|
217
|
+
let placed = false;
|
|
218
|
+
for (let el = tree; el && el !== el.ownerDocument.body; el = el.parentElement) {
|
|
219
|
+
const style = win.getComputedStyle(el);
|
|
220
|
+
const block = style.position !== "static" || style.transform !== "none";
|
|
221
|
+
if (placed && !block)
|
|
222
|
+
continue;
|
|
223
|
+
placed = style.position === "absolute";
|
|
224
|
+
// Overflow does not apply to a box that is not one (`display: contents`, inline).
|
|
225
|
+
if (style.overflowY !== "visible" && style.display !== "contents" && style.display !== "inline") {
|
|
226
|
+
const edge = el.getBoundingClientRect().top + el.clientTop;
|
|
227
|
+
top = Math.max(top, edge);
|
|
228
|
+
bottom = Math.min(bottom, edge + el.clientHeight);
|
|
229
|
+
}
|
|
230
|
+
// The boxes around a fixed one (a drawer) do not clip it.
|
|
231
|
+
if (style.position === "fixed")
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
const origin = (tree.firstElementChild ?? tree).getBoundingClientRect().top;
|
|
235
|
+
// Off screen, the rows nearest to view stay rendered, and the focused one with them.
|
|
236
|
+
return { offset: top - origin, size: Math.max(bottom - top, 1) };
|
|
237
|
+
}
|
|
238
|
+
/** Calls `onSpan` with the visible span now, on every scroll that moves the tree, and on resize. */
|
|
239
|
+
function watchVisible(instance, onSpan) {
|
|
240
|
+
const tree = instance.scrollElement;
|
|
241
|
+
const win = instance.targetWindow;
|
|
242
|
+
if (!tree || !win)
|
|
243
|
+
return;
|
|
244
|
+
let settle = 0;
|
|
245
|
+
const update = (scrolling) => onSpan(visibleSpan(tree, win), scrolling);
|
|
246
|
+
const onScroll = (event) => {
|
|
247
|
+
// Scroll events do not bubble; captured on the window they come from every scroller.
|
|
248
|
+
if (!event.target?.contains?.(tree))
|
|
249
|
+
return;
|
|
250
|
+
update(true);
|
|
251
|
+
win.clearTimeout(settle);
|
|
252
|
+
settle = win.setTimeout(() => update(false), 150);
|
|
253
|
+
};
|
|
254
|
+
const onResize = () => update(false);
|
|
255
|
+
const resize = new win.ResizeObserver(onResize);
|
|
256
|
+
resize.observe(tree);
|
|
257
|
+
// Whatever else moves the tree — content above it growing or shrinking, with no scroll — shows
|
|
258
|
+
// as a spacer (rows not rendered) coming into view or leaving it.
|
|
259
|
+
const spacers = new win.IntersectionObserver(onResize);
|
|
260
|
+
const observeSpacers = () => tree.querySelectorAll(':scope > [data-slot="tree-spacer"]').forEach((el) => spacers.observe(el));
|
|
261
|
+
const rows = new win.MutationObserver(observeSpacers);
|
|
262
|
+
rows.observe(tree, { childList: true });
|
|
263
|
+
observeSpacers();
|
|
264
|
+
win.addEventListener("scroll", onScroll, { capture: true, passive: true });
|
|
265
|
+
win.addEventListener("resize", onResize, { passive: true });
|
|
266
|
+
update(false);
|
|
267
|
+
return () => {
|
|
268
|
+
win.clearTimeout(settle);
|
|
269
|
+
resize.disconnect();
|
|
270
|
+
spacers.disconnect();
|
|
271
|
+
rows.disconnect();
|
|
272
|
+
win.removeEventListener("scroll", onScroll, { capture: true });
|
|
273
|
+
win.removeEventListener("resize", onResize);
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const observeVisibleRect = (instance, cb) => watchVisible(instance, (span) => cb({ width: 0, height: span.size }));
|
|
277
|
+
const observeVisibleOffset = (instance, cb) => watchVisible(instance, (span, scrolling) => cb(span.offset, scrolling));
|
|
278
|
+
// The tree never scrolls itself: rows are brought into view with `scrollIntoView`, by whichever
|
|
279
|
+
// box scrolls, and the browser's scroll anchoring keeps the view still as rows are measured.
|
|
280
|
+
const noScroll = () => { };
|
|
281
|
+
const noAdjust = () => false;
|
|
282
|
+
/** The height the server renders rows for, before anything is measured: a tall screen. */
|
|
283
|
+
const FIRST_WINDOW = { width: 0, height: 1200 };
|
|
284
|
+
/**
|
|
285
|
+
* The rows of a virtual tree in view, a few either side and the tab stop, in normal flow between
|
|
286
|
+
* spacers that stand in for the rest — so the tree is as tall as all of its rows, and the page,
|
|
287
|
+
* a `ScrollArea` or a box with `overflow-auto` scrolls it as it would scroll every row.
|
|
288
|
+
*/
|
|
289
|
+
function TreeVirtualRows({ order, index, states, focusAt, tree }) {
|
|
290
|
+
const ctx = React.useContext(TreeContext);
|
|
291
|
+
// A row, and the gap above every row but the first: the measured ones replace the guess.
|
|
292
|
+
const estimate = React.useRef({ row: sizes[ctx.size].estimate, gap: 2 });
|
|
293
|
+
const virtualizer = useVirtualizer({
|
|
294
|
+
count: order.length,
|
|
295
|
+
getScrollElement: () => tree,
|
|
296
|
+
estimateSize: React.useCallback((i) => estimate.current.row + (i > 0 ? estimate.current.gap : 0), []),
|
|
297
|
+
getItemKey: React.useCallback((i) => order[i], [order]),
|
|
298
|
+
rangeExtractor: React.useCallback((range) => {
|
|
299
|
+
const out = defaultRangeExtractor(range);
|
|
300
|
+
if (focusAt >= 0 && !out.includes(focusAt))
|
|
301
|
+
return [...out, focusAt].sort((a, b) => a - b);
|
|
302
|
+
return out;
|
|
303
|
+
}, [focusAt]),
|
|
304
|
+
overscan: 8,
|
|
305
|
+
initialRect: FIRST_WINDOW,
|
|
306
|
+
initialOffset: 0,
|
|
307
|
+
observeElementRect: observeVisibleRect,
|
|
308
|
+
observeElementOffset: observeVisibleOffset,
|
|
309
|
+
scrollToFn: noScroll,
|
|
310
|
+
});
|
|
311
|
+
virtualizer.shouldAdjustScrollPositionOnItemSizeChange = noAdjust;
|
|
312
|
+
// Rows are one height (labels truncate): the first ones measured size all the others, so the
|
|
313
|
+
// tree is as tall as it will be before they are seen — also where a dense `Sidebar` resets the
|
|
314
|
+
// control height.
|
|
315
|
+
React.useLayoutEffect(() => {
|
|
316
|
+
const row = tree?.querySelector(':scope > [data-index]:not([data-index="0"])');
|
|
317
|
+
if (!row)
|
|
318
|
+
return;
|
|
319
|
+
const gap = parseFloat(getComputedStyle(row).paddingTop) || 0;
|
|
320
|
+
const measured = { row: row.offsetHeight - gap, gap };
|
|
321
|
+
if (measured.row > 0 && (measured.row !== estimate.current.row || gap !== estimate.current.gap)) {
|
|
322
|
+
estimate.current = measured;
|
|
323
|
+
virtualizer.measure();
|
|
324
|
+
}
|
|
325
|
+
}, [ctx.size, virtualizer, tree]);
|
|
326
|
+
const out = [];
|
|
327
|
+
let y = 0;
|
|
328
|
+
const spacer = (key, height) => (_jsx("li", { role: "none", "aria-hidden": true, "data-slot": "tree-spacer", style: { height } }, key));
|
|
329
|
+
virtualizer.getVirtualItems().forEach((item, k) => {
|
|
330
|
+
if (item.start > y)
|
|
331
|
+
out.push(spacer(`gap-${k}`, item.start - y));
|
|
332
|
+
const id = order[item.index];
|
|
333
|
+
const entry = index.get(id);
|
|
334
|
+
out.push(_jsx(TreeFlatItem, { node: entry.node, level: entry.level, posinset: entry.posinset, setsize: entry.setsize, index: item.index, expanded: entry.node.children !== undefined && states.expanded.has(id), selected: states.selected.has(id), focused: states.focusId === id, measure: virtualizer.measureElement }, id));
|
|
335
|
+
y = item.end;
|
|
336
|
+
});
|
|
337
|
+
const total = virtualizer.getTotalSize();
|
|
338
|
+
if (total > y)
|
|
339
|
+
out.push(spacer("end", total - y));
|
|
340
|
+
return out;
|
|
341
|
+
}
|
|
342
|
+
/* ── Tree ──────────────────────────────────────────────────────────────────── */
|
|
343
|
+
/**
|
|
344
|
+
* Tree — a hierarchical list: files and folders, nested settings, a docs table of contents. Rows
|
|
345
|
+
* are 38px (30px with `size="sm"`) at 7px corners: hover lifts a row like a highlighted menu item,
|
|
346
|
+
* the selection is the raised row, a chevron turns as a branch opens, and a hairline guide runs
|
|
347
|
+
* down from each open branch.
|
|
348
|
+
*
|
|
349
|
+
* Data in, not parts: pass `items` and the tree owns the WAI-ARIA tree pattern — one tab stop,
|
|
350
|
+
* arrows that walk and open, Home/End, type-ahead, Space/Enter to select, Shift and ⌘ (Ctrl off
|
|
351
|
+
* a Mac) to extend in `multiple` mode. Past 500 nodes it renders only the rows in view (`virtualized`).
|
|
352
|
+
* The rule people break: a tree for two levels of a few items — that is a `Sidebar` with groups,
|
|
353
|
+
* or an `Accordion`.
|
|
354
|
+
*/
|
|
355
|
+
export function Tree({ items, size = "default", selectionMode = "single", selected: selectedProp, defaultSelected = [], onSelectedChange, expanded: expandedProp, defaultExpanded = [], onExpandedChange, onAction, guides = true, virtualized, ref, className, onKeyDown, onFocus, onBlur, ...props }) {
|
|
356
|
+
const [expandedIds, setExpanded] = useControllable(expandedProp, defaultExpanded, onExpandedChange);
|
|
357
|
+
const [selectedIds, setSelected] = useControllable(selectedProp, defaultSelected, onSelectedChange);
|
|
358
|
+
const expanded = React.useMemo(() => new Set(expandedIds), [expandedIds]);
|
|
359
|
+
const selected = React.useMemo(() => new Set(selectedIds), [selectedIds]);
|
|
360
|
+
const index = React.useMemo(() => indexTree(items), [items]);
|
|
361
|
+
const order = React.useMemo(() => visibleOrder(items, expanded), [items, expanded]);
|
|
362
|
+
// Each visible id's place in `order`; an id that is not here is not in view.
|
|
363
|
+
const position = React.useMemo(() => new Map(order.map((id, i) => [id, i])), [order]);
|
|
364
|
+
const virtual = virtualized ?? index.size > VIRTUALIZE_FROM;
|
|
365
|
+
const tree = React.useRef(null);
|
|
366
|
+
const treeRef = React.useMemo(() => mergeRefs(tree, ref), [ref]);
|
|
367
|
+
// Virtual rows watch the tree element, which is attached only after their own first effects
|
|
368
|
+
// have run: they get it once it is there.
|
|
369
|
+
const [treeEl, setTreeEl] = React.useState(null);
|
|
370
|
+
React.useLayoutEffect(() => setTreeEl(virtual ? tree.current : null), [virtual]);
|
|
371
|
+
const elements = React.useRef(new Map());
|
|
372
|
+
const register = React.useCallback((id, el) => {
|
|
373
|
+
if (el)
|
|
374
|
+
elements.current.set(id, el);
|
|
375
|
+
else
|
|
376
|
+
elements.current.delete(id);
|
|
377
|
+
}, []);
|
|
378
|
+
// The roving tab stop. It starts on the first selected node in view, else the first node; when
|
|
379
|
+
// its branch closes under it, it moves up to the nearest ancestor still in view; when its node
|
|
380
|
+
// leaves the tree (deleted, or the items replaced), to the row that took its place — the next
|
|
381
|
+
// one in view before the change, else the one before it.
|
|
382
|
+
const [focusState, setFocusState] = React.useState(null);
|
|
383
|
+
const lastOrder = React.useRef(order);
|
|
384
|
+
let focusId = focusState ?? selectedIds.find((id) => position.has(id)) ?? order[0] ?? null;
|
|
385
|
+
if (focusId && !index.has(focusId)) {
|
|
386
|
+
const before = lastOrder.current;
|
|
387
|
+
const at = before.indexOf(focusId);
|
|
388
|
+
const around = [...before.slice(at + 1), ...before.slice(0, Math.max(at, 0)).reverse()];
|
|
389
|
+
focusId = around.find((id) => position.has(id)) ?? order[0] ?? null;
|
|
390
|
+
}
|
|
391
|
+
while (focusId && !position.has(focusId))
|
|
392
|
+
focusId = index.get(focusId)?.parent ?? order[0] ?? null;
|
|
393
|
+
// What the rows last rendered with, so a nested row can tell whether it changed.
|
|
394
|
+
const committed = React.useRef(null);
|
|
395
|
+
const view = React.useMemo(() => {
|
|
396
|
+
const states = { expanded, selected, focusId };
|
|
397
|
+
return { ...states, changed: changedRows(committed.current, states, index) };
|
|
398
|
+
}, [expanded, selected, focusId, index]);
|
|
399
|
+
// A row of a virtual tree that is not rendered yet: it takes the focus once it is.
|
|
400
|
+
const pendingFocus = React.useRef(null);
|
|
401
|
+
const focusRow = (el) => {
|
|
402
|
+
if (!virtual)
|
|
403
|
+
return el.focus();
|
|
404
|
+
// Only as far as it takes: the row is often just past the edge of the box that scrolls.
|
|
405
|
+
el.focus({ preventScroll: true });
|
|
406
|
+
el.scrollIntoView({ block: "nearest" });
|
|
407
|
+
};
|
|
408
|
+
// The treeitem that has the focus. If it leaves the DOM with it, the focus would drop to the
|
|
409
|
+
// page: it goes to the new tab stop instead. A real blur (the element is still there once the
|
|
410
|
+
// event is over) forgets it, so a node removed later never pulls the focus back.
|
|
411
|
+
const focused = React.useRef(null);
|
|
412
|
+
React.useLayoutEffect(() => {
|
|
413
|
+
committed.current = view;
|
|
414
|
+
lastOrder.current = order;
|
|
415
|
+
if (focusState !== null && !index.has(focusState))
|
|
416
|
+
setFocusState(focusId);
|
|
417
|
+
const pending = pendingFocus.current && elements.current.get(pendingFocus.current);
|
|
418
|
+
if (pending) {
|
|
419
|
+
pendingFocus.current = null;
|
|
420
|
+
focusRow(pending);
|
|
421
|
+
}
|
|
422
|
+
const gone = focused.current && !focused.current.isConnected;
|
|
423
|
+
const active = document.activeElement;
|
|
424
|
+
const next = focusId && elements.current.get(focusId);
|
|
425
|
+
if (gone && (!active || active === document.body)) {
|
|
426
|
+
focused.current = null;
|
|
427
|
+
if (next)
|
|
428
|
+
focusRow(next);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
const anchor = React.useRef(null);
|
|
432
|
+
// Where the last Shift range ended. The next one replaces it, so it shrinks as well as grows.
|
|
433
|
+
const rangeEnd = React.useRef(null);
|
|
434
|
+
const typeahead = React.useRef({ text: "", at: 0 });
|
|
435
|
+
const focus = (id) => {
|
|
436
|
+
if (!id)
|
|
437
|
+
return;
|
|
438
|
+
setFocusState(id);
|
|
439
|
+
const el = elements.current.get(id);
|
|
440
|
+
pendingFocus.current = el ? null : id;
|
|
441
|
+
if (el)
|
|
442
|
+
focusRow(el);
|
|
443
|
+
};
|
|
444
|
+
const toggle = (node, open = !expanded.has(node.id)) => {
|
|
445
|
+
if (node.disabled || !node.children || open === expanded.has(node.id))
|
|
446
|
+
return;
|
|
447
|
+
setExpanded(open ? [...expandedIds, node.id] : expandedIds.filter((id) => id !== node.id));
|
|
448
|
+
};
|
|
449
|
+
const selectable = (id) => !index.get(id)?.node.disabled;
|
|
450
|
+
/** Apply a selection gesture: `replace` (click, Enter), `toggle` (⌘/Ctrl, Space), `range` (Shift). */
|
|
451
|
+
const select = (id, how) => {
|
|
452
|
+
if (selectionMode === "none")
|
|
453
|
+
return;
|
|
454
|
+
const from = anchor.current === null ? undefined : position.get(anchor.current);
|
|
455
|
+
if (selectionMode === "multiple" && how === "range" && from !== undefined) {
|
|
456
|
+
// From the anchor to here, in place of the last range: Shift+↑ after Shift+↓ gives rows
|
|
457
|
+
// back. What was selected outside the range stays selected.
|
|
458
|
+
const span = (to) => order.slice(Math.min(from, to), Math.max(from, to) + 1);
|
|
459
|
+
const last = new Set(span(position.get(rangeEnd.current ?? "") ?? from));
|
|
460
|
+
const range = span(position.get(id) ?? from).filter(selectable);
|
|
461
|
+
setSelected([...new Set([...selectedIds.filter((s) => !last.has(s)), ...range])]);
|
|
462
|
+
rangeEnd.current = id;
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if (!selectable(id))
|
|
466
|
+
return;
|
|
467
|
+
anchor.current = rangeEnd.current = id;
|
|
468
|
+
if (selectionMode === "single") {
|
|
469
|
+
if (!selected.has(id) || selectedIds.length !== 1)
|
|
470
|
+
setSelected([id]);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (how === "toggle")
|
|
474
|
+
setSelected(selected.has(id) ? selectedIds.filter((s) => s !== id) : [...selectedIds, id]);
|
|
475
|
+
else
|
|
476
|
+
setSelected([id]);
|
|
477
|
+
};
|
|
478
|
+
const onRowClick = (node, event) => {
|
|
479
|
+
// On a Mac, Ctrl-click is a right-click: it belongs to a context menu, not to the row.
|
|
480
|
+
if (event.ctrlKey && isApple())
|
|
481
|
+
return;
|
|
482
|
+
// A disabled link row is not followed, by the pointer as by Enter.
|
|
483
|
+
if (node.disabled)
|
|
484
|
+
event.preventDefault();
|
|
485
|
+
// The treeitem keeps the focus, also when a link row took it on mousedown.
|
|
486
|
+
setFocusState(node.id);
|
|
487
|
+
elements.current.get(node.id)?.focus({ preventScroll: true });
|
|
488
|
+
// ⌘ on Apple devices, Ctrl elsewhere.
|
|
489
|
+
const extend = modPressed(event);
|
|
490
|
+
if (selectionMode === "multiple" && (event.shiftKey || extend)) {
|
|
491
|
+
// The modifier selects: it doesn't also open a link row in a new tab or window.
|
|
492
|
+
event.preventDefault();
|
|
493
|
+
select(node.id, event.shiftKey ? "range" : "toggle");
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
select(node.id, "replace");
|
|
497
|
+
// A plain click on a branch also opens or closes it, as in a file explorer.
|
|
498
|
+
toggle(node);
|
|
499
|
+
}
|
|
500
|
+
if (!node.disabled)
|
|
501
|
+
onAction?.(node, event);
|
|
502
|
+
};
|
|
503
|
+
const onChevronClick = (node, event) => {
|
|
504
|
+
// The chevron only opens and closes; the selection stays where it is.
|
|
505
|
+
event.stopPropagation();
|
|
506
|
+
event.preventDefault();
|
|
507
|
+
setFocusState(node.id);
|
|
508
|
+
toggle(node);
|
|
509
|
+
};
|
|
510
|
+
// Rows call the handlers of the latest render through stable functions, so they stay memoised.
|
|
511
|
+
const handlers = React.useRef({ onRowClick, onChevronClick });
|
|
512
|
+
React.useLayoutEffect(() => {
|
|
513
|
+
handlers.current = { onRowClick, onChevronClick };
|
|
514
|
+
});
|
|
515
|
+
const ctx = React.useMemo(() => ({
|
|
516
|
+
size,
|
|
517
|
+
guides,
|
|
518
|
+
selectionMode,
|
|
519
|
+
register,
|
|
520
|
+
onRowClick: (node, event) => handlers.current.onRowClick(node, event),
|
|
521
|
+
onChevronClick: (node, event) => handlers.current.onChevronClick(node, event),
|
|
522
|
+
}), [size, guides, selectionMode, register]);
|
|
523
|
+
const handleKeyDown = (event) => {
|
|
524
|
+
onKeyDown?.(event);
|
|
525
|
+
if (event.defaultPrevented)
|
|
526
|
+
return;
|
|
527
|
+
const item = event.target.closest('[data-slot="tree-item"]');
|
|
528
|
+
const id = item?.dataset.treeId;
|
|
529
|
+
const entry = id ? index.get(id) : undefined;
|
|
530
|
+
if (!id || !entry || item !== event.target)
|
|
531
|
+
return;
|
|
532
|
+
const { node } = entry;
|
|
533
|
+
const at = position.get(id) ?? 0;
|
|
534
|
+
const multiple = selectionMode === "multiple";
|
|
535
|
+
const step = (to) => {
|
|
536
|
+
if (!to)
|
|
537
|
+
return;
|
|
538
|
+
focus(to);
|
|
539
|
+
if (!multiple || !event.shiftKey)
|
|
540
|
+
return;
|
|
541
|
+
// Shift+arrows extend from where the last selection started, or from the row being left.
|
|
542
|
+
if (!anchor.current || !position.has(anchor.current))
|
|
543
|
+
anchor.current = rangeEnd.current = id;
|
|
544
|
+
select(to, "range");
|
|
545
|
+
};
|
|
546
|
+
switch (event.key) {
|
|
547
|
+
case "ArrowDown":
|
|
548
|
+
step(order[at + 1]);
|
|
549
|
+
break;
|
|
550
|
+
case "ArrowUp":
|
|
551
|
+
step(order[at - 1]);
|
|
552
|
+
break;
|
|
553
|
+
case "ArrowRight":
|
|
554
|
+
case "ArrowLeft": {
|
|
555
|
+
const forward = (event.key === "ArrowRight") === (getComputedStyle(item).direction !== "rtl");
|
|
556
|
+
if (forward) {
|
|
557
|
+
if (node.children && !expanded.has(node.id))
|
|
558
|
+
toggle(node, true);
|
|
559
|
+
else if (node.children?.length && expanded.has(node.id))
|
|
560
|
+
focus(node.children[0].id);
|
|
561
|
+
}
|
|
562
|
+
else if (node.children && expanded.has(node.id))
|
|
563
|
+
toggle(node, false);
|
|
564
|
+
else
|
|
565
|
+
focus(entry.parent ?? undefined);
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
case "Home":
|
|
569
|
+
step(order[0]);
|
|
570
|
+
break;
|
|
571
|
+
case "End":
|
|
572
|
+
step(order[order.length - 1]);
|
|
573
|
+
break;
|
|
574
|
+
case "Enter": {
|
|
575
|
+
select(id, "replace");
|
|
576
|
+
if (node.disabled)
|
|
577
|
+
break;
|
|
578
|
+
// A link row follows its href as a click would (onAction runs in its click handler).
|
|
579
|
+
const link = item.querySelector(':scope > [data-slot="tree-row"][href]');
|
|
580
|
+
if (link)
|
|
581
|
+
link.click();
|
|
582
|
+
else
|
|
583
|
+
onAction?.(node, event);
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
case " ":
|
|
587
|
+
// Shift+Space selects from the last selected row to this one (WAI-ARIA tree pattern).
|
|
588
|
+
if (multiple && event.shiftKey) {
|
|
589
|
+
if (!anchor.current || !position.has(anchor.current))
|
|
590
|
+
anchor.current = rangeEnd.current = id;
|
|
591
|
+
select(id, "range");
|
|
592
|
+
}
|
|
593
|
+
else
|
|
594
|
+
select(id, multiple ? "toggle" : "replace");
|
|
595
|
+
break;
|
|
596
|
+
case "*": {
|
|
597
|
+
// Open every sibling branch at this level.
|
|
598
|
+
const siblings = entry.parent ? index.get(entry.parent).node.children : items;
|
|
599
|
+
const open = siblings
|
|
600
|
+
.filter((n) => n.children && !n.disabled && !expanded.has(n.id))
|
|
601
|
+
.map((n) => n.id);
|
|
602
|
+
if (open.length)
|
|
603
|
+
setExpanded([...expandedIds, ...open]);
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
default: {
|
|
607
|
+
// ⌘A on Apple devices, Ctrl+A elsewhere: a Mac's Ctrl+A is not select-all.
|
|
608
|
+
if (multiple && modPressed(event) && event.key.toLowerCase() === "a") {
|
|
609
|
+
setSelected(order.filter(selectable));
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
// Type-ahead: letters typed within half a second build a prefix; the next match gets focus.
|
|
613
|
+
if (event.key.length !== 1 || event.metaKey || event.ctrlKey || event.altKey)
|
|
614
|
+
return;
|
|
615
|
+
const now = event.timeStamp;
|
|
616
|
+
const t = typeahead.current;
|
|
617
|
+
t.text = now - t.at > 500 ? event.key : t.text + event.key;
|
|
618
|
+
t.at = now;
|
|
619
|
+
const prefix = t.text.toLowerCase();
|
|
620
|
+
const label = (i) => {
|
|
621
|
+
const n = index.get(i).node;
|
|
622
|
+
return (n.textValue ?? textOf(n.label)).toLowerCase();
|
|
623
|
+
};
|
|
624
|
+
// A repeated single letter cycles through the matches; a longer prefix stays on a match.
|
|
625
|
+
const from = prefix.length === 1 ? at + 1 : at;
|
|
626
|
+
const match = [...order.slice(from), ...order.slice(0, from)].find((i) => label(i).startsWith(prefix));
|
|
627
|
+
if (match)
|
|
628
|
+
focus(match);
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
event.preventDefault();
|
|
633
|
+
};
|
|
634
|
+
return (_jsx(TreeContext.Provider, { value: ctx, children: _jsx("ul", { ref: treeRef, role: "tree", "data-slot": "tree", "data-size": size, "data-virtualized": virtual ? "" : undefined, "aria-multiselectable": selectionMode === "multiple" || undefined, onKeyDown: handleKeyDown, onFocus: (event) => {
|
|
635
|
+
onFocus?.(event);
|
|
636
|
+
const id = event.target.dataset.treeId;
|
|
637
|
+
if (!id)
|
|
638
|
+
return;
|
|
639
|
+
setFocusState(id);
|
|
640
|
+
focused.current = event.target;
|
|
641
|
+
}, onBlur: (event) => {
|
|
642
|
+
onBlur?.(event);
|
|
643
|
+
const el = event.target;
|
|
644
|
+
queueMicrotask(() => {
|
|
645
|
+
if (focused.current === el && el.isConnected)
|
|
646
|
+
focused.current = null;
|
|
647
|
+
});
|
|
648
|
+
}, className: cn("m-0 w-full list-none p-0 font-body", virtual ? "block" : "flex flex-col gap-0.5", className), ...props, children: virtual ? (_jsx(TreeVirtualRows, { order: order, index: index, states: view, focusAt: focusId === null ? -1 : (position.get(focusId) ?? -1), tree: treeEl })) : (items.map((node, i) => (_jsx(TreeItem, { node: node, level: 1, posinset: i + 1, setsize: items.length, view: view }, node.id)))) }) }));
|
|
649
|
+
}
|