@zonsh/ui 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +76 -2
- 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/breadcrumb.d.ts +22 -0
- package/dist/components/breadcrumb.js +32 -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 +164 -0
- package/dist/components/card.d.ts +42 -0
- package/dist/components/card.js +76 -0
- package/dist/components/carousel.d.ts +90 -0
- package/dist/components/carousel.js +213 -0
- package/dist/components/chart.d.ts +180 -0
- package/dist/components/chart.js +286 -0
- package/dist/components/checkbox.d.ts +23 -0
- package/dist/components/checkbox.js +43 -0
- package/dist/components/code-block.d.ts +45 -0
- package/dist/components/code-block.js +58 -0
- package/dist/components/code-highlight.d.ts +13 -0
- package/dist/components/code-highlight.js +107 -0
- package/dist/components/collapsible.d.ts +20 -0
- package/dist/components/collapsible.js +32 -0
- package/dist/components/color-picker.d.ts +85 -0
- package/dist/components/color-picker.js +407 -0
- package/dist/components/combobox.d.ts +81 -0
- package/dist/components/combobox.js +100 -0
- package/dist/components/command.d.ts +112 -0
- package/dist/components/command.js +212 -0
- package/dist/components/context-menu.d.ts +29 -0
- package/dist/components/context-menu.js +35 -0
- package/dist/components/conversation.d.ts +27 -0
- package/dist/components/conversation.js +293 -0
- package/dist/components/copy-button.d.ts +46 -0
- package/dist/components/copy-button.js +118 -0
- package/dist/components/data-table.d.ts +175 -0
- package/dist/components/data-table.js +302 -0
- package/dist/components/date-picker.d.ts +91 -0
- package/dist/components/date-picker.js +207 -0
- package/dist/components/dialog.d.ts +48 -0
- package/dist/components/dialog.js +92 -0
- package/dist/components/direction.d.ts +16 -0
- package/dist/components/direction.js +18 -0
- package/dist/components/drawer.d.ts +60 -0
- package/dist/components/drawer.js +76 -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 +15 -0
- package/dist/components/field.js +36 -0
- package/dist/components/file-drop.d.ts +55 -0
- package/dist/components/file-drop.js +197 -0
- package/dist/components/filter-bar.d.ts +106 -0
- package/dist/components/filter-bar.js +296 -0
- package/dist/components/form.d.ts +33 -0
- package/dist/components/form.js +34 -0
- package/dist/components/graph.d.ts +105 -0
- package/dist/components/graph.js +786 -0
- package/dist/components/illustration.d.ts +85 -0
- package/dist/components/illustration.js +165 -0
- package/dist/components/input-group.d.ts +127 -0
- package/dist/components/input-group.js +292 -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 +33 -0
- package/dist/components/kbd.js +38 -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/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 +138 -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 +56 -0
- package/dist/components/meter.d.ts +31 -0
- package/dist/components/meter.js +25 -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 +36 -0
- package/dist/components/number-field.js +153 -0
- package/dist/components/otp-field.d.ts +35 -0
- package/dist/components/otp-field.js +94 -0
- package/dist/components/pagination.d.ts +31 -0
- package/dist/components/pagination.js +70 -0
- package/dist/components/pdf-viewer.d.ts +69 -0
- package/dist/components/pdf-viewer.js +929 -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 +23 -0
- package/dist/components/prompt-input.d.ts +131 -0
- package/dist/components/prompt-input.js +403 -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/reasoning.d.ts +31 -0
- package/dist/components/reasoning.js +70 -0
- package/dist/components/resizable.d.ts +38 -0
- package/dist/components/resizable.js +41 -0
- package/dist/components/response.d.ts +30 -0
- package/dist/components/response.js +538 -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 +60 -0
- package/dist/components/separator.d.ts +14 -0
- package/dist/components/separator.js +17 -0
- package/dist/components/sidebar.d.ts +147 -0
- package/dist/components/sidebar.js +489 -0
- package/dist/components/site-header.d.ts +59 -0
- package/dist/components/site-header.js +67 -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 +129 -0
- package/dist/components/sources.d.ts +25 -0
- package/dist/components/sources.js +35 -0
- package/dist/components/spinner.d.ts +36 -0
- package/dist/components/spinner.js +72 -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 +162 -0
- package/dist/components/table.js +758 -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 +40 -0
- package/dist/components/tags-input.js +239 -0
- package/dist/components/textarea.d.ts +13 -0
- package/dist/components/textarea.js +16 -0
- package/dist/components/theme.d.ts +41 -0
- package/dist/components/theme.js +112 -0
- package/dist/components/time-field.d.ts +51 -0
- package/dist/components/time-field.js +437 -0
- package/dist/components/timeline.d.ts +76 -0
- package/dist/components/timeline.js +99 -0
- package/dist/components/toast.d.ts +72 -0
- package/dist/components/toast.js +196 -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 +52 -0
- package/dist/components/tool-call.js +57 -0
- package/dist/components/toolbar.d.ts +17 -0
- package/dist/components/toolbar.js +34 -0
- package/dist/components/tooltip.d.ts +42 -0
- package/dist/components/tooltip.js +47 -0
- package/dist/components/tree.d.ts +75 -0
- package/dist/components/tree.js +636 -0
- package/dist/components/typography.d.ts +134 -0
- package/dist/components/typography.js +176 -0
- package/dist/components/video-player.d.ts +276 -0
- package/dist/components/video-player.js +1352 -0
- package/dist/components/whiteboard.d.ts +80 -0
- package/dist/components/whiteboard.js +389 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +86 -0
- package/dist/lib/cn.d.ts +20 -0
- package/dist/lib/cn.js +38 -0
- package/dist/lib/code-highlight.d.ts +31 -0
- package/dist/lib/code-highlight.js +24 -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/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 +200 -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/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/platform.d.ts +33 -0
- package/dist/lib/platform.js +68 -0
- package/dist/lib/room.d.ts +25 -0
- package/dist/lib/room.js +46 -0
- package/dist/lib/table-fit.d.ts +143 -0
- package/dist/lib/table-fit.js +577 -0
- package/dist/lib/theme-script.d.ts +18 -0
- package/dist/lib/theme-script.js +29 -0
- package/dist/styles/expressive.css +188 -0
- package/dist/styles/fonts.css +145 -0
- package/dist/styles/index.css +206 -0
- package/dist/styles/material.css +313 -0
- package/dist/styles/parts/ai.css +360 -0
- package/dist/styles/parts/brand.css +75 -0
- package/dist/styles/parts/controls.css +725 -0
- package/dist/styles/parts/data.css +222 -0
- package/dist/styles/parts/editorial.css +120 -0
- package/dist/styles/parts/feedback.css +273 -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 +232 -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/parts/whiteboard.css +855 -0
- package/dist/styles/tokens.css +290 -0
- package/dist/vite.d.ts +116 -0
- package/dist/vite.js +129 -0
- package/package.json +189 -3
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FileIcon, UploadIcon, XIcon } from "lucide-react";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { cn } from "../lib/cn.js";
|
|
6
|
+
import { useShortcutKeys } from "../lib/platform.js";
|
|
7
|
+
import { Button } from "./button.js";
|
|
8
|
+
import { Item, ItemActions, ItemContent, ItemDescription, ItemMedia, ItemTitle } from "./item.js";
|
|
9
|
+
import { Kbd, KbdGroup } from "./kbd.js";
|
|
10
|
+
/** Does `file` match an `accept` list: extensions (`.pdf`), types (`image/png`) and families (`image/*`)? */
|
|
11
|
+
function accepts(file, accept) {
|
|
12
|
+
if (!accept?.trim())
|
|
13
|
+
return true;
|
|
14
|
+
const name = file.name.toLowerCase();
|
|
15
|
+
const type = file.type.toLowerCase();
|
|
16
|
+
return accept.split(",").some((raw) => {
|
|
17
|
+
const token = raw.trim().toLowerCase();
|
|
18
|
+
if (!token)
|
|
19
|
+
return false;
|
|
20
|
+
if (token.startsWith("."))
|
|
21
|
+
return name.endsWith(token);
|
|
22
|
+
if (token.endsWith("/*"))
|
|
23
|
+
return type.startsWith(token.slice(0, -1));
|
|
24
|
+
return type === token;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** The files in a drop or a paste: `files`, or file items where a browser only lists those. */
|
|
28
|
+
function filesOf(data) {
|
|
29
|
+
if (!data)
|
|
30
|
+
return [];
|
|
31
|
+
if (data.files.length)
|
|
32
|
+
return [...data.files];
|
|
33
|
+
return [...data.items].flatMap((item) => item.kind === "file" ? [item.getAsFile()].filter((f) => !!f) : []);
|
|
34
|
+
}
|
|
35
|
+
/** A field that takes typed text, so a paste while it has focus is meant for it. */
|
|
36
|
+
const takesText = (el) => !!el &&
|
|
37
|
+
(el.isContentEditable ||
|
|
38
|
+
el.matches("textarea, input:not([type=checkbox], [type=radio], [type=button], [type=submit], [type=reset], [type=file], [type=range], [type=color])"));
|
|
39
|
+
/**
|
|
40
|
+
* FileDrop — a place to add files, three ways: drop one or more on it, click it (or press Enter or
|
|
41
|
+
* Space) to choose them in the file picker, or paste them with ⌘V / Ctrl+V while it is focused or
|
|
42
|
+
* under the pointer. A recessed field with a dashed edge and a raised upload well; the edge takes
|
|
43
|
+
* the focus colour while files are dragged over it. It checks `accept`, `maxSize` and `multiple`
|
|
44
|
+
* the same way for all three, and hands what it takes to `onFiles` — show them with
|
|
45
|
+
* `FileDropItem`s.
|
|
46
|
+
*
|
|
47
|
+
* The rule people break: a zone that only takes drops. Dragging needs a mouse and a file manager
|
|
48
|
+
* beside the page; clicking and pasting are how most people add a file.
|
|
49
|
+
*/
|
|
50
|
+
export function FileDrop({ onFiles, onReject, accept, multiple = true, maxSize, disabled = false, title, description, hint, children, className, onKeyDown, onClick, onDragEnter, onDragOver, onDragLeave, onPointerEnter, onPointerLeave, ...props }) {
|
|
51
|
+
const zone = React.useRef(null);
|
|
52
|
+
const input = React.useRef(null);
|
|
53
|
+
const hovered = React.useRef(false);
|
|
54
|
+
const [dragging, setDragging] = React.useState(false);
|
|
55
|
+
const hintId = React.useId();
|
|
56
|
+
// One check for drops, the picker and pastes.
|
|
57
|
+
const take = React.useCallback((files) => {
|
|
58
|
+
if (disabled || !files.length)
|
|
59
|
+
return;
|
|
60
|
+
const taken = [];
|
|
61
|
+
const rejected = [];
|
|
62
|
+
for (const file of files) {
|
|
63
|
+
if (!accepts(file, accept))
|
|
64
|
+
rejected.push({ file, reason: "type" });
|
|
65
|
+
else if (maxSize != null && file.size > maxSize)
|
|
66
|
+
rejected.push({ file, reason: "size" });
|
|
67
|
+
else if (!multiple && taken.length)
|
|
68
|
+
rejected.push({ file, reason: "count" });
|
|
69
|
+
else
|
|
70
|
+
taken.push(file);
|
|
71
|
+
}
|
|
72
|
+
if (taken.length)
|
|
73
|
+
onFiles(taken);
|
|
74
|
+
if (rejected.length)
|
|
75
|
+
onReject?.(rejected);
|
|
76
|
+
}, [accept, disabled, maxSize, multiple, onFiles, onReject]);
|
|
77
|
+
// Paste: files pasted while the zone has focus, or while the pointer is over it — unless a text
|
|
78
|
+
// field elsewhere has focus (the paste is for it), or something on the way took the paste already.
|
|
79
|
+
React.useEffect(() => {
|
|
80
|
+
if (disabled)
|
|
81
|
+
return;
|
|
82
|
+
const paste = (event) => {
|
|
83
|
+
const el = zone.current;
|
|
84
|
+
const active = document.activeElement;
|
|
85
|
+
if (!el || event.defaultPrevented)
|
|
86
|
+
return;
|
|
87
|
+
if (!(el.contains(active) || (hovered.current && !takesText(active))))
|
|
88
|
+
return;
|
|
89
|
+
const files = filesOf(event.clipboardData);
|
|
90
|
+
if (!files.length)
|
|
91
|
+
return;
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
take(files);
|
|
94
|
+
};
|
|
95
|
+
document.addEventListener("paste", paste);
|
|
96
|
+
return () => document.removeEventListener("paste", paste);
|
|
97
|
+
}, [disabled, take]);
|
|
98
|
+
const open = () => {
|
|
99
|
+
if (!disabled)
|
|
100
|
+
input.current?.click();
|
|
101
|
+
};
|
|
102
|
+
const hasFiles = (event) => event.dataTransfer.types.includes("Files");
|
|
103
|
+
return (_jsxs("div", { ref: zone, role: "button", tabIndex: disabled ? -1 : 0, "aria-disabled": disabled || undefined, "aria-describedby": hintId, "data-slot": "file-drop", "data-dragging": dragging ? "" : undefined, "data-disabled": disabled ? "" : undefined, className: cn("group/file-drop relative flex min-h-40 w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-control border border-dashed border-field-edge bg-field-surface px-6 py-8 text-center shadow-field focus-ring outline-none select-none", "transition-[background-color,border-color] duration-(--duration) ease-(--ease)", "hover:border-muted-foreground data-dragging:border-control-focus data-dragging:bg-control-hover",
|
|
104
|
+
// A contrast theme keeps neither colour: there, the edge turns solid while files are over it.
|
|
105
|
+
"forced-colors:data-dragging:border-solid", "data-disabled:pointer-events-none data-disabled:opacity-55", className), onClick: (event) => {
|
|
106
|
+
onClick?.(event);
|
|
107
|
+
// Clicks on the zone's own controls (a remove button inside custom children) stay theirs.
|
|
108
|
+
if (event.defaultPrevented || event.target.closest("button, a, input"))
|
|
109
|
+
return;
|
|
110
|
+
open();
|
|
111
|
+
}, onKeyDown: (event) => {
|
|
112
|
+
onKeyDown?.(event);
|
|
113
|
+
if (event.defaultPrevented || event.target !== event.currentTarget)
|
|
114
|
+
return;
|
|
115
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
open();
|
|
118
|
+
}
|
|
119
|
+
}, onDragEnter: (event) => {
|
|
120
|
+
onDragEnter?.(event);
|
|
121
|
+
if (disabled || !hasFiles(event))
|
|
122
|
+
return;
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
setDragging(true);
|
|
125
|
+
}, onDragOver: (event) => {
|
|
126
|
+
onDragOver?.(event);
|
|
127
|
+
if (disabled || !hasFiles(event))
|
|
128
|
+
return;
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
event.dataTransfer.dropEffect = "copy";
|
|
131
|
+
setDragging(true);
|
|
132
|
+
}, onDragLeave: (event) => {
|
|
133
|
+
onDragLeave?.(event);
|
|
134
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
135
|
+
setDragging(false);
|
|
136
|
+
}, onDrop: (event) => {
|
|
137
|
+
setDragging(false);
|
|
138
|
+
if (disabled || !hasFiles(event))
|
|
139
|
+
return;
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
take(filesOf(event.dataTransfer));
|
|
142
|
+
}, onPointerEnter: (event) => {
|
|
143
|
+
onPointerEnter?.(event);
|
|
144
|
+
hovered.current = true;
|
|
145
|
+
}, onPointerLeave: (event) => {
|
|
146
|
+
onPointerLeave?.(event);
|
|
147
|
+
hovered.current = false;
|
|
148
|
+
}, ...props, children: [_jsx("input", { ref: input, type: "file", hidden: true, tabIndex: -1, accept: accept, multiple: multiple, disabled: disabled, "data-slot": "file-drop-input", onChange: (event) => {
|
|
149
|
+
take([...(event.currentTarget.files ?? [])]);
|
|
150
|
+
// Reset, so the same file can be chosen again.
|
|
151
|
+
event.currentTarget.value = "";
|
|
152
|
+
} }), children ?? (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, "data-slot": "file-drop-icon", className: "mb-3 inline-flex size-(--control-h-lg) items-center justify-center rounded-full bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent text-foreground shadow-raised transition-[translate] duration-(--duration) ease-(--ease) group-data-dragging/file-drop:-translate-y-0.5 [&_svg]:size-5", children: _jsx(UploadIcon, {}) }), _jsx("span", { "data-slot": "file-drop-title", className: "text-sm font-medium text-foreground", children: title ?? (multiple ? "Drop files here" : "Drop a file here") }), _jsx("span", { "data-slot": "file-drop-description", className: "text-[13px] text-muted-foreground", children: description ?? _jsx(DefaultDescription, {}) })] })), _jsx("span", { id: hintId, "data-slot": "file-drop-hint", className: cn("mt-2 font-mono text-[11px] text-muted-foreground", (children != null || hint == null) && "sr-only"), children: hint ?? `Drop, choose or paste ${multiple ? "files" : "a file"}` })] }));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* How else to add files: click to choose, or paste with the device's own keys (⌘ V on Apple,
|
|
156
|
+
* Ctrl V elsewhere). A touch-only phone or tablet has no keys to press, so it only says tap.
|
|
157
|
+
*/
|
|
158
|
+
function DefaultDescription() {
|
|
159
|
+
const { mod, hasKeyboard } = useShortcutKeys();
|
|
160
|
+
if (!hasKeyboard)
|
|
161
|
+
return "or tap to choose";
|
|
162
|
+
return (_jsxs(_Fragment, { children: ["or click to choose \u2014 paste with", " ", _jsxs(KbdGroup, { className: "align-middle", children: [_jsx(Kbd, { children: mod }), _jsx(Kbd, { children: "V" })] })] }));
|
|
163
|
+
}
|
|
164
|
+
/** A size in bytes, as people read it: 840 B, 12 KB, 3.4 MB. */
|
|
165
|
+
export function formatFileSize(bytes) {
|
|
166
|
+
if (bytes < 1024)
|
|
167
|
+
return `${bytes} B`;
|
|
168
|
+
const units = ["KB", "MB", "GB"];
|
|
169
|
+
let size = bytes / 1024;
|
|
170
|
+
let unit = 0;
|
|
171
|
+
while (size >= 1024 && unit < units.length - 1) {
|
|
172
|
+
size /= 1024;
|
|
173
|
+
unit++;
|
|
174
|
+
}
|
|
175
|
+
return `${size < 10 ? size.toFixed(1) : Math.round(size)} ${units[unit]}`;
|
|
176
|
+
}
|
|
177
|
+
/** An object URL for an image file while it is shown, revoked after. */
|
|
178
|
+
function usePreview(file) {
|
|
179
|
+
const [url, setUrl] = React.useState();
|
|
180
|
+
React.useEffect(() => {
|
|
181
|
+
if (!file || !file.type.startsWith("image/"))
|
|
182
|
+
return setUrl(undefined);
|
|
183
|
+
const next = URL.createObjectURL(file);
|
|
184
|
+
setUrl(next);
|
|
185
|
+
return () => URL.revokeObjectURL(next);
|
|
186
|
+
}, [file]);
|
|
187
|
+
return url;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* FileDropItem — one file added through a `FileDrop`: a thumbnail for an image (an icon for
|
|
191
|
+
* anything else), the name, its size in mono, and a remove button. Outlined 12px rows; stack
|
|
192
|
+
* them in a list under the zone.
|
|
193
|
+
*/
|
|
194
|
+
export function FileDropItem({ file, onRemove, removeLabel, className, ...props }) {
|
|
195
|
+
const preview = usePreview(file);
|
|
196
|
+
return (_jsxs(Item, { variant: "outline", size: "sm", "data-slot": "file-drop-item", className: className, ...props, children: [preview ? (_jsx(ItemMedia, { variant: "image", children: _jsx("img", { src: preview, alt: "" }) })) : (_jsx(ItemMedia, { variant: "image", className: "grid place-items-center bg-control-surface text-muted-foreground", children: _jsx(FileIcon, { className: "size-4" }) })), _jsxs(ItemContent, { className: "min-w-0", children: [_jsx(ItemTitle, { className: "block max-w-full truncate", title: file.name, children: file.name }), _jsx(ItemDescription, { className: "font-mono text-[11px] tabular-nums", children: formatFileSize(file.size) })] }), onRemove && (_jsx(ItemActions, { children: _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": removeLabel ?? `Remove ${file.name}`, onClick: onRemove, children: _jsx(XIcon, {}) }) }))] }));
|
|
197
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** One choice of a `select` field. */
|
|
3
|
+
export interface FilterOption {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
/** A 16px icon or status dot before the label in the list. */
|
|
7
|
+
icon?: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
interface FilterFieldBase<Row> {
|
|
10
|
+
/** The filter's key, and the row property `matchesFilters` reads unless `accessor` says otherwise. */
|
|
11
|
+
id: string;
|
|
12
|
+
/** The field's name in the menu and on the chip: "Status", "Amount". */
|
|
13
|
+
label: string;
|
|
14
|
+
/** A 16px icon in the "Filter" menu. */
|
|
15
|
+
icon?: React.ReactNode;
|
|
16
|
+
/** Reads the value to compare from a row, for `matchesFilters`. Defaults to `row[id]`. */
|
|
17
|
+
accessor?: (row: Row) => unknown;
|
|
18
|
+
}
|
|
19
|
+
/** A field from a fixed list: "Status is Active, Paused". Rows may hold one value or an array. */
|
|
20
|
+
export interface FilterSelectField<Row = any> extends FilterFieldBase<Row> {
|
|
21
|
+
kind: "select";
|
|
22
|
+
options: FilterOption[];
|
|
23
|
+
/** Show a search field over the options. Defaults to on from 8 options. */
|
|
24
|
+
searchable?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** Free text: "Customer contains “berg”". Case-insensitive. */
|
|
27
|
+
export interface FilterTextField<Row = any> extends FilterFieldBase<Row> {
|
|
28
|
+
kind: "text";
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
}
|
|
31
|
+
/** A number compared with an operator: "Amount ≥ 500". */
|
|
32
|
+
export interface FilterNumberField<Row = any> extends FilterFieldBase<Row> {
|
|
33
|
+
kind: "number";
|
|
34
|
+
min?: number;
|
|
35
|
+
max?: number;
|
|
36
|
+
step?: number;
|
|
37
|
+
/** How the number reads on the chip and in the field: `{ style: "currency", currency: "EUR" }`. */
|
|
38
|
+
format?: Intl.NumberFormatOptions;
|
|
39
|
+
}
|
|
40
|
+
/** A date range: "Due 1 Oct – 15 Oct 2026". Either end may be open. */
|
|
41
|
+
export interface FilterDateField<Row = any> extends FilterFieldBase<Row> {
|
|
42
|
+
kind: "date";
|
|
43
|
+
/**
|
|
44
|
+
* Replace the range `Calendar` with your own editor — presets, two months. It receives the
|
|
45
|
+
* range as ISO dates and a setter.
|
|
46
|
+
*/
|
|
47
|
+
editor?: (props: FilterDateEditorProps) => React.ReactNode;
|
|
48
|
+
}
|
|
49
|
+
export type FilterField<Row = any> = FilterSelectField<Row> | FilterTextField<Row> | FilterNumberField<Row> | FilterDateField<Row>;
|
|
50
|
+
/** A range of ISO dates (`"2026-10-01"`), both ends inclusive and optional. */
|
|
51
|
+
export interface FilterDateRange {
|
|
52
|
+
from?: string;
|
|
53
|
+
to?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface FilterDateEditorProps {
|
|
56
|
+
value: FilterDateRange;
|
|
57
|
+
onChange: (value: FilterDateRange) => void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* How a filter compares. `select`: `is`, `is-not`. `text`: `contains`, `does-not-contain`.
|
|
61
|
+
* `number`: `eq`, `neq`, `gt`, `gte`, `lt`, `lte`. `date`: `between`.
|
|
62
|
+
*/
|
|
63
|
+
export type FilterOperator = "is" | "is-not" | "contains" | "does-not-contain" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "between";
|
|
64
|
+
/** `select`: `string[]` · `text`: `string` · `number`: `number | null` · `date`: `FilterDateRange`. */
|
|
65
|
+
export type FilterValue = string[] | string | number | null | FilterDateRange;
|
|
66
|
+
/** One applied filter. A filter with no value yet (an empty list, "", null) matches every row. */
|
|
67
|
+
export interface Filter {
|
|
68
|
+
/** The `id` of its field. */
|
|
69
|
+
field: string;
|
|
70
|
+
operator: FilterOperator;
|
|
71
|
+
value: FilterValue;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Whether a row passes every filter — for filtering on the client:
|
|
75
|
+
* `rows.filter((row) => matchesFilters(row, filters, fields))`. Filters without a value yet, and
|
|
76
|
+
* filters on fields not in `fields`, are skipped. Text compares case-insensitively; dates compare
|
|
77
|
+
* as local days, from `Date`s, timestamps or ISO strings.
|
|
78
|
+
*/
|
|
79
|
+
export declare function matchesFilters<Row>(row: Row, filters: readonly Filter[], fields: readonly FilterField<Row>[]): boolean;
|
|
80
|
+
export interface FilterBarProps extends Omit<React.ComponentProps<"div">, "defaultValue" | "onChange"> {
|
|
81
|
+
/** What can be filtered on, in the order the "Filter" menu lists them. */
|
|
82
|
+
fields: readonly FilterField[];
|
|
83
|
+
/** The applied filters, controlled. Pair with `onValueChange`. */
|
|
84
|
+
value?: Filter[];
|
|
85
|
+
/** The applied filters on first render, uncontrolled. */
|
|
86
|
+
defaultValue?: Filter[];
|
|
87
|
+
/** Every change: a filter added, edited, removed or cleared. Filters still empty are included. */
|
|
88
|
+
onValueChange?: (value: Filter[]) => void;
|
|
89
|
+
/** `sm` (default) 30px chips for toolbars above tables; `default` 38px. */
|
|
90
|
+
size?: "sm" | "default";
|
|
91
|
+
/** The locale for dates and numbers on the chips. Defaults to the browser's. */
|
|
92
|
+
locale?: string;
|
|
93
|
+
/** The add button's label. Defaults to "Filter". */
|
|
94
|
+
addLabel?: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* FilterBar — faceted filters above a list or a table: each applied filter is a raised chip
|
|
98
|
+
* ("Status is Active, Paused") that opens a popover to edit it, with × to remove it; "Filter"
|
|
99
|
+
* opens a menu of the fields to add one, and "Clear all" removes them all.
|
|
100
|
+
*
|
|
101
|
+
* It holds filters, not rows: filter your data with `matchesFilters` on the client, or send the
|
|
102
|
+
* value to a server. The rule people break: a filter bar for one or two fixed choices — that is a
|
|
103
|
+
* `ToggleGroup` or a `Select` beside the table, always visible.
|
|
104
|
+
*/
|
|
105
|
+
export declare function FilterBar({ fields, value: valueProp, defaultValue, onValueChange, size, locale, addLabel, className, ...props }: FilterBarProps): React.JSX.Element;
|
|
106
|
+
export {};
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Combobox as BaseCombobox } from "@base-ui/react/combobox";
|
|
4
|
+
import { PlusIcon, XIcon } from "lucide-react";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { cn } from "../lib/cn.js";
|
|
7
|
+
import { Button } from "./button.js";
|
|
8
|
+
import { ButtonGroup } from "./button-group.js";
|
|
9
|
+
import { Calendar } from "./calendar.js";
|
|
10
|
+
import { ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from "./combobox.js";
|
|
11
|
+
import { Input } from "./input.js";
|
|
12
|
+
import { Menu, MenuContent, MenuItem, MenuTrigger } from "./menu.js";
|
|
13
|
+
import { NumberField } from "./number-field.js";
|
|
14
|
+
import { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from "./popover.js";
|
|
15
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
|
|
16
|
+
/* ── Matching ──────────────────────────────────────────────────────────────── */
|
|
17
|
+
const operators = {
|
|
18
|
+
select: [
|
|
19
|
+
{ value: "is", label: "is", symbol: "is" },
|
|
20
|
+
{ value: "is-not", label: "is not", symbol: "is not" },
|
|
21
|
+
],
|
|
22
|
+
text: [
|
|
23
|
+
{ value: "contains", label: "contains", symbol: "contains" },
|
|
24
|
+
{ value: "does-not-contain", label: "does not contain", symbol: "does not contain" },
|
|
25
|
+
],
|
|
26
|
+
number: [
|
|
27
|
+
{ value: "gte", label: "at least", symbol: "≥" },
|
|
28
|
+
{ value: "lte", label: "at most", symbol: "≤" },
|
|
29
|
+
{ value: "gt", label: "more than", symbol: ">" },
|
|
30
|
+
{ value: "lt", label: "less than", symbol: "<" },
|
|
31
|
+
{ value: "eq", label: "is", symbol: "=" },
|
|
32
|
+
{ value: "neq", label: "is not", symbol: "≠" },
|
|
33
|
+
],
|
|
34
|
+
date: [{ value: "between", label: "between", symbol: "" }],
|
|
35
|
+
};
|
|
36
|
+
function emptyValue(kind) {
|
|
37
|
+
return kind === "select" ? [] : kind === "text" ? "" : kind === "number" ? null : {};
|
|
38
|
+
}
|
|
39
|
+
/** An end of a range as an ISO day, or nothing: a value from a URL may be any text. */
|
|
40
|
+
const dayOf = (iso) => typeof iso === "string" && /^\d{4}-\d{2}-\d{2}/.test(iso) ? iso.slice(0, 10) : undefined;
|
|
41
|
+
/** A date filter's range with only real days in it, in order: "15 Oct – 1 Oct" is 1–15 Oct. */
|
|
42
|
+
function rangeOf(value) {
|
|
43
|
+
const range = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
44
|
+
const from = dayOf(range.from);
|
|
45
|
+
const to = dayOf(range.to);
|
|
46
|
+
return from && to && from > to ? { from: to, to: from } : { from, to };
|
|
47
|
+
}
|
|
48
|
+
/** True when a filter has nothing to compare yet, so it matches every row. */
|
|
49
|
+
function isEmpty(filter) {
|
|
50
|
+
const v = filter.value;
|
|
51
|
+
if (v == null)
|
|
52
|
+
return true;
|
|
53
|
+
if (Array.isArray(v))
|
|
54
|
+
return v.length === 0;
|
|
55
|
+
if (typeof v === "string")
|
|
56
|
+
return v.trim() === "";
|
|
57
|
+
if (typeof v === "number")
|
|
58
|
+
return Number.isNaN(v);
|
|
59
|
+
const { from, to } = rangeOf(v);
|
|
60
|
+
return !from && !to;
|
|
61
|
+
}
|
|
62
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
63
|
+
/** A row's date as a local ISO day, so it compares with the range as text. */
|
|
64
|
+
function isoDay(value) {
|
|
65
|
+
if (value instanceof Date) {
|
|
66
|
+
if (Number.isNaN(value.getTime()))
|
|
67
|
+
return null;
|
|
68
|
+
return `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(value.getDate())}`;
|
|
69
|
+
}
|
|
70
|
+
if (typeof value === "number")
|
|
71
|
+
return isoDay(new Date(value));
|
|
72
|
+
if (typeof value === "string" && /^\d{4}-\d{2}-\d{2}/.test(value))
|
|
73
|
+
return value.slice(0, 10);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
function matchOne(raw, filter) {
|
|
77
|
+
switch (filter.operator) {
|
|
78
|
+
case "is":
|
|
79
|
+
case "is-not": {
|
|
80
|
+
const wanted = filter.value;
|
|
81
|
+
const values = (Array.isArray(raw) ? raw : [raw]).map(String);
|
|
82
|
+
const hit = values.some((v) => wanted.includes(v));
|
|
83
|
+
return filter.operator === "is" ? hit : !hit;
|
|
84
|
+
}
|
|
85
|
+
case "contains":
|
|
86
|
+
case "does-not-contain": {
|
|
87
|
+
const hit = String(raw ?? "")
|
|
88
|
+
.toLowerCase()
|
|
89
|
+
.includes(filter.value.trim().toLowerCase());
|
|
90
|
+
return filter.operator === "contains" ? hit : !hit;
|
|
91
|
+
}
|
|
92
|
+
case "between": {
|
|
93
|
+
const day = isoDay(raw);
|
|
94
|
+
const { from, to } = rangeOf(filter.value);
|
|
95
|
+
if (!day)
|
|
96
|
+
return false;
|
|
97
|
+
return (!from || day >= from) && (!to || day <= to);
|
|
98
|
+
}
|
|
99
|
+
default: {
|
|
100
|
+
if (raw == null || raw === "")
|
|
101
|
+
return false;
|
|
102
|
+
const n = Number(raw);
|
|
103
|
+
const v = filter.value;
|
|
104
|
+
if (Number.isNaN(n))
|
|
105
|
+
return false;
|
|
106
|
+
if (filter.operator === "eq")
|
|
107
|
+
return n === v;
|
|
108
|
+
if (filter.operator === "neq")
|
|
109
|
+
return n !== v;
|
|
110
|
+
if (filter.operator === "gt")
|
|
111
|
+
return n > v;
|
|
112
|
+
if (filter.operator === "gte")
|
|
113
|
+
return n >= v;
|
|
114
|
+
if (filter.operator === "lt")
|
|
115
|
+
return n < v;
|
|
116
|
+
return n <= v;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Whether a row passes every filter — for filtering on the client:
|
|
122
|
+
* `rows.filter((row) => matchesFilters(row, filters, fields))`. Filters without a value yet, and
|
|
123
|
+
* filters on fields not in `fields`, are skipped. Text compares case-insensitively; dates compare
|
|
124
|
+
* as local days, from `Date`s, timestamps or ISO strings.
|
|
125
|
+
*/
|
|
126
|
+
export function matchesFilters(row, filters, fields) {
|
|
127
|
+
return filters.every((filter) => {
|
|
128
|
+
const field = fields.find((f) => f.id === filter.field);
|
|
129
|
+
if (!field || isEmpty(filter))
|
|
130
|
+
return true;
|
|
131
|
+
const raw = field.accessor ? field.accessor(row) : row[field.id];
|
|
132
|
+
return matchOne(raw, filter);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/* ── Chip text ─────────────────────────────────────────────────────────────── */
|
|
136
|
+
function formatDay(iso, locale) {
|
|
137
|
+
const [y, m, d] = iso.split("-").map(Number);
|
|
138
|
+
return new Intl.DateTimeFormat(locale, { day: "numeric", month: "short", year: "numeric" }).format(new Date(y, m - 1, d));
|
|
139
|
+
}
|
|
140
|
+
/** What the chip says after the field's name: the operator and the value, or null while empty. */
|
|
141
|
+
function describe(filter, field, locale) {
|
|
142
|
+
if (isEmpty(filter))
|
|
143
|
+
return null;
|
|
144
|
+
const op = operators[field.kind].find((o) => o.value === filter.operator);
|
|
145
|
+
switch (field.kind) {
|
|
146
|
+
case "select": {
|
|
147
|
+
// In the options' order, not the order they were picked in; a value no option has (from a
|
|
148
|
+
// URL, or an option since removed) as it is, after them.
|
|
149
|
+
const picked = new Set(filter.value);
|
|
150
|
+
const known = new Set(field.options.map((o) => o.value));
|
|
151
|
+
const labels = [
|
|
152
|
+
...field.options.filter((o) => picked.has(o.value)).map((o) => o.label),
|
|
153
|
+
...[...picked].filter((v) => !known.has(v)).map(String),
|
|
154
|
+
];
|
|
155
|
+
const shown = labels.length > 2 ? `${labels.slice(0, 2).join(", ")} +${labels.length - 2}` : labels.join(", ");
|
|
156
|
+
return [op?.symbol ?? "is", shown];
|
|
157
|
+
}
|
|
158
|
+
case "text":
|
|
159
|
+
return [op?.symbol ?? "contains", `“${filter.value.trim()}”`];
|
|
160
|
+
case "number":
|
|
161
|
+
return [op?.symbol ?? "=", new Intl.NumberFormat(locale, field.format).format(filter.value)];
|
|
162
|
+
case "date": {
|
|
163
|
+
const { from, to } = rangeOf(filter.value);
|
|
164
|
+
if (from && to)
|
|
165
|
+
return ["", `${formatDay(from, locale)} – ${formatDay(to, locale)}`];
|
|
166
|
+
return from ? ["from", formatDay(from, locale)] : ["until", formatDay(to, locale)];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function OperatorSelect({ field, filter, onChange }) {
|
|
171
|
+
const ops = operators[field.kind];
|
|
172
|
+
if (ops.length < 2)
|
|
173
|
+
return null;
|
|
174
|
+
return (_jsxs(Select, { value: filter.operator, onValueChange: (operator) => operator && onChange({ ...filter, operator: operator }), items: ops.map((o) => ({ value: o.value, label: o.label })), children: [_jsx(SelectTrigger, { size: "sm", "aria-label": `${field.label}: condition`, className: "w-auto min-w-0 gap-1.5", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: ops.map((o) => (_jsx(SelectItem, { value: o.value, children: o.label }, o.value))) })] }));
|
|
175
|
+
}
|
|
176
|
+
/** The options as an inline Combobox: a search field over them when the list is long, checks for the picked. */
|
|
177
|
+
function SelectEditor({ field, filter, onChange }) {
|
|
178
|
+
const searchable = field.searchable ?? field.options.length >= 8;
|
|
179
|
+
const byValue = React.useMemo(() => new Map(field.options.map((o) => [o.value, o])), [field.options]);
|
|
180
|
+
return (_jsxs(BaseCombobox.Root, { inline: true, open: true, multiple: true, items: field.options.map((o) => o.value), value: filter.value, onValueChange: (value) => onChange({ ...filter, value }), itemToStringLabel: (value) => byValue.get(value)?.label ?? value, autoHighlight: true, children: [searchable ? (_jsx(ComboboxInput, { size: "sm", showTrigger: false, placeholder: `Search ${field.label.toLowerCase()}…`, "aria-label": `Search ${field.label.toLowerCase()}` })) : (_jsx(BaseCombobox.Input, { "data-slot": "filter-bar-list-focus", "aria-label": field.label, className: "sr-only", readOnly: true })), _jsxs(ComboboxEmpty, { children: ["No ", field.label.toLowerCase(), " matches."] }), _jsx(ComboboxList, { children: (value) => {
|
|
181
|
+
const option = byValue.get(value);
|
|
182
|
+
return (_jsx(ComboboxItem, { value: value, children: _jsxs("span", { className: "flex items-center gap-2.5 [&_svg]:size-4 [&_svg]:text-muted-foreground", children: [option.icon, option.label] }) }, value));
|
|
183
|
+
} })] }));
|
|
184
|
+
}
|
|
185
|
+
function TextEditor({ field, filter, onChange, onDone }) {
|
|
186
|
+
return (_jsx(Input, { size: "sm", value: filter.value, onValueChange: (value) => onChange({ ...filter, value }), onKeyDown: (event) => event.key === "Enter" && onDone(), placeholder: field.placeholder ?? `${field.label}…`, "aria-label": field.label }));
|
|
187
|
+
}
|
|
188
|
+
function NumberEditor({ field, filter, onChange, onDone }) {
|
|
189
|
+
// NumberField puts its `id` on the input; a hidden label names it (the popover's title shows it).
|
|
190
|
+
const id = React.useId();
|
|
191
|
+
return (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: id, className: "sr-only", children: field.label }), _jsx(NumberField, { id: id, size: "sm", steppers: "stacked", value: filter.value, onValueChange: (value) => onChange({ ...filter, value }), onKeyDown: (event) => event.key === "Enter" && onDone(), min: field.min, max: field.max, step: field.step, format: field.format, className: "w-full [&>[data-slot]]:w-full" })] }));
|
|
192
|
+
}
|
|
193
|
+
/** An ISO day as a local date, and back: the range is stored as text, the Calendar takes dates. */
|
|
194
|
+
const toDate = (iso) => {
|
|
195
|
+
if (!iso)
|
|
196
|
+
return undefined;
|
|
197
|
+
const [y, m, d] = iso.split("-").map(Number);
|
|
198
|
+
return new Date(y, m - 1, d);
|
|
199
|
+
};
|
|
200
|
+
const toIso = (date) => (date ? (isoDay(date) ?? undefined) : undefined);
|
|
201
|
+
function DateEditor({ field, filter, onChange }) {
|
|
202
|
+
const range = rangeOf(filter.value);
|
|
203
|
+
const set = (next) => onChange({ ...filter, value: { from: next.from || undefined, to: next.to || undefined } });
|
|
204
|
+
if (field.editor)
|
|
205
|
+
return _jsx(_Fragment, { children: field.editor({ value: range, onChange: set }) });
|
|
206
|
+
return (_jsx(Calendar, { mode: "range", defaultMonth: toDate(range.from ?? range.to), selected: { from: toDate(range.from), to: toDate(range.to) }, onSelect: (next) => set({ from: toIso(next?.from), to: toIso(next?.to) }), className: "p-0" }));
|
|
207
|
+
}
|
|
208
|
+
function Editor(props) {
|
|
209
|
+
const { field } = props;
|
|
210
|
+
if (field.kind === "select")
|
|
211
|
+
return _jsx(SelectEditor, { ...props, field: field });
|
|
212
|
+
if (field.kind === "text")
|
|
213
|
+
return _jsx(TextEditor, { ...props, field: field });
|
|
214
|
+
if (field.kind === "number")
|
|
215
|
+
return _jsx(NumberEditor, { ...props, field: field });
|
|
216
|
+
return _jsx(DateEditor, { ...props, field: field });
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* FilterBar — faceted filters above a list or a table: each applied filter is a raised chip
|
|
220
|
+
* ("Status is Active, Paused") that opens a popover to edit it, with × to remove it; "Filter"
|
|
221
|
+
* opens a menu of the fields to add one, and "Clear all" removes them all.
|
|
222
|
+
*
|
|
223
|
+
* It holds filters, not rows: filter your data with `matchesFilters` on the client, or send the
|
|
224
|
+
* value to a server. The rule people break: a filter bar for one or two fixed choices — that is a
|
|
225
|
+
* `ToggleGroup` or a `Select` beside the table, always visible.
|
|
226
|
+
*/
|
|
227
|
+
export function FilterBar({ fields, value: valueProp, defaultValue = [], onValueChange, size = "sm", locale, addLabel = "Filter", className, ...props }) {
|
|
228
|
+
const [inner, setInner] = React.useState(defaultValue);
|
|
229
|
+
const value = valueProp ?? inner;
|
|
230
|
+
const setValue = (next) => {
|
|
231
|
+
if (valueProp === undefined)
|
|
232
|
+
setInner(next);
|
|
233
|
+
onValueChange?.(next);
|
|
234
|
+
};
|
|
235
|
+
const [open, setOpen] = React.useState(null);
|
|
236
|
+
const pending = React.useRef(null);
|
|
237
|
+
const addRef = React.useRef(null);
|
|
238
|
+
const fieldOf = (id) => fields.find((f) => f.id === id);
|
|
239
|
+
const update = (filter) => setValue(value.map((f) => (f.field === filter.field ? filter : f)));
|
|
240
|
+
const remove = (id) => {
|
|
241
|
+
setValue(value.filter((f) => f.field !== id));
|
|
242
|
+
addRef.current?.focus();
|
|
243
|
+
};
|
|
244
|
+
const add = (field) => {
|
|
245
|
+
if (!value.some((f) => f.field === field.id))
|
|
246
|
+
setValue([
|
|
247
|
+
...value,
|
|
248
|
+
{ field: field.id, operator: operators[field.kind][0].value, value: emptyValue(field.kind) },
|
|
249
|
+
]);
|
|
250
|
+
// Open its editor once the menu has closed and handed the focus back.
|
|
251
|
+
pending.current = field.id;
|
|
252
|
+
};
|
|
253
|
+
const onOpenChange = (id, next) => {
|
|
254
|
+
setOpen(next ? id : null);
|
|
255
|
+
// A filter closed without a value is not kept.
|
|
256
|
+
const filter = value.find((f) => f.field === id);
|
|
257
|
+
if (!next && filter && isEmpty(filter))
|
|
258
|
+
setValue(value.filter((f) => f.field !== id));
|
|
259
|
+
};
|
|
260
|
+
const chipSize = size === "sm" ? "sm" : "default";
|
|
261
|
+
const applied = value.filter((f) => fieldOf(f.field));
|
|
262
|
+
return (_jsxs("div", { role: "group", "aria-label": "Filters", "data-slot": "filter-bar", "data-size": size, className: cn("flex flex-wrap items-center gap-2 font-body", className), ...props, children: [applied.map((filter) => {
|
|
263
|
+
const field = fieldOf(filter.field);
|
|
264
|
+
const text = describe(filter, field, locale);
|
|
265
|
+
return (_jsxs(ButtonGroup, { "data-slot": "filter-bar-chip", "aria-label": `${field.label} filter`,
|
|
266
|
+
// In a narrow bar a long value ends in an ellipsis; the chip never runs past the bar.
|
|
267
|
+
className: "max-w-full min-w-0", children: [_jsxs(Popover, { open: open === filter.field, onOpenChange: (next) => onOpenChange(filter.field, next), children: [_jsxs(PopoverTrigger, { render: _jsx(Button, { variant: "secondary", size: chipSize }), "data-slot": "filter-bar-chip-trigger", className: "max-w-[22rem] min-w-0 shrink gap-1.5 font-normal", children: [_jsx("span", { className: "shrink-0 text-muted-foreground", children: field.label }), text ? (_jsxs(_Fragment, { children: [text[0] && _jsx("span", { className: "shrink-0 text-muted-foreground", children: text[0] }), _jsx("span", { className: "truncate font-medium text-foreground", children: text[1] })] })) : (_jsx("span", { className: "text-muted-foreground", children: "\u2026" }))] }), _jsxs(PopoverContent, { "data-slot": "filter-bar-editor", align: "start", sideOffset: 6, className: cn("gap-2 p-2", field.kind === "date" ? "w-auto" : "w-64"),
|
|
268
|
+
// Straight to the value — the search, the list, the text, the number, the calendar's
|
|
269
|
+
// day — not the condition.
|
|
270
|
+
initialFocus: () => {
|
|
271
|
+
const editor = `[data-filter-editor="${CSS.escape(filter.field)}"]`;
|
|
272
|
+
return (document.querySelector(`${editor} input:not([type=hidden]), ${editor} [data-slot=calendar-day-button][tabindex="0"]`) ?? true);
|
|
273
|
+
},
|
|
274
|
+
// Back to the chip, or to "Filter" for a filter that is not kept — unless the focus
|
|
275
|
+
// has moved on: into another chip's editor, or to a field elsewhere that was clicked.
|
|
276
|
+
finalFocus: () => {
|
|
277
|
+
const active = document.activeElement;
|
|
278
|
+
const own = active
|
|
279
|
+
?.closest('[data-slot="filter-bar-editor"]')
|
|
280
|
+
?.querySelector(`[data-filter-editor="${CSS.escape(filter.field)}"]`);
|
|
281
|
+
if (active && active !== document.body && !own)
|
|
282
|
+
return false;
|
|
283
|
+
return isEmpty(filter) ? addRef.current : true;
|
|
284
|
+
}, children: [_jsxs("div", { className: "flex min-h-(--control-h-sm) items-center justify-between gap-2 pl-1", children: [_jsx(PopoverTitle, { className: "eyebrow text-[11px]", children: field.label }), _jsx(OperatorSelect, { field: field, filter: filter, onChange: update })] }), _jsx("div", { "data-filter-editor": filter.field,
|
|
285
|
+
// The options scroll within 15rem, and within the room below the chip less the header.
|
|
286
|
+
className: "flex flex-col gap-1 [&_[data-slot=scroll-area]]:max-h-[min(15rem,calc(var(--available-height)-6rem))]", children: _jsx(Editor, { field: field, filter: filter, onChange: update, onDone: () => onOpenChange(filter.field, false) }) })] })] }), _jsx(Button, { variant: "secondary", size: chipSize, "data-slot": "filter-bar-chip-remove", "aria-label": `Remove ${field.label} filter`, onClick: () => remove(filter.field), className: cn("text-muted-foreground hover:text-foreground", size === "sm" ? "px-2" : "px-2.5"), children: _jsx(XIcon, { className: "size-3.5" }) })] }, filter.field));
|
|
287
|
+
}), _jsxs(Menu, { onOpenChangeComplete: (next) => {
|
|
288
|
+
if (next || !pending.current)
|
|
289
|
+
return;
|
|
290
|
+
setOpen(pending.current);
|
|
291
|
+
pending.current = null;
|
|
292
|
+
}, children: [_jsxs(MenuTrigger, { ref: addRef, render: _jsx(Button, { variant: "ghost", size: chipSize }), "data-slot": "filter-bar-add", className: "text-foreground-soft", children: [_jsx(PlusIcon, {}), addLabel] }), _jsx(MenuContent, { className: "min-w-48", children: fields.map((field) => (_jsxs(MenuItem, { onClick: () => add(field), children: [field.icon, field.label] }, field.id))) })] }), applied.length > 0 && (_jsx(Button, { variant: "ghost", size: chipSize, "data-slot": "filter-bar-clear", onClick: () => {
|
|
293
|
+
setValue([]);
|
|
294
|
+
addRef.current?.focus();
|
|
295
|
+
}, className: "text-muted-foreground", children: "Clear all" }))] }));
|
|
296
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Form as BaseForm } from "@base-ui/react/form";
|
|
2
|
+
import type * as React from "react";
|
|
3
|
+
/**
|
|
4
|
+
* Form — a native `<form>` that collects `Field` validation and shows server errors.
|
|
5
|
+
*
|
|
6
|
+
* Fields stack with 20px between them. Pass `errors` (keyed by each `Field`'s `name`) to show
|
|
7
|
+
* errors returned by the server, and use `onFormSubmit` to receive the values as an object.
|
|
8
|
+
* End the form with `FormActions`, which puts the submit button on the right.
|
|
9
|
+
* The rule people break: validating only on the server — add `required`, `type` and
|
|
10
|
+
* `pattern` to the controls so people see what is wrong before they submit.
|
|
11
|
+
*/
|
|
12
|
+
export declare function Form<FormValues extends Record<string, any> = Record<string, any>>({ className, ...props }: BaseForm.Props<FormValues>): React.JSX.Element;
|
|
13
|
+
declare const actionAlign: {
|
|
14
|
+
/** Actions on the right, the primary last. The default. */
|
|
15
|
+
readonly end: "justify-end";
|
|
16
|
+
/** A note or a quiet link on the left, the actions on the right. */
|
|
17
|
+
readonly between: "justify-between";
|
|
18
|
+
/** Actions on the left — only for forms that read as a single column of steps. */
|
|
19
|
+
readonly start: "justify-start";
|
|
20
|
+
};
|
|
21
|
+
export interface FormActionsProps extends React.ComponentProps<"div"> {
|
|
22
|
+
/** `end` (default) puts the actions on the right; `between` adds a note on the left. */
|
|
23
|
+
align?: keyof typeof actionAlign;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* FormActions — the footer row of a form: the submit button on the right, any secondary
|
|
27
|
+
* action (Cancel, Back) to its left, and with `align="between"` a short note at the start.
|
|
28
|
+
* It sits 8px further from the last field than the fields sit from each other.
|
|
29
|
+
*
|
|
30
|
+
* The rule people break: more than one primary — Cancel and Back are `secondary` or `ghost`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function FormActions({ align, className, ...props }: FormActionsProps): React.JSX.Element;
|
|
33
|
+
export {};
|