@robert-stackflow/oneui 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.
Files changed (380) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +72 -2
  3. package/assets/LUCIDE-LICENSE.txt +43 -0
  4. package/assets/character-metadata.json +1 -0
  5. package/assets/emoji.json +1 -0
  6. package/assets/icon-catalog.json +1 -0
  7. package/assets/symbols.json +1 -0
  8. package/components/Accessibility.module.css +8 -0
  9. package/components/Accordion.d.ts +7 -0
  10. package/components/Accordion.js +41 -0
  11. package/components/Accordion.module.css +38 -0
  12. package/components/Alert.d.ts +9 -0
  13. package/components/Alert.js +42 -0
  14. package/components/Alert.module.css +56 -0
  15. package/components/AppShell.d.ts +30 -0
  16. package/components/AppShell.js +152 -0
  17. package/components/AppShell.module.css +239 -0
  18. package/components/AppearanceSettings.d.ts +7 -0
  19. package/components/AppearanceSettings.js +201 -0
  20. package/components/AppearanceSettings.module.css +32 -0
  21. package/components/Avatar.d.ts +14 -0
  22. package/components/Avatar.js +69 -0
  23. package/components/Avatar.module.css +70 -0
  24. package/components/AvatarGroup.d.ts +15 -0
  25. package/components/AvatarGroup.js +115 -0
  26. package/components/AvatarGroup.module.css +54 -0
  27. package/components/Badge.d.ts +5 -0
  28. package/components/Badge.js +11 -0
  29. package/components/Badge.module.css +30 -0
  30. package/components/BlockedTab.d.ts +4 -0
  31. package/components/BlockedTab.js +10 -0
  32. package/components/Breadcrumb.d.ts +16 -0
  33. package/components/Breadcrumb.js +157 -0
  34. package/components/Breadcrumb.module.css +97 -0
  35. package/components/Button.d.ts +13 -0
  36. package/components/Button.js +52 -0
  37. package/components/Button.module.css +88 -0
  38. package/components/Calendar.d.ts +10 -0
  39. package/components/Calendar.js +260 -0
  40. package/components/Calendar.module.css +106 -0
  41. package/components/Card.d.ts +8 -0
  42. package/components/Card.js +29 -0
  43. package/components/Card.module.css +47 -0
  44. package/components/Cascader.d.ts +14 -0
  45. package/components/Cascader.js +296 -0
  46. package/components/CatalogIcon.d.ts +3 -0
  47. package/components/CatalogIcon.js +11 -0
  48. package/components/CharacterPicker.d.ts +15 -0
  49. package/components/CharacterPicker.js +200 -0
  50. package/components/Checkbox.d.ts +12 -0
  51. package/components/Checkbox.js +82 -0
  52. package/components/Checkbox.module.css +95 -0
  53. package/components/ColorField.d.ts +6 -0
  54. package/components/ColorField.js +61 -0
  55. package/components/ColorField.module.css +15 -0
  56. package/components/ColorPicker.d.ts +5 -0
  57. package/components/ColorPicker.js +188 -0
  58. package/components/ColorPicker.module.css +90 -0
  59. package/components/Combobox.d.ts +13 -0
  60. package/components/Combobox.js +338 -0
  61. package/components/Combobox.module.css +24 -0
  62. package/components/CommandPalette.d.ts +25 -0
  63. package/components/CommandPalette.js +269 -0
  64. package/components/CommandPalette.module.css +49 -0
  65. package/components/ContextMenu.d.ts +9 -0
  66. package/components/ContextMenu.js +363 -0
  67. package/components/ContextMenu.module.css +42 -0
  68. package/components/ContextMenuPanel.d.ts +22 -0
  69. package/components/ContextMenuPanel.js +155 -0
  70. package/components/ContributionCalendar.d.ts +18 -0
  71. package/components/ContributionCalendar.js +201 -0
  72. package/components/ContributionCalendar.module.css +114 -0
  73. package/components/ContributionCell.d.ts +11 -0
  74. package/components/ContributionCell.js +41 -0
  75. package/components/Control.module.css +86 -0
  76. package/components/DataTable.d.ts +49 -0
  77. package/components/DataTable.js +220 -0
  78. package/components/DataTable.module.css +112 -0
  79. package/components/DatePicker.d.ts +15 -0
  80. package/components/DatePicker.js +186 -0
  81. package/components/DatePicker.module.css +85 -0
  82. package/components/DateRangePicker.d.ts +9 -0
  83. package/components/DateRangePicker.js +168 -0
  84. package/components/Descriptions.d.ts +21 -0
  85. package/components/Descriptions.js +162 -0
  86. package/components/Descriptions.module.css +117 -0
  87. package/components/Dialog.d.ts +14 -0
  88. package/components/Dialog.js +125 -0
  89. package/components/Dialog.module.css +88 -0
  90. package/components/DialogVariants.d.ts +27 -0
  91. package/components/DialogVariants.js +161 -0
  92. package/components/DialogVariants.module.css +29 -0
  93. package/components/DisclosureChevron.d.ts +3 -0
  94. package/components/DisclosureChevron.js +17 -0
  95. package/components/DisclosureChevron.module.css +17 -0
  96. package/components/Divider.d.ts +5 -0
  97. package/components/Divider.js +24 -0
  98. package/components/Divider.module.css +19 -0
  99. package/components/Drawer.d.ts +18 -0
  100. package/components/Drawer.js +145 -0
  101. package/components/Drawer.module.css +109 -0
  102. package/components/EmojiPicker.d.ts +6 -0
  103. package/components/EmojiPicker.js +19 -0
  104. package/components/EmptyState.d.ts +8 -0
  105. package/components/EmptyState.js +20 -0
  106. package/components/EmptyState.module.css +30 -0
  107. package/components/FieldLabel.d.ts +8 -0
  108. package/components/FieldLabel.js +20 -0
  109. package/components/FieldMessages.d.ts +5 -0
  110. package/components/FieldMessages.js +15 -0
  111. package/components/FileDropOverlay.d.ts +5 -0
  112. package/components/FileDropOverlay.js +26 -0
  113. package/components/FileDropOverlay.module.css +55 -0
  114. package/components/FileDropZone.d.ts +15 -0
  115. package/components/FileDropZone.js +113 -0
  116. package/components/FileDropZone.module.css +6 -0
  117. package/components/FilePicker.d.ts +10 -0
  118. package/components/FilePicker.js +59 -0
  119. package/components/FileSelectionFeedback.d.ts +5 -0
  120. package/components/FileSelectionFeedback.js +23 -0
  121. package/components/FileSelectionFeedback.module.css +14 -0
  122. package/components/FileTree.d.ts +13 -0
  123. package/components/FileTree.js +125 -0
  124. package/components/FileTree.module.css +66 -0
  125. package/components/Form.d.ts +7 -0
  126. package/components/Form.js +26 -0
  127. package/components/Form.module.css +7 -0
  128. package/components/FormErrorSummary.d.ts +6 -0
  129. package/components/FormErrorSummary.js +27 -0
  130. package/components/FormErrorSummary.module.css +27 -0
  131. package/components/FormField.d.ts +9 -0
  132. package/components/FormField.js +59 -0
  133. package/components/FormField.module.css +85 -0
  134. package/components/FormGroup.d.ts +9 -0
  135. package/components/FormGroup.js +32 -0
  136. package/components/HierarchyPicker.module.css +181 -0
  137. package/components/IconButton.d.ts +7 -0
  138. package/components/IconButton.js +30 -0
  139. package/components/IconButton.module.css +42 -0
  140. package/components/IconPicker.d.ts +6 -0
  141. package/components/IconPicker.js +111 -0
  142. package/components/Indicator.d.ts +18 -0
  143. package/components/Indicator.js +97 -0
  144. package/components/Indicator.module.css +83 -0
  145. package/components/Input.d.ts +8 -0
  146. package/components/Input.js +37 -0
  147. package/components/Input.module.css +40 -0
  148. package/components/LoadingOverlay.d.ts +6 -0
  149. package/components/LoadingOverlay.js +16 -0
  150. package/components/LoadingOverlay.module.css +22 -0
  151. package/components/LoadingState.d.ts +7 -0
  152. package/components/LoadingState.js +40 -0
  153. package/components/LoadingState.module.css +17 -0
  154. package/components/Menu.d.ts +11 -0
  155. package/components/Menu.js +82 -0
  156. package/components/MenuItem.d.ts +15 -0
  157. package/components/MenuItem.js +51 -0
  158. package/components/MenuItem.module.css +172 -0
  159. package/components/MenuItemContent.d.ts +8 -0
  160. package/components/MenuItemContent.js +19 -0
  161. package/components/MultiSelect.d.ts +13 -0
  162. package/components/MultiSelect.js +225 -0
  163. package/components/MultiSelect.module.css +99 -0
  164. package/components/NumberInput.d.ts +12 -0
  165. package/components/NumberInput.js +114 -0
  166. package/components/NumberInput.module.css +33 -0
  167. package/components/OptionList.module.css +12 -0
  168. package/components/Page.d.ts +7 -0
  169. package/components/Page.js +22 -0
  170. package/components/Page.module.css +44 -0
  171. package/components/Pagination.d.ts +11 -0
  172. package/components/Pagination.js +160 -0
  173. package/components/Pagination.module.css +70 -0
  174. package/components/PasswordField.d.ts +9 -0
  175. package/components/PasswordField.js +102 -0
  176. package/components/PasswordField.module.css +64 -0
  177. package/components/Picker.module.css +52 -0
  178. package/components/PinInput.d.ts +13 -0
  179. package/components/PinInput.js +173 -0
  180. package/components/PinInput.module.css +72 -0
  181. package/components/Placeholder.d.ts +31 -0
  182. package/components/Placeholder.js +36 -0
  183. package/components/Popconfirm.d.ts +17 -0
  184. package/components/Popconfirm.js +159 -0
  185. package/components/Popconfirm.module.css +49 -0
  186. package/components/Popover.d.ts +16 -0
  187. package/components/Popover.js +156 -0
  188. package/components/Popover.module.css +19 -0
  189. package/components/Progress.d.ts +5 -0
  190. package/components/Progress.js +31 -0
  191. package/components/Progress.module.css +33 -0
  192. package/components/RadioGroup.d.ts +15 -0
  193. package/components/RadioGroup.js +73 -0
  194. package/components/RadioGroup.module.css +87 -0
  195. package/components/RangeSlider.d.ts +22 -0
  196. package/components/RangeSlider.js +278 -0
  197. package/components/RangeSlider.module.css +141 -0
  198. package/components/ResizablePanel.d.ts +21 -0
  199. package/components/ResizablePanel.js +219 -0
  200. package/components/ResizablePanel.module.css +101 -0
  201. package/components/SearchField.d.ts +11 -0
  202. package/components/SearchField.js +67 -0
  203. package/components/SearchField.module.css +37 -0
  204. package/components/Section.d.ts +6 -0
  205. package/components/Section.js +18 -0
  206. package/components/Section.module.css +14 -0
  207. package/components/Segmented.d.ts +11 -0
  208. package/components/Segmented.js +77 -0
  209. package/components/Segmented.module.css +82 -0
  210. package/components/Select.d.ts +11 -0
  211. package/components/Select.js +172 -0
  212. package/components/Select.module.css +24 -0
  213. package/components/SelectOptionContent.d.ts +5 -0
  214. package/components/SelectOptionContent.js +20 -0
  215. package/components/SelectOptionContent.module.css +7 -0
  216. package/components/SelectTrigger.d.ts +5 -0
  217. package/components/SelectTrigger.js +32 -0
  218. package/components/SelectTrigger.module.css +24 -0
  219. package/components/SelectionTag.d.ts +8 -0
  220. package/components/SelectionTag.js +39 -0
  221. package/components/SettingRow.d.ts +7 -0
  222. package/components/SettingRow.js +19 -0
  223. package/components/SettingRow.module.css +44 -0
  224. package/components/SettingsLayout.d.ts +11 -0
  225. package/components/SettingsLayout.js +61 -0
  226. package/components/SettingsLayout.module.css +68 -0
  227. package/components/ShortcutInput.d.ts +8 -0
  228. package/components/ShortcutInput.js +131 -0
  229. package/components/ShortcutInput.module.css +39 -0
  230. package/components/Skeleton.d.ts +5 -0
  231. package/components/Skeleton.js +19 -0
  232. package/components/Skeleton.module.css +27 -0
  233. package/components/SkeletonRows.d.ts +4 -0
  234. package/components/SkeletonRows.js +19 -0
  235. package/components/SkeletonRows.module.css +19 -0
  236. package/components/SkinTonePicker.d.ts +4 -0
  237. package/components/SkinTonePicker.js +43 -0
  238. package/components/SkinTonePicker.module.css +50 -0
  239. package/components/Slider.d.ts +10 -0
  240. package/components/Slider.js +40 -0
  241. package/components/Slider.module.css +19 -0
  242. package/components/Spinner.d.ts +6 -0
  243. package/components/Spinner.js +31 -0
  244. package/components/Spinner.module.css +57 -0
  245. package/components/SplitButton.d.ts +17 -0
  246. package/components/SplitButton.js +102 -0
  247. package/components/SplitButton.module.css +56 -0
  248. package/components/Statistic.d.ts +22 -0
  249. package/components/Statistic.js +102 -0
  250. package/components/Statistic.module.css +55 -0
  251. package/components/Steps.d.ts +19 -0
  252. package/components/Steps.js +102 -0
  253. package/components/Steps.module.css +176 -0
  254. package/components/Switch.d.ts +6 -0
  255. package/components/Switch.js +25 -0
  256. package/components/Switch.module.css +59 -0
  257. package/components/SymbolPicker.d.ts +6 -0
  258. package/components/SymbolPicker.js +18 -0
  259. package/components/Tab.module.css +145 -0
  260. package/components/TabList.d.ts +11 -0
  261. package/components/TabList.js +51 -0
  262. package/components/Table.d.ts +16 -0
  263. package/components/Table.js +30 -0
  264. package/components/Table.module.css +48 -0
  265. package/components/TableColumnFilter.d.ts +6 -0
  266. package/components/TableColumnFilter.js +76 -0
  267. package/components/TableColumnVisibility.d.ts +11 -0
  268. package/components/TableColumnVisibility.js +76 -0
  269. package/components/Tabs.d.ts +13 -0
  270. package/components/Tabs.js +49 -0
  271. package/components/Tabs.module.css +3 -0
  272. package/components/TagInput.d.ts +11 -0
  273. package/components/TagInput.js +142 -0
  274. package/components/TagInput.module.css +64 -0
  275. package/components/Textarea.d.ts +6 -0
  276. package/components/Textarea.js +24 -0
  277. package/components/Textarea.module.css +9 -0
  278. package/components/ThemePicker.d.ts +6 -0
  279. package/components/ThemePicker.js +78 -0
  280. package/components/ThemePicker.module.css +178 -0
  281. package/components/ThemeProvider.d.ts +11 -0
  282. package/components/ThemeProvider.js +94 -0
  283. package/components/ThemeStylePicker.d.ts +5 -0
  284. package/components/ThemeStylePicker.js +22 -0
  285. package/components/TimeColumns.d.ts +6 -0
  286. package/components/TimeColumns.js +55 -0
  287. package/components/TimeColumns.module.css +47 -0
  288. package/components/Timeline.d.ts +26 -0
  289. package/components/Timeline.js +131 -0
  290. package/components/Timeline.module.css +202 -0
  291. package/components/Toast.d.ts +6 -0
  292. package/components/Toast.js +181 -0
  293. package/components/Toast.module.css +175 -0
  294. package/components/ToastProvider.d.ts +35 -0
  295. package/components/ToastProvider.js +47 -0
  296. package/components/Tooltip.d.ts +10 -0
  297. package/components/Tooltip.js +169 -0
  298. package/components/Tooltip.module.css +53 -0
  299. package/components/TreeGuides.d.ts +9 -0
  300. package/components/TreeGuides.js +39 -0
  301. package/components/TreeGuides.module.css +45 -0
  302. package/components/TreeSelect.d.ts +26 -0
  303. package/components/TreeSelect.js +337 -0
  304. package/components/TreeTable.d.ts +15 -0
  305. package/components/TreeTable.js +151 -0
  306. package/components/TreeTable.module.css +53 -0
  307. package/components/UIProvider.d.ts +10 -0
  308. package/components/UIProvider.js +20 -0
  309. package/components/UnderlinedTab.d.ts +2 -0
  310. package/components/UnderlinedTab.js +8 -0
  311. package/components/Upload.d.ts +22 -0
  312. package/components/Upload.js +165 -0
  313. package/components/Upload.module.css +36 -0
  314. package/components/UploadList.d.ts +9 -0
  315. package/components/UploadList.js +14 -0
  316. package/components/UploadList.module.css +130 -0
  317. package/components/UploadListItem.d.ts +13 -0
  318. package/components/UploadListItem.js +122 -0
  319. package/components/VirtualPickerList.d.ts +25 -0
  320. package/components/VirtualPickerList.js +269 -0
  321. package/components/VirtualPickerList.module.css +93 -0
  322. package/components/appearance.d.ts +20 -0
  323. package/components/appearance.js +69 -0
  324. package/components/characterCatalog.d.ts +9 -0
  325. package/components/characterCatalog.js +55 -0
  326. package/components/color.d.ts +7 -0
  327. package/components/color.js +18 -0
  328. package/components/contribution.d.ts +57 -0
  329. package/components/contribution.js +86 -0
  330. package/components/dateConstraints.d.ts +13 -0
  331. package/components/dateConstraints.js +44 -0
  332. package/components/field.d.ts +58 -0
  333. package/components/field.js +57 -0
  334. package/components/fileSelection.d.ts +21 -0
  335. package/components/fileSelection.js +43 -0
  336. package/components/hierarchy.d.ts +23 -0
  337. package/components/hierarchy.js +33 -0
  338. package/components/iconCatalog.d.ts +13 -0
  339. package/components/iconCatalog.js +80 -0
  340. package/components/index.d.ts +152 -0
  341. package/components/index.js +225 -0
  342. package/components/menuFocus.d.ts +7 -0
  343. package/components/menuFocus.js +21 -0
  344. package/components/menuPointer.d.ts +6 -0
  345. package/components/menuPointer.js +13 -0
  346. package/components/menuTypes.d.ts +24 -0
  347. package/components/menuTypes.js +0 -0
  348. package/components/motion.d.ts +9 -0
  349. package/components/motion.js +82 -0
  350. package/components/rangeMath.d.ts +12 -0
  351. package/components/rangeMath.js +30 -0
  352. package/components/surfacePortal.d.ts +13 -0
  353. package/components/surfacePortal.js +22 -0
  354. package/components/tooltipState.d.ts +5 -0
  355. package/components/tooltipState.js +48 -0
  356. package/components/types.d.ts +9 -0
  357. package/components/types.js +0 -0
  358. package/components/uploadTypes.d.ts +21 -0
  359. package/components/uploadTypes.js +0 -0
  360. package/components/useFormState.d.ts +51 -0
  361. package/components/useFormState.js +218 -0
  362. package/components/useHierarchy.d.ts +8 -0
  363. package/components/useHierarchy.js +80 -0
  364. package/components/useMenuLayers.d.ts +17 -0
  365. package/components/useMenuLayers.js +23 -0
  366. package/components/useModalScrollLock.d.ts +1 -0
  367. package/components/useModalScrollLock.js +18 -0
  368. package/components/usePopover.d.ts +8 -0
  369. package/components/usePopover.js +22 -0
  370. package/components/useTabIndicator.d.ts +12 -0
  371. package/components/useTabIndicator.js +63 -0
  372. package/components/useUploadQueue.d.ts +20 -0
  373. package/components/useUploadQueue.js +175 -0
  374. package/package.json +810 -3
  375. package/styles/base.css +206 -0
  376. package/styles/blue.css +268 -0
  377. package/styles/desktop.css +2 -0
  378. package/styles/minimal.css +337 -0
  379. package/styles/themes.css +2 -0
  380. package/styles/web.css +2 -0
@@ -0,0 +1,90 @@
1
+ .panel {
2
+ padding: 9px;
3
+ }
4
+ .plane {
5
+ position: relative;
6
+ height: 150px;
7
+ border-radius: 10px;
8
+ background-image: linear-gradient(to top, #000, transparent),
9
+ linear-gradient(to right, #fff, transparent);
10
+ touch-action: none;
11
+ cursor: crosshair;
12
+ }
13
+ .marker {
14
+ position: absolute;
15
+ width: 12px;
16
+ height: 12px;
17
+ border: 2px solid white;
18
+ border-radius: 50%;
19
+ translate: -50% -50%;
20
+ box-shadow: 0 0 0 1px #0006;
21
+ pointer-events: none;
22
+ }
23
+ .hue {
24
+ display: block;
25
+ width: 100%;
26
+ height: 12px;
27
+ margin: 18px 0;
28
+ appearance: none;
29
+ border: 0;
30
+ padding: 0;
31
+ border-radius: 999px;
32
+ background: linear-gradient(
33
+ to right,
34
+ #f00,
35
+ #ff0,
36
+ #0f0,
37
+ #0ff,
38
+ #00f,
39
+ #f0f,
40
+ #f00
41
+ );
42
+ cursor: pointer;
43
+ }
44
+ .hue::-webkit-slider-thumb {
45
+ appearance: none;
46
+ width: 18px;
47
+ height: 18px;
48
+ border: 2px solid white;
49
+ border-radius: 50%;
50
+ background: var(--surface);
51
+ box-shadow: 0 1px 5px #0005;
52
+ }
53
+ .presets {
54
+ display: grid;
55
+ grid-template-columns: repeat(8, 1fr);
56
+ gap: 7px;
57
+ margin-bottom: 14px;
58
+ }
59
+ .presets button {
60
+ width: 22px;
61
+ height: 22px;
62
+ padding: 0;
63
+ border: 1px solid #80808040;
64
+ border-radius: 50%;
65
+ transition: scale var(--motion-hover);
66
+ }
67
+ .presets button:hover {
68
+ scale: 1.12;
69
+ }
70
+ .presets button[aria-pressed="true"] {
71
+ outline: 2px solid var(--fg);
72
+ outline-offset: 2px;
73
+ }
74
+ .rgb {
75
+ display: grid;
76
+ grid-template-columns: repeat(3, minmax(0, 1fr));
77
+ gap: 8px;
78
+ margin-top: 10px;
79
+ }
80
+ .rgb label {
81
+ display: grid;
82
+ gap: 4px;
83
+ font-size: 11px;
84
+ color: var(--muted);
85
+ min-width: 0;
86
+ }
87
+ .rgb label > div {
88
+ width: 100%;
89
+ grid-template-columns: 20px minmax(0, 1fr) 20px;
90
+ }
@@ -0,0 +1,13 @@
1
+ import { type FieldOptions } from "./field";
2
+ import type { SelectOption } from "./types";
3
+ export type ComboboxProps = FieldOptions & {
4
+ value: string;
5
+ onChange(value: string): void;
6
+ options?: SelectOption[];
7
+ loadOptions?(query: string, signal: AbortSignal): Promise<SelectOption[]>;
8
+ onCreate?(label: string): string | void | Promise<string | void>;
9
+ label?: string;
10
+ placeholder?: string;
11
+ mode?: "panel" | "input";
12
+ };
13
+ export declare function Combobox({ value, onChange, options, loadOptions, onCreate, label, placeholder, mode, ...props }: ComboboxProps): import("react").JSX.Element;
@@ -0,0 +1,338 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import {
3
+ useCallback,
4
+ useEffect,
5
+ useId,
6
+ useRef,
7
+ useState
8
+ } from "react";
9
+ import { Plus } from "lucide-react";
10
+ import {
11
+ FieldContext,
12
+ fieldInputProps,
13
+ fieldTriggerProps,
14
+ useFieldControl
15
+ } from "./field.js";
16
+ import { SelectTrigger } from "./SelectTrigger.js";
17
+ import { Popover } from "./Popover.js";
18
+ import { SearchField } from "./SearchField.js";
19
+ import { Input } from "./Input.js";
20
+ import { MenuItem } from "./MenuItem.js";
21
+ import { Spinner } from "./Spinner.js";
22
+ import { Button } from "./Button.js";
23
+ import { DisclosureChevron } from "./DisclosureChevron.js";
24
+ import s from "./Combobox.module.css";
25
+ function Combobox({
26
+ value,
27
+ onChange,
28
+ options = [],
29
+ loadOptions,
30
+ onCreate,
31
+ label = "\u641C\u7D22\u9009\u62E9",
32
+ placeholder = "\u8BF7\u9009\u62E9",
33
+ mode = "panel",
34
+ ...props
35
+ }) {
36
+ const field = useFieldControl({ ...props, label }), anchor = useRef(null), list = useRef(null), id = useId();
37
+ const [open, setOpen] = useState(false), [query, setQuery] = useState(""), [editing, setEditing] = useState(false), [remote, setRemote] = useState([]), [loading, setLoading] = useState(false), [error, setError] = useState(""), [failure, setFailure] = useState("load"), [active, setActive] = useState(-1), [created, setCreated] = useState(), [chosen, setChosen] = useState(), [creating, setCreating] = useState(false), [retry, setRetry] = useState(0);
38
+ const generation = useRef(0), restoring = useRef(false), loader = useRef(loadOptions);
39
+ loader.current = loadOptions;
40
+ const inline = mode === "input", async = !!loadOptions;
41
+ const close = useCallback(() => {
42
+ generation.current++;
43
+ setOpen(false);
44
+ setEditing(false);
45
+ setCreating(false);
46
+ setLoading(false);
47
+ restoring.current = true;
48
+ queueMicrotask(() => {
49
+ restoring.current = false;
50
+ });
51
+ }, []);
52
+ useEffect(
53
+ () => () => {
54
+ generation.current++;
55
+ },
56
+ []
57
+ );
58
+ useEffect(() => {
59
+ if (!open || !async) return;
60
+ const controller = new AbortController(), revision = generation.current;
61
+ setLoading(true);
62
+ setError("");
63
+ const timer = setTimeout(() => {
64
+ Promise.resolve().then(() => loader.current(query, controller.signal)).then((items) => {
65
+ if (!controller.signal.aborted && revision === generation.current) {
66
+ setRemote(items);
67
+ setLoading(false);
68
+ setActive(inline ? -1 : items.findIndex((item) => !item.disabled));
69
+ }
70
+ }).catch(() => {
71
+ if (!controller.signal.aborted && revision === generation.current) {
72
+ setFailure("load");
73
+ setError("\u9009\u9879\u52A0\u8F7D\u5931\u8D25");
74
+ setLoading(false);
75
+ }
76
+ });
77
+ }, 180);
78
+ return () => {
79
+ clearTimeout(timer);
80
+ controller.abort();
81
+ };
82
+ }, [open, query, async, retry, inline]);
83
+ useEffect(() => {
84
+ if (field.disabled || field.readOnly) close();
85
+ }, [field.disabled, field.readOnly, close]);
86
+ const terms = query.trim().toLowerCase().split(/\s+/).filter(Boolean), filtered = async ? remote : options.filter(
87
+ (item) => terms.every(
88
+ (term) => (item.label + " " + (item.description || "") + " " + item.value).toLowerCase().includes(term)
89
+ )
90
+ );
91
+ const selected = [...options, ...remote, created, chosen].find(
92
+ (item) => item?.value === value
93
+ ), first = filtered.findIndex((item) => !item.disabled);
94
+ const activeIndex = active >= 0 && filtered[active] && !filtered[active].disabled ? active : inline ? -1 : first;
95
+ const choose = (item) => {
96
+ if (item.disabled || field.disabled || field.readOnly) return;
97
+ setChosen(item);
98
+ onChange(item.value);
99
+ close();
100
+ anchor.current?.focus();
101
+ };
102
+ const show = () => {
103
+ if (field.disabled || field.readOnly || creating) return;
104
+ generation.current++;
105
+ setLoading(async);
106
+ setQuery("");
107
+ setEditing(false);
108
+ setActive(inline ? -1 : 0);
109
+ setError("");
110
+ setOpen(true);
111
+ };
112
+ const search = (text) => {
113
+ if (field.disabled || field.readOnly || creating) return;
114
+ generation.current++;
115
+ setLoading(async);
116
+ setQuery(text);
117
+ setEditing(true);
118
+ setActive(inline ? -1 : 0);
119
+ setError("");
120
+ setOpen(true);
121
+ };
122
+ useEffect(() => {
123
+ list.current?.querySelector('[data-active="true"]')?.scrollIntoView({ block: "nearest" });
124
+ }, [activeIndex, query, loading]);
125
+ const canCreate = !!onCreate && !!query.trim() && !filtered.some(
126
+ (item) => item.label.toLowerCase() === query.trim().toLowerCase()
127
+ );
128
+ const create = async () => {
129
+ if (!onCreate || creating || loading || !canCreate) return;
130
+ const revision = generation.current, text = query.trim();
131
+ setCreating(true);
132
+ setError("");
133
+ try {
134
+ const result = await onCreate(text);
135
+ if (revision !== generation.current) return;
136
+ const item = { value: result || text, label: text };
137
+ setCreated(item);
138
+ choose(item);
139
+ } catch {
140
+ if (revision === generation.current) {
141
+ setFailure("create");
142
+ setError("\u521B\u5EFA\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002");
143
+ }
144
+ } finally {
145
+ if (revision === generation.current) setCreating(false);
146
+ }
147
+ };
148
+ const navigate = (event) => {
149
+ if (event.nativeEvent.isComposing || event.keyCode === 229 || field.readOnly || field.disabled)
150
+ return;
151
+ if (event.key === "Escape" && open) {
152
+ event.preventDefault();
153
+ event.stopPropagation();
154
+ close();
155
+ anchor.current?.focus();
156
+ return;
157
+ }
158
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
159
+ event.preventDefault();
160
+ if (!open) {
161
+ show();
162
+ return;
163
+ }
164
+ const direction = event.key === "ArrowDown" ? 1 : -1, start = activeIndex < 0 ? direction === 1 ? -1 : 0 : activeIndex;
165
+ for (let step = 1; step <= filtered.length; step++) {
166
+ const next = (start + direction * step + filtered.length * 2) % filtered.length;
167
+ if (!filtered[next].disabled) {
168
+ setActive(next);
169
+ break;
170
+ }
171
+ }
172
+ } else if (event.key === "Enter" && open) {
173
+ event.preventDefault();
174
+ if (!loading && !creating && !error) {
175
+ const item = filtered[activeIndex < 0 ? first : activeIndex];
176
+ if (item) choose(item);
177
+ else void create();
178
+ }
179
+ }
180
+ };
181
+ const activeId = open && !loading && !error && activeIndex >= 0 ? id + "-" + activeIndex : void 0;
182
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
183
+ inline ? /* @__PURE__ */ jsx(FieldContext, { value: { ...field, name: void 0 }, children: /* @__PURE__ */ jsx(
184
+ Input,
185
+ {
186
+ ...fieldInputProps(field),
187
+ name: void 0,
188
+ ref: anchor,
189
+ role: "combobox",
190
+ "aria-label": field.label,
191
+ "aria-expanded": open,
192
+ "aria-busy": loading || creating,
193
+ "aria-controls": id + "-list",
194
+ "aria-autocomplete": "list",
195
+ "aria-activedescendant": activeId,
196
+ autoComplete: "off",
197
+ disabled: field.disabled || creating,
198
+ className: s.inputTrigger,
199
+ value: open && editing ? query : selected?.label || value,
200
+ placeholder,
201
+ leading: selected?.icon,
202
+ trailing: loading || creating ? /* @__PURE__ */ jsx(Spinner, { size: 16, decorative: true }) : /* @__PURE__ */ jsx(DisclosureChevron, { expanded: open }),
203
+ onChange: (event) => search(event.target.value),
204
+ onFocus: () => {
205
+ if (!restoring.current && !open) show();
206
+ },
207
+ onClick: () => {
208
+ if (!open) show();
209
+ },
210
+ onKeyDown: navigate
211
+ }
212
+ ) }) : /* @__PURE__ */ jsx(
213
+ SelectTrigger,
214
+ {
215
+ ...fieldTriggerProps(field),
216
+ ref: anchor,
217
+ expanded: open,
218
+ disabled: field.disabled || creating,
219
+ "aria-controls": id,
220
+ "aria-haspopup": "dialog",
221
+ icon: creating ? /* @__PURE__ */ jsx(Spinner, { size: 16, decorative: true }) : selected?.icon,
222
+ onClick: () => {
223
+ if (!field.readOnly) open ? close() : show();
224
+ },
225
+ onKeyDown: navigate,
226
+ children: /* @__PURE__ */ jsx("span", { children: selected?.label || value || placeholder })
227
+ }
228
+ ),
229
+ field.name && /* @__PURE__ */ jsx(
230
+ "input",
231
+ {
232
+ type: "hidden",
233
+ name: field.name,
234
+ value,
235
+ disabled: field.disabled
236
+ }
237
+ ),
238
+ /* @__PURE__ */ jsx(
239
+ Popover,
240
+ {
241
+ id,
242
+ open,
243
+ onClose: close,
244
+ anchor,
245
+ label: field.label + "\u9009\u9879",
246
+ width: 300,
247
+ autoFocus: !inline,
248
+ matchAnchorWidth: inline,
249
+ children: /* @__PURE__ */ jsxs("div", { className: s.panel, children: [
250
+ !inline && /* @__PURE__ */ jsx(
251
+ SearchField,
252
+ {
253
+ label: "\u641C\u7D22" + field.label,
254
+ placeholder: "\u641C\u7D22\u9009\u9879\u2026",
255
+ value: query,
256
+ onChange: search,
257
+ loading,
258
+ disabled: creating,
259
+ "aria-controls": id + "-list",
260
+ "aria-activedescendant": activeId,
261
+ onKeyDown: navigate
262
+ }
263
+ ),
264
+ /* @__PURE__ */ jsx(
265
+ "div",
266
+ {
267
+ ref: list,
268
+ id: id + "-list",
269
+ role: "listbox",
270
+ "aria-label": field.label,
271
+ className: s.list,
272
+ "aria-busy": loading,
273
+ children: error ? /* @__PURE__ */ jsxs("div", { className: s.empty, role: "alert", children: [
274
+ /* @__PURE__ */ jsx("span", { children: error }),
275
+ /* @__PURE__ */ jsx(
276
+ Button,
277
+ {
278
+ size: "small",
279
+ variant: "ghost",
280
+ onClick: () => {
281
+ setError("");
282
+ if (failure === "create") void create();
283
+ else {
284
+ generation.current++;
285
+ setLoading(true);
286
+ setRetry((value2) => value2 + 1);
287
+ }
288
+ },
289
+ children: "\u91CD\u8BD5"
290
+ }
291
+ )
292
+ ] }) : loading ? /* @__PURE__ */ jsx("div", { className: s.empty, children: /* @__PURE__ */ jsx(Spinner, { label: "\u52A0\u8F7D\u9009\u9879" }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
293
+ filtered.map((item, index) => /* @__PURE__ */ jsx(
294
+ MenuItem,
295
+ {
296
+ as: "div",
297
+ id: id + "-" + index,
298
+ role: "option",
299
+ label: item.label,
300
+ icon: item.icon,
301
+ description: item.description,
302
+ shortcut: item.shortcut,
303
+ reserveIcon: filtered.some((option) => !!option.icon),
304
+ selected: value === item.value,
305
+ active: activeIndex === index,
306
+ disabled: item.disabled,
307
+ "aria-selected": value === item.value,
308
+ selection: "check",
309
+ onMouseDown: (event) => event.preventDefault(),
310
+ onPointerMove: () => {
311
+ if (!item.disabled) setActive(index);
312
+ },
313
+ onClick: () => choose(item)
314
+ },
315
+ item.value
316
+ )),
317
+ !filtered.length && !canCreate && /* @__PURE__ */ jsx("p", { className: s.empty, children: "\u6CA1\u6709\u5339\u914D\u7684\u9009\u9879" })
318
+ ] })
319
+ }
320
+ ),
321
+ canCreate && !loading && /* @__PURE__ */ jsx(
322
+ MenuItem,
323
+ {
324
+ label: "\u521B\u5EFA\u201C" + query.trim() + "\u201D",
325
+ icon: /* @__PURE__ */ jsx(Plus, {}),
326
+ disabled: creating,
327
+ onMouseDown: (event) => event.preventDefault(),
328
+ onClick: () => void create()
329
+ }
330
+ )
331
+ ] })
332
+ }
333
+ )
334
+ ] });
335
+ }
336
+ export {
337
+ Combobox
338
+ };
@@ -0,0 +1,24 @@
1
+ .panel {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: 7px;
5
+ }
6
+ .inputTrigger {
7
+ min-width: 0;
8
+ width: 100%;
9
+ }
10
+ .list {
11
+ composes: stack from "./OptionList.module.css";
12
+ max-height: 240px;
13
+ min-height: 40px;
14
+ overflow: auto;
15
+ }
16
+ .empty {
17
+ display: flex;
18
+ align-items: center;
19
+ justify-content: center;
20
+ gap: 12px;
21
+ padding: 22px 10px;
22
+ color: var(--muted);
23
+ font-size: 12px;
24
+ }
@@ -0,0 +1,25 @@
1
+ import { type ReactNode } from "react";
2
+ export type CommandPaletteItem = {
3
+ value: string;
4
+ label: string;
5
+ description?: string;
6
+ group?: string;
7
+ icon?: ReactNode;
8
+ shortcut?: string;
9
+ keywords?: string[];
10
+ disabled?: boolean;
11
+ onSelect?(signal: AbortSignal): void | Promise<void>;
12
+ };
13
+ export type CommandPaletteProps = {
14
+ open: boolean;
15
+ onClose(): void;
16
+ onOpen?(): void;
17
+ items: CommandPaletteItem[];
18
+ onSelect?(item: CommandPaletteItem, signal: AbortSignal): void | Promise<void>;
19
+ title?: string;
20
+ placeholder?: string;
21
+ hotkey?: boolean;
22
+ closeOnSelect?: boolean;
23
+ emptyText?: string;
24
+ };
25
+ export declare function CommandPalette({ open, onClose, onOpen, items, onSelect, title, placeholder, hotkey, closeOnSelect, emptyText, }: CommandPaletteProps): import("react").JSX.Element;