@tscircuit/cli 0.0.394 → 0.1.2

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 (246) hide show
  1. package/.github/workflows/bun-formatcheck.yml +26 -0
  2. package/.github/workflows/bun-pver-release.yml +25 -0
  3. package/.github/workflows/{typecheck.yml → bun-typecheck.yml} +0 -3
  4. package/LICENSE +21 -0
  5. package/README.md +33 -36
  6. package/biome.json +9 -9
  7. package/bun.lockb +0 -0
  8. package/cli/CliContext.ts +8 -0
  9. package/cli/auth/login/register.ts +73 -0
  10. package/cli/auth/logout/register.ts +11 -0
  11. package/cli/auth/register.ts +5 -0
  12. package/cli/clone/register.ts +99 -0
  13. package/cli/config/print/register.ts +12 -0
  14. package/cli/config/register.ts +5 -0
  15. package/cli/dev/register.ts +111 -0
  16. package/cli/main.ts +33 -0
  17. package/dist/main.js +537 -0
  18. package/docs/file-server-api-usage.md +57 -0
  19. package/docs/run-frame-usage.md +14 -0
  20. package/example-dir/manual-edits.json +1 -0
  21. package/example-dir/snippet.d.ts +13 -0
  22. package/example-dir/snippet.tsx +20 -0
  23. package/example-dir/types.d.ts +11 -0
  24. package/lib/cli-config/TypedConfigStore.ts +50 -0
  25. package/lib/cli-config/index.ts +16 -0
  26. package/lib/dependency-analysis/DependencyAnalyzer.ts +129 -0
  27. package/lib/dependency-analysis/getLocalFileDependencies.ts +101 -0
  28. package/lib/dependency-analysis/installNodeModuleTypes.ts +74 -0
  29. package/lib/index.ts +2 -0
  30. package/lib/project-config/index.ts +5 -0
  31. package/lib/registry-api/endpoint-types.ts +20 -0
  32. package/lib/registry-api/get-ky.ts +30 -0
  33. package/lib/server/EventsWatcher.ts +75 -0
  34. package/lib/server/createServer.ts +62 -0
  35. package/lib/site/getIndex.ts +18 -0
  36. package/package.json +27 -144
  37. package/tsconfig.json +25 -22
  38. package/.github/workflows/formatbot.yml +0 -63
  39. package/.github/workflows/release.yml +0 -40
  40. package/.github/workflows/test.yml +0 -32
  41. package/.github/workflows/windows-tests.yml +0 -32
  42. package/.prettierrc +0 -1
  43. package/DEVELOPMENT.md +0 -7
  44. package/api/README.md +0 -3
  45. package/api/db/generic-json-level.ts +0 -123
  46. package/api/db/get-db.ts +0 -26
  47. package/api/db/schema.ts +0 -65
  48. package/api/db/zod-level-db.ts +0 -148
  49. package/api/index.ts +0 -4
  50. package/api/lib/middlewares/with-db.ts +0 -18
  51. package/api/lib/middlewares/with-debug-request-logging.ts +0 -13
  52. package/api/lib/middlewares/with-error-response.ts +0 -37
  53. package/api/lib/with-winter-spec.ts +0 -9
  54. package/api/lib/zod/export_parameters.ts +0 -25
  55. package/api/routes/api/db/download.ts +0 -25
  56. package/api/routes/api/dev_package_examples/create.ts +0 -43
  57. package/api/routes/api/dev_package_examples/get.ts +0 -46
  58. package/api/routes/api/dev_package_examples/list.ts +0 -36
  59. package/api/routes/api/dev_package_examples/update.ts +0 -59
  60. package/api/routes/api/dev_server/reset.ts +0 -13
  61. package/api/routes/api/export_files/create.ts +0 -27
  62. package/api/routes/api/export_files/download.ts +0 -25
  63. package/api/routes/api/export_requests/create.ts +0 -30
  64. package/api/routes/api/export_requests/get.ts +0 -43
  65. package/api/routes/api/export_requests/list.ts +0 -26
  66. package/api/routes/api/export_requests/update.ts +0 -34
  67. package/api/routes/api/health.ts +0 -11
  68. package/api/routes/api/package_info/create.ts +0 -26
  69. package/api/routes/api/package_info/get.ts +0 -16
  70. package/api/routes/health.ts +0 -11
  71. package/api/routes/index.ts +0 -16
  72. package/api/server.ts +0 -20
  73. package/api/static-routes.ts +0 -24
  74. package/api/tests/fixtures/get-test-server.ts +0 -31
  75. package/api/tests/fixtures/start-server.ts +0 -41
  76. package/api/tests/routes/dev_package_examples/create.test.ts +0 -19
  77. package/api/tests/routes/dev_package_examples/get.test.ts +0 -25
  78. package/api/tests/routes/dev_package_examples/list.test.ts +0 -32
  79. package/api/tests/routes/dev_package_examples/update.test.ts +0 -38
  80. package/api/tests/routes/export_files/create.test.ts +0 -18
  81. package/api/tests/routes/export_files/download.test.ts +0 -29
  82. package/api/tests/routes/export_requests/create.test.ts +0 -24
  83. package/api/tests/routes/export_requests/get.test.ts +0 -41
  84. package/api/tests/routes/export_requests/list.test.ts +0 -35
  85. package/api/tests/routes/export_requests/update.test.ts +0 -50
  86. package/api/tests/routes/health.test.ts +0 -10
  87. package/bunfig.toml +0 -2
  88. package/cli/cli.ts +0 -13
  89. package/cli/lib/cmd-fns/add.ts +0 -34
  90. package/cli/lib/cmd-fns/auth-login.ts +0 -59
  91. package/cli/lib/cmd-fns/auth-logout.ts +0 -7
  92. package/cli/lib/cmd-fns/auth-sessions-create.ts +0 -3
  93. package/cli/lib/cmd-fns/auth-sessions-get.ts +0 -3
  94. package/cli/lib/cmd-fns/auth-sessions-list.ts +0 -5
  95. package/cli/lib/cmd-fns/config-clear.ts +0 -5
  96. package/cli/lib/cmd-fns/config-print-config.ts +0 -6
  97. package/cli/lib/cmd-fns/config-reveal-location.ts +0 -5
  98. package/cli/lib/cmd-fns/config-set-log-requests.ts +0 -7
  99. package/cli/lib/cmd-fns/config-set-registry.ts +0 -9
  100. package/cli/lib/cmd-fns/config-set-runtime.ts +0 -7
  101. package/cli/lib/cmd-fns/config-set-session.ts +0 -7
  102. package/cli/lib/cmd-fns/dev/check-if-initialized.ts +0 -22
  103. package/cli/lib/cmd-fns/dev/derive-selector-from-pcb-component-id.ts +0 -23
  104. package/cli/lib/cmd-fns/dev/dev-server-request-handler.ts +0 -61
  105. package/cli/lib/cmd-fns/dev/find-available-port.ts +0 -32
  106. package/cli/lib/cmd-fns/dev/fulfill-export-requests.ts +0 -162
  107. package/cli/lib/cmd-fns/dev/get-dev-server-axios.ts +0 -29
  108. package/cli/lib/cmd-fns/dev/index.ts +0 -168
  109. package/cli/lib/cmd-fns/dev/infer-export-name-from-source.ts +0 -17
  110. package/cli/lib/cmd-fns/dev/mark-all-examples-loading.ts +0 -18
  111. package/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts +0 -62
  112. package/cli/lib/cmd-fns/dev/start-dev-server.ts +0 -34
  113. package/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts +0 -347
  114. package/cli/lib/cmd-fns/dev/start-export-request-watcher.ts +0 -33
  115. package/cli/lib/cmd-fns/dev/start-fs-watcher.ts +0 -54
  116. package/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts +0 -42
  117. package/cli/lib/cmd-fns/dev-server-fulfill-export-requests.ts +0 -43
  118. package/cli/lib/cmd-fns/dev-server-upload.ts +0 -56
  119. package/cli/lib/cmd-fns/export-gerbers.ts +0 -28
  120. package/cli/lib/cmd-fns/export-kicad-pcb.ts +0 -36
  121. package/cli/lib/cmd-fns/export-pnp-csv.ts +0 -32
  122. package/cli/lib/cmd-fns/gen-jlcpcb-component.ts +0 -64
  123. package/cli/lib/cmd-fns/go.ts +0 -14
  124. package/cli/lib/cmd-fns/index.ts +0 -46
  125. package/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts +0 -21
  126. package/cli/lib/cmd-fns/init/get-generated-npmrc.ts +0 -8
  127. package/cli/lib/cmd-fns/init/get-generated-readme.ts +0 -41
  128. package/cli/lib/cmd-fns/init/get-generated-tsconfig.ts +0 -34
  129. package/cli/lib/cmd-fns/init/index.ts +0 -193
  130. package/cli/lib/cmd-fns/install.ts +0 -34
  131. package/cli/lib/cmd-fns/lint.ts +0 -43
  132. package/cli/lib/cmd-fns/open.ts +0 -19
  133. package/cli/lib/cmd-fns/package-examples-create.ts +0 -36
  134. package/cli/lib/cmd-fns/package-examples-get.ts +0 -20
  135. package/cli/lib/cmd-fns/package-examples-list.ts +0 -18
  136. package/cli/lib/cmd-fns/package-files-create.ts +0 -31
  137. package/cli/lib/cmd-fns/package-files-download.ts +0 -29
  138. package/cli/lib/cmd-fns/package-files-get.ts +0 -3
  139. package/cli/lib/cmd-fns/package-files-list.ts +0 -28
  140. package/cli/lib/cmd-fns/package-files-upload-directory.ts +0 -6
  141. package/cli/lib/cmd-fns/package-releases-create.ts +0 -35
  142. package/cli/lib/cmd-fns/package-releases-get.ts +0 -3
  143. package/cli/lib/cmd-fns/package-releases-list.ts +0 -32
  144. package/cli/lib/cmd-fns/package-releases-update.ts +0 -45
  145. package/cli/lib/cmd-fns/packages-create.ts +0 -16
  146. package/cli/lib/cmd-fns/packages-get.ts +0 -16
  147. package/cli/lib/cmd-fns/packages-list.ts +0 -16
  148. package/cli/lib/cmd-fns/publish/index.ts +0 -336
  149. package/cli/lib/cmd-fns/remove.ts +0 -31
  150. package/cli/lib/cmd-fns/render.ts +0 -45
  151. package/cli/lib/cmd-fns/soupify.ts +0 -31
  152. package/cli/lib/cmd-fns/uninstall.ts +0 -31
  153. package/cli/lib/cmd-fns/version.ts +0 -38
  154. package/cli/lib/create-config-manager.ts +0 -97
  155. package/cli/lib/export-fns/export-bom-csv.ts +0 -32
  156. package/cli/lib/export-fns/export-gerbers.ts +0 -108
  157. package/cli/lib/export-fns/export-kicad-pcb.ts +0 -32
  158. package/cli/lib/export-fns/export-pnp-csv.ts +0 -31
  159. package/cli/lib/get-program.ts +0 -387
  160. package/cli/lib/param-handlers/index.ts +0 -21
  161. package/cli/lib/param-handlers/interact-for-local-directory.ts +0 -58
  162. package/cli/lib/param-handlers/interact-for-local-file.ts +0 -59
  163. package/cli/lib/param-handlers/interact-for-package-example-id.ts +0 -25
  164. package/cli/lib/param-handlers/interact-for-package-name-with-version.ts +0 -63
  165. package/cli/lib/param-handlers/interact-for-package-name.ts +0 -45
  166. package/cli/lib/param-handlers/interact-for-package-release-id.ts +0 -15
  167. package/cli/lib/param-handlers/interact-for-registry-url.ts +0 -27
  168. package/cli/lib/param-handlers/interact-for-runtime.ts +0 -33
  169. package/cli/lib/param-handlers/param-handler-type.ts +0 -7
  170. package/cli/lib/posthog.ts +0 -23
  171. package/cli/lib/soupify/get-export-name-from-file.ts +0 -29
  172. package/cli/lib/soupify/get-tmp-entrpoint-filepath.ts +0 -15
  173. package/cli/lib/soupify/index.ts +0 -1
  174. package/cli/lib/soupify/run-entrypoint-file.ts +0 -59
  175. package/cli/lib/soupify/soupify-with-core.ts +0 -74
  176. package/cli/lib/soupify/soupify.ts +0 -6
  177. package/cli/lib/util/app-context.ts +0 -17
  178. package/cli/lib/util/create-context-and-run-program.ts +0 -168
  179. package/cli/lib/util/get-all-package-files.ts +0 -66
  180. package/cli/lib/util/lint-project.ts +0 -137
  181. package/cli/tests/export-gerber-keyboard.test.ts +0 -16
  182. package/cli/tests/export-gerber.test.ts +0 -49
  183. package/cli/tests/export-kicad-pcb.test.ts +0 -23
  184. package/cli/tests/export-pnp-csv.test.ts +0 -24
  185. package/cli/tests/fixtures/preload.ts +0 -54
  186. package/cli/tests/init.test.ts +0 -9
  187. package/cli/tests/open.test.ts +0 -9
  188. package/cli/tests/soupify-builder.test.ts +0 -9
  189. package/cli/tests/soupify-core.test.ts +0 -9
  190. package/dist/cli.js +0 -3676
  191. package/docs/EDIT_EVENT_PIPELINE.md +0 -34
  192. package/example-project/README.md +0 -18
  193. package/example-project/examples/basic-capacitor.tsx +0 -5
  194. package/example-project/examples/basic-chip.tsx +0 -26
  195. package/example-project/examples/basic-resistor.tsx +0 -3
  196. package/example-project/examples/macrokeypad.tsx +0 -59
  197. package/example-project/index.ts +0 -1
  198. package/example-project/package.json +0 -5
  199. package/example-project/src/ArduinoProMicroBreakout.tsx +0 -37
  200. package/example-project/src/Key.tsx +0 -46
  201. package/example-project/src/Keyswitch.tsx +0 -26
  202. package/example-project/src/KeyswitchSocket.tsx +0 -56
  203. package/example-project/src/MyCircuit.tsx +0 -38
  204. package/example-project/src/manual-edits.ts +0 -93
  205. package/frontend/README.md +0 -3
  206. package/frontend/bun.lockb +0 -0
  207. package/frontend/components/command-k.tsx +0 -86
  208. package/frontend/components/dialogs/generic-export-dialog.tsx +0 -189
  209. package/frontend/components/dialogs/gerber-export-dialog.tsx +0 -168
  210. package/frontend/components/global-context-providers.tsx +0 -11
  211. package/frontend/components/select-example-search.tsx +0 -118
  212. package/frontend/components/ui/alert-dialog.tsx +0 -139
  213. package/frontend/components/ui/alert.tsx +0 -59
  214. package/frontend/components/ui/breadcrumb.tsx +0 -115
  215. package/frontend/components/ui/button.tsx +0 -57
  216. package/frontend/components/ui/card.tsx +0 -76
  217. package/frontend/components/ui/command.tsx +0 -153
  218. package/frontend/components/ui/context-menu.tsx +0 -202
  219. package/frontend/components/ui/dialog.tsx +0 -120
  220. package/frontend/components/ui/menubar.tsx +0 -238
  221. package/frontend/components/ui/navigation-menu.tsx +0 -128
  222. package/frontend/components/ui/popover.tsx +0 -31
  223. package/frontend/components/ui/select.tsx +0 -162
  224. package/frontend/components/ui/tabs.tsx +0 -53
  225. package/frontend/components/ui/toggle-group.tsx +0 -59
  226. package/frontend/components/ui/toggle.tsx +0 -43
  227. package/frontend/components/ui/tooltip.tsx +0 -28
  228. package/frontend/components.json +0 -17
  229. package/frontend/hooks/toast-if-api-not-connected.ts +0 -23
  230. package/frontend/hooks/use-active-dev-package-example-lite.ts +0 -39
  231. package/frontend/hooks/use-dev-package-examples.tsx +0 -18
  232. package/frontend/hooks/use-global-store.ts +0 -42
  233. package/frontend/index.css +0 -76
  234. package/frontend/index.html +0 -13
  235. package/frontend/lib/utils.ts +0 -6
  236. package/frontend/main.tsx +0 -13
  237. package/frontend/tailwind.config.js +0 -74
  238. package/frontend/views/App.tsx +0 -22
  239. package/frontend/views/Header.tsx +0 -55
  240. package/frontend/views/HeaderMenu.tsx +0 -326
  241. package/frontend/views/MainContentView.tsx +0 -172
  242. package/frontend/vite-env.d.ts +0 -1
  243. package/frontend/vite.config.ts +0 -50
  244. package/renovate.json +0 -16
  245. package/scripts/build-cli.ts +0 -12
  246. package/tsup.config.ts +0 -7
@@ -1,189 +0,0 @@
1
- import { useMemo, useState } from "react"
2
- import { Dialog } from "@headlessui/react"
3
- import { useGlobalStore } from "frontend/hooks/use-global-store"
4
- import { useActiveDevPackageExampleLite } from "frontend/hooks/use-active-dev-package-example-lite"
5
- import { Button } from "../ui/button"
6
- import axios from "axios"
7
- import type { ExportParametersInput } from "api/lib/zod/export_parameters"
8
-
9
- export const useGenericExportDialog = ({
10
- exportFileName,
11
- dialogTitle,
12
- dialogDescription,
13
- exportParameters,
14
- fileExtension = "",
15
- }: {
16
- exportFileName: string
17
- dialogTitle: string
18
- dialogDescription: string
19
- exportParameters: ExportParametersInput
20
- fileExtension?: string
21
- }) => {
22
- const [open, setIsOpen] = useState(false)
23
- const activeDevExamplePackage = useActiveDevPackageExampleLite()
24
- const [isExporting, setIsExporting] = useState(false)
25
- const [exportError, setExportError] = useState<string | null>(null)
26
-
27
- return useMemo(() => {
28
- const openDialog = () => {
29
- setIsOpen(true)
30
- }
31
- const closeDialog = () => {
32
- setIsOpen(false)
33
- setIsExporting(false)
34
- }
35
- if (!activeDevExamplePackage)
36
- return {
37
- openDialog,
38
- closeDialog,
39
- Component: () => null,
40
- }
41
- const { file_path: inputFilePath, export_name: exampleExportName } =
42
- activeDevExamplePackage
43
- const outputName = `${
44
- inputFilePath.split("/").pop()?.split(".")[0]
45
- }-${exampleExportName}-${exportFileName}${fileExtension}`
46
-
47
- return {
48
- openDialog,
49
- closeDialog,
50
- Component: () => (
51
- <GenericExportDialog
52
- dialogTitle={dialogTitle}
53
- dialogDescription={dialogDescription}
54
- open={open}
55
- isExporting={isExporting}
56
- filePath={inputFilePath}
57
- tsCircuitExportName={exampleExportName}
58
- outputName={outputName}
59
- exportError={exportError}
60
- onClickExport={async () => {
61
- setExportError(null)
62
- setIsExporting(true)
63
- try {
64
- if (exportParameters.should_export_pnp_csv) {
65
- exportParameters.pnp_csv_file_name ??= exportFileName
66
- }
67
- if (exportParameters.should_export_bom_csv) {
68
- exportParameters.bom_csv_file_name ??= exportFileName
69
- }
70
- if (exportParameters.should_export_soup_json) {
71
- exportParameters.soup_json_file_name ??= exportFileName
72
- }
73
-
74
- let export_request = await axios
75
- .post("/api/export_requests/create", {
76
- example_file_path: activeDevExamplePackage.file_path,
77
- export_name: activeDevExamplePackage.export_name,
78
- export_parameters: exportParameters,
79
- })
80
- .then((r) => r.data.export_request)
81
- const pollExportRequest = async () => {
82
- while (!export_request.is_complete) {
83
- try {
84
- export_request = await axios
85
- .post("/api/export_requests/get", {
86
- export_request_id: export_request.export_request_id,
87
- })
88
- .then((r) => r.data.export_request)
89
- } catch (e: any) {
90
- console.error(e)
91
- setExportError(
92
- `${e.toString()}\n\n${e.response?.data?.error?.message}`,
93
- )
94
- setIsExporting(false)
95
- return
96
- }
97
- await new Promise((resolve) => setTimeout(resolve, 100))
98
- }
99
- setIsExporting(false)
100
- }
101
- await pollExportRequest()
102
- // open /api/export_files/download?export_file_id=... in new tab
103
- const export_file_id =
104
- export_request.file_summary[0].export_file_id
105
- window.open(
106
- `/api/export_files/download?export_file_id=${export_file_id}`,
107
- "_blank",
108
- )
109
- setIsExporting(false)
110
- } catch (e: any) {
111
- console.error(e)
112
- setExportError(
113
- `${e.toString()}\n\n${e.response?.data?.error?.message}`,
114
- )
115
- setIsExporting(false)
116
- }
117
- }}
118
- onClose={() => closeDialog()}
119
- />
120
- ),
121
- }
122
- }, [open, isExporting, exportError])
123
- }
124
-
125
- export const GenericExportDialog = ({
126
- open,
127
- dialogTitle,
128
- dialogDescription,
129
- isExporting,
130
- filePath,
131
- tsCircuitExportName,
132
- outputName,
133
- exportError,
134
- onClose,
135
- onClickExport,
136
- }: {
137
- open: boolean
138
- dialogTitle: string
139
- dialogDescription: string
140
- filePath: string
141
- tsCircuitExportName: string
142
- isExporting: boolean
143
- outputName: string
144
- exportError?: string | null
145
- onClose: (value: boolean) => void
146
- onClickExport: () => any
147
- }) => {
148
- return (
149
- <Dialog open={open} onClose={onClose} className="relative z-[101]">
150
- <div className="fixed inset-0 bg-black/30" aria-hidden="true" />
151
- <div className="fixed inset-0 flex w-screen items-center justify-center p-4">
152
- <Dialog.Panel className="w-full max-w-lg rounded bg-white p-6 border border-[rgba(0,0,0,0.3)]">
153
- <Dialog.Title className="text-lg font-semibold tracking-tight text-black">
154
- {dialogTitle}
155
- </Dialog.Title>
156
- <Dialog.Description className="text-sm font-medium text-muted-foreground">
157
- {dialogDescription}
158
- </Dialog.Description>
159
- {exportError && (
160
- <div className="text-red-700 bg-red-100 border-red-200 border whitespace-pre-wrap font-mono text-xs p-4 mt-8">
161
- {exportError}
162
- </div>
163
- )}
164
- <div className="text-xs font-medium grid grid-cols-4 font-mono mt-8 gap-4">
165
- <div className="text-muted-foreground font-sans">Status</div>
166
- <div className="col-span-3 text-muted-foreground font-sans">
167
- {isExporting ? "Exporting" : "Not Started"}
168
- </div>
169
- <div className="text-muted-foreground font-sans">File Path</div>
170
- <div className="col-span-3">{filePath.split("/examples/")[1]}</div>
171
- <div className="text-muted-foreground font-sans">Export Name</div>
172
- <div className="col-span-3">{tsCircuitExportName}</div>
173
- <div className="text-muted-foreground font-sans">Output Name</div>
174
- <div className="col-span-3">{outputName}</div>
175
- </div>
176
- <div className="flex mt-8 justify-end">
177
- <Button
178
- variant={isExporting ? "ghost" : "default"}
179
- disabled={isExporting}
180
- onClick={onClickExport}
181
- >
182
- {isExporting ? `Exporting...` : `Export`}
183
- </Button>
184
- </div>
185
- </Dialog.Panel>
186
- </div>
187
- </Dialog>
188
- )
189
- }
@@ -1,168 +0,0 @@
1
- import { useMemo, useState } from "react"
2
- import { Dialog } from "@headlessui/react"
3
- import { useGlobalStore } from "frontend/hooks/use-global-store"
4
- import { useActiveDevPackageExampleLite } from "frontend/hooks/use-active-dev-package-example-lite"
5
- import { Button } from "../ui/button"
6
- import axios from "axios"
7
-
8
- export const useGerberExportDialog = () => {
9
- const [open, setIsOpen] = useState(false)
10
- const activeDevExamplePackage = useActiveDevPackageExampleLite()
11
- const [isExporting, setIsExporting] = useState(false)
12
- const [exportError, setExportError] = useState<string | null>(null)
13
-
14
- return useMemo(() => {
15
- const openDialog = () => {
16
- setIsOpen(true)
17
- }
18
- const closeDialog = () => {
19
- setIsOpen(false)
20
- setIsExporting(false)
21
- }
22
- if (!activeDevExamplePackage)
23
- return {
24
- openDialog,
25
- closeDialog,
26
- Component: () => null,
27
- }
28
- const { file_path, export_name } = activeDevExamplePackage
29
- const outputName = `${
30
- file_path.split("/").pop()?.split(".")[0]
31
- }-${export_name}-gerbers.zip`
32
-
33
- return {
34
- openDialog,
35
- closeDialog,
36
- Component: () => (
37
- <GerberExportDialog
38
- open={open}
39
- isExporting={isExporting}
40
- filePath={file_path}
41
- exportName={export_name}
42
- outputName={outputName}
43
- exportError={exportError}
44
- onClickExport={async () => {
45
- setExportError(null)
46
- setIsExporting(true)
47
- try {
48
- let export_request = await axios
49
- .post("/api/export_requests/create", {
50
- example_file_path: activeDevExamplePackage.file_path,
51
- export_name: activeDevExamplePackage.export_name,
52
- export_parameters: {
53
- should_export_gerber_zip: true,
54
- gerbers_zip_file_name: outputName,
55
- },
56
- })
57
- .then((r) => r.data.export_request)
58
-
59
- const pollExportRequest = async () => {
60
- while (!export_request.is_complete) {
61
- try {
62
- export_request = await axios
63
- .post("/api/export_requests/get", {
64
- export_request_id: export_request.export_request_id,
65
- })
66
- .then((r) => r.data.export_request)
67
- } catch (e: any) {
68
- console.error(e)
69
- setExportError(
70
- `${e.toString()}\n\n${e.response?.data?.error?.message}`,
71
- )
72
- setIsExporting(false)
73
- return
74
- }
75
- await new Promise((resolve) => setTimeout(resolve, 100))
76
- }
77
- setIsExporting(false)
78
- }
79
-
80
- await pollExportRequest()
81
-
82
- // open /api/export_files/download?export_file_id=... in new tab
83
-
84
- const export_file_id =
85
- export_request.file_summary[0].export_file_id
86
-
87
- window.open(
88
- `/api/export_files/download?export_file_id=${export_file_id}`,
89
- "_blank",
90
- )
91
-
92
- setIsExporting(false)
93
- } catch (e: any) {
94
- console.error(e)
95
- setExportError(
96
- `${e.toString()}\n\n${e.response?.data?.error?.message}`,
97
- )
98
- setIsExporting(false)
99
- }
100
- }}
101
- onClose={() => closeDialog()}
102
- />
103
- ),
104
- }
105
- }, [open, isExporting, exportError])
106
- }
107
-
108
- export const GerberExportDialog = ({
109
- open,
110
- isExporting,
111
- filePath,
112
- exportName,
113
- outputName,
114
- exportError,
115
- onClose,
116
- onClickExport,
117
- }: {
118
- open: boolean
119
- filePath: string
120
- exportName: string
121
- isExporting: boolean
122
- outputName: string
123
- exportError?: string | null
124
- onClose: (value: boolean) => void
125
- onClickExport: () => any
126
- }) => {
127
- return (
128
- <Dialog open={open} onClose={onClose} className="relative z-[101]">
129
- <div className="fixed inset-0 bg-black/30" aria-hidden="true" />
130
- <div className="fixed inset-0 flex w-screen items-center justify-center p-4">
131
- <Dialog.Panel className="w-full max-w-lg rounded bg-white p-6 border border-[rgba(0,0,0,0.3)]">
132
- <Dialog.Title className="text-lg font-semibold tracking-tight text-black">
133
- Export Gerbers
134
- </Dialog.Title>
135
- <Dialog.Description className="text-sm font-medium text-muted-foreground">
136
- Export your PCB design to Gerber files.
137
- </Dialog.Description>
138
- {exportError && (
139
- <div className="text-red-700 bg-red-100 border-red-200 border whitespace-pre-wrap font-mono text-xs p-4 mt-8">
140
- {exportError}
141
- </div>
142
- )}
143
- <div className="text-xs font-medium grid grid-cols-4 font-mono mt-8 gap-4">
144
- <div className="text-muted-foreground font-sans">Status</div>
145
- <div className="col-span-3 text-muted-foreground font-sans">
146
- {isExporting ? "Exporting" : "Not Started"}
147
- </div>
148
- <div className="text-muted-foreground font-sans">File Path</div>
149
- <div className="col-span-3">{filePath.split("/examples/")[1]}</div>
150
- <div className="text-muted-foreground font-sans">Export Name</div>
151
- <div className="col-span-3">{exportName}</div>
152
- <div className="text-muted-foreground font-sans">Output Name</div>
153
- <div className="col-span-3">{outputName}</div>
154
- </div>
155
- <div className="flex mt-8 justify-end">
156
- <Button
157
- variant={isExporting ? "ghost" : "default"}
158
- disabled={isExporting}
159
- onClick={onClickExport}
160
- >
161
- {isExporting ? `Exporting...` : `Export`}
162
- </Button>
163
- </div>
164
- </Dialog.Panel>
165
- </div>
166
- </Dialog>
167
- )
168
- }
@@ -1,11 +0,0 @@
1
- import { Toaster } from "react-hot-toast"
2
- import { QueryClient, QueryClientProvider } from "react-query"
3
-
4
- const queryClient = new QueryClient()
5
-
6
- export const GlobalContextProviders = ({ children }: any) => (
7
- <>
8
- <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
9
- <Toaster />
10
- </>
11
- )
@@ -1,118 +0,0 @@
1
- "use client"
2
-
3
- import * as React from "react"
4
- import { CaretSortIcon, CheckIcon } from "@radix-ui/react-icons"
5
-
6
- import { cn } from "frontend/lib/utils"
7
- import { Button } from "frontend/components/ui/button"
8
- import {
9
- Command,
10
- CommandEmpty,
11
- CommandGroup,
12
- CommandInput,
13
- CommandItem,
14
- CommandList,
15
- CommandShortcut,
16
- } from "frontend/components/ui/command"
17
- import {
18
- Popover,
19
- PopoverContent,
20
- PopoverTrigger,
21
- } from "frontend/components/ui/popover"
22
- import { useGlobalStore } from "frontend/hooks/use-global-store"
23
- import { useDevPackageExamples } from "../hooks/use-dev-package-examples"
24
- import { useActiveDevPackageExampleLite } from "frontend/hooks/use-active-dev-package-example-lite"
25
-
26
- export function inflatePackageExample(ex: any) {
27
- if (!ex) return ex
28
- return {
29
- ...ex,
30
- expath: ex.file_path.replace(/.*examples\//, ""),
31
- searchable_id: `${ex.file_path.replace(/.*examples\//, "")} | ${
32
- ex.export_name
33
- }`,
34
- }
35
- }
36
-
37
- export const SelectExampleSearch = () => {
38
- const [open, setOpen] = React.useState(false)
39
- const { data: examples } = useDevPackageExamples()
40
- const [active_dev_example_package_id, setActiveDevExamplePackageId] =
41
- useGlobalStore((s) => [
42
- s.active_dev_example_package_id,
43
- s.setActiveDevExamplePackageId,
44
- ])
45
-
46
- const activeDevExamplePackage = useActiveDevPackageExampleLite()
47
-
48
- React.useEffect(() => {
49
- const down = (e: KeyboardEvent) => {
50
- if (e.key === "o" && (e.metaKey || e.ctrlKey)) {
51
- e.preventDefault()
52
- setOpen((open) => !open)
53
- }
54
- }
55
-
56
- document.addEventListener("keydown", down)
57
- return () => document.removeEventListener("keydown", down)
58
- }, [])
59
-
60
- return (
61
- <Popover open={open} onOpenChange={setOpen} modal>
62
- <PopoverTrigger asChild>
63
- <Button
64
- variant="outline"
65
- role="combobox"
66
- aria-expanded={open}
67
- className="w-[200px] justify-between"
68
- >
69
- <div>
70
- {activeDevExamplePackage
71
- ? activeDevExamplePackage.expath
72
- : "Select Circuit"}
73
- </div>
74
- <CommandShortcut>
75
- <kbd>⌘O</kbd>
76
- </CommandShortcut>
77
- <CaretSortIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
78
- </Button>
79
- </PopoverTrigger>
80
- <PopoverContent className="w-[400px] p-0 z-[101]">
81
- <Command value={active_dev_example_package_id ?? "none"}>
82
- <CommandInput placeholder="Search for circuit..." className="h-9" />
83
- <CommandList>
84
- <CommandEmpty>
85
- <div className="text-gray-600 mt-8">
86
- No matching circuits in{" "}
87
- <span className="font-mono bg-gray-100 py-0.5 px-1 rounded-sm">
88
- ./examples
89
- </span>
90
- </div>
91
- <Button className="mt-12 mb-8">Create Circuit</Button>
92
- </CommandEmpty>
93
- <CommandGroup>
94
- {examples?.map((example) => (
95
- <CommandItem
96
- key={example.dev_package_example_id}
97
- value={example.searchable_id}
98
- onSelect={() => {
99
- setActiveDevExamplePackageId(
100
- example.dev_package_example_id.toString(),
101
- )
102
- setOpen(false)
103
- }}
104
- className="flex justify-between cursor-pointer hover:bg-gray-100"
105
- >
106
- <div className="text-gray-800">{example.expath}</div>
107
- <div className="font-mono text-xs text-gray-600">
108
- {example.export_name}
109
- </div>
110
- </CommandItem>
111
- ))}
112
- </CommandGroup>
113
- </CommandList>
114
- </Command>
115
- </PopoverContent>
116
- </Popover>
117
- )
118
- }
@@ -1,139 +0,0 @@
1
- import * as React from "react"
2
- import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"
3
-
4
- import { cn } from "frontend/lib/utils"
5
- import { buttonVariants } from "frontend/components/ui/button"
6
-
7
- const AlertDialog = AlertDialogPrimitive.Root
8
-
9
- const AlertDialogTrigger = AlertDialogPrimitive.Trigger
10
-
11
- const AlertDialogPortal = AlertDialogPrimitive.Portal
12
-
13
- const AlertDialogOverlay = React.forwardRef<
14
- React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
15
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
16
- >(({ className, ...props }, ref) => (
17
- <AlertDialogPrimitive.Overlay
18
- className={cn(
19
- "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
20
- className,
21
- )}
22
- {...props}
23
- ref={ref}
24
- />
25
- ))
26
- AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName
27
-
28
- const AlertDialogContent = React.forwardRef<
29
- React.ElementRef<typeof AlertDialogPrimitive.Content>,
30
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
31
- >(({ className, ...props }, ref) => (
32
- <AlertDialogPortal>
33
- <AlertDialogOverlay />
34
- <AlertDialogPrimitive.Content
35
- ref={ref}
36
- className={cn(
37
- "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
38
- className,
39
- )}
40
- {...props}
41
- />
42
- </AlertDialogPortal>
43
- ))
44
- AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName
45
-
46
- const AlertDialogHeader = ({
47
- className,
48
- ...props
49
- }: React.HTMLAttributes<HTMLDivElement>) => (
50
- <div
51
- className={cn(
52
- "flex flex-col space-y-2 text-center sm:text-left",
53
- className,
54
- )}
55
- {...props}
56
- />
57
- )
58
- AlertDialogHeader.displayName = "AlertDialogHeader"
59
-
60
- const AlertDialogFooter = ({
61
- className,
62
- ...props
63
- }: React.HTMLAttributes<HTMLDivElement>) => (
64
- <div
65
- className={cn(
66
- "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
67
- className,
68
- )}
69
- {...props}
70
- />
71
- )
72
- AlertDialogFooter.displayName = "AlertDialogFooter"
73
-
74
- const AlertDialogTitle = React.forwardRef<
75
- React.ElementRef<typeof AlertDialogPrimitive.Title>,
76
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
77
- >(({ className, ...props }, ref) => (
78
- <AlertDialogPrimitive.Title
79
- ref={ref}
80
- className={cn("text-lg font-semibold", className)}
81
- {...props}
82
- />
83
- ))
84
- AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName
85
-
86
- const AlertDialogDescription = React.forwardRef<
87
- React.ElementRef<typeof AlertDialogPrimitive.Description>,
88
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
89
- >(({ className, ...props }, ref) => (
90
- <AlertDialogPrimitive.Description
91
- ref={ref}
92
- className={cn("text-sm text-muted-foreground", className)}
93
- {...props}
94
- />
95
- ))
96
- AlertDialogDescription.displayName =
97
- AlertDialogPrimitive.Description.displayName
98
-
99
- const AlertDialogAction = React.forwardRef<
100
- React.ElementRef<typeof AlertDialogPrimitive.Action>,
101
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
102
- >(({ className, ...props }, ref) => (
103
- <AlertDialogPrimitive.Action
104
- ref={ref}
105
- className={cn(buttonVariants(), className)}
106
- {...props}
107
- />
108
- ))
109
- AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName
110
-
111
- const AlertDialogCancel = React.forwardRef<
112
- React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
113
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
114
- >(({ className, ...props }, ref) => (
115
- <AlertDialogPrimitive.Cancel
116
- ref={ref}
117
- className={cn(
118
- buttonVariants({ variant: "outline" }),
119
- "mt-2 sm:mt-0",
120
- className,
121
- )}
122
- {...props}
123
- />
124
- ))
125
- AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName
126
-
127
- export {
128
- AlertDialog,
129
- AlertDialogPortal,
130
- AlertDialogOverlay,
131
- AlertDialogTrigger,
132
- AlertDialogContent,
133
- AlertDialogHeader,
134
- AlertDialogFooter,
135
- AlertDialogTitle,
136
- AlertDialogDescription,
137
- AlertDialogAction,
138
- AlertDialogCancel,
139
- }
@@ -1,59 +0,0 @@
1
- import * as React from "react"
2
- import { cva, type VariantProps } from "class-variance-authority"
3
-
4
- import { cn } from "frontend/lib/utils"
5
-
6
- const alertVariants = cva(
7
- "relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",
8
- {
9
- variants: {
10
- variant: {
11
- default: "bg-background text-foreground",
12
- destructive:
13
- "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",
14
- },
15
- },
16
- defaultVariants: {
17
- variant: "default",
18
- },
19
- },
20
- )
21
-
22
- const Alert = React.forwardRef<
23
- HTMLDivElement,
24
- React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
25
- >(({ className, variant, ...props }, ref) => (
26
- <div
27
- ref={ref}
28
- role="alert"
29
- className={cn(alertVariants({ variant }), className)}
30
- {...props}
31
- />
32
- ))
33
- Alert.displayName = "Alert"
34
-
35
- const AlertTitle = React.forwardRef<
36
- HTMLParagraphElement,
37
- React.HTMLAttributes<HTMLHeadingElement>
38
- >(({ className, ...props }, ref) => (
39
- <h5
40
- ref={ref}
41
- className={cn("mb-1 font-medium leading-none tracking-tight", className)}
42
- {...props}
43
- />
44
- ))
45
- AlertTitle.displayName = "AlertTitle"
46
-
47
- const AlertDescription = React.forwardRef<
48
- HTMLParagraphElement,
49
- React.HTMLAttributes<HTMLParagraphElement>
50
- >(({ className, ...props }, ref) => (
51
- <div
52
- ref={ref}
53
- className={cn("text-sm [&_p]:leading-relaxed", className)}
54
- {...props}
55
- />
56
- ))
57
- AlertDescription.displayName = "AlertDescription"
58
-
59
- export { Alert, AlertTitle, AlertDescription }