@tscircuit/runframe 0.0.306 → 0.0.307

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/runner.js CHANGED
@@ -458,7 +458,6 @@ var RunFrame = (props) => {
458
458
  }).then(() => {
459
459
  return { success: true };
460
460
  }).catch((e) => {
461
- console.log("error", e);
462
461
  const message = e.message.replace("Error: ", "");
463
462
  props.onError?.(e);
464
463
  setError({ error: message, stack: e.stack });
@@ -1473,8 +1472,9 @@ var importComponentFromJlcpcb = async (jlcpcbPartNumber) => {
1473
1472
  import { useState as useState8 } from "react";
1474
1473
 
1475
1474
  // lib/components/OrderDialog/OrderDialog.tsx
1476
- import ky2 from "ky";
1475
+ import ky3 from "ky";
1477
1476
  import { useState as useState7 } from "react";
1477
+ import { QueryClient, QueryClientProvider } from "react-query";
1478
1478
 
1479
1479
  // lib/components/OrderDialog/CheckoutOrder.tsx
1480
1480
  import { MapPin } from "lucide-react";
@@ -1484,7 +1484,7 @@ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
1484
1484
  var CheckoutOrder = ({
1485
1485
  finalCost,
1486
1486
  onConfirmCheckout,
1487
- onBack
1487
+ onCancel
1488
1488
  }) => {
1489
1489
  const [selectedAddressId, setSelectedAddressId] = useState6(
1490
1490
  null
@@ -1706,9 +1706,9 @@ var CheckoutOrder = ({
1706
1706
  Button,
1707
1707
  {
1708
1708
  variant: "outline",
1709
- onClick: onBack,
1709
+ onClick: onCancel,
1710
1710
  className: "rf-w-full rf-mt-3",
1711
- children: "Back to PCB Order"
1711
+ children: "Cancel"
1712
1712
  }
1713
1713
  )
1714
1714
  ] })
@@ -1750,7 +1750,7 @@ var InitialOrderScreen = ({
1750
1750
  };
1751
1751
 
1752
1752
  // lib/components/OrderDialog/StepwiseProgress.tsx
1753
- import { Check as Check2, Loader2 as Loader23, ArrowDown } from "lucide-react";
1753
+ import ky2 from "ky";
1754
1754
 
1755
1755
  // lib/components/ui/progress.tsx
1756
1756
  import * as React5 from "react";
@@ -1777,84 +1777,10 @@ var Progress = React5.forwardRef(({ className, value, ...props }, ref) => /* @__
1777
1777
  Progress.displayName = "Progress";
1778
1778
 
1779
1779
  // lib/components/OrderDialog/StepwiseProgress.tsx
1780
- import { Fragment as Fragment2, jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
1781
- var StepwiseProgressPanel = ({
1782
- steps,
1783
- title = "Order PCB",
1784
- onCancel,
1785
- onContinue,
1786
- continueButtonText = "Continue",
1787
- cancelButtonText = "Cancel",
1788
- loading = false
1789
- }) => {
1790
- const completedSteps = steps.filter((step) => step.completed);
1791
- const activeStep = steps.find((step) => step.active);
1792
- const totalSteps = steps.length;
1793
- const progress = Math.round(completedSteps.length / totalSteps * 100);
1794
- const displayedCompletedSteps = completedSteps.slice(-1);
1795
- return /* @__PURE__ */ jsxs8("div", { className: "rf-flex rf-flex-col rf-bg-white rf-rounded-xl rf-p-6 rf-max-w-xl rf-w-full rf-mx-auto", children: [
1796
- /* @__PURE__ */ jsxs8("div", { className: "rf-flex rf-items-center rf-justify-between rf-mb-6", children: [
1797
- /* @__PURE__ */ jsx11("h2", { className: "rf-text-2xl rf-font-bold", children: title }),
1798
- /* @__PURE__ */ jsxs8("div", { className: "rf-text-sm rf-text-muted-foreground", children: [
1799
- completedSteps.length,
1800
- " of ",
1801
- totalSteps,
1802
- " completed"
1803
- ] })
1804
- ] }),
1805
- /* @__PURE__ */ jsx11(Progress, { value: progress, className: "rf-h-2 rf-mb-8" }),
1806
- /* @__PURE__ */ jsxs8("div", { className: "rf-space-y-6 rf-mb-8", children: [
1807
- displayedCompletedSteps.map((step, index) => /* @__PURE__ */ jsxs8(
1808
- "div",
1809
- {
1810
- className: "rf-flex rf-items-start rf-gap-4",
1811
- children: [
1812
- /* @__PURE__ */ jsx11("div", { className: "rf-flex-shrink-0 rf-mt-0.5", children: /* @__PURE__ */ jsx11("div", { className: "rf-w-8 rf-h-8 rf-rounded-full rf-bg-green-100 rf-flex rf-items-center rf-justify-center", children: /* @__PURE__ */ jsx11(Check2, { className: "rf-h-5 rf-w-5 rf-text-green-600" }) }) }),
1813
- /* @__PURE__ */ jsxs8("div", { className: "rf-flex-1", children: [
1814
- /* @__PURE__ */ jsx11("p", { className: "rf-text-sm rf-font-medium rf-text-muted-foreground", children: index === displayedCompletedSteps.length - 1 ? "Last Completed" : "Completed" }),
1815
- /* @__PURE__ */ jsxs8("p", { className: "rf-font-medium rf-text-green-600", children: [
1816
- step.order_step_id,
1817
- ". ",
1818
- step.title
1819
- ] })
1820
- ] })
1821
- ]
1822
- },
1823
- step.order_step_id
1824
- )),
1825
- completedSteps.length > 0 && activeStep && /* @__PURE__ */ jsx11("div", { className: "rf-pl-4", children: /* @__PURE__ */ jsx11(ArrowDown, { className: "rf-h-5 rf-w-5 rf-text-muted-foreground" }) }),
1826
- activeStep && /* @__PURE__ */ jsxs8("div", { className: "rf-flex rf-items-start rf-gap-4", children: [
1827
- /* @__PURE__ */ jsx11("div", { className: "rf-flex-shrink-0 rf-mt-0.5", children: /* @__PURE__ */ jsx11("div", { className: "rf-w-8 rf-h-8 rf-rounded-full rf-bg-blue-100 rf-flex rf-items-center rf-justify-center", children: loading ? /* @__PURE__ */ jsx11(Loader23, { className: "rf-h-5 rf-w-5 rf-text-blue-600 rf-animate-spin" }) : /* @__PURE__ */ jsx11("div", { className: "rf-h-2.5 rf-w-2.5 rf-rounded-full rf-bg-blue-600" }) }) }),
1828
- /* @__PURE__ */ jsxs8("div", { className: "rf-flex-1", children: [
1829
- /* @__PURE__ */ jsx11("p", { className: "rf-text-sm rf-font-medium rf-text-muted-foreground", children: "Current Step" }),
1830
- /* @__PURE__ */ jsxs8("p", { className: "rf-font-medium rf-text-blue-600", children: [
1831
- activeStep.order_step_id,
1832
- ". ",
1833
- activeStep.title
1834
- ] })
1835
- ] })
1836
- ] })
1837
- ] }),
1838
- /* @__PURE__ */ jsxs8("div", { className: "rf-flex rf-justify-end rf-gap-3 rf-mt-auto", children: [
1839
- onCancel && /* @__PURE__ */ jsx11(Button, { variant: "outline", onClick: onCancel, className: "rf-px-6", children: cancelButtonText }),
1840
- onContinue && /* @__PURE__ */ jsx11(
1841
- Button,
1842
- {
1843
- onClick: onContinue,
1844
- className: "rf-px-6 rf-bg-gray-700 rf-hover:bg-gray-800",
1845
- disabled: loading || !activeStep,
1846
- children: loading ? /* @__PURE__ */ jsxs8(Fragment2, { children: [
1847
- /* @__PURE__ */ jsx11(Loader23, { className: "rf-mr-2 rf-h-4 rf-w-4 rf-animate-spin" }),
1848
- "Processing..."
1849
- ] }) : continueButtonText
1850
- }
1851
- )
1852
- ] })
1853
- ] });
1854
- };
1780
+ import { ArrowDown, Check as Check2, Loader2 as Loader23 } from "lucide-react";
1781
+ import { useQuery } from "react-query";
1855
1782
 
1856
- // lib/components/OrderDialog/OrderDialog.tsx
1857
- import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
1783
+ // lib/utils/order-steps.ts
1858
1784
  var orderSteps = [
1859
1785
  { order_step_id: 1, key: "are_gerbers_generated", title: "Generate Gerbers" },
1860
1786
  { order_step_id: 2, key: "are_gerbers_uploaded", title: "Upload Gerbers" },
@@ -1916,6 +1842,96 @@ var orderSteps = [
1916
1842
  active: index === 0
1917
1843
  // First step starts as active
1918
1844
  }));
1845
+
1846
+ // lib/components/OrderDialog/StepwiseProgress.tsx
1847
+ import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
1848
+ var StepwiseProgressPanel = ({
1849
+ orderId,
1850
+ title = "Order PCB",
1851
+ onCancel,
1852
+ loading: externalLoading = false,
1853
+ setStage
1854
+ }) => {
1855
+ const { data, isLoading } = useQuery({
1856
+ queryKey: ["orderState", orderId],
1857
+ queryFn: async () => {
1858
+ const response = await ky2.get("registry/orders/get", {
1859
+ searchParams: { order_id: orderId },
1860
+ headers: {
1861
+ Authorization: `Bearer account-1234`
1862
+ }
1863
+ }).json();
1864
+ if (response.orderState.current_step === "is_added_to_cart") {
1865
+ setStage("checkout");
1866
+ }
1867
+ return response;
1868
+ },
1869
+ refetchInterval: 2e3,
1870
+ refetchIntervalInBackground: true
1871
+ });
1872
+ const steps = orderSteps.map((step) => {
1873
+ if (!data?.orderState) return step;
1874
+ const currentStepIndex = orderSteps.findIndex(
1875
+ (orderStep) => orderStep.key === data.orderState.current_step
1876
+ );
1877
+ const stepIndex = orderSteps.findIndex(
1878
+ (orderStep) => orderStep.key === step.key
1879
+ );
1880
+ return {
1881
+ ...step,
1882
+ completed: stepIndex < currentStepIndex,
1883
+ active: stepIndex === currentStepIndex
1884
+ };
1885
+ });
1886
+ const completedSteps = steps.filter((step) => step.completed);
1887
+ const activeStep = steps.find((step) => step.active);
1888
+ const lastCompletedStep = completedSteps[completedSteps.length - 1];
1889
+ const totalSteps = steps.length;
1890
+ const progress = Math.round(completedSteps.length / totalSteps * 100);
1891
+ const loading = isLoading || externalLoading;
1892
+ return /* @__PURE__ */ jsxs8("div", { className: "rf-flex rf-flex-col rf-bg-white rf-rounded-xl rf-p-6 rf-max-w-xl rf-w-full rf-mx-auto", children: [
1893
+ /* @__PURE__ */ jsxs8("div", { className: "rf-flex rf-items-center rf-justify-between rf-mb-6", children: [
1894
+ /* @__PURE__ */ jsx11("h2", { className: "rf-text-2xl rf-font-bold", children: title }),
1895
+ /* @__PURE__ */ jsxs8("div", { className: "rf-text-sm rf-text-muted-foreground", children: [
1896
+ completedSteps.length,
1897
+ " of ",
1898
+ totalSteps,
1899
+ " completed"
1900
+ ] })
1901
+ ] }),
1902
+ /* @__PURE__ */ jsx11(Progress, { value: progress, className: "rf-h-2 rf-mb-8" }),
1903
+ /* @__PURE__ */ jsxs8("div", { className: "rf-space-y-6 rf-mb-8", children: [
1904
+ lastCompletedStep && /* @__PURE__ */ jsxs8("div", { className: "rf-flex rf-items-start rf-gap-4", children: [
1905
+ /* @__PURE__ */ jsx11("div", { className: "rf-flex-shrink-0 rf-mt-0.5", children: /* @__PURE__ */ jsx11("div", { className: "rf-w-8 rf-h-8 rf-rounded-full rf-bg-green-100 rf-flex rf-items-center rf-justify-center", children: /* @__PURE__ */ jsx11(Check2, { className: "rf-h-5 rf-w-5 rf-text-green-600" }) }) }),
1906
+ /* @__PURE__ */ jsxs8("div", { className: "rf-flex-1", children: [
1907
+ /* @__PURE__ */ jsx11("p", { className: "rf-text-sm rf-font-medium rf-text-muted-foreground", children: "Last Completed" }),
1908
+ /* @__PURE__ */ jsxs8("p", { className: "rf-font-medium rf-text-green-600", children: [
1909
+ lastCompletedStep.order_step_id,
1910
+ ". ",
1911
+ lastCompletedStep.title
1912
+ ] })
1913
+ ] })
1914
+ ] }),
1915
+ lastCompletedStep && activeStep && /* @__PURE__ */ jsx11("div", { className: "rf-pl-4", children: /* @__PURE__ */ jsx11(ArrowDown, { className: "rf-h-5 rf-w-5 rf-text-muted-foreground" }) }),
1916
+ activeStep && /* @__PURE__ */ jsxs8("div", { className: "rf-flex rf-items-start rf-gap-4", children: [
1917
+ /* @__PURE__ */ jsx11("div", { className: "rf-flex-shrink-0 rf-mt-0.5", children: /* @__PURE__ */ jsx11("div", { className: "rf-w-8 rf-h-8 rf-rounded-full rf-bg-blue-100 rf-flex rf-items-center rf-justify-center", children: loading ? /* @__PURE__ */ jsx11(Loader23, { className: "rf-h-5 rf-w-5 rf-text-blue-600 rf-animate-spin" }) : /* @__PURE__ */ jsx11("div", { className: "rf-h-2.5 rf-w-2.5 rf-rounded-full rf-bg-blue-600" }) }) }),
1918
+ /* @__PURE__ */ jsxs8("div", { className: "rf-flex-1", children: [
1919
+ /* @__PURE__ */ jsx11("p", { className: "rf-text-sm rf-font-medium rf-text-muted-foreground", children: "Current Step" }),
1920
+ /* @__PURE__ */ jsxs8("p", { className: "rf-font-medium rf-text-blue-600", children: [
1921
+ activeStep.order_step_id,
1922
+ ". ",
1923
+ activeStep.title
1924
+ ] })
1925
+ ] })
1926
+ ] })
1927
+ ] }),
1928
+ /* @__PURE__ */ jsx11("div", { className: "rf-flex rf-justify-end rf-gap-3 rf-mt-auto", children: onCancel && /* @__PURE__ */ jsx11(Button, { variant: "outline", onClick: onCancel, className: "rf-px-6", children: "Cancel" }) })
1929
+ ] });
1930
+ };
1931
+
1932
+ // lib/components/OrderDialog/OrderDialog.tsx
1933
+ import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
1934
+ var queryClient = new QueryClient();
1919
1935
  var OrderDialog = ({
1920
1936
  isOpen,
1921
1937
  onClose,
@@ -1923,15 +1939,13 @@ var OrderDialog = ({
1923
1939
  setStage
1924
1940
  }) => {
1925
1941
  const [order, setOrder] = useState7(null);
1926
- const [orderState, setOrderState] = useState7(null);
1927
- const [steps, setSteps] = useState7(orderSteps);
1928
1942
  const [loading, setLoading] = useState7(false);
1929
1943
  const circuitJson = useRunFrameStore((state) => state.circuitJson);
1930
1944
  const simulateScenarioOrder = useRunFrameStore(
1931
1945
  (state) => state.simulateScenarioOrder
1932
1946
  );
1933
1947
  const createOrder = async () => {
1934
- const { order: order2 } = await ky2.post("registry/orders/create", {
1948
+ const { order: order2 } = await ky3.post("registry/orders/create", {
1935
1949
  json: {
1936
1950
  circuit_json: circuitJson
1937
1951
  },
@@ -1941,57 +1955,12 @@ var OrderDialog = ({
1941
1955
  }).json();
1942
1956
  return order2;
1943
1957
  };
1944
- const getOrderState = async (orderId) => {
1945
- let response;
1946
- try {
1947
- response = await ky2.get("registry/orders/get", {
1948
- searchParams: {
1949
- order_id: orderId,
1950
- ...simulateScenarioOrder ? { _simulate_scenario: simulateScenarioOrder } : {}
1951
- },
1952
- headers: {
1953
- Authorization: `Bearer account-1234`
1954
- }
1955
- }).json();
1956
- } catch (error) {
1957
- console.error(error);
1958
- }
1959
- setOrder(response.order);
1960
- setOrderState(response.orderState);
1961
- setStage("progress");
1962
- };
1963
- const handleProgressContinue = async () => {
1964
- setLoading(true);
1965
- try {
1966
- await new Promise((resolve) => setTimeout(resolve, 1e3));
1967
- setSteps((currentSteps) => {
1968
- const activeStepIndex = currentSteps.findIndex((step) => step.active);
1969
- if (activeStepIndex === -1) return currentSteps;
1970
- const newSteps = [...currentSteps];
1971
- newSteps[activeStepIndex] = {
1972
- ...newSteps[activeStepIndex],
1973
- completed: true,
1974
- active: false
1975
- };
1976
- if (activeStepIndex === currentSteps.length - 1) {
1977
- setTimeout(() => setStage("checkout"), 500);
1978
- } else {
1979
- newSteps[activeStepIndex + 1] = {
1980
- ...newSteps[activeStepIndex + 1],
1981
- active: true
1982
- };
1983
- }
1984
- return newSteps;
1985
- });
1986
- } catch (error) {
1987
- console.error(error);
1988
- }
1989
- setLoading(false);
1990
- };
1991
- const handleInitialContinue = () => {
1958
+ const handleInitialContinue = async () => {
1959
+ const order2 = await createOrder();
1960
+ setOrder(order2);
1992
1961
  setStage("progress");
1993
1962
  };
1994
- return /* @__PURE__ */ jsx12(AlertDialog, { open: isOpen, onOpenChange: onClose, children: /* @__PURE__ */ jsx12(AlertDialogContent, { className: "!rf-max-w-[660px] !rf-p-0", children: /* @__PURE__ */ jsxs9("div", { className: "rf-relative rf-w-full", children: [
1963
+ return /* @__PURE__ */ jsx12(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx12(AlertDialog, { open: isOpen, onOpenChange: onClose, children: /* @__PURE__ */ jsx12(AlertDialogContent, { className: "!rf-max-w-[660px] !rf-p-0", children: /* @__PURE__ */ jsxs9("div", { className: "rf-relative rf-w-full", children: [
1995
1964
  stage === "initial" && /* @__PURE__ */ jsx12(
1996
1965
  InitialOrderScreen,
1997
1966
  {
@@ -1999,13 +1968,13 @@ var OrderDialog = ({
1999
1968
  onContinue: handleInitialContinue
2000
1969
  }
2001
1970
  ),
2002
- stage === "progress" && /* @__PURE__ */ jsx12(
1971
+ stage === "progress" && order?.order_id && /* @__PURE__ */ jsx12(
2003
1972
  StepwiseProgressPanel,
2004
1973
  {
2005
- steps,
2006
1974
  onCancel: onClose,
2007
- onContinue: handleProgressContinue,
2008
- loading
1975
+ loading,
1976
+ orderId: order?.order_id,
1977
+ setStage
2009
1978
  }
2010
1979
  ),
2011
1980
  stage === "checkout" && /* @__PURE__ */ jsx12(
@@ -2013,14 +1982,30 @@ var OrderDialog = ({
2013
1982
  {
2014
1983
  finalCost: 0,
2015
1984
  onConfirmCheckout: () => onClose(),
2016
- onBack: () => setStage("progress")
1985
+ onCancel: () => onClose()
2017
1986
  }
2018
1987
  )
2019
- ] }) }) });
1988
+ ] }) }) }) });
2020
1989
  };
2021
1990
 
2022
1991
  // lib/components/OrderDialog/useOrderDialog.tsx
2023
1992
  import { jsx as jsx13 } from "react/jsx-runtime";
1993
+ var OrderDialogComponent = ({
1994
+ isOpen,
1995
+ onClose,
1996
+ stage,
1997
+ setStage
1998
+ }) => {
1999
+ return /* @__PURE__ */ jsx13(
2000
+ OrderDialog,
2001
+ {
2002
+ isOpen,
2003
+ onClose,
2004
+ stage,
2005
+ setStage
2006
+ }
2007
+ );
2008
+ };
2024
2009
  var useOrderDialog = () => {
2025
2010
  const [isOpen, setIsOpen] = useState8(false);
2026
2011
  const [stage, setStage] = useState8("initial");
@@ -2036,22 +2021,13 @@ var useOrderDialog = () => {
2036
2021
  open: () => setIsOpen(true),
2037
2022
  close: handleClose,
2038
2023
  setStage,
2039
- OrderDialog: () => {
2040
- return /* @__PURE__ */ jsx13(
2041
- OrderDialog,
2042
- {
2043
- isOpen,
2044
- onClose: handleClose,
2045
- stage,
2046
- setStage
2047
- }
2048
- );
2049
- }
2024
+ OrderDialog: OrderDialogComponent
2025
+ // returns reference and not factory
2050
2026
  };
2051
2027
  };
2052
2028
 
2053
2029
  // lib/components/RunFrameForCli/LeftHeader.tsx
2054
- import { Fragment as Fragment3, jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
2030
+ import { Fragment as Fragment2, jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
2055
2031
  var RunframeCliLeftHeader = (props) => {
2056
2032
  const lastRunEvalVersion = useRunnerStore((s) => s.lastRunEvalVersion);
2057
2033
  const [snippetName, setSnippetName] = useState9(null);
@@ -2142,7 +2118,7 @@ var RunframeCliLeftHeader = (props) => {
2142
2118
  };
2143
2119
  const circuitJson = useRunFrameStore((state) => state.circuitJson);
2144
2120
  const [isImportDialogOpen, setIsImportDialogOpen] = useState9(false);
2145
- return /* @__PURE__ */ jsxs10(Fragment3, { children: [
2121
+ return /* @__PURE__ */ jsxs10(Fragment2, { children: [
2146
2122
  /* @__PURE__ */ jsxs10(DropdownMenu, { children: [
2147
2123
  /* @__PURE__ */ jsx14(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx14("div", { className: "rf-whitespace-nowrap rf-text-xs font-medium rf-p-2 rf-mx-1 rf-cursor-pointer rf-relative", children: "File" }) }),
2148
2124
  /* @__PURE__ */ jsxs10(DropdownMenuContent, { children: [
@@ -2299,7 +2275,15 @@ var RunframeCliLeftHeader = (props) => {
2299
2275
  }
2300
2276
  ),
2301
2277
  /* @__PURE__ */ jsx14(Toaster, { position: "top-center", reverseOrder: false }),
2302
- /* @__PURE__ */ jsx14(orderDialog.OrderDialog, {})
2278
+ /* @__PURE__ */ jsx14(
2279
+ orderDialog.OrderDialog,
2280
+ {
2281
+ isOpen: orderDialog.isOpen,
2282
+ onClose: orderDialog.close,
2283
+ stage: orderDialog.stage,
2284
+ setStage: orderDialog.setStage
2285
+ }
2286
+ )
2303
2287
  ] });
2304
2288
  };
2305
2289