@researai/deepscientist 1.5.15 → 1.5.17

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 (202) hide show
  1. package/README.md +385 -104
  2. package/bin/ds.js +1241 -110
  3. package/docs/en/00_QUICK_START.md +100 -19
  4. package/docs/en/01_SETTINGS_REFERENCE.md +34 -1
  5. package/docs/en/02_START_RESEARCH_GUIDE.md +7 -0
  6. package/docs/en/05_TUI_GUIDE.md +6 -0
  7. package/docs/en/06_RUNTIME_AND_CANVAS.md +4 -3
  8. package/docs/en/09_DOCTOR.md +25 -8
  9. package/docs/en/14_PROMPT_SKILLS_AND_MCP_GUIDE.md +63 -13
  10. package/docs/en/15_CODEX_PROVIDER_SETUP.md +37 -11
  11. package/docs/en/19_EXTERNAL_CONTROLLER_GUIDE.md +226 -0
  12. package/docs/en/19_LOCAL_BROWSER_AUTH.md +70 -0
  13. package/docs/en/20_WORKSPACE_MODES_GUIDE.md +250 -0
  14. package/docs/en/21_LOCAL_MODEL_BACKENDS_GUIDE.md +283 -0
  15. package/docs/en/91_DEVELOPMENT.md +237 -0
  16. package/docs/en/README.md +24 -2
  17. package/docs/zh/00_QUICK_START.md +89 -19
  18. package/docs/zh/01_SETTINGS_REFERENCE.md +34 -1
  19. package/docs/zh/02_START_RESEARCH_GUIDE.md +7 -0
  20. package/docs/zh/05_TUI_GUIDE.md +6 -0
  21. package/docs/zh/09_DOCTOR.md +26 -9
  22. package/docs/zh/14_PROMPT_SKILLS_AND_MCP_GUIDE.md +63 -13
  23. package/docs/zh/15_CODEX_PROVIDER_SETUP.md +37 -11
  24. package/docs/zh/19_EXTERNAL_CONTROLLER_GUIDE.md +226 -0
  25. package/docs/zh/19_LOCAL_BROWSER_AUTH.md +68 -0
  26. package/docs/zh/20_WORKSPACE_MODES_GUIDE.md +251 -0
  27. package/docs/zh/21_LOCAL_MODEL_BACKENDS_GUIDE.md +281 -0
  28. package/docs/zh/README.md +24 -2
  29. package/install.sh +46 -4
  30. package/package.json +2 -1
  31. package/pyproject.toml +1 -1
  32. package/src/deepscientist/__init__.py +1 -1
  33. package/src/deepscientist/acp/envelope.py +6 -0
  34. package/src/deepscientist/artifact/service.py +647 -22
  35. package/src/deepscientist/bash_exec/service.py +234 -9
  36. package/src/deepscientist/bridges/connectors.py +8 -2
  37. package/src/deepscientist/cli.py +115 -19
  38. package/src/deepscientist/codex_cli_compat.py +367 -22
  39. package/src/deepscientist/config/models.py +2 -1
  40. package/src/deepscientist/config/service.py +183 -13
  41. package/src/deepscientist/daemon/api/handlers.py +255 -31
  42. package/src/deepscientist/daemon/api/router.py +9 -0
  43. package/src/deepscientist/daemon/app.py +1146 -105
  44. package/src/deepscientist/diagnostics/__init__.py +6 -0
  45. package/src/deepscientist/diagnostics/runner_failures.py +130 -0
  46. package/src/deepscientist/doctor.py +207 -3
  47. package/src/deepscientist/gitops/__init__.py +10 -1
  48. package/src/deepscientist/gitops/diff.py +129 -0
  49. package/src/deepscientist/gitops/service.py +4 -1
  50. package/src/deepscientist/mcp/server.py +39 -0
  51. package/src/deepscientist/prompts/builder.py +275 -34
  52. package/src/deepscientist/quest/layout.py +15 -2
  53. package/src/deepscientist/quest/service.py +707 -55
  54. package/src/deepscientist/quest/stage_views.py +6 -1
  55. package/src/deepscientist/runners/codex.py +143 -43
  56. package/src/deepscientist/shared.py +19 -0
  57. package/src/deepscientist/skills/__init__.py +2 -2
  58. package/src/deepscientist/skills/installer.py +196 -5
  59. package/src/deepscientist/skills/registry.py +66 -0
  60. package/src/prompts/connectors/qq.md +18 -8
  61. package/src/prompts/connectors/weixin.md +16 -6
  62. package/src/prompts/contracts/shared_interaction.md +14 -2
  63. package/src/prompts/system.md +23 -5
  64. package/src/prompts/system_copilot.md +56 -0
  65. package/src/skills/analysis-campaign/SKILL.md +1 -0
  66. package/src/skills/baseline/SKILL.md +8 -0
  67. package/src/skills/decision/SKILL.md +8 -0
  68. package/src/skills/experiment/SKILL.md +8 -0
  69. package/src/skills/figure-polish/SKILL.md +1 -0
  70. package/src/skills/finalize/SKILL.md +1 -0
  71. package/src/skills/idea/SKILL.md +1 -0
  72. package/src/skills/intake-audit/SKILL.md +8 -0
  73. package/src/skills/mentor/SKILL.md +217 -0
  74. package/src/skills/mentor/references/correction-rules.md +210 -0
  75. package/src/skills/mentor/references/knowledge-profile.md +91 -0
  76. package/src/skills/mentor/references/persona-profile.md +138 -0
  77. package/src/skills/mentor/references/taste-profile.md +128 -0
  78. package/src/skills/mentor/references/thought-style-profile.md +138 -0
  79. package/src/skills/mentor/references/work-profile.md +289 -0
  80. package/src/skills/mentor/references/workflow-profile.md +240 -0
  81. package/src/skills/optimize/SKILL.md +1 -0
  82. package/src/skills/rebuttal/SKILL.md +1 -0
  83. package/src/skills/review/SKILL.md +1 -0
  84. package/src/skills/scout/SKILL.md +8 -0
  85. package/src/skills/write/SKILL.md +1 -0
  86. package/src/tui/dist/app/AppContainer.js +19 -11
  87. package/src/tui/dist/index.js +4 -1
  88. package/src/tui/dist/lib/api.js +33 -3
  89. package/src/tui/package.json +1 -1
  90. package/src/ui/dist/assets/AiManusChatView-Bv-Z8YpU.js +204 -0
  91. package/src/ui/dist/assets/AnalysisPlugin-BCKAfjba.js +1 -0
  92. package/src/ui/dist/assets/CliPlugin-BCKcpc35.js +109 -0
  93. package/src/ui/dist/assets/CodeEditorPlugin-DbOfSJ8K.js +2 -0
  94. package/src/ui/dist/assets/CodeViewerPlugin-CbaFRrUU.js +270 -0
  95. package/src/ui/dist/assets/DocViewerPlugin-DAjLVeQD.js +7 -0
  96. package/src/ui/dist/assets/GitCommitViewerPlugin-CIUqbUDO.js +1 -0
  97. package/src/ui/dist/assets/GitDiffViewerPlugin-CQACjoAA.js +6 -0
  98. package/src/ui/dist/assets/GitSnapshotViewer-0r4nLPke.js +30 -0
  99. package/src/ui/dist/assets/ImageViewerPlugin-nBOmI2v_.js +26 -0
  100. package/src/ui/dist/assets/LabCopilotPanel-BHxOxF4z.js +14 -0
  101. package/src/ui/dist/assets/LabPlugin-BKoZGs95.js +22 -0
  102. package/src/ui/dist/assets/LatexPlugin-ZwtV8pIp.js +25 -0
  103. package/src/ui/dist/assets/MarkdownViewerPlugin-DKqVfKyW.js +128 -0
  104. package/src/ui/dist/assets/MarketplacePlugin-BwxStZ9D.js +13 -0
  105. package/src/ui/dist/assets/NotebookEditor-BEQhaQbt.js +81 -0
  106. package/src/ui/dist/assets/{NotebookEditor-CccQYZjX.css → NotebookEditor-BHH8rdGj.css} +1 -1
  107. package/src/ui/dist/assets/NotebookEditor-BOr3x3Ej.css +1 -0
  108. package/src/ui/dist/assets/NotebookEditor-DB9N_T9q.js +361 -0
  109. package/src/ui/dist/assets/PdfLoader-Cy5jtWrr.css +1 -0
  110. package/src/ui/dist/assets/PdfLoader-eWBONbQP.js +16 -0
  111. package/src/ui/dist/assets/PdfMarkdownPlugin-D22YOZL3.js +1 -0
  112. package/src/ui/dist/assets/PdfViewerPlugin-c-RK9DLM.js +17 -0
  113. package/src/ui/dist/assets/PdfViewerPlugin-nwwE-fjJ.css +1 -0
  114. package/src/ui/dist/assets/SearchPlugin-CxF9ytAx.js +16 -0
  115. package/src/ui/dist/assets/SearchPlugin-DA4en4hK.css +1 -0
  116. package/src/ui/dist/assets/TextViewerPlugin-C5xqeeUH.js +54 -0
  117. package/src/ui/dist/assets/VNCViewer-BoLGLnHz.js +11 -0
  118. package/src/ui/dist/assets/bot-DREQOxzP.js +6 -0
  119. package/src/ui/dist/assets/browser-CTB2jwNe.js +8 -0
  120. package/src/ui/dist/assets/chevron-up-C9Qpx4DE.js +6 -0
  121. package/src/ui/dist/assets/code-WlFHE7z_.js +6 -0
  122. package/src/ui/dist/assets/file-content-BZMz3RYp.js +1 -0
  123. package/src/ui/dist/assets/file-diff-panel-CQhw0jS2.js +1 -0
  124. package/src/ui/dist/assets/file-jump-queue-DA-SdG__.js +1 -0
  125. package/src/ui/dist/assets/file-socket-CfQPKQKj.js +1 -0
  126. package/src/ui/dist/assets/git-commit-horizontal-DxZ8DCZh.js +6 -0
  127. package/src/ui/dist/assets/image-Bgl4VIyx.js +6 -0
  128. package/src/ui/dist/assets/index-BpV6lusQ.css +33 -0
  129. package/src/ui/dist/assets/index-CBNVuWcP.js +2496 -0
  130. package/src/ui/dist/assets/index-CwNu1aH4.js +11 -0
  131. package/src/ui/dist/assets/index-DrUnlf6K.js +1 -0
  132. package/src/ui/dist/assets/index-NW-h8VzN.js +1 -0
  133. package/src/ui/dist/assets/monaco-CiHMMNH_.js +1 -0
  134. package/src/ui/dist/assets/pdf-effect-queue-J8OnM0jE.js +6 -0
  135. package/src/ui/dist/assets/plugin-monaco-C8UgLomw.js +19 -0
  136. package/src/ui/dist/assets/plugin-notebook-HbW2K-1c.js +169 -0
  137. package/src/ui/dist/assets/plugin-pdf-CR8hgQBV.js +357 -0
  138. package/src/ui/dist/assets/plugin-terminal-MXFIPun8.js +227 -0
  139. package/src/ui/dist/assets/popover-CLc0pPP8.js +1 -0
  140. package/src/ui/dist/assets/project-sync-C9IdzdZW.js +1 -0
  141. package/src/ui/dist/assets/select-Cs2PmzwL.js +11 -0
  142. package/src/ui/dist/assets/sigma-ClKcHAXm.js +6 -0
  143. package/src/ui/dist/assets/trash-DwpbFr3w.js +11 -0
  144. package/src/ui/dist/assets/useCliAccess-NQ8m0Let.js +1 -0
  145. package/src/ui/dist/assets/useFileDiffOverlay-FuhcnKiw.js +1 -0
  146. package/src/ui/dist/assets/wrap-text-BC-Hltpd.js +11 -0
  147. package/src/ui/dist/assets/zoom-out-E_gaeAxL.js +11 -0
  148. package/src/ui/dist/index.html +5 -2
  149. package/src/ui/dist/assets/AiManusChatView-DDjbFnbt.js +0 -26597
  150. package/src/ui/dist/assets/AnalysisPlugin-Yb5IdmaU.js +0 -123
  151. package/src/ui/dist/assets/CliPlugin-e64sreyu.js +0 -31037
  152. package/src/ui/dist/assets/CodeEditorPlugin-C4D2TIkU.js +0 -427
  153. package/src/ui/dist/assets/CodeViewerPlugin-BVoNZIvC.js +0 -905
  154. package/src/ui/dist/assets/DocViewerPlugin-CLChbllo.js +0 -278
  155. package/src/ui/dist/assets/GitDiffViewerPlugin-C4xeFyFQ.js +0 -2661
  156. package/src/ui/dist/assets/ImageViewerPlugin-OiMUAcLi.js +0 -500
  157. package/src/ui/dist/assets/LabCopilotPanel-BjD2ThQF.js +0 -4104
  158. package/src/ui/dist/assets/LabPlugin-DQPg-NrB.js +0 -2677
  159. package/src/ui/dist/assets/LatexPlugin-CI05XAV9.js +0 -1792
  160. package/src/ui/dist/assets/MarkdownViewerPlugin-DpeBLYZf.js +0 -308
  161. package/src/ui/dist/assets/MarketplacePlugin-DolE58Q2.js +0 -413
  162. package/src/ui/dist/assets/NotebookEditor-7Qm2rSWD.js +0 -4214
  163. package/src/ui/dist/assets/NotebookEditor-C1kWaxKi.js +0 -84873
  164. package/src/ui/dist/assets/NotebookEditor-C3VQ7ylN.css +0 -1405
  165. package/src/ui/dist/assets/PdfLoader-BfOHw8Zw.js +0 -25468
  166. package/src/ui/dist/assets/PdfLoader-C-Y707R3.css +0 -49
  167. package/src/ui/dist/assets/PdfMarkdownPlugin-BulDREv1.js +0 -409
  168. package/src/ui/dist/assets/PdfViewerPlugin-C-daaOaL.js +0 -3095
  169. package/src/ui/dist/assets/PdfViewerPlugin-DQ11QcSf.css +0 -3627
  170. package/src/ui/dist/assets/SearchPlugin-CjpaiJ3A.js +0 -741
  171. package/src/ui/dist/assets/SearchPlugin-DDMrGDkh.css +0 -379
  172. package/src/ui/dist/assets/TextViewerPlugin-BxIyqPQC.js +0 -472
  173. package/src/ui/dist/assets/VNCViewer-HAg9mF7M.js +0 -18821
  174. package/src/ui/dist/assets/awareness-C0NPR2Dj.js +0 -292
  175. package/src/ui/dist/assets/bot-0DYntytV.js +0 -21
  176. package/src/ui/dist/assets/browser-BAcuE0Xj.js +0 -2895
  177. package/src/ui/dist/assets/code-B20Slj_w.js +0 -17
  178. package/src/ui/dist/assets/file-content-DT24KFma.js +0 -377
  179. package/src/ui/dist/assets/file-diff-panel-DK13YPql.js +0 -92
  180. package/src/ui/dist/assets/file-jump-queue-r5XKgJEV.js +0 -16
  181. package/src/ui/dist/assets/file-socket-B4T2o4nR.js +0 -58
  182. package/src/ui/dist/assets/function-B5QZkkHC.js +0 -1895
  183. package/src/ui/dist/assets/image-DSeR_sDS.js +0 -18
  184. package/src/ui/dist/assets/index-BrFje2Uk.js +0 -120
  185. package/src/ui/dist/assets/index-BwRJaoTl.js +0 -25
  186. package/src/ui/dist/assets/index-D_E4281X.js +0 -221322
  187. package/src/ui/dist/assets/index-DnYB3xb1.js +0 -159
  188. package/src/ui/dist/assets/index-G7AcWcMu.css +0 -12594
  189. package/src/ui/dist/assets/monaco-LExaAN3Y.js +0 -623
  190. package/src/ui/dist/assets/pdf-effect-queue-BJk5okWJ.js +0 -47
  191. package/src/ui/dist/assets/pdf_viewer-e0g1is2C.js +0 -8206
  192. package/src/ui/dist/assets/popover-D3Gg_FoV.js +0 -476
  193. package/src/ui/dist/assets/project-sync-C_ygLlVU.js +0 -297
  194. package/src/ui/dist/assets/select-CpAK6uWm.js +0 -1690
  195. package/src/ui/dist/assets/sigma-DEccaSgk.js +0 -22
  196. package/src/ui/dist/assets/square-check-big-uUfyVsbD.js +0 -17
  197. package/src/ui/dist/assets/trash-CXvwwSe8.js +0 -32
  198. package/src/ui/dist/assets/useCliAccess-Bnop4mgR.js +0 -957
  199. package/src/ui/dist/assets/useFileDiffOverlay-B8eUAX0I.js +0 -53
  200. package/src/ui/dist/assets/wrap-text-9vbOBpkW.js +0 -35
  201. package/src/ui/dist/assets/yjs-DncrqiZ8.js +0 -11243
  202. package/src/ui/dist/assets/zoom-out-BgVMmOW4.js +0 -34
@@ -1,1690 +0,0 @@
1
- import { w as createLucideIcon, r as reactExports, j as jsxRuntimeExports, aj as composeRefs, bN as useDirection, ak as useControllableState, al as Root2$1, am as useId, aq as createPopperScope, bO as createCollection, an as useComposedRefs, ap as Anchor, ao as composeEventHandlers, as as Portal$1, bP as useLayoutEffect2, aR as reactDomExports, bQ as useCallbackRef, at as hideOthers, av as useFocusGuards, au as ReactRemoveScroll, aw as FocusScope, ax as DismissableLayer, ay as Content, az as Arrow, m as ChevronDown, b as cn, d as Check } from './index-D_E4281X.js';
2
- import { C as ChevronUp } from './index-BwRJaoTl.js';
3
-
4
- /**
5
- * @license lucide-react v0.511.0 - ISC
6
- *
7
- * This source code is licensed under the ISC license.
8
- * See the LICENSE file in the root directory of this source tree.
9
- */
10
-
11
-
12
- const __iconNode$1 = [
13
- [
14
- "path",
15
- {
16
- d: "M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",
17
- key: "zw3jo"
18
- }
19
- ],
20
- [
21
- "path",
22
- {
23
- d: "M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",
24
- key: "1wduqc"
25
- }
26
- ],
27
- [
28
- "path",
29
- {
30
- d: "M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",
31
- key: "kqbvx6"
32
- }
33
- ]
34
- ];
35
- const Layers = createLucideIcon("layers", __iconNode$1);
36
-
37
- /**
38
- * @license lucide-react v0.511.0 - ISC
39
- *
40
- * This source code is licensed under the ISC license.
41
- * See the LICENSE file in the root directory of this source tree.
42
- */
43
-
44
-
45
- const __iconNode = [
46
- ["rect", { width: "20", height: "8", x: "2", y: "2", rx: "2", ry: "2", key: "ngkwjq" }],
47
- ["rect", { width: "20", height: "8", x: "2", y: "14", rx: "2", ry: "2", key: "iecqi9" }],
48
- ["line", { x1: "6", x2: "6.01", y1: "6", y2: "6", key: "16zg32" }],
49
- ["line", { x1: "6", x2: "6.01", y1: "18", y2: "18", key: "nzw8ys" }]
50
- ];
51
- const Server = createLucideIcon("server", __iconNode);
52
-
53
- function formatFileSize(size) {
54
- if (size == null || Number.isNaN(size)) return "n/a";
55
- if (size < 1024) return `${size} B`;
56
- const kb = size / 1024;
57
- if (kb < 1024) return `${kb.toFixed(1)} KB`;
58
- const mb = kb / 1024;
59
- if (mb < 1024) return `${mb.toFixed(1)} MB`;
60
- const gb = mb / 1024;
61
- return `${gb.toFixed(1)} GB`;
62
- }
63
- function normalizePath(path) {
64
- if (!path) return "/";
65
- const normalized = path.replace(/\\/g, "/");
66
- let withLeading = normalized.startsWith("/") ? normalized : `/${normalized}`;
67
- withLeading = withLeading.replace(/\/{2,}/g, "/");
68
- if (withLeading.length > 1 && withLeading.endsWith("/")) {
69
- withLeading = withLeading.replace(/\/+$/, "");
70
- }
71
- return withLeading;
72
- }
73
- function splitPath(path) {
74
- const normalized = normalizePath(path);
75
- return normalized === "/" ? [] : normalized.split("/").filter(Boolean);
76
- }
77
- function joinPath(segments) {
78
- if (segments.length === 0) return "/";
79
- return `/${segments.join("/")}`;
80
- }
81
- const TEXT_PREVIEW_MAX_BYTES = 1024 * 1024;
82
- const DOWNLOAD_MAX_BYTES = 50 * 1024 * 1024;
83
- const SENSITIVE_PATH_MARKERS = [
84
- "/.env",
85
- "/.env.",
86
- "/.ssh/",
87
- "/credentials.json",
88
- "/secrets.yaml",
89
- "/secrets.yml",
90
- "/id_rsa",
91
- "/id_ed25519",
92
- "/.aws/credentials",
93
- "/.docker/config.json",
94
- "/etc/passwd",
95
- "/etc/shadow",
96
- "/etc/gshadow",
97
- "/proc/",
98
- "/sys/kernel/",
99
- "/dev/mem",
100
- "/dev/kmem"
101
- ];
102
- function findSensitiveMarker(path) {
103
- const normalized = normalizePath(path).toLowerCase();
104
- for (const marker of SENSITIVE_PATH_MARKERS) {
105
- if (normalized.includes(marker)) return marker;
106
- }
107
- return null;
108
- }
109
-
110
- // packages/core/number/src/number.ts
111
- function clamp(value, [min, max]) {
112
- return Math.min(max, Math.max(min, value));
113
- }
114
-
115
- // packages/react/context/src/create-context.tsx
116
- function createContextScope(scopeName, createContextScopeDeps = []) {
117
- let defaultContexts = [];
118
- function createContext3(rootComponentName, defaultContext) {
119
- const BaseContext = reactExports.createContext(defaultContext);
120
- const index = defaultContexts.length;
121
- defaultContexts = [...defaultContexts, defaultContext];
122
- const Provider = (props) => {
123
- const { scope, children, ...context } = props;
124
- const Context = scope?.[scopeName]?.[index] || BaseContext;
125
- const value = reactExports.useMemo(() => context, Object.values(context));
126
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Context.Provider, { value, children });
127
- };
128
- Provider.displayName = rootComponentName + "Provider";
129
- function useContext2(consumerName, scope) {
130
- const Context = scope?.[scopeName]?.[index] || BaseContext;
131
- const context = reactExports.useContext(Context);
132
- if (context) return context;
133
- if (defaultContext !== void 0) return defaultContext;
134
- throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
135
- }
136
- return [Provider, useContext2];
137
- }
138
- const createScope = () => {
139
- const scopeContexts = defaultContexts.map((defaultContext) => {
140
- return reactExports.createContext(defaultContext);
141
- });
142
- return function useScope(scope) {
143
- const contexts = scope?.[scopeName] || scopeContexts;
144
- return reactExports.useMemo(
145
- () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),
146
- [scope, contexts]
147
- );
148
- };
149
- };
150
- createScope.scopeName = scopeName;
151
- return [createContext3, composeContextScopes(createScope, ...createContextScopeDeps)];
152
- }
153
- function composeContextScopes(...scopes) {
154
- const baseScope = scopes[0];
155
- if (scopes.length === 1) return baseScope;
156
- const createScope = () => {
157
- const scopeHooks = scopes.map((createScope2) => ({
158
- useScope: createScope2(),
159
- scopeName: createScope2.scopeName
160
- }));
161
- return function useComposedScopes(overrideScopes) {
162
- const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
163
- const scopeProps = useScope(overrideScopes);
164
- const currentScope = scopeProps[`__scope${scopeName}`];
165
- return { ...nextScopes2, ...currentScope };
166
- }, {});
167
- return reactExports.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
168
- };
169
- };
170
- createScope.scopeName = baseScope.scopeName;
171
- return createScope;
172
- }
173
-
174
- // src/slot.tsx
175
- // @__NO_SIDE_EFFECTS__
176
- function createSlot$1(ownerName) {
177
- const SlotClone = /* @__PURE__ */ createSlotClone$1(ownerName);
178
- const Slot2 = reactExports.forwardRef((props, forwardedRef) => {
179
- const { children, ...slotProps } = props;
180
- const childrenArray = reactExports.Children.toArray(children);
181
- const slottable = childrenArray.find(isSlottable$1);
182
- if (slottable) {
183
- const newElement = slottable.props.children;
184
- const newChildren = childrenArray.map((child) => {
185
- if (child === slottable) {
186
- if (reactExports.Children.count(newElement) > 1) return reactExports.Children.only(null);
187
- return reactExports.isValidElement(newElement) ? newElement.props.children : null;
188
- } else {
189
- return child;
190
- }
191
- });
192
- return /* @__PURE__ */ jsxRuntimeExports.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: reactExports.isValidElement(newElement) ? reactExports.cloneElement(newElement, void 0, newChildren) : null });
193
- }
194
- return /* @__PURE__ */ jsxRuntimeExports.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
195
- });
196
- Slot2.displayName = `${ownerName}.Slot`;
197
- return Slot2;
198
- }
199
- // @__NO_SIDE_EFFECTS__
200
- function createSlotClone$1(ownerName) {
201
- const SlotClone = reactExports.forwardRef((props, forwardedRef) => {
202
- const { children, ...slotProps } = props;
203
- if (reactExports.isValidElement(children)) {
204
- const childrenRef = getElementRef$1(children);
205
- const props2 = mergeProps$1(slotProps, children.props);
206
- if (children.type !== reactExports.Fragment) {
207
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
208
- }
209
- return reactExports.cloneElement(children, props2);
210
- }
211
- return reactExports.Children.count(children) > 1 ? reactExports.Children.only(null) : null;
212
- });
213
- SlotClone.displayName = `${ownerName}.SlotClone`;
214
- return SlotClone;
215
- }
216
- var SLOTTABLE_IDENTIFIER$1 = Symbol("radix.slottable");
217
- function isSlottable$1(child) {
218
- return reactExports.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$1;
219
- }
220
- function mergeProps$1(slotProps, childProps) {
221
- const overrideProps = { ...childProps };
222
- for (const propName in childProps) {
223
- const slotPropValue = slotProps[propName];
224
- const childPropValue = childProps[propName];
225
- const isHandler = /^on[A-Z]/.test(propName);
226
- if (isHandler) {
227
- if (slotPropValue && childPropValue) {
228
- overrideProps[propName] = (...args) => {
229
- const result = childPropValue(...args);
230
- slotPropValue(...args);
231
- return result;
232
- };
233
- } else if (slotPropValue) {
234
- overrideProps[propName] = slotPropValue;
235
- }
236
- } else if (propName === "style") {
237
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
238
- } else if (propName === "className") {
239
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
240
- }
241
- }
242
- return { ...slotProps, ...overrideProps };
243
- }
244
- function getElementRef$1(element) {
245
- let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
246
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
247
- if (mayWarn) {
248
- return element.ref;
249
- }
250
- getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
251
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
252
- if (mayWarn) {
253
- return element.props.ref;
254
- }
255
- return element.props.ref || element.ref;
256
- }
257
-
258
- // src/primitive.tsx
259
- var NODES$1 = [
260
- "a",
261
- "button",
262
- "div",
263
- "form",
264
- "h2",
265
- "h3",
266
- "img",
267
- "input",
268
- "label",
269
- "li",
270
- "nav",
271
- "ol",
272
- "p",
273
- "select",
274
- "span",
275
- "svg",
276
- "ul"
277
- ];
278
- var Primitive$1 = NODES$1.reduce((primitive, node) => {
279
- const Slot = createSlot$1(`Primitive.${node}`);
280
- const Node = reactExports.forwardRef((props, forwardedRef) => {
281
- const { asChild, ...primitiveProps } = props;
282
- const Comp = asChild ? Slot : node;
283
- if (typeof window !== "undefined") {
284
- window[Symbol.for("radix-ui")] = true;
285
- }
286
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Comp, { ...primitiveProps, ref: forwardedRef });
287
- });
288
- Node.displayName = `Primitive.${node}`;
289
- return { ...primitive, [node]: Node };
290
- }, {});
291
-
292
- // packages/react/use-previous/src/use-previous.tsx
293
- function usePrevious(value) {
294
- const ref = reactExports.useRef({ value, previous: value });
295
- return reactExports.useMemo(() => {
296
- if (ref.current.value !== value) {
297
- ref.current.previous = ref.current.value;
298
- ref.current.value = value;
299
- }
300
- return ref.current.previous;
301
- }, [value]);
302
- }
303
-
304
- // src/slot.tsx
305
- // @__NO_SIDE_EFFECTS__
306
- function createSlot(ownerName) {
307
- const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
308
- const Slot2 = reactExports.forwardRef((props, forwardedRef) => {
309
- const { children, ...slotProps } = props;
310
- const childrenArray = reactExports.Children.toArray(children);
311
- const slottable = childrenArray.find(isSlottable);
312
- if (slottable) {
313
- const newElement = slottable.props.children;
314
- const newChildren = childrenArray.map((child) => {
315
- if (child === slottable) {
316
- if (reactExports.Children.count(newElement) > 1) return reactExports.Children.only(null);
317
- return reactExports.isValidElement(newElement) ? newElement.props.children : null;
318
- } else {
319
- return child;
320
- }
321
- });
322
- return /* @__PURE__ */ jsxRuntimeExports.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: reactExports.isValidElement(newElement) ? reactExports.cloneElement(newElement, void 0, newChildren) : null });
323
- }
324
- return /* @__PURE__ */ jsxRuntimeExports.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
325
- });
326
- Slot2.displayName = `${ownerName}.Slot`;
327
- return Slot2;
328
- }
329
- // @__NO_SIDE_EFFECTS__
330
- function createSlotClone(ownerName) {
331
- const SlotClone = reactExports.forwardRef((props, forwardedRef) => {
332
- const { children, ...slotProps } = props;
333
- if (reactExports.isValidElement(children)) {
334
- const childrenRef = getElementRef(children);
335
- const props2 = mergeProps(slotProps, children.props);
336
- if (children.type !== reactExports.Fragment) {
337
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
338
- }
339
- return reactExports.cloneElement(children, props2);
340
- }
341
- return reactExports.Children.count(children) > 1 ? reactExports.Children.only(null) : null;
342
- });
343
- SlotClone.displayName = `${ownerName}.SlotClone`;
344
- return SlotClone;
345
- }
346
- var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
347
- function isSlottable(child) {
348
- return reactExports.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
349
- }
350
- function mergeProps(slotProps, childProps) {
351
- const overrideProps = { ...childProps };
352
- for (const propName in childProps) {
353
- const slotPropValue = slotProps[propName];
354
- const childPropValue = childProps[propName];
355
- const isHandler = /^on[A-Z]/.test(propName);
356
- if (isHandler) {
357
- if (slotPropValue && childPropValue) {
358
- overrideProps[propName] = (...args) => {
359
- const result = childPropValue(...args);
360
- slotPropValue(...args);
361
- return result;
362
- };
363
- } else if (slotPropValue) {
364
- overrideProps[propName] = slotPropValue;
365
- }
366
- } else if (propName === "style") {
367
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
368
- } else if (propName === "className") {
369
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
370
- }
371
- }
372
- return { ...slotProps, ...overrideProps };
373
- }
374
- function getElementRef(element) {
375
- let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
376
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
377
- if (mayWarn) {
378
- return element.ref;
379
- }
380
- getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
381
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
382
- if (mayWarn) {
383
- return element.props.ref;
384
- }
385
- return element.props.ref || element.ref;
386
- }
387
-
388
- // src/primitive.tsx
389
- var NODES = [
390
- "a",
391
- "button",
392
- "div",
393
- "form",
394
- "h2",
395
- "h3",
396
- "img",
397
- "input",
398
- "label",
399
- "li",
400
- "nav",
401
- "ol",
402
- "p",
403
- "select",
404
- "span",
405
- "svg",
406
- "ul"
407
- ];
408
- var Primitive = NODES.reduce((primitive, node) => {
409
- const Slot = createSlot(`Primitive.${node}`);
410
- const Node = reactExports.forwardRef((props, forwardedRef) => {
411
- const { asChild, ...primitiveProps } = props;
412
- const Comp = asChild ? Slot : node;
413
- if (typeof window !== "undefined") {
414
- window[Symbol.for("radix-ui")] = true;
415
- }
416
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Comp, { ...primitiveProps, ref: forwardedRef });
417
- });
418
- Node.displayName = `Primitive.${node}`;
419
- return { ...primitive, [node]: Node };
420
- }, {});
421
-
422
- // src/visually-hidden.tsx
423
- var VISUALLY_HIDDEN_STYLES = Object.freeze({
424
- // See: https://github.com/twbs/bootstrap/blob/main/scss/mixins/_visually-hidden.scss
425
- position: "absolute",
426
- border: 0,
427
- width: 1,
428
- height: 1,
429
- padding: 0,
430
- margin: -1,
431
- overflow: "hidden",
432
- clip: "rect(0, 0, 0, 0)",
433
- whiteSpace: "nowrap",
434
- wordWrap: "normal"
435
- });
436
- var NAME = "VisuallyHidden";
437
- var VisuallyHidden = reactExports.forwardRef(
438
- (props, forwardedRef) => {
439
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
440
- Primitive.span,
441
- {
442
- ...props,
443
- ref: forwardedRef,
444
- style: { ...VISUALLY_HIDDEN_STYLES, ...props.style }
445
- }
446
- );
447
- }
448
- );
449
- VisuallyHidden.displayName = NAME;
450
-
451
- var OPEN_KEYS = [" ", "Enter", "ArrowUp", "ArrowDown"];
452
- var SELECTION_KEYS = [" ", "Enter"];
453
- var SELECT_NAME = "Select";
454
- var [Collection, useCollection, createCollectionScope] = createCollection(SELECT_NAME);
455
- var [createSelectContext] = createContextScope(SELECT_NAME, [
456
- createCollectionScope,
457
- createPopperScope
458
- ]);
459
- var usePopperScope = createPopperScope();
460
- var [SelectProvider, useSelectContext] = createSelectContext(SELECT_NAME);
461
- var [SelectNativeOptionsProvider, useSelectNativeOptionsContext] = createSelectContext(SELECT_NAME);
462
- var Select$1 = (props) => {
463
- const {
464
- __scopeSelect,
465
- children,
466
- open: openProp,
467
- defaultOpen,
468
- onOpenChange,
469
- value: valueProp,
470
- defaultValue,
471
- onValueChange,
472
- dir,
473
- name,
474
- autoComplete,
475
- disabled,
476
- required,
477
- form
478
- } = props;
479
- const popperScope = usePopperScope(__scopeSelect);
480
- const [trigger, setTrigger] = reactExports.useState(null);
481
- const [valueNode, setValueNode] = reactExports.useState(null);
482
- const [valueNodeHasChildren, setValueNodeHasChildren] = reactExports.useState(false);
483
- const direction = useDirection(dir);
484
- const [open, setOpen] = useControllableState({
485
- prop: openProp,
486
- defaultProp: defaultOpen ?? false,
487
- onChange: onOpenChange,
488
- caller: SELECT_NAME
489
- });
490
- const [value, setValue] = useControllableState({
491
- prop: valueProp,
492
- defaultProp: defaultValue,
493
- onChange: onValueChange,
494
- caller: SELECT_NAME
495
- });
496
- const triggerPointerDownPosRef = reactExports.useRef(null);
497
- const isFormControl = trigger ? form || !!trigger.closest("form") : true;
498
- const [nativeOptionsSet, setNativeOptionsSet] = reactExports.useState(/* @__PURE__ */ new Set());
499
- const nativeSelectKey = Array.from(nativeOptionsSet).map((option) => option.props.value).join(";");
500
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Root2$1, { ...popperScope, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
501
- SelectProvider,
502
- {
503
- required,
504
- scope: __scopeSelect,
505
- trigger,
506
- onTriggerChange: setTrigger,
507
- valueNode,
508
- onValueNodeChange: setValueNode,
509
- valueNodeHasChildren,
510
- onValueNodeHasChildrenChange: setValueNodeHasChildren,
511
- contentId: useId(),
512
- value,
513
- onValueChange: setValue,
514
- open,
515
- onOpenChange: setOpen,
516
- dir: direction,
517
- triggerPointerDownPosRef,
518
- disabled,
519
- children: [
520
- /* @__PURE__ */ jsxRuntimeExports.jsx(Collection.Provider, { scope: __scopeSelect, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
521
- SelectNativeOptionsProvider,
522
- {
523
- scope: props.__scopeSelect,
524
- onNativeOptionAdd: reactExports.useCallback((option) => {
525
- setNativeOptionsSet((prev) => new Set(prev).add(option));
526
- }, []),
527
- onNativeOptionRemove: reactExports.useCallback((option) => {
528
- setNativeOptionsSet((prev) => {
529
- const optionsSet = new Set(prev);
530
- optionsSet.delete(option);
531
- return optionsSet;
532
- });
533
- }, []),
534
- children
535
- }
536
- ) }),
537
- isFormControl ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
538
- SelectBubbleInput,
539
- {
540
- "aria-hidden": true,
541
- required,
542
- tabIndex: -1,
543
- name,
544
- autoComplete,
545
- value,
546
- onChange: (event) => setValue(event.target.value),
547
- disabled,
548
- form,
549
- children: [
550
- value === void 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "" }) : null,
551
- Array.from(nativeOptionsSet)
552
- ]
553
- },
554
- nativeSelectKey
555
- ) : null
556
- ]
557
- }
558
- ) });
559
- };
560
- Select$1.displayName = SELECT_NAME;
561
- var TRIGGER_NAME = "SelectTrigger";
562
- var SelectTrigger$1 = reactExports.forwardRef(
563
- (props, forwardedRef) => {
564
- const { __scopeSelect, disabled = false, ...triggerProps } = props;
565
- const popperScope = usePopperScope(__scopeSelect);
566
- const context = useSelectContext(TRIGGER_NAME, __scopeSelect);
567
- const isDisabled = context.disabled || disabled;
568
- const composedRefs = useComposedRefs(forwardedRef, context.onTriggerChange);
569
- const getItems = useCollection(__scopeSelect);
570
- const pointerTypeRef = reactExports.useRef("touch");
571
- const [searchRef, handleTypeaheadSearch, resetTypeahead] = useTypeaheadSearch((search) => {
572
- const enabledItems = getItems().filter((item) => !item.disabled);
573
- const currentItem = enabledItems.find((item) => item.value === context.value);
574
- const nextItem = findNextItem(enabledItems, search, currentItem);
575
- if (nextItem !== void 0) {
576
- context.onValueChange(nextItem.value);
577
- }
578
- });
579
- const handleOpen = (pointerEvent) => {
580
- if (!isDisabled) {
581
- context.onOpenChange(true);
582
- resetTypeahead();
583
- }
584
- if (pointerEvent) {
585
- context.triggerPointerDownPosRef.current = {
586
- x: Math.round(pointerEvent.pageX),
587
- y: Math.round(pointerEvent.pageY)
588
- };
589
- }
590
- };
591
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Anchor, { asChild: true, ...popperScope, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
592
- Primitive$1.button,
593
- {
594
- type: "button",
595
- role: "combobox",
596
- "aria-controls": context.contentId,
597
- "aria-expanded": context.open,
598
- "aria-required": context.required,
599
- "aria-autocomplete": "none",
600
- dir: context.dir,
601
- "data-state": context.open ? "open" : "closed",
602
- disabled: isDisabled,
603
- "data-disabled": isDisabled ? "" : void 0,
604
- "data-placeholder": shouldShowPlaceholder(context.value) ? "" : void 0,
605
- ...triggerProps,
606
- ref: composedRefs,
607
- onClick: composeEventHandlers(triggerProps.onClick, (event) => {
608
- event.currentTarget.focus();
609
- if (pointerTypeRef.current !== "mouse") {
610
- handleOpen(event);
611
- }
612
- }),
613
- onPointerDown: composeEventHandlers(triggerProps.onPointerDown, (event) => {
614
- pointerTypeRef.current = event.pointerType;
615
- const target = event.target;
616
- if (target.hasPointerCapture(event.pointerId)) {
617
- target.releasePointerCapture(event.pointerId);
618
- }
619
- if (event.button === 0 && event.ctrlKey === false && event.pointerType === "mouse") {
620
- handleOpen(event);
621
- event.preventDefault();
622
- }
623
- }),
624
- onKeyDown: composeEventHandlers(triggerProps.onKeyDown, (event) => {
625
- const isTypingAhead = searchRef.current !== "";
626
- const isModifierKey = event.ctrlKey || event.altKey || event.metaKey;
627
- if (!isModifierKey && event.key.length === 1) handleTypeaheadSearch(event.key);
628
- if (isTypingAhead && event.key === " ") return;
629
- if (OPEN_KEYS.includes(event.key)) {
630
- handleOpen();
631
- event.preventDefault();
632
- }
633
- })
634
- }
635
- ) });
636
- }
637
- );
638
- SelectTrigger$1.displayName = TRIGGER_NAME;
639
- var VALUE_NAME = "SelectValue";
640
- var SelectValue$1 = reactExports.forwardRef(
641
- (props, forwardedRef) => {
642
- const { __scopeSelect, className, style, children, placeholder = "", ...valueProps } = props;
643
- const context = useSelectContext(VALUE_NAME, __scopeSelect);
644
- const { onValueNodeHasChildrenChange } = context;
645
- const hasChildren = children !== void 0;
646
- const composedRefs = useComposedRefs(forwardedRef, context.onValueNodeChange);
647
- useLayoutEffect2(() => {
648
- onValueNodeHasChildrenChange(hasChildren);
649
- }, [onValueNodeHasChildrenChange, hasChildren]);
650
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
651
- Primitive$1.span,
652
- {
653
- ...valueProps,
654
- ref: composedRefs,
655
- style: { pointerEvents: "none" },
656
- children: shouldShowPlaceholder(context.value) ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: placeholder }) : children
657
- }
658
- );
659
- }
660
- );
661
- SelectValue$1.displayName = VALUE_NAME;
662
- var ICON_NAME = "SelectIcon";
663
- var SelectIcon = reactExports.forwardRef(
664
- (props, forwardedRef) => {
665
- const { __scopeSelect, children, ...iconProps } = props;
666
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Primitive$1.span, { "aria-hidden": true, ...iconProps, ref: forwardedRef, children: children || "\u25BC" });
667
- }
668
- );
669
- SelectIcon.displayName = ICON_NAME;
670
- var PORTAL_NAME = "SelectPortal";
671
- var SelectPortal = (props) => {
672
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Portal$1, { asChild: true, ...props });
673
- };
674
- SelectPortal.displayName = PORTAL_NAME;
675
- var CONTENT_NAME = "SelectContent";
676
- var SelectContent$1 = reactExports.forwardRef(
677
- (props, forwardedRef) => {
678
- const context = useSelectContext(CONTENT_NAME, props.__scopeSelect);
679
- const [fragment, setFragment] = reactExports.useState();
680
- useLayoutEffect2(() => {
681
- setFragment(new DocumentFragment());
682
- }, []);
683
- if (!context.open) {
684
- const frag = fragment;
685
- return frag ? reactDomExports.createPortal(
686
- /* @__PURE__ */ jsxRuntimeExports.jsx(SelectContentProvider, { scope: props.__scopeSelect, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Collection.Slot, { scope: props.__scopeSelect, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: props.children }) }) }),
687
- frag
688
- ) : null;
689
- }
690
- return /* @__PURE__ */ jsxRuntimeExports.jsx(SelectContentImpl, { ...props, ref: forwardedRef });
691
- }
692
- );
693
- SelectContent$1.displayName = CONTENT_NAME;
694
- var CONTENT_MARGIN = 10;
695
- var [SelectContentProvider, useSelectContentContext] = createSelectContext(CONTENT_NAME);
696
- var CONTENT_IMPL_NAME = "SelectContentImpl";
697
- var Slot = createSlot$1("SelectContent.RemoveScroll");
698
- var SelectContentImpl = reactExports.forwardRef(
699
- (props, forwardedRef) => {
700
- const {
701
- __scopeSelect,
702
- position = "item-aligned",
703
- onCloseAutoFocus,
704
- onEscapeKeyDown,
705
- onPointerDownOutside,
706
- //
707
- // PopperContent props
708
- side,
709
- sideOffset,
710
- align,
711
- alignOffset,
712
- arrowPadding,
713
- collisionBoundary,
714
- collisionPadding,
715
- sticky,
716
- hideWhenDetached,
717
- avoidCollisions,
718
- //
719
- ...contentProps
720
- } = props;
721
- const context = useSelectContext(CONTENT_NAME, __scopeSelect);
722
- const [content, setContent] = reactExports.useState(null);
723
- const [viewport, setViewport] = reactExports.useState(null);
724
- const composedRefs = useComposedRefs(forwardedRef, (node) => setContent(node));
725
- const [selectedItem, setSelectedItem] = reactExports.useState(null);
726
- const [selectedItemText, setSelectedItemText] = reactExports.useState(
727
- null
728
- );
729
- const getItems = useCollection(__scopeSelect);
730
- const [isPositioned, setIsPositioned] = reactExports.useState(false);
731
- const firstValidItemFoundRef = reactExports.useRef(false);
732
- reactExports.useEffect(() => {
733
- if (content) return hideOthers(content);
734
- }, [content]);
735
- useFocusGuards();
736
- const focusFirst = reactExports.useCallback(
737
- (candidates) => {
738
- const [firstItem, ...restItems] = getItems().map((item) => item.ref.current);
739
- const [lastItem] = restItems.slice(-1);
740
- const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
741
- for (const candidate of candidates) {
742
- if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
743
- candidate?.scrollIntoView({ block: "nearest" });
744
- if (candidate === firstItem && viewport) viewport.scrollTop = 0;
745
- if (candidate === lastItem && viewport) viewport.scrollTop = viewport.scrollHeight;
746
- candidate?.focus();
747
- if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
748
- }
749
- },
750
- [getItems, viewport]
751
- );
752
- const focusSelectedItem = reactExports.useCallback(
753
- () => focusFirst([selectedItem, content]),
754
- [focusFirst, selectedItem, content]
755
- );
756
- reactExports.useEffect(() => {
757
- if (isPositioned) {
758
- focusSelectedItem();
759
- }
760
- }, [isPositioned, focusSelectedItem]);
761
- const { onOpenChange, triggerPointerDownPosRef } = context;
762
- reactExports.useEffect(() => {
763
- if (content) {
764
- let pointerMoveDelta = { x: 0, y: 0 };
765
- const handlePointerMove = (event) => {
766
- pointerMoveDelta = {
767
- x: Math.abs(Math.round(event.pageX) - (triggerPointerDownPosRef.current?.x ?? 0)),
768
- y: Math.abs(Math.round(event.pageY) - (triggerPointerDownPosRef.current?.y ?? 0))
769
- };
770
- };
771
- const handlePointerUp = (event) => {
772
- if (pointerMoveDelta.x <= 10 && pointerMoveDelta.y <= 10) {
773
- event.preventDefault();
774
- } else {
775
- if (!content.contains(event.target)) {
776
- onOpenChange(false);
777
- }
778
- }
779
- document.removeEventListener("pointermove", handlePointerMove);
780
- triggerPointerDownPosRef.current = null;
781
- };
782
- if (triggerPointerDownPosRef.current !== null) {
783
- document.addEventListener("pointermove", handlePointerMove);
784
- document.addEventListener("pointerup", handlePointerUp, { capture: true, once: true });
785
- }
786
- return () => {
787
- document.removeEventListener("pointermove", handlePointerMove);
788
- document.removeEventListener("pointerup", handlePointerUp, { capture: true });
789
- };
790
- }
791
- }, [content, onOpenChange, triggerPointerDownPosRef]);
792
- reactExports.useEffect(() => {
793
- const close = () => onOpenChange(false);
794
- window.addEventListener("blur", close);
795
- window.addEventListener("resize", close);
796
- return () => {
797
- window.removeEventListener("blur", close);
798
- window.removeEventListener("resize", close);
799
- };
800
- }, [onOpenChange]);
801
- const [searchRef, handleTypeaheadSearch] = useTypeaheadSearch((search) => {
802
- const enabledItems = getItems().filter((item) => !item.disabled);
803
- const currentItem = enabledItems.find((item) => item.ref.current === document.activeElement);
804
- const nextItem = findNextItem(enabledItems, search, currentItem);
805
- if (nextItem) {
806
- setTimeout(() => nextItem.ref.current.focus());
807
- }
808
- });
809
- const itemRefCallback = reactExports.useCallback(
810
- (node, value, disabled) => {
811
- const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
812
- const isSelectedItem = context.value !== void 0 && context.value === value;
813
- if (isSelectedItem || isFirstValidItem) {
814
- setSelectedItem(node);
815
- if (isFirstValidItem) firstValidItemFoundRef.current = true;
816
- }
817
- },
818
- [context.value]
819
- );
820
- const handleItemLeave = reactExports.useCallback(() => content?.focus(), [content]);
821
- const itemTextRefCallback = reactExports.useCallback(
822
- (node, value, disabled) => {
823
- const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
824
- const isSelectedItem = context.value !== void 0 && context.value === value;
825
- if (isSelectedItem || isFirstValidItem) {
826
- setSelectedItemText(node);
827
- }
828
- },
829
- [context.value]
830
- );
831
- const SelectPosition = position === "popper" ? SelectPopperPosition : SelectItemAlignedPosition;
832
- const popperContentProps = SelectPosition === SelectPopperPosition ? {
833
- side,
834
- sideOffset,
835
- align,
836
- alignOffset,
837
- arrowPadding,
838
- collisionBoundary,
839
- collisionPadding,
840
- sticky,
841
- hideWhenDetached,
842
- avoidCollisions
843
- } : {};
844
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
845
- SelectContentProvider,
846
- {
847
- scope: __scopeSelect,
848
- content,
849
- viewport,
850
- onViewportChange: setViewport,
851
- itemRefCallback,
852
- selectedItem,
853
- onItemLeave: handleItemLeave,
854
- itemTextRefCallback,
855
- focusSelectedItem,
856
- selectedItemText,
857
- position,
858
- isPositioned,
859
- searchRef,
860
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(ReactRemoveScroll, { as: Slot, allowPinchZoom: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
861
- FocusScope,
862
- {
863
- asChild: true,
864
- trapped: context.open,
865
- onMountAutoFocus: (event) => {
866
- event.preventDefault();
867
- },
868
- onUnmountAutoFocus: composeEventHandlers(onCloseAutoFocus, (event) => {
869
- context.trigger?.focus({ preventScroll: true });
870
- event.preventDefault();
871
- }),
872
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(
873
- DismissableLayer,
874
- {
875
- asChild: true,
876
- disableOutsidePointerEvents: true,
877
- onEscapeKeyDown,
878
- onPointerDownOutside,
879
- onFocusOutside: (event) => event.preventDefault(),
880
- onDismiss: () => context.onOpenChange(false),
881
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(
882
- SelectPosition,
883
- {
884
- role: "listbox",
885
- id: context.contentId,
886
- "data-state": context.open ? "open" : "closed",
887
- dir: context.dir,
888
- onContextMenu: (event) => event.preventDefault(),
889
- ...contentProps,
890
- ...popperContentProps,
891
- onPlaced: () => setIsPositioned(true),
892
- ref: composedRefs,
893
- style: {
894
- // flex layout so we can place the scroll buttons properly
895
- display: "flex",
896
- flexDirection: "column",
897
- // reset the outline by default as the content MAY get focused
898
- outline: "none",
899
- ...contentProps.style
900
- },
901
- onKeyDown: composeEventHandlers(contentProps.onKeyDown, (event) => {
902
- const isModifierKey = event.ctrlKey || event.altKey || event.metaKey;
903
- if (event.key === "Tab") event.preventDefault();
904
- if (!isModifierKey && event.key.length === 1) handleTypeaheadSearch(event.key);
905
- if (["ArrowUp", "ArrowDown", "Home", "End"].includes(event.key)) {
906
- const items = getItems().filter((item) => !item.disabled);
907
- let candidateNodes = items.map((item) => item.ref.current);
908
- if (["ArrowUp", "End"].includes(event.key)) {
909
- candidateNodes = candidateNodes.slice().reverse();
910
- }
911
- if (["ArrowUp", "ArrowDown"].includes(event.key)) {
912
- const currentElement = event.target;
913
- const currentIndex = candidateNodes.indexOf(currentElement);
914
- candidateNodes = candidateNodes.slice(currentIndex + 1);
915
- }
916
- setTimeout(() => focusFirst(candidateNodes));
917
- event.preventDefault();
918
- }
919
- })
920
- }
921
- )
922
- }
923
- )
924
- }
925
- ) })
926
- }
927
- );
928
- }
929
- );
930
- SelectContentImpl.displayName = CONTENT_IMPL_NAME;
931
- var ITEM_ALIGNED_POSITION_NAME = "SelectItemAlignedPosition";
932
- var SelectItemAlignedPosition = reactExports.forwardRef((props, forwardedRef) => {
933
- const { __scopeSelect, onPlaced, ...popperProps } = props;
934
- const context = useSelectContext(CONTENT_NAME, __scopeSelect);
935
- const contentContext = useSelectContentContext(CONTENT_NAME, __scopeSelect);
936
- const [contentWrapper, setContentWrapper] = reactExports.useState(null);
937
- const [content, setContent] = reactExports.useState(null);
938
- const composedRefs = useComposedRefs(forwardedRef, (node) => setContent(node));
939
- const getItems = useCollection(__scopeSelect);
940
- const shouldExpandOnScrollRef = reactExports.useRef(false);
941
- const shouldRepositionRef = reactExports.useRef(true);
942
- const { viewport, selectedItem, selectedItemText, focusSelectedItem } = contentContext;
943
- const position = reactExports.useCallback(() => {
944
- if (context.trigger && context.valueNode && contentWrapper && content && viewport && selectedItem && selectedItemText) {
945
- const triggerRect = context.trigger.getBoundingClientRect();
946
- const contentRect = content.getBoundingClientRect();
947
- const valueNodeRect = context.valueNode.getBoundingClientRect();
948
- const itemTextRect = selectedItemText.getBoundingClientRect();
949
- if (context.dir !== "rtl") {
950
- const itemTextOffset = itemTextRect.left - contentRect.left;
951
- const left = valueNodeRect.left - itemTextOffset;
952
- const leftDelta = triggerRect.left - left;
953
- const minContentWidth = triggerRect.width + leftDelta;
954
- const contentWidth = Math.max(minContentWidth, contentRect.width);
955
- const rightEdge = window.innerWidth - CONTENT_MARGIN;
956
- const clampedLeft = clamp(left, [
957
- CONTENT_MARGIN,
958
- // Prevents the content from going off the starting edge of the
959
- // viewport. It may still go off the ending edge, but this can be
960
- // controlled by the user since they may want to manage overflow in a
961
- // specific way.
962
- // https://github.com/radix-ui/primitives/issues/2049
963
- Math.max(CONTENT_MARGIN, rightEdge - contentWidth)
964
- ]);
965
- contentWrapper.style.minWidth = minContentWidth + "px";
966
- contentWrapper.style.left = clampedLeft + "px";
967
- } else {
968
- const itemTextOffset = contentRect.right - itemTextRect.right;
969
- const right = window.innerWidth - valueNodeRect.right - itemTextOffset;
970
- const rightDelta = window.innerWidth - triggerRect.right - right;
971
- const minContentWidth = triggerRect.width + rightDelta;
972
- const contentWidth = Math.max(minContentWidth, contentRect.width);
973
- const leftEdge = window.innerWidth - CONTENT_MARGIN;
974
- const clampedRight = clamp(right, [
975
- CONTENT_MARGIN,
976
- Math.max(CONTENT_MARGIN, leftEdge - contentWidth)
977
- ]);
978
- contentWrapper.style.minWidth = minContentWidth + "px";
979
- contentWrapper.style.right = clampedRight + "px";
980
- }
981
- const items = getItems();
982
- const availableHeight = window.innerHeight - CONTENT_MARGIN * 2;
983
- const itemsHeight = viewport.scrollHeight;
984
- const contentStyles = window.getComputedStyle(content);
985
- const contentBorderTopWidth = parseInt(contentStyles.borderTopWidth, 10);
986
- const contentPaddingTop = parseInt(contentStyles.paddingTop, 10);
987
- const contentBorderBottomWidth = parseInt(contentStyles.borderBottomWidth, 10);
988
- const contentPaddingBottom = parseInt(contentStyles.paddingBottom, 10);
989
- const fullContentHeight = contentBorderTopWidth + contentPaddingTop + itemsHeight + contentPaddingBottom + contentBorderBottomWidth;
990
- const minContentHeight = Math.min(selectedItem.offsetHeight * 5, fullContentHeight);
991
- const viewportStyles = window.getComputedStyle(viewport);
992
- const viewportPaddingTop = parseInt(viewportStyles.paddingTop, 10);
993
- const viewportPaddingBottom = parseInt(viewportStyles.paddingBottom, 10);
994
- const topEdgeToTriggerMiddle = triggerRect.top + triggerRect.height / 2 - CONTENT_MARGIN;
995
- const triggerMiddleToBottomEdge = availableHeight - topEdgeToTriggerMiddle;
996
- const selectedItemHalfHeight = selectedItem.offsetHeight / 2;
997
- const itemOffsetMiddle = selectedItem.offsetTop + selectedItemHalfHeight;
998
- const contentTopToItemMiddle = contentBorderTopWidth + contentPaddingTop + itemOffsetMiddle;
999
- const itemMiddleToContentBottom = fullContentHeight - contentTopToItemMiddle;
1000
- const willAlignWithoutTopOverflow = contentTopToItemMiddle <= topEdgeToTriggerMiddle;
1001
- if (willAlignWithoutTopOverflow) {
1002
- const isLastItem = items.length > 0 && selectedItem === items[items.length - 1].ref.current;
1003
- contentWrapper.style.bottom = "0px";
1004
- const viewportOffsetBottom = content.clientHeight - viewport.offsetTop - viewport.offsetHeight;
1005
- const clampedTriggerMiddleToBottomEdge = Math.max(
1006
- triggerMiddleToBottomEdge,
1007
- selectedItemHalfHeight + // viewport might have padding bottom, include it to avoid a scrollable viewport
1008
- (isLastItem ? viewportPaddingBottom : 0) + viewportOffsetBottom + contentBorderBottomWidth
1009
- );
1010
- const height = contentTopToItemMiddle + clampedTriggerMiddleToBottomEdge;
1011
- contentWrapper.style.height = height + "px";
1012
- } else {
1013
- const isFirstItem = items.length > 0 && selectedItem === items[0].ref.current;
1014
- contentWrapper.style.top = "0px";
1015
- const clampedTopEdgeToTriggerMiddle = Math.max(
1016
- topEdgeToTriggerMiddle,
1017
- contentBorderTopWidth + viewport.offsetTop + // viewport might have padding top, include it to avoid a scrollable viewport
1018
- (isFirstItem ? viewportPaddingTop : 0) + selectedItemHalfHeight
1019
- );
1020
- const height = clampedTopEdgeToTriggerMiddle + itemMiddleToContentBottom;
1021
- contentWrapper.style.height = height + "px";
1022
- viewport.scrollTop = contentTopToItemMiddle - topEdgeToTriggerMiddle + viewport.offsetTop;
1023
- }
1024
- contentWrapper.style.margin = `${CONTENT_MARGIN}px 0`;
1025
- contentWrapper.style.minHeight = minContentHeight + "px";
1026
- contentWrapper.style.maxHeight = availableHeight + "px";
1027
- onPlaced?.();
1028
- requestAnimationFrame(() => shouldExpandOnScrollRef.current = true);
1029
- }
1030
- }, [
1031
- getItems,
1032
- context.trigger,
1033
- context.valueNode,
1034
- contentWrapper,
1035
- content,
1036
- viewport,
1037
- selectedItem,
1038
- selectedItemText,
1039
- context.dir,
1040
- onPlaced
1041
- ]);
1042
- useLayoutEffect2(() => position(), [position]);
1043
- const [contentZIndex, setContentZIndex] = reactExports.useState();
1044
- useLayoutEffect2(() => {
1045
- if (content) setContentZIndex(window.getComputedStyle(content).zIndex);
1046
- }, [content]);
1047
- const handleScrollButtonChange = reactExports.useCallback(
1048
- (node) => {
1049
- if (node && shouldRepositionRef.current === true) {
1050
- position();
1051
- focusSelectedItem?.();
1052
- shouldRepositionRef.current = false;
1053
- }
1054
- },
1055
- [position, focusSelectedItem]
1056
- );
1057
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
1058
- SelectViewportProvider,
1059
- {
1060
- scope: __scopeSelect,
1061
- contentWrapper,
1062
- shouldExpandOnScrollRef,
1063
- onScrollButtonChange: handleScrollButtonChange,
1064
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1065
- "div",
1066
- {
1067
- ref: setContentWrapper,
1068
- style: {
1069
- display: "flex",
1070
- flexDirection: "column",
1071
- position: "fixed",
1072
- zIndex: contentZIndex
1073
- },
1074
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1075
- Primitive$1.div,
1076
- {
1077
- ...popperProps,
1078
- ref: composedRefs,
1079
- style: {
1080
- // When we get the height of the content, it includes borders. If we were to set
1081
- // the height without having `boxSizing: 'border-box'` it would be too big.
1082
- boxSizing: "border-box",
1083
- // We need to ensure the content doesn't get taller than the wrapper
1084
- maxHeight: "100%",
1085
- ...popperProps.style
1086
- }
1087
- }
1088
- )
1089
- }
1090
- )
1091
- }
1092
- );
1093
- });
1094
- SelectItemAlignedPosition.displayName = ITEM_ALIGNED_POSITION_NAME;
1095
- var POPPER_POSITION_NAME = "SelectPopperPosition";
1096
- var SelectPopperPosition = reactExports.forwardRef((props, forwardedRef) => {
1097
- const {
1098
- __scopeSelect,
1099
- align = "start",
1100
- collisionPadding = CONTENT_MARGIN,
1101
- ...popperProps
1102
- } = props;
1103
- const popperScope = usePopperScope(__scopeSelect);
1104
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
1105
- Content,
1106
- {
1107
- ...popperScope,
1108
- ...popperProps,
1109
- ref: forwardedRef,
1110
- align,
1111
- collisionPadding,
1112
- style: {
1113
- // Ensure border-box for floating-ui calculations
1114
- boxSizing: "border-box",
1115
- ...popperProps.style,
1116
- // re-namespace exposed content custom properties
1117
- ...{
1118
- "--radix-select-content-transform-origin": "var(--radix-popper-transform-origin)",
1119
- "--radix-select-content-available-width": "var(--radix-popper-available-width)",
1120
- "--radix-select-content-available-height": "var(--radix-popper-available-height)",
1121
- "--radix-select-trigger-width": "var(--radix-popper-anchor-width)",
1122
- "--radix-select-trigger-height": "var(--radix-popper-anchor-height)"
1123
- }
1124
- }
1125
- }
1126
- );
1127
- });
1128
- SelectPopperPosition.displayName = POPPER_POSITION_NAME;
1129
- var [SelectViewportProvider, useSelectViewportContext] = createSelectContext(CONTENT_NAME, {});
1130
- var VIEWPORT_NAME = "SelectViewport";
1131
- var SelectViewport = reactExports.forwardRef(
1132
- (props, forwardedRef) => {
1133
- const { __scopeSelect, nonce, ...viewportProps } = props;
1134
- const contentContext = useSelectContentContext(VIEWPORT_NAME, __scopeSelect);
1135
- const viewportContext = useSelectViewportContext(VIEWPORT_NAME, __scopeSelect);
1136
- const composedRefs = useComposedRefs(forwardedRef, contentContext.onViewportChange);
1137
- const prevScrollTopRef = reactExports.useRef(0);
1138
- return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
1139
- /* @__PURE__ */ jsxRuntimeExports.jsx(
1140
- "style",
1141
- {
1142
- dangerouslySetInnerHTML: {
1143
- __html: `[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`
1144
- },
1145
- nonce
1146
- }
1147
- ),
1148
- /* @__PURE__ */ jsxRuntimeExports.jsx(Collection.Slot, { scope: __scopeSelect, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1149
- Primitive$1.div,
1150
- {
1151
- "data-radix-select-viewport": "",
1152
- role: "presentation",
1153
- ...viewportProps,
1154
- ref: composedRefs,
1155
- style: {
1156
- // we use position: 'relative' here on the `viewport` so that when we call
1157
- // `selectedItem.offsetTop` in calculations, the offset is relative to the viewport
1158
- // (independent of the scrollUpButton).
1159
- position: "relative",
1160
- flex: 1,
1161
- // Viewport should only be scrollable in the vertical direction.
1162
- // This won't work in vertical writing modes, so we'll need to
1163
- // revisit this if/when that is supported
1164
- // https://developer.chrome.com/blog/vertical-form-controls
1165
- overflow: "hidden auto",
1166
- ...viewportProps.style
1167
- },
1168
- onScroll: composeEventHandlers(viewportProps.onScroll, (event) => {
1169
- const viewport = event.currentTarget;
1170
- const { contentWrapper, shouldExpandOnScrollRef } = viewportContext;
1171
- if (shouldExpandOnScrollRef?.current && contentWrapper) {
1172
- const scrolledBy = Math.abs(prevScrollTopRef.current - viewport.scrollTop);
1173
- if (scrolledBy > 0) {
1174
- const availableHeight = window.innerHeight - CONTENT_MARGIN * 2;
1175
- const cssMinHeight = parseFloat(contentWrapper.style.minHeight);
1176
- const cssHeight = parseFloat(contentWrapper.style.height);
1177
- const prevHeight = Math.max(cssMinHeight, cssHeight);
1178
- if (prevHeight < availableHeight) {
1179
- const nextHeight = prevHeight + scrolledBy;
1180
- const clampedNextHeight = Math.min(availableHeight, nextHeight);
1181
- const heightDiff = nextHeight - clampedNextHeight;
1182
- contentWrapper.style.height = clampedNextHeight + "px";
1183
- if (contentWrapper.style.bottom === "0px") {
1184
- viewport.scrollTop = heightDiff > 0 ? heightDiff : 0;
1185
- contentWrapper.style.justifyContent = "flex-end";
1186
- }
1187
- }
1188
- }
1189
- }
1190
- prevScrollTopRef.current = viewport.scrollTop;
1191
- })
1192
- }
1193
- ) })
1194
- ] });
1195
- }
1196
- );
1197
- SelectViewport.displayName = VIEWPORT_NAME;
1198
- var GROUP_NAME = "SelectGroup";
1199
- var [SelectGroupContextProvider, useSelectGroupContext] = createSelectContext(GROUP_NAME);
1200
- var SelectGroup = reactExports.forwardRef(
1201
- (props, forwardedRef) => {
1202
- const { __scopeSelect, ...groupProps } = props;
1203
- const groupId = useId();
1204
- return /* @__PURE__ */ jsxRuntimeExports.jsx(SelectGroupContextProvider, { scope: __scopeSelect, id: groupId, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Primitive$1.div, { role: "group", "aria-labelledby": groupId, ...groupProps, ref: forwardedRef }) });
1205
- }
1206
- );
1207
- SelectGroup.displayName = GROUP_NAME;
1208
- var LABEL_NAME = "SelectLabel";
1209
- var SelectLabel$1 = reactExports.forwardRef(
1210
- (props, forwardedRef) => {
1211
- const { __scopeSelect, ...labelProps } = props;
1212
- const groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect);
1213
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Primitive$1.div, { id: groupContext.id, ...labelProps, ref: forwardedRef });
1214
- }
1215
- );
1216
- SelectLabel$1.displayName = LABEL_NAME;
1217
- var ITEM_NAME = "SelectItem";
1218
- var [SelectItemContextProvider, useSelectItemContext] = createSelectContext(ITEM_NAME);
1219
- var SelectItem$1 = reactExports.forwardRef(
1220
- (props, forwardedRef) => {
1221
- const {
1222
- __scopeSelect,
1223
- value,
1224
- disabled = false,
1225
- textValue: textValueProp,
1226
- ...itemProps
1227
- } = props;
1228
- const context = useSelectContext(ITEM_NAME, __scopeSelect);
1229
- const contentContext = useSelectContentContext(ITEM_NAME, __scopeSelect);
1230
- const isSelected = context.value === value;
1231
- const [textValue, setTextValue] = reactExports.useState(textValueProp ?? "");
1232
- const [isFocused, setIsFocused] = reactExports.useState(false);
1233
- const composedRefs = useComposedRefs(
1234
- forwardedRef,
1235
- (node) => contentContext.itemRefCallback?.(node, value, disabled)
1236
- );
1237
- const textId = useId();
1238
- const pointerTypeRef = reactExports.useRef("touch");
1239
- const handleSelect = () => {
1240
- if (!disabled) {
1241
- context.onValueChange(value);
1242
- context.onOpenChange(false);
1243
- }
1244
- };
1245
- if (value === "") {
1246
- throw new Error(
1247
- "A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder."
1248
- );
1249
- }
1250
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
1251
- SelectItemContextProvider,
1252
- {
1253
- scope: __scopeSelect,
1254
- value,
1255
- disabled,
1256
- textId,
1257
- isSelected,
1258
- onItemTextChange: reactExports.useCallback((node) => {
1259
- setTextValue((prevTextValue) => prevTextValue || (node?.textContent ?? "").trim());
1260
- }, []),
1261
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1262
- Collection.ItemSlot,
1263
- {
1264
- scope: __scopeSelect,
1265
- value,
1266
- disabled,
1267
- textValue,
1268
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1269
- Primitive$1.div,
1270
- {
1271
- role: "option",
1272
- "aria-labelledby": textId,
1273
- "data-highlighted": isFocused ? "" : void 0,
1274
- "aria-selected": isSelected && isFocused,
1275
- "data-state": isSelected ? "checked" : "unchecked",
1276
- "aria-disabled": disabled || void 0,
1277
- "data-disabled": disabled ? "" : void 0,
1278
- tabIndex: disabled ? void 0 : -1,
1279
- ...itemProps,
1280
- ref: composedRefs,
1281
- onFocus: composeEventHandlers(itemProps.onFocus, () => setIsFocused(true)),
1282
- onBlur: composeEventHandlers(itemProps.onBlur, () => setIsFocused(false)),
1283
- onClick: composeEventHandlers(itemProps.onClick, () => {
1284
- if (pointerTypeRef.current !== "mouse") handleSelect();
1285
- }),
1286
- onPointerUp: composeEventHandlers(itemProps.onPointerUp, () => {
1287
- if (pointerTypeRef.current === "mouse") handleSelect();
1288
- }),
1289
- onPointerDown: composeEventHandlers(itemProps.onPointerDown, (event) => {
1290
- pointerTypeRef.current = event.pointerType;
1291
- }),
1292
- onPointerMove: composeEventHandlers(itemProps.onPointerMove, (event) => {
1293
- pointerTypeRef.current = event.pointerType;
1294
- if (disabled) {
1295
- contentContext.onItemLeave?.();
1296
- } else if (pointerTypeRef.current === "mouse") {
1297
- event.currentTarget.focus({ preventScroll: true });
1298
- }
1299
- }),
1300
- onPointerLeave: composeEventHandlers(itemProps.onPointerLeave, (event) => {
1301
- if (event.currentTarget === document.activeElement) {
1302
- contentContext.onItemLeave?.();
1303
- }
1304
- }),
1305
- onKeyDown: composeEventHandlers(itemProps.onKeyDown, (event) => {
1306
- const isTypingAhead = contentContext.searchRef?.current !== "";
1307
- if (isTypingAhead && event.key === " ") return;
1308
- if (SELECTION_KEYS.includes(event.key)) handleSelect();
1309
- if (event.key === " ") event.preventDefault();
1310
- })
1311
- }
1312
- )
1313
- }
1314
- )
1315
- }
1316
- );
1317
- }
1318
- );
1319
- SelectItem$1.displayName = ITEM_NAME;
1320
- var ITEM_TEXT_NAME = "SelectItemText";
1321
- var SelectItemText = reactExports.forwardRef(
1322
- (props, forwardedRef) => {
1323
- const { __scopeSelect, className, style, ...itemTextProps } = props;
1324
- const context = useSelectContext(ITEM_TEXT_NAME, __scopeSelect);
1325
- const contentContext = useSelectContentContext(ITEM_TEXT_NAME, __scopeSelect);
1326
- const itemContext = useSelectItemContext(ITEM_TEXT_NAME, __scopeSelect);
1327
- const nativeOptionsContext = useSelectNativeOptionsContext(ITEM_TEXT_NAME, __scopeSelect);
1328
- const [itemTextNode, setItemTextNode] = reactExports.useState(null);
1329
- const composedRefs = useComposedRefs(
1330
- forwardedRef,
1331
- (node) => setItemTextNode(node),
1332
- itemContext.onItemTextChange,
1333
- (node) => contentContext.itemTextRefCallback?.(node, itemContext.value, itemContext.disabled)
1334
- );
1335
- const textContent = itemTextNode?.textContent;
1336
- const nativeOption = reactExports.useMemo(
1337
- () => /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: itemContext.value, disabled: itemContext.disabled, children: textContent }, itemContext.value),
1338
- [itemContext.disabled, itemContext.value, textContent]
1339
- );
1340
- const { onNativeOptionAdd, onNativeOptionRemove } = nativeOptionsContext;
1341
- useLayoutEffect2(() => {
1342
- onNativeOptionAdd(nativeOption);
1343
- return () => onNativeOptionRemove(nativeOption);
1344
- }, [onNativeOptionAdd, onNativeOptionRemove, nativeOption]);
1345
- return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
1346
- /* @__PURE__ */ jsxRuntimeExports.jsx(Primitive$1.span, { id: itemContext.textId, ...itemTextProps, ref: composedRefs }),
1347
- itemContext.isSelected && context.valueNode && !context.valueNodeHasChildren ? reactDomExports.createPortal(itemTextProps.children, context.valueNode) : null
1348
- ] });
1349
- }
1350
- );
1351
- SelectItemText.displayName = ITEM_TEXT_NAME;
1352
- var ITEM_INDICATOR_NAME = "SelectItemIndicator";
1353
- var SelectItemIndicator = reactExports.forwardRef(
1354
- (props, forwardedRef) => {
1355
- const { __scopeSelect, ...itemIndicatorProps } = props;
1356
- const itemContext = useSelectItemContext(ITEM_INDICATOR_NAME, __scopeSelect);
1357
- return itemContext.isSelected ? /* @__PURE__ */ jsxRuntimeExports.jsx(Primitive$1.span, { "aria-hidden": true, ...itemIndicatorProps, ref: forwardedRef }) : null;
1358
- }
1359
- );
1360
- SelectItemIndicator.displayName = ITEM_INDICATOR_NAME;
1361
- var SCROLL_UP_BUTTON_NAME = "SelectScrollUpButton";
1362
- var SelectScrollUpButton$1 = reactExports.forwardRef((props, forwardedRef) => {
1363
- const contentContext = useSelectContentContext(SCROLL_UP_BUTTON_NAME, props.__scopeSelect);
1364
- const viewportContext = useSelectViewportContext(SCROLL_UP_BUTTON_NAME, props.__scopeSelect);
1365
- const [canScrollUp, setCanScrollUp] = reactExports.useState(false);
1366
- const composedRefs = useComposedRefs(forwardedRef, viewportContext.onScrollButtonChange);
1367
- useLayoutEffect2(() => {
1368
- if (contentContext.viewport && contentContext.isPositioned) {
1369
- let handleScroll2 = function() {
1370
- const canScrollUp2 = viewport.scrollTop > 0;
1371
- setCanScrollUp(canScrollUp2);
1372
- };
1373
- const viewport = contentContext.viewport;
1374
- handleScroll2();
1375
- viewport.addEventListener("scroll", handleScroll2);
1376
- return () => viewport.removeEventListener("scroll", handleScroll2);
1377
- }
1378
- }, [contentContext.viewport, contentContext.isPositioned]);
1379
- return canScrollUp ? /* @__PURE__ */ jsxRuntimeExports.jsx(
1380
- SelectScrollButtonImpl,
1381
- {
1382
- ...props,
1383
- ref: composedRefs,
1384
- onAutoScroll: () => {
1385
- const { viewport, selectedItem } = contentContext;
1386
- if (viewport && selectedItem) {
1387
- viewport.scrollTop = viewport.scrollTop - selectedItem.offsetHeight;
1388
- }
1389
- }
1390
- }
1391
- ) : null;
1392
- });
1393
- SelectScrollUpButton$1.displayName = SCROLL_UP_BUTTON_NAME;
1394
- var SCROLL_DOWN_BUTTON_NAME = "SelectScrollDownButton";
1395
- var SelectScrollDownButton$1 = reactExports.forwardRef((props, forwardedRef) => {
1396
- const contentContext = useSelectContentContext(SCROLL_DOWN_BUTTON_NAME, props.__scopeSelect);
1397
- const viewportContext = useSelectViewportContext(SCROLL_DOWN_BUTTON_NAME, props.__scopeSelect);
1398
- const [canScrollDown, setCanScrollDown] = reactExports.useState(false);
1399
- const composedRefs = useComposedRefs(forwardedRef, viewportContext.onScrollButtonChange);
1400
- useLayoutEffect2(() => {
1401
- if (contentContext.viewport && contentContext.isPositioned) {
1402
- let handleScroll2 = function() {
1403
- const maxScroll = viewport.scrollHeight - viewport.clientHeight;
1404
- const canScrollDown2 = Math.ceil(viewport.scrollTop) < maxScroll;
1405
- setCanScrollDown(canScrollDown2);
1406
- };
1407
- const viewport = contentContext.viewport;
1408
- handleScroll2();
1409
- viewport.addEventListener("scroll", handleScroll2);
1410
- return () => viewport.removeEventListener("scroll", handleScroll2);
1411
- }
1412
- }, [contentContext.viewport, contentContext.isPositioned]);
1413
- return canScrollDown ? /* @__PURE__ */ jsxRuntimeExports.jsx(
1414
- SelectScrollButtonImpl,
1415
- {
1416
- ...props,
1417
- ref: composedRefs,
1418
- onAutoScroll: () => {
1419
- const { viewport, selectedItem } = contentContext;
1420
- if (viewport && selectedItem) {
1421
- viewport.scrollTop = viewport.scrollTop + selectedItem.offsetHeight;
1422
- }
1423
- }
1424
- }
1425
- ) : null;
1426
- });
1427
- SelectScrollDownButton$1.displayName = SCROLL_DOWN_BUTTON_NAME;
1428
- var SelectScrollButtonImpl = reactExports.forwardRef((props, forwardedRef) => {
1429
- const { __scopeSelect, onAutoScroll, ...scrollIndicatorProps } = props;
1430
- const contentContext = useSelectContentContext("SelectScrollButton", __scopeSelect);
1431
- const autoScrollTimerRef = reactExports.useRef(null);
1432
- const getItems = useCollection(__scopeSelect);
1433
- const clearAutoScrollTimer = reactExports.useCallback(() => {
1434
- if (autoScrollTimerRef.current !== null) {
1435
- window.clearInterval(autoScrollTimerRef.current);
1436
- autoScrollTimerRef.current = null;
1437
- }
1438
- }, []);
1439
- reactExports.useEffect(() => {
1440
- return () => clearAutoScrollTimer();
1441
- }, [clearAutoScrollTimer]);
1442
- useLayoutEffect2(() => {
1443
- const activeItem = getItems().find((item) => item.ref.current === document.activeElement);
1444
- activeItem?.ref.current?.scrollIntoView({ block: "nearest" });
1445
- }, [getItems]);
1446
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
1447
- Primitive$1.div,
1448
- {
1449
- "aria-hidden": true,
1450
- ...scrollIndicatorProps,
1451
- ref: forwardedRef,
1452
- style: { flexShrink: 0, ...scrollIndicatorProps.style },
1453
- onPointerDown: composeEventHandlers(scrollIndicatorProps.onPointerDown, () => {
1454
- if (autoScrollTimerRef.current === null) {
1455
- autoScrollTimerRef.current = window.setInterval(onAutoScroll, 50);
1456
- }
1457
- }),
1458
- onPointerMove: composeEventHandlers(scrollIndicatorProps.onPointerMove, () => {
1459
- contentContext.onItemLeave?.();
1460
- if (autoScrollTimerRef.current === null) {
1461
- autoScrollTimerRef.current = window.setInterval(onAutoScroll, 50);
1462
- }
1463
- }),
1464
- onPointerLeave: composeEventHandlers(scrollIndicatorProps.onPointerLeave, () => {
1465
- clearAutoScrollTimer();
1466
- })
1467
- }
1468
- );
1469
- });
1470
- var SEPARATOR_NAME = "SelectSeparator";
1471
- var SelectSeparator$1 = reactExports.forwardRef(
1472
- (props, forwardedRef) => {
1473
- const { __scopeSelect, ...separatorProps } = props;
1474
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Primitive$1.div, { "aria-hidden": true, ...separatorProps, ref: forwardedRef });
1475
- }
1476
- );
1477
- SelectSeparator$1.displayName = SEPARATOR_NAME;
1478
- var ARROW_NAME = "SelectArrow";
1479
- var SelectArrow = reactExports.forwardRef(
1480
- (props, forwardedRef) => {
1481
- const { __scopeSelect, ...arrowProps } = props;
1482
- const popperScope = usePopperScope(__scopeSelect);
1483
- const context = useSelectContext(ARROW_NAME, __scopeSelect);
1484
- const contentContext = useSelectContentContext(ARROW_NAME, __scopeSelect);
1485
- return context.open && contentContext.position === "popper" ? /* @__PURE__ */ jsxRuntimeExports.jsx(Arrow, { ...popperScope, ...arrowProps, ref: forwardedRef }) : null;
1486
- }
1487
- );
1488
- SelectArrow.displayName = ARROW_NAME;
1489
- var BUBBLE_INPUT_NAME = "SelectBubbleInput";
1490
- var SelectBubbleInput = reactExports.forwardRef(
1491
- ({ __scopeSelect, value, ...props }, forwardedRef) => {
1492
- const ref = reactExports.useRef(null);
1493
- const composedRefs = useComposedRefs(forwardedRef, ref);
1494
- const prevValue = usePrevious(value);
1495
- reactExports.useEffect(() => {
1496
- const select = ref.current;
1497
- if (!select) return;
1498
- const selectProto = window.HTMLSelectElement.prototype;
1499
- const descriptor = Object.getOwnPropertyDescriptor(
1500
- selectProto,
1501
- "value"
1502
- );
1503
- const setValue = descriptor.set;
1504
- if (prevValue !== value && setValue) {
1505
- const event = new Event("change", { bubbles: true });
1506
- setValue.call(select, value);
1507
- select.dispatchEvent(event);
1508
- }
1509
- }, [prevValue, value]);
1510
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
1511
- Primitive$1.select,
1512
- {
1513
- ...props,
1514
- style: { ...VISUALLY_HIDDEN_STYLES, ...props.style },
1515
- ref: composedRefs,
1516
- defaultValue: value
1517
- }
1518
- );
1519
- }
1520
- );
1521
- SelectBubbleInput.displayName = BUBBLE_INPUT_NAME;
1522
- function shouldShowPlaceholder(value) {
1523
- return value === "" || value === void 0;
1524
- }
1525
- function useTypeaheadSearch(onSearchChange) {
1526
- const handleSearchChange = useCallbackRef(onSearchChange);
1527
- const searchRef = reactExports.useRef("");
1528
- const timerRef = reactExports.useRef(0);
1529
- const handleTypeaheadSearch = reactExports.useCallback(
1530
- (key) => {
1531
- const search = searchRef.current + key;
1532
- handleSearchChange(search);
1533
- (function updateSearch(value) {
1534
- searchRef.current = value;
1535
- window.clearTimeout(timerRef.current);
1536
- if (value !== "") timerRef.current = window.setTimeout(() => updateSearch(""), 1e3);
1537
- })(search);
1538
- },
1539
- [handleSearchChange]
1540
- );
1541
- const resetTypeahead = reactExports.useCallback(() => {
1542
- searchRef.current = "";
1543
- window.clearTimeout(timerRef.current);
1544
- }, []);
1545
- reactExports.useEffect(() => {
1546
- return () => window.clearTimeout(timerRef.current);
1547
- }, []);
1548
- return [searchRef, handleTypeaheadSearch, resetTypeahead];
1549
- }
1550
- function findNextItem(items, search, currentItem) {
1551
- const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
1552
- const normalizedSearch = isRepeated ? search[0] : search;
1553
- const currentItemIndex = currentItem ? items.indexOf(currentItem) : -1;
1554
- let wrappedItems = wrapArray(items, Math.max(currentItemIndex, 0));
1555
- const excludeCurrentItem = normalizedSearch.length === 1;
1556
- if (excludeCurrentItem) wrappedItems = wrappedItems.filter((v) => v !== currentItem);
1557
- const nextItem = wrappedItems.find(
1558
- (item) => item.textValue.toLowerCase().startsWith(normalizedSearch.toLowerCase())
1559
- );
1560
- return nextItem !== currentItem ? nextItem : void 0;
1561
- }
1562
- function wrapArray(array, startIndex) {
1563
- return array.map((_, index) => array[(startIndex + index) % array.length]);
1564
- }
1565
- var Root2 = Select$1;
1566
- var Trigger = SelectTrigger$1;
1567
- var Value = SelectValue$1;
1568
- var Icon = SelectIcon;
1569
- var Portal = SelectPortal;
1570
- var Content2 = SelectContent$1;
1571
- var Viewport = SelectViewport;
1572
- var Label = SelectLabel$1;
1573
- var Item = SelectItem$1;
1574
- var ItemText = SelectItemText;
1575
- var ItemIndicator = SelectItemIndicator;
1576
- var ScrollUpButton = SelectScrollUpButton$1;
1577
- var ScrollDownButton = SelectScrollDownButton$1;
1578
- var Separator = SelectSeparator$1;
1579
-
1580
- const Select = Root2;
1581
- const SelectValue = Value;
1582
- const SelectTrigger = reactExports.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
1583
- Trigger,
1584
- {
1585
- ref,
1586
- className: cn(
1587
- "flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background",
1588
- "placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
1589
- "disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
1590
- className
1591
- ),
1592
- ...props,
1593
- children: [
1594
- children,
1595
- /* @__PURE__ */ jsxRuntimeExports.jsx(Icon, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronDown, { className: "h-4 w-4 opacity-50" }) })
1596
- ]
1597
- }
1598
- ));
1599
- SelectTrigger.displayName = Trigger.displayName;
1600
- const SelectScrollUpButton = reactExports.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(
1601
- ScrollUpButton,
1602
- {
1603
- ref,
1604
- className: cn("flex cursor-default items-center justify-center py-1", className),
1605
- ...props,
1606
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronUp, { className: "h-4 w-4" })
1607
- }
1608
- ));
1609
- SelectScrollUpButton.displayName = ScrollUpButton.displayName;
1610
- const SelectScrollDownButton = reactExports.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(
1611
- ScrollDownButton,
1612
- {
1613
- ref,
1614
- className: cn("flex cursor-default items-center justify-center py-1", className),
1615
- ...props,
1616
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronDown, { className: "h-4 w-4" })
1617
- }
1618
- ));
1619
- SelectScrollDownButton.displayName = ScrollDownButton.displayName;
1620
- const SelectContent = reactExports.forwardRef(({ className, children, position = "popper", ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(Portal, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
1621
- Content2,
1622
- {
1623
- ref,
1624
- className: cn(
1625
- "relative z-[10002] max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md",
1626
- "data-[state=open]:animate-in data-[state=closed]:animate-out",
1627
- "data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
1628
- "data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
1629
- "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2",
1630
- "data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
1631
- position === "popper" && "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
1632
- className
1633
- ),
1634
- position,
1635
- ...props,
1636
- children: [
1637
- /* @__PURE__ */ jsxRuntimeExports.jsx(SelectScrollUpButton, {}),
1638
- /* @__PURE__ */ jsxRuntimeExports.jsx(
1639
- Viewport,
1640
- {
1641
- className: cn(
1642
- "p-1",
1643
- position === "popper" && "w-full min-w-[var(--radix-select-trigger-width)] max-h-[var(--radix-select-content-available-height)]"
1644
- ),
1645
- children
1646
- }
1647
- ),
1648
- /* @__PURE__ */ jsxRuntimeExports.jsx(SelectScrollDownButton, {})
1649
- ]
1650
- }
1651
- ) }));
1652
- SelectContent.displayName = Content2.displayName;
1653
- const SelectLabel = reactExports.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(
1654
- Label,
1655
- {
1656
- ref,
1657
- className: cn("py-1.5 pl-8 pr-2 text-sm font-semibold", className),
1658
- ...props
1659
- }
1660
- ));
1661
- SelectLabel.displayName = Label.displayName;
1662
- const SelectItem = reactExports.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
1663
- Item,
1664
- {
1665
- ref,
1666
- className: cn(
1667
- "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none",
1668
- "focus:bg-accent focus:text-accent-foreground",
1669
- "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
1670
- className
1671
- ),
1672
- ...props,
1673
- children: [
1674
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(ItemIndicator, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Check, { className: "h-4 w-4" }) }) }),
1675
- /* @__PURE__ */ jsxRuntimeExports.jsx(ItemText, { children })
1676
- ]
1677
- }
1678
- ));
1679
- SelectItem.displayName = Item.displayName;
1680
- const SelectSeparator = reactExports.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(
1681
- Separator,
1682
- {
1683
- ref,
1684
- className: cn("-mx-1 my-1 h-px bg-muted", className),
1685
- ...props
1686
- }
1687
- ));
1688
- SelectSeparator.displayName = Separator.displayName;
1689
-
1690
- export { DOWNLOAD_MAX_BYTES as D, Layers as L, Select as S, TEXT_PREVIEW_MAX_BYTES as T, SelectTrigger as a, SelectValue as b, SelectContent as c, SelectItem as d, Server as e, formatFileSize as f, findSensitiveMarker as g, joinPath as j, normalizePath as n, splitPath as s };