@tscircuit/cli 0.0.58 → 0.0.60

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.
@@ -0,0 +1,39 @@
1
+ import { useDevPackageExamples } from "./use-dev-package-examples"
2
+ import { useGlobalStore } from "./use-global-store"
3
+
4
+ export function inflatePackageExample(ex: any): {
5
+ dev_package_example_id: number
6
+ searchable_id: string
7
+ file_path: string
8
+ expath: string
9
+ export_name: string
10
+ last_updated_at: string
11
+ } {
12
+ if (!ex) return ex
13
+ return {
14
+ ...ex,
15
+ expath: ex.file_path.replace(/.*examples\//, ""),
16
+ searchable_id: `${ex.file_path.replace(/.*examples\//, "")} | ${
17
+ ex.export_name
18
+ }`,
19
+ }
20
+ }
21
+
22
+ export const useActiveDevPackageExampleLite = () => {
23
+ const { data: examples } = useDevPackageExamples()
24
+
25
+ const [active_dev_example_package_id, setActiveDevExamplePackageId] =
26
+ useGlobalStore((s) => [
27
+ s.active_dev_example_package_id,
28
+ s.setActiveDevExamplePackageId,
29
+ ])
30
+
31
+ const activeDevExamplePackage = inflatePackageExample(
32
+ examples?.find(
33
+ (ex) =>
34
+ ex.dev_package_example_id.toString() === active_dev_example_package_id
35
+ )
36
+ )
37
+
38
+ return activeDevExamplePackage
39
+ }
@@ -0,0 +1,18 @@
1
+ "use client"
2
+ import { useQuery } from "react-query"
3
+ import axios from "axios"
4
+ import { inflatePackageExample } from "../components/select-example-search"
5
+
6
+ export const useDevPackageExamples = () => {
7
+ return useQuery("examples", async () => {
8
+ const { data } = await axios.get("/api/dev_package_examples/list")
9
+ return data.dev_package_examples.map(inflatePackageExample) as Array<{
10
+ dev_package_example_id: number
11
+ searchable_id: string
12
+ file_path: string
13
+ expath: string
14
+ export_name: string
15
+ last_updated_at: string
16
+ }>
17
+ })
18
+ }