@robert-stackflow/oneui 0.0.0-stage → 0.1.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/README.md +45 -2
- package/assets/LUCIDE-LICENSE.txt +43 -0
- package/assets/character-metadata.json +1 -0
- package/assets/emoji.json +1 -0
- package/assets/icon-catalog.json +1 -0
- package/assets/symbols.json +1 -0
- package/components/Accessibility.module.css +8 -0
- package/components/Accordion.d.ts +7 -0
- package/components/Accordion.js +41 -0
- package/components/Accordion.module.css +38 -0
- package/components/Alert.d.ts +9 -0
- package/components/Alert.js +42 -0
- package/components/Alert.module.css +56 -0
- package/components/AppShell.d.ts +30 -0
- package/components/AppShell.js +152 -0
- package/components/AppShell.module.css +239 -0
- package/components/AppearanceSettings.d.ts +7 -0
- package/components/AppearanceSettings.js +201 -0
- package/components/AppearanceSettings.module.css +32 -0
- package/components/Avatar.d.ts +14 -0
- package/components/Avatar.js +69 -0
- package/components/Avatar.module.css +70 -0
- package/components/AvatarGroup.d.ts +15 -0
- package/components/AvatarGroup.js +115 -0
- package/components/AvatarGroup.module.css +54 -0
- package/components/Badge.d.ts +5 -0
- package/components/Badge.js +11 -0
- package/components/Badge.module.css +30 -0
- package/components/BlockedTab.d.ts +4 -0
- package/components/BlockedTab.js +10 -0
- package/components/Breadcrumb.d.ts +16 -0
- package/components/Breadcrumb.js +157 -0
- package/components/Breadcrumb.module.css +97 -0
- package/components/Button.d.ts +6 -0
- package/components/Button.js +29 -0
- package/components/Button.module.css +79 -0
- package/components/Calendar.d.ts +10 -0
- package/components/Calendar.js +260 -0
- package/components/Calendar.module.css +106 -0
- package/components/Card.d.ts +7 -0
- package/components/Card.js +19 -0
- package/components/Card.module.css +28 -0
- package/components/Cascader.d.ts +14 -0
- package/components/Cascader.js +296 -0
- package/components/CatalogIcon.d.ts +3 -0
- package/components/CatalogIcon.js +11 -0
- package/components/CharacterPicker.d.ts +15 -0
- package/components/CharacterPicker.js +200 -0
- package/components/Checkbox.d.ts +12 -0
- package/components/Checkbox.js +82 -0
- package/components/Checkbox.module.css +95 -0
- package/components/ColorField.d.ts +6 -0
- package/components/ColorField.js +61 -0
- package/components/ColorField.module.css +15 -0
- package/components/ColorPicker.d.ts +5 -0
- package/components/ColorPicker.js +188 -0
- package/components/ColorPicker.module.css +90 -0
- package/components/Combobox.d.ts +11 -0
- package/components/Combobox.js +252 -0
- package/components/Combobox.module.css +26 -0
- package/components/CommandPalette.d.ts +25 -0
- package/components/CommandPalette.js +269 -0
- package/components/CommandPalette.module.css +49 -0
- package/components/ContextMenu.d.ts +9 -0
- package/components/ContextMenu.js +363 -0
- package/components/ContextMenu.module.css +42 -0
- package/components/ContextMenuPanel.d.ts +22 -0
- package/components/ContextMenuPanel.js +155 -0
- package/components/ContributionCalendar.d.ts +18 -0
- package/components/ContributionCalendar.js +201 -0
- package/components/ContributionCalendar.module.css +114 -0
- package/components/ContributionCell.d.ts +11 -0
- package/components/ContributionCell.js +41 -0
- package/components/Control.module.css +73 -0
- package/components/DataTable.d.ts +49 -0
- package/components/DataTable.js +220 -0
- package/components/DataTable.module.css +112 -0
- package/components/DatePicker.d.ts +15 -0
- package/components/DatePicker.js +186 -0
- package/components/DatePicker.module.css +85 -0
- package/components/DateRangePicker.d.ts +9 -0
- package/components/DateRangePicker.js +168 -0
- package/components/Descriptions.d.ts +21 -0
- package/components/Descriptions.js +162 -0
- package/components/Descriptions.module.css +117 -0
- package/components/Dialog.d.ts +9 -0
- package/components/Dialog.js +112 -0
- package/components/Dialog.module.css +71 -0
- package/components/DisclosureChevron.d.ts +3 -0
- package/components/DisclosureChevron.js +17 -0
- package/components/DisclosureChevron.module.css +17 -0
- package/components/Divider.d.ts +5 -0
- package/components/Divider.js +24 -0
- package/components/Divider.module.css +19 -0
- package/components/Drawer.d.ts +18 -0
- package/components/Drawer.js +145 -0
- package/components/Drawer.module.css +109 -0
- package/components/EmojiPicker.d.ts +6 -0
- package/components/EmojiPicker.js +19 -0
- package/components/EmptyState.d.ts +8 -0
- package/components/EmptyState.js +20 -0
- package/components/EmptyState.module.css +30 -0
- package/components/FieldLabel.d.ts +8 -0
- package/components/FieldLabel.js +20 -0
- package/components/FieldMessages.d.ts +5 -0
- package/components/FieldMessages.js +15 -0
- package/components/FileDropOverlay.d.ts +5 -0
- package/components/FileDropOverlay.js +26 -0
- package/components/FileDropOverlay.module.css +55 -0
- package/components/FileDropZone.d.ts +15 -0
- package/components/FileDropZone.js +113 -0
- package/components/FileDropZone.module.css +6 -0
- package/components/FilePicker.d.ts +10 -0
- package/components/FilePicker.js +59 -0
- package/components/FileSelectionFeedback.d.ts +5 -0
- package/components/FileSelectionFeedback.js +23 -0
- package/components/FileSelectionFeedback.module.css +14 -0
- package/components/FileTree.d.ts +13 -0
- package/components/FileTree.js +125 -0
- package/components/FileTree.module.css +66 -0
- package/components/Form.d.ts +7 -0
- package/components/Form.js +26 -0
- package/components/Form.module.css +7 -0
- package/components/FormErrorSummary.d.ts +6 -0
- package/components/FormErrorSummary.js +27 -0
- package/components/FormErrorSummary.module.css +27 -0
- package/components/FormField.d.ts +9 -0
- package/components/FormField.js +59 -0
- package/components/FormField.module.css +85 -0
- package/components/FormGroup.d.ts +9 -0
- package/components/FormGroup.js +32 -0
- package/components/HierarchyPicker.module.css +146 -0
- package/components/IconButton.d.ts +7 -0
- package/components/IconButton.js +30 -0
- package/components/IconButton.module.css +39 -0
- package/components/IconPicker.d.ts +6 -0
- package/components/IconPicker.js +111 -0
- package/components/Indicator.d.ts +18 -0
- package/components/Indicator.js +97 -0
- package/components/Indicator.module.css +83 -0
- package/components/Input.d.ts +7 -0
- package/components/Input.js +29 -0
- package/components/Input.module.css +23 -0
- package/components/LoadingOverlay.d.ts +6 -0
- package/components/LoadingOverlay.js +16 -0
- package/components/LoadingOverlay.module.css +22 -0
- package/components/LoadingState.d.ts +5 -0
- package/components/LoadingState.js +29 -0
- package/components/LoadingState.module.css +14 -0
- package/components/Menu.d.ts +11 -0
- package/components/Menu.js +82 -0
- package/components/MenuItem.d.ts +14 -0
- package/components/MenuItem.js +49 -0
- package/components/MenuItem.module.css +163 -0
- package/components/MenuItemContent.d.ts +8 -0
- package/components/MenuItemContent.js +19 -0
- package/components/MultiSelect.d.ts +12 -0
- package/components/MultiSelect.js +161 -0
- package/components/MultiSelect.module.css +61 -0
- package/components/NumberInput.d.ts +12 -0
- package/components/NumberInput.js +113 -0
- package/components/NumberInput.module.css +33 -0
- package/components/Page.d.ts +7 -0
- package/components/Page.js +22 -0
- package/components/Page.module.css +44 -0
- package/components/Pagination.d.ts +11 -0
- package/components/Pagination.js +160 -0
- package/components/Pagination.module.css +70 -0
- package/components/PasswordField.d.ts +9 -0
- package/components/PasswordField.js +101 -0
- package/components/PasswordField.module.css +64 -0
- package/components/Picker.module.css +52 -0
- package/components/PinInput.d.ts +13 -0
- package/components/PinInput.js +172 -0
- package/components/PinInput.module.css +72 -0
- package/components/Placeholder.d.ts +31 -0
- package/components/Placeholder.js +36 -0
- package/components/Popconfirm.d.ts +17 -0
- package/components/Popconfirm.js +159 -0
- package/components/Popconfirm.module.css +49 -0
- package/components/Popover.d.ts +13 -0
- package/components/Popover.js +150 -0
- package/components/Popover.module.css +16 -0
- package/components/Progress.d.ts +5 -0
- package/components/Progress.js +31 -0
- package/components/Progress.module.css +33 -0
- package/components/RadioGroup.d.ts +15 -0
- package/components/RadioGroup.js +73 -0
- package/components/RadioGroup.module.css +87 -0
- package/components/RangeSlider.d.ts +22 -0
- package/components/RangeSlider.js +278 -0
- package/components/RangeSlider.module.css +141 -0
- package/components/ResizablePanel.d.ts +21 -0
- package/components/ResizablePanel.js +219 -0
- package/components/ResizablePanel.module.css +101 -0
- package/components/SearchField.d.ts +11 -0
- package/components/SearchField.js +66 -0
- package/components/SearchField.module.css +37 -0
- package/components/Section.d.ts +6 -0
- package/components/Section.js +18 -0
- package/components/Section.module.css +14 -0
- package/components/Segmented.d.ts +11 -0
- package/components/Segmented.js +77 -0
- package/components/Segmented.module.css +82 -0
- package/components/Select.d.ts +11 -0
- package/components/Select.js +171 -0
- package/components/Select.module.css +21 -0
- package/components/SelectOptionContent.d.ts +5 -0
- package/components/SelectOptionContent.js +20 -0
- package/components/SelectOptionContent.module.css +7 -0
- package/components/SelectTrigger.d.ts +5 -0
- package/components/SelectTrigger.js +32 -0
- package/components/SelectTrigger.module.css +24 -0
- package/components/SettingRow.d.ts +7 -0
- package/components/SettingRow.js +19 -0
- package/components/SettingRow.module.css +44 -0
- package/components/SettingsLayout.d.ts +9 -0
- package/components/SettingsLayout.js +45 -0
- package/components/SettingsLayout.module.css +48 -0
- package/components/ShortcutInput.d.ts +8 -0
- package/components/ShortcutInput.js +131 -0
- package/components/ShortcutInput.module.css +39 -0
- package/components/Skeleton.d.ts +5 -0
- package/components/Skeleton.js +19 -0
- package/components/Skeleton.module.css +27 -0
- package/components/SkeletonRows.d.ts +4 -0
- package/components/SkeletonRows.js +19 -0
- package/components/SkeletonRows.module.css +19 -0
- package/components/SkinTonePicker.d.ts +4 -0
- package/components/SkinTonePicker.js +43 -0
- package/components/SkinTonePicker.module.css +50 -0
- package/components/Slider.d.ts +10 -0
- package/components/Slider.js +40 -0
- package/components/Slider.module.css +19 -0
- package/components/Spinner.d.ts +6 -0
- package/components/Spinner.js +31 -0
- package/components/Spinner.module.css +57 -0
- package/components/SplitButton.d.ts +17 -0
- package/components/SplitButton.js +102 -0
- package/components/SplitButton.module.css +56 -0
- package/components/Statistic.d.ts +22 -0
- package/components/Statistic.js +102 -0
- package/components/Statistic.module.css +55 -0
- package/components/Steps.d.ts +19 -0
- package/components/Steps.js +102 -0
- package/components/Steps.module.css +176 -0
- package/components/Switch.d.ts +6 -0
- package/components/Switch.js +25 -0
- package/components/Switch.module.css +56 -0
- package/components/SymbolPicker.d.ts +6 -0
- package/components/SymbolPicker.js +18 -0
- package/components/Tab.module.css +145 -0
- package/components/TabList.d.ts +11 -0
- package/components/TabList.js +51 -0
- package/components/Table.d.ts +12 -0
- package/components/Table.js +20 -0
- package/components/Table.module.css +48 -0
- package/components/TableColumnFilter.d.ts +6 -0
- package/components/TableColumnFilter.js +76 -0
- package/components/TableColumnVisibility.d.ts +11 -0
- package/components/TableColumnVisibility.js +76 -0
- package/components/Tabs.d.ts +13 -0
- package/components/Tabs.js +49 -0
- package/components/Tabs.module.css +3 -0
- package/components/TagInput.d.ts +11 -0
- package/components/TagInput.js +154 -0
- package/components/TagInput.module.css +64 -0
- package/components/Textarea.d.ts +6 -0
- package/components/Textarea.js +24 -0
- package/components/Textarea.module.css +9 -0
- package/components/ThemePicker.d.ts +6 -0
- package/components/ThemePicker.js +78 -0
- package/components/ThemePicker.module.css +178 -0
- package/components/ThemeProvider.d.ts +11 -0
- package/components/ThemeProvider.js +80 -0
- package/components/ThemeStylePicker.d.ts +5 -0
- package/components/ThemeStylePicker.js +22 -0
- package/components/TimeColumns.d.ts +6 -0
- package/components/TimeColumns.js +55 -0
- package/components/TimeColumns.module.css +47 -0
- package/components/Timeline.d.ts +26 -0
- package/components/Timeline.js +131 -0
- package/components/Timeline.module.css +202 -0
- package/components/Toast.d.ts +6 -0
- package/components/Toast.js +181 -0
- package/components/Toast.module.css +175 -0
- package/components/ToastProvider.d.ts +35 -0
- package/components/ToastProvider.js +47 -0
- package/components/Tooltip.d.ts +10 -0
- package/components/Tooltip.js +169 -0
- package/components/Tooltip.module.css +53 -0
- package/components/TreeSelect.d.ts +23 -0
- package/components/TreeSelect.js +309 -0
- package/components/UIProvider.d.ts +10 -0
- package/components/UIProvider.js +20 -0
- package/components/UnderlinedTab.d.ts +2 -0
- package/components/UnderlinedTab.js +8 -0
- package/components/Upload.d.ts +22 -0
- package/components/Upload.js +165 -0
- package/components/Upload.module.css +36 -0
- package/components/UploadList.d.ts +9 -0
- package/components/UploadList.js +14 -0
- package/components/UploadList.module.css +130 -0
- package/components/UploadListItem.d.ts +13 -0
- package/components/UploadListItem.js +122 -0
- package/components/VirtualPickerList.d.ts +25 -0
- package/components/VirtualPickerList.js +269 -0
- package/components/VirtualPickerList.module.css +89 -0
- package/components/appearance.d.ts +19 -0
- package/components/appearance.js +60 -0
- package/components/characterCatalog.d.ts +9 -0
- package/components/characterCatalog.js +55 -0
- package/components/color.d.ts +7 -0
- package/components/color.js +18 -0
- package/components/contribution.d.ts +57 -0
- package/components/contribution.js +86 -0
- package/components/dateConstraints.d.ts +13 -0
- package/components/dateConstraints.js +44 -0
- package/components/field.d.ts +58 -0
- package/components/field.js +57 -0
- package/components/fileSelection.d.ts +21 -0
- package/components/fileSelection.js +43 -0
- package/components/hierarchy.d.ts +22 -0
- package/components/hierarchy.js +33 -0
- package/components/iconCatalog.d.ts +13 -0
- package/components/iconCatalog.js +80 -0
- package/components/index.d.ts +150 -0
- package/components/index.js +219 -0
- package/components/menuFocus.d.ts +7 -0
- package/components/menuFocus.js +21 -0
- package/components/menuPointer.d.ts +6 -0
- package/components/menuPointer.js +13 -0
- package/components/menuTypes.d.ts +24 -0
- package/components/menuTypes.js +0 -0
- package/components/motion.d.ts +9 -0
- package/components/motion.js +82 -0
- package/components/rangeMath.d.ts +12 -0
- package/components/rangeMath.js +30 -0
- package/components/surfacePortal.d.ts +13 -0
- package/components/surfacePortal.js +22 -0
- package/components/tooltipState.d.ts +5 -0
- package/components/tooltipState.js +48 -0
- package/components/types.d.ts +9 -0
- package/components/types.js +0 -0
- package/components/uploadTypes.d.ts +21 -0
- package/components/uploadTypes.js +0 -0
- package/components/useFormState.d.ts +51 -0
- package/components/useFormState.js +218 -0
- package/components/useHierarchy.d.ts +8 -0
- package/components/useHierarchy.js +80 -0
- package/components/useMenuLayers.d.ts +17 -0
- package/components/useMenuLayers.js +23 -0
- package/components/useModalScrollLock.d.ts +1 -0
- package/components/useModalScrollLock.js +18 -0
- package/components/usePopover.d.ts +8 -0
- package/components/usePopover.js +22 -0
- package/components/useTabIndicator.d.ts +12 -0
- package/components/useTabIndicator.js +63 -0
- package/components/useUploadQueue.d.ts +20 -0
- package/components/useUploadQueue.js +175 -0
- package/package.json +783 -3
- package/styles/base.css +189 -0
- package/styles/blue.css +254 -0
- package/styles/desktop.css +2 -0
- package/styles/minimal.css +337 -0
- package/styles/themes.css +2 -0
- package/styles/web.css +2 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { FileDropOverlay } from "./FileDropOverlay.js";
|
|
4
|
+
import s from "./FileDropZone.module.css";
|
|
5
|
+
import {
|
|
6
|
+
validateFiles
|
|
7
|
+
} from "./fileSelection.js";
|
|
8
|
+
import { FileSelectionFeedback } from "./FileSelectionFeedback.js";
|
|
9
|
+
function FileDropZone({
|
|
10
|
+
children,
|
|
11
|
+
onFiles,
|
|
12
|
+
title = "\u6DFB\u52A0\u6587\u4EF6",
|
|
13
|
+
description,
|
|
14
|
+
disabled = false,
|
|
15
|
+
label = "\u6587\u4EF6\u62D6\u62FD\u533A\u57DF",
|
|
16
|
+
className = "",
|
|
17
|
+
onReject,
|
|
18
|
+
onValidation,
|
|
19
|
+
showErrors = true,
|
|
20
|
+
...constraints
|
|
21
|
+
}) {
|
|
22
|
+
const [dragging, setDragging] = useState(false), [rejections, setRejections] = useState([]), depth = useRef(0);
|
|
23
|
+
const clear = () => {
|
|
24
|
+
depth.current = 0;
|
|
25
|
+
setDragging(false);
|
|
26
|
+
};
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (disabled) clear();
|
|
29
|
+
}, [disabled]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const key = (e) => {
|
|
32
|
+
if (e.key === "Escape") clear();
|
|
33
|
+
};
|
|
34
|
+
window.addEventListener("blur", clear);
|
|
35
|
+
window.addEventListener("dragend", clear);
|
|
36
|
+
window.addEventListener("drop", clear);
|
|
37
|
+
window.addEventListener("keydown", key);
|
|
38
|
+
return () => {
|
|
39
|
+
window.removeEventListener("blur", clear);
|
|
40
|
+
window.removeEventListener("dragend", clear);
|
|
41
|
+
window.removeEventListener("drop", clear);
|
|
42
|
+
window.removeEventListener("keydown", key);
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
const isFiles = (e) => e.dataTransfer.types.includes("Files");
|
|
46
|
+
return /* @__PURE__ */ jsxs(
|
|
47
|
+
"div",
|
|
48
|
+
{
|
|
49
|
+
role: "region",
|
|
50
|
+
"aria-label": label,
|
|
51
|
+
className: s.zone + " " + className,
|
|
52
|
+
"data-dragging": dragging && !disabled,
|
|
53
|
+
onDragEnter: (e) => {
|
|
54
|
+
if (!isFiles(e)) return;
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
e.stopPropagation();
|
|
57
|
+
if (!disabled) {
|
|
58
|
+
depth.current++;
|
|
59
|
+
setDragging(true);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
onDragOver: (e) => {
|
|
63
|
+
if (!isFiles(e)) return;
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
e.stopPropagation();
|
|
66
|
+
e.dataTransfer.dropEffect = disabled ? "none" : "copy";
|
|
67
|
+
if (!disabled) setDragging(true);
|
|
68
|
+
},
|
|
69
|
+
onDragLeave: (e) => {
|
|
70
|
+
if (!isFiles(e)) return;
|
|
71
|
+
e.stopPropagation();
|
|
72
|
+
depth.current = Math.max(0, depth.current - 1);
|
|
73
|
+
if (e.relatedTarget instanceof Node) {
|
|
74
|
+
if (e.currentTarget.contains(e.relatedTarget)) return;
|
|
75
|
+
clear();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (!depth.current) setDragging(false);
|
|
79
|
+
},
|
|
80
|
+
onDrop: (e) => {
|
|
81
|
+
if (!isFiles(e)) return;
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
e.stopPropagation();
|
|
84
|
+
clear();
|
|
85
|
+
if (!disabled && e.dataTransfer.files.length) {
|
|
86
|
+
const result = validateFiles(
|
|
87
|
+
Array.from(e.dataTransfer.files),
|
|
88
|
+
constraints
|
|
89
|
+
);
|
|
90
|
+
setRejections(result.rejected);
|
|
91
|
+
onValidation?.(result);
|
|
92
|
+
if (result.rejected.length) onReject?.(result.rejected);
|
|
93
|
+
if (result.accepted.length) onFiles(result.accepted);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
children: [
|
|
97
|
+
children,
|
|
98
|
+
showErrors && /* @__PURE__ */ jsx(FileSelectionFeedback, { rejections }),
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
FileDropOverlay,
|
|
101
|
+
{
|
|
102
|
+
active: dragging && !disabled,
|
|
103
|
+
title,
|
|
104
|
+
description
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
export {
|
|
112
|
+
FileDropZone
|
|
113
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type FileConstraints, type FileRejection, type FileSelectionResult } from "./fileSelection";
|
|
2
|
+
export type FilePickerProps = FileConstraints & {
|
|
3
|
+
onFiles(files: File[]): void;
|
|
4
|
+
onReject?(rejections: FileRejection[]): void;
|
|
5
|
+
onValidation?(result: FileSelectionResult): void;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
label?: string;
|
|
8
|
+
showErrors?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function FilePicker({ onFiles, onReject, onValidation, disabled, label, showErrors, ...constraints }: FilePickerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useRef, useState } from "react";
|
|
3
|
+
import { Upload } from "lucide-react";
|
|
4
|
+
import { Button } from "./Button.js";
|
|
5
|
+
import {
|
|
6
|
+
validateFiles
|
|
7
|
+
} from "./fileSelection.js";
|
|
8
|
+
import { FileSelectionFeedback } from "./FileSelectionFeedback.js";
|
|
9
|
+
function FilePicker({
|
|
10
|
+
onFiles,
|
|
11
|
+
onReject,
|
|
12
|
+
onValidation,
|
|
13
|
+
disabled = false,
|
|
14
|
+
label = "\u9009\u62E9\u6587\u4EF6",
|
|
15
|
+
showErrors = true,
|
|
16
|
+
...constraints
|
|
17
|
+
}) {
|
|
18
|
+
const ref = useRef(null), id = useId(), [rejections, setRejections] = useState([]);
|
|
19
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
20
|
+
/* @__PURE__ */ jsx(
|
|
21
|
+
"input",
|
|
22
|
+
{
|
|
23
|
+
ref,
|
|
24
|
+
type: "file",
|
|
25
|
+
multiple: constraints.multiple !== false,
|
|
26
|
+
accept: constraints.accept,
|
|
27
|
+
disabled,
|
|
28
|
+
hidden: true,
|
|
29
|
+
onChange: (e) => {
|
|
30
|
+
const files = Array.from(e.target.files || []);
|
|
31
|
+
if (files.length && !disabled) {
|
|
32
|
+
const result = validateFiles(files, constraints);
|
|
33
|
+
setRejections(result.rejected);
|
|
34
|
+
onValidation?.(result);
|
|
35
|
+
if (result.rejected.length) onReject?.(result.rejected);
|
|
36
|
+
if (result.accepted.length) onFiles(result.accepted);
|
|
37
|
+
}
|
|
38
|
+
e.target.value = "";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
),
|
|
42
|
+
/* @__PURE__ */ jsxs(
|
|
43
|
+
Button,
|
|
44
|
+
{
|
|
45
|
+
disabled,
|
|
46
|
+
"aria-describedby": showErrors && rejections.length ? id : void 0,
|
|
47
|
+
onClick: () => ref.current?.click(),
|
|
48
|
+
children: [
|
|
49
|
+
/* @__PURE__ */ jsx(Upload, {}),
|
|
50
|
+
label
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
),
|
|
54
|
+
showErrors && /* @__PURE__ */ jsx(FileSelectionFeedback, { id, rejections })
|
|
55
|
+
] });
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
FilePicker
|
|
59
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import s from "./FileSelectionFeedback.module.css";
|
|
3
|
+
function FileSelectionFeedback({
|
|
4
|
+
rejections,
|
|
5
|
+
id
|
|
6
|
+
}) {
|
|
7
|
+
if (!rejections.length) return null;
|
|
8
|
+
return /* @__PURE__ */ jsxs("div", { id, className: s.feedback, role: "alert", children: [
|
|
9
|
+
/* @__PURE__ */ jsx("ul", { children: rejections.slice(0, 3).map((item, index) => /* @__PURE__ */ jsxs("li", { children: [
|
|
10
|
+
/* @__PURE__ */ jsx("span", { children: item.file.name }),
|
|
11
|
+
"\uFF1A",
|
|
12
|
+
item.message
|
|
13
|
+
] }, `${item.file.name}-${index}`)) }),
|
|
14
|
+
rejections.length > 3 && /* @__PURE__ */ jsxs("p", { children: [
|
|
15
|
+
"\u53E6\u6709 ",
|
|
16
|
+
rejections.length - 3,
|
|
17
|
+
" \u4E2A\u6587\u4EF6\u672A\u6DFB\u52A0"
|
|
18
|
+
] })
|
|
19
|
+
] });
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
FileSelectionFeedback
|
|
23
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface FileTreeNode {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
children?: FileTreeNode[];
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function FileTree({ nodes, label, selected, onSelect, defaultExpanded, }: {
|
|
8
|
+
nodes: FileTreeNode[];
|
|
9
|
+
label?: string;
|
|
10
|
+
selected?: string;
|
|
11
|
+
onSelect?(id: string): void;
|
|
12
|
+
defaultExpanded?: string[];
|
|
13
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useRef, useState } from "react";
|
|
3
|
+
import { ChevronRight, File, Folder, FolderOpen } from "lucide-react";
|
|
4
|
+
import s from "./FileTree.module.css";
|
|
5
|
+
function FileTree({
|
|
6
|
+
nodes,
|
|
7
|
+
label = "\u6587\u4EF6\u6811",
|
|
8
|
+
selected,
|
|
9
|
+
onSelect,
|
|
10
|
+
defaultExpanded = []
|
|
11
|
+
}) {
|
|
12
|
+
const [expanded, setExpanded] = useState(new Set(defaultExpanded)), [focused, setFocused] = useState();
|
|
13
|
+
const root = useRef(null);
|
|
14
|
+
const rows = useMemo(() => {
|
|
15
|
+
const result = [];
|
|
16
|
+
const walk = (items, level, parent) => items.forEach((node, i) => {
|
|
17
|
+
result.push({ node, level, parent, pos: i + 1, size: items.length });
|
|
18
|
+
if (node.children && expanded.has(node.id))
|
|
19
|
+
walk(node.children, level + 1, node.id);
|
|
20
|
+
});
|
|
21
|
+
walk(nodes, 1);
|
|
22
|
+
return result;
|
|
23
|
+
}, [nodes, expanded]);
|
|
24
|
+
const active = rows.find((r) => r.node.id === focused && !r.node.disabled)?.node.id || rows.find((r) => r.node.id === selected && !r.node.disabled)?.node.id || rows.find((r) => !r.node.disabled)?.node.id;
|
|
25
|
+
const toggle = (id) => setExpanded((old) => {
|
|
26
|
+
const next = new Set(old);
|
|
27
|
+
next.has(id) ? next.delete(id) : next.add(id);
|
|
28
|
+
return next;
|
|
29
|
+
});
|
|
30
|
+
const focus = (id) => {
|
|
31
|
+
if (!id) return;
|
|
32
|
+
setFocused(id);
|
|
33
|
+
root.current?.querySelectorAll('[role="treeitem"]').forEach((el) => {
|
|
34
|
+
if (el.dataset.id === id) el.focus();
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
return /* @__PURE__ */ jsxs("div", { ref: root, role: "tree", "aria-label": label, className: s.tree, children: [
|
|
38
|
+
rows.map(({ node, level, parent, pos, size }, index) => /* @__PURE__ */ jsxs(
|
|
39
|
+
"div",
|
|
40
|
+
{
|
|
41
|
+
role: "treeitem",
|
|
42
|
+
"data-id": node.id,
|
|
43
|
+
tabIndex: node.id === active ? 0 : -1,
|
|
44
|
+
"aria-level": level,
|
|
45
|
+
"aria-posinset": pos,
|
|
46
|
+
"aria-setsize": size,
|
|
47
|
+
"aria-selected": selected === node.id,
|
|
48
|
+
"aria-expanded": node.children ? expanded.has(node.id) : void 0,
|
|
49
|
+
"aria-disabled": node.disabled || void 0,
|
|
50
|
+
className: s.row,
|
|
51
|
+
style: { paddingLeft: 8 + (level - 1) * 20 },
|
|
52
|
+
onFocus: () => setFocused(node.id),
|
|
53
|
+
onClick: () => {
|
|
54
|
+
if (!node.disabled) {
|
|
55
|
+
onSelect?.(node.id);
|
|
56
|
+
focus(node.id);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
onDoubleClick: () => {
|
|
60
|
+
if (node.children && !node.disabled) toggle(node.id);
|
|
61
|
+
},
|
|
62
|
+
onKeyDown: (e) => {
|
|
63
|
+
if (node.disabled) return;
|
|
64
|
+
const enabled = rows.filter((r) => !r.node.disabled), i = enabled.findIndex((r) => r.node.id === node.id);
|
|
65
|
+
if ([
|
|
66
|
+
"ArrowDown",
|
|
67
|
+
"ArrowUp",
|
|
68
|
+
"Home",
|
|
69
|
+
"End",
|
|
70
|
+
"ArrowRight",
|
|
71
|
+
"ArrowLeft",
|
|
72
|
+
"Enter",
|
|
73
|
+
" "
|
|
74
|
+
].includes(e.key))
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
if (e.key === "ArrowDown")
|
|
77
|
+
focus(enabled[Math.min(enabled.length - 1, i + 1)]?.node.id);
|
|
78
|
+
if (e.key === "ArrowUp")
|
|
79
|
+
focus(enabled[Math.max(0, i - 1)]?.node.id);
|
|
80
|
+
if (e.key === "Home") focus(enabled[0]?.node.id);
|
|
81
|
+
if (e.key === "End") focus(enabled.at(-1)?.node.id);
|
|
82
|
+
if (e.key === "ArrowRight" && node.children) {
|
|
83
|
+
if (!expanded.has(node.id)) toggle(node.id);
|
|
84
|
+
else
|
|
85
|
+
focus(
|
|
86
|
+
rows[index + 1]?.parent === node.id ? rows[index + 1]?.node.id : void 0
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (e.key === "ArrowLeft") {
|
|
90
|
+
if (node.children && expanded.has(node.id)) toggle(node.id);
|
|
91
|
+
else focus(parent);
|
|
92
|
+
}
|
|
93
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
94
|
+
onSelect?.(node.id);
|
|
95
|
+
if (node.children) toggle(node.id);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
children: [
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
"span",
|
|
101
|
+
{
|
|
102
|
+
className: s.disclosure,
|
|
103
|
+
"data-open": expanded.has(node.id),
|
|
104
|
+
onClick: (e) => {
|
|
105
|
+
if (node.children && !node.disabled) {
|
|
106
|
+
e.stopPropagation();
|
|
107
|
+
toggle(node.id);
|
|
108
|
+
focus(node.id);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
children: node.children && /* @__PURE__ */ jsx(ChevronRight, {})
|
|
112
|
+
}
|
|
113
|
+
),
|
|
114
|
+
node.children ? expanded.has(node.id) ? /* @__PURE__ */ jsx(FolderOpen, {}) : /* @__PURE__ */ jsx(Folder, {}) : /* @__PURE__ */ jsx(File, {}),
|
|
115
|
+
/* @__PURE__ */ jsx("span", { className: s.name, children: node.name })
|
|
116
|
+
]
|
|
117
|
+
},
|
|
118
|
+
node.id
|
|
119
|
+
)),
|
|
120
|
+
!nodes.length && /* @__PURE__ */ jsx("p", { className: s.empty, children: "\u6CA1\u6709\u6587\u4EF6" })
|
|
121
|
+
] });
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
FileTree
|
|
125
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
.tree {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: 2px;
|
|
5
|
+
padding: 6px;
|
|
6
|
+
border: 1px solid var(--line);
|
|
7
|
+
border-radius: var(--radius);
|
|
8
|
+
min-height: 180px;
|
|
9
|
+
overflow: auto;
|
|
10
|
+
}
|
|
11
|
+
.row {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
gap: 7px;
|
|
15
|
+
min-height: 34px;
|
|
16
|
+
padding: 5px 10px;
|
|
17
|
+
border-radius: 6px;
|
|
18
|
+
cursor: default;
|
|
19
|
+
transition: background var(--motion-hover);
|
|
20
|
+
}
|
|
21
|
+
.row:hover {
|
|
22
|
+
background: var(--hover);
|
|
23
|
+
}
|
|
24
|
+
.row[aria-selected="true"] {
|
|
25
|
+
background: var(--selected);
|
|
26
|
+
}
|
|
27
|
+
.row[aria-disabled="true"] {
|
|
28
|
+
opacity: 0.4;
|
|
29
|
+
}
|
|
30
|
+
.row:focus-visible {
|
|
31
|
+
outline-offset: -2px;
|
|
32
|
+
}
|
|
33
|
+
.disclosure {
|
|
34
|
+
display: grid;
|
|
35
|
+
place-items: center;
|
|
36
|
+
flex-shrink: 0;
|
|
37
|
+
width: 18px;
|
|
38
|
+
height: 22px;
|
|
39
|
+
}
|
|
40
|
+
.disclosure svg {
|
|
41
|
+
width: 14px;
|
|
42
|
+
transition: transform var(--motion-chevron) var(--ease);
|
|
43
|
+
}
|
|
44
|
+
.disclosure[data-open="true"] svg {
|
|
45
|
+
transform: rotate(90deg);
|
|
46
|
+
}
|
|
47
|
+
.name {
|
|
48
|
+
overflow: hidden;
|
|
49
|
+
text-overflow: ellipsis;
|
|
50
|
+
white-space: nowrap;
|
|
51
|
+
}
|
|
52
|
+
.empty {
|
|
53
|
+
margin: auto;
|
|
54
|
+
color: var(--muted);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.row > svg {
|
|
58
|
+
width: 17px;
|
|
59
|
+
height: 17px;
|
|
60
|
+
flex-shrink: 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.disclosure svg {
|
|
64
|
+
width: 14px;
|
|
65
|
+
height: 14px;
|
|
66
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FormHTMLAttributes, ReactNode } from "react";
|
|
2
|
+
import type { FormController } from "./useFormState";
|
|
3
|
+
export declare function Form<T extends Record<string, unknown>>({ controller, onSubmit, children, ...props }: Omit<FormHTMLAttributes<HTMLFormElement>, "onSubmit" | "onReset" | "children"> & {
|
|
4
|
+
controller: FormController<T>;
|
|
5
|
+
onSubmit(values: T): void | Promise<void>;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import s from "./Form.module.css";
|
|
3
|
+
function Form({
|
|
4
|
+
controller,
|
|
5
|
+
onSubmit,
|
|
6
|
+
children,
|
|
7
|
+
...props
|
|
8
|
+
}) {
|
|
9
|
+
return /* @__PURE__ */ jsx(
|
|
10
|
+
"form",
|
|
11
|
+
{
|
|
12
|
+
...props,
|
|
13
|
+
noValidate: true,
|
|
14
|
+
"aria-busy": controller.isSubmitting || void 0,
|
|
15
|
+
onSubmit: controller.handleSubmit(onSubmit),
|
|
16
|
+
onReset: (event) => {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
controller.reset();
|
|
19
|
+
},
|
|
20
|
+
children: /* @__PURE__ */ jsx("fieldset", { className: s.fields, disabled: controller.isSubmitting, children })
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
Form
|
|
26
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import s from "./FormErrorSummary.module.css";
|
|
3
|
+
function FormErrorSummary({
|
|
4
|
+
errors,
|
|
5
|
+
labels,
|
|
6
|
+
onFocus,
|
|
7
|
+
submitError
|
|
8
|
+
}) {
|
|
9
|
+
const entries = Object.entries(errors).filter(
|
|
10
|
+
(entry) => !!entry[1]
|
|
11
|
+
);
|
|
12
|
+
if (!entries.length && !submitError) return null;
|
|
13
|
+
return /* @__PURE__ */ jsxs("div", { className: s.summary, role: "alert", children: [
|
|
14
|
+
submitError && /* @__PURE__ */ jsx("p", { children: submitError }),
|
|
15
|
+
entries.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
16
|
+
/* @__PURE__ */ jsx("strong", { children: "\u8BF7\u68C0\u67E5\u4EE5\u4E0B\u5185\u5BB9" }),
|
|
17
|
+
/* @__PURE__ */ jsx("ul", { children: entries.map(([name, error]) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("button", { type: "button", onClick: () => onFocus(name), children: [
|
|
18
|
+
labels?.[name] || name,
|
|
19
|
+
"\uFF1A",
|
|
20
|
+
error
|
|
21
|
+
] }) }, name)) })
|
|
22
|
+
] })
|
|
23
|
+
] });
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
FormErrorSummary
|
|
27
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
.summary {
|
|
2
|
+
padding: 12px 14px;
|
|
3
|
+
border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--surface));
|
|
4
|
+
border-radius: var(--radius);
|
|
5
|
+
background: color-mix(in srgb, var(--danger) 5%, var(--surface));
|
|
6
|
+
color: var(--danger);
|
|
7
|
+
font-size: 12px;
|
|
8
|
+
line-height: 1.6;
|
|
9
|
+
}
|
|
10
|
+
.summary strong {
|
|
11
|
+
font-weight: 550;
|
|
12
|
+
}
|
|
13
|
+
.summary ul {
|
|
14
|
+
margin: 5px 0 0;
|
|
15
|
+
padding-left: 18px;
|
|
16
|
+
}
|
|
17
|
+
.summary button {
|
|
18
|
+
border: 0;
|
|
19
|
+
background: transparent;
|
|
20
|
+
color: inherit;
|
|
21
|
+
text-align: left;
|
|
22
|
+
padding: 2px 0;
|
|
23
|
+
font-size: 12px;
|
|
24
|
+
}
|
|
25
|
+
.summary button:hover {
|
|
26
|
+
text-decoration: underline;
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { FieldOptions } from "./field";
|
|
3
|
+
export declare function FormField({ children, pending, requiredIndicator, optional, onBlur, ...options }: FieldOptions & {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
pending?: boolean;
|
|
6
|
+
requiredIndicator?: "asterisk" | "text" | "none";
|
|
7
|
+
optional?: boolean;
|
|
8
|
+
onBlur?(): void;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useUIConfig } from "./UIProvider.js";
|
|
3
|
+
import { FieldMessages } from "./FieldMessages.js";
|
|
4
|
+
import { Spinner } from "./Spinner.js";
|
|
5
|
+
import { useRef } from "react";
|
|
6
|
+
import { FieldContext, useFieldControl } from "./field.js";
|
|
7
|
+
import { FieldLabel } from "./FieldLabel.js";
|
|
8
|
+
import s from "./FormField.module.css";
|
|
9
|
+
function FormField({
|
|
10
|
+
children,
|
|
11
|
+
pending = false,
|
|
12
|
+
requiredIndicator,
|
|
13
|
+
optional = false,
|
|
14
|
+
onBlur,
|
|
15
|
+
...options
|
|
16
|
+
}) {
|
|
17
|
+
const config = useUIConfig();
|
|
18
|
+
const field = useFieldControl(options), root = useRef(null);
|
|
19
|
+
return /* @__PURE__ */ jsx(FieldContext, { value: field, children: /* @__PURE__ */ jsxs(
|
|
20
|
+
"div",
|
|
21
|
+
{
|
|
22
|
+
ref: root,
|
|
23
|
+
className: s.field,
|
|
24
|
+
"data-invalid": !!field.error,
|
|
25
|
+
"data-disabled": field.disabled || void 0,
|
|
26
|
+
onBlur: (event) => {
|
|
27
|
+
const next = event.relatedTarget, node = root.current;
|
|
28
|
+
if (next && node.contains(next)) return;
|
|
29
|
+
const portals = [...node.querySelectorAll("[aria-controls]")].map(
|
|
30
|
+
(control) => document.getElementById(
|
|
31
|
+
control.getAttribute("aria-controls") || ""
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
if (next && portals.some((portal) => portal?.contains(next))) return;
|
|
35
|
+
onBlur?.();
|
|
36
|
+
},
|
|
37
|
+
children: [
|
|
38
|
+
/* @__PURE__ */ jsxs("div", { className: s.labelRow, children: [
|
|
39
|
+
/* @__PURE__ */ jsx(
|
|
40
|
+
FieldLabel,
|
|
41
|
+
{
|
|
42
|
+
label: field.label,
|
|
43
|
+
htmlFor: field.id,
|
|
44
|
+
required: field.required,
|
|
45
|
+
indicator: requiredIndicator ?? config.requiredIndicator,
|
|
46
|
+
optional
|
|
47
|
+
}
|
|
48
|
+
),
|
|
49
|
+
pending && /* @__PURE__ */ jsx(Spinner, { size: 13, label: "\u6B63\u5728\u6821\u9A8C" + field.label })
|
|
50
|
+
] }),
|
|
51
|
+
children,
|
|
52
|
+
/* @__PURE__ */ jsx(FieldMessages, { id: field.id, hint: field.hint, error: field.error })
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
) });
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
FormField
|
|
59
|
+
};
|