@tscircuit/runframe 0.0.379 → 0.0.381
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/{chunk-4OLYVIGV.js → chunk-QVSJAK7O.js} +79 -84
- package/dist/preview.js +1 -1
- package/dist/runner.js +1 -1
- package/dist/standalone-preview.min.js +375 -375
- package/dist/standalone.min.js +701 -701
- package/package.json +3 -2
|
@@ -1037,7 +1037,7 @@ var RenderLogViewer = ({
|
|
|
1037
1037
|
};
|
|
1038
1038
|
|
|
1039
1039
|
// package.json
|
|
1040
|
-
var version = "0.0.
|
|
1040
|
+
var version = "0.0.380";
|
|
1041
1041
|
|
|
1042
1042
|
// lib/components/CircuitJsonPreview/CircuitJsonPreview.tsx
|
|
1043
1043
|
import { jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
@@ -1754,111 +1754,108 @@ var registryKy = {
|
|
|
1754
1754
|
patch: (url, options) => getRegistryKy().patch(url, options)
|
|
1755
1755
|
};
|
|
1756
1756
|
|
|
1757
|
+
// lib/hooks/use-create-order-quote.ts
|
|
1758
|
+
import { useMutation } from "react-query";
|
|
1759
|
+
|
|
1760
|
+
// lib/api/order-quotes.ts
|
|
1761
|
+
var createOrderQuote = async (packageReleaseId) => {
|
|
1762
|
+
const { order_quote_id } = await registryKy.post("order_quotes/create", {
|
|
1763
|
+
json: {
|
|
1764
|
+
package_release_id: packageReleaseId,
|
|
1765
|
+
vendor_name: "jlcpcb"
|
|
1766
|
+
// TODO: Remove this once we have more vendor
|
|
1767
|
+
}
|
|
1768
|
+
}).json();
|
|
1769
|
+
return order_quote_id;
|
|
1770
|
+
};
|
|
1771
|
+
var getOrderQuote = async (orderQuoteId) => {
|
|
1772
|
+
const { order_quote } = await registryKy.get(`order_quotes/get`, {
|
|
1773
|
+
searchParams: {
|
|
1774
|
+
order_quote_id: orderQuoteId
|
|
1775
|
+
}
|
|
1776
|
+
}).json();
|
|
1777
|
+
return order_quote;
|
|
1778
|
+
};
|
|
1779
|
+
|
|
1780
|
+
// lib/hooks/use-create-order-quote.ts
|
|
1781
|
+
var useCreateOrderQuote = () => {
|
|
1782
|
+
return useMutation(
|
|
1783
|
+
(packageReleaseId) => createOrderQuote(packageReleaseId)
|
|
1784
|
+
);
|
|
1785
|
+
};
|
|
1786
|
+
|
|
1787
|
+
// lib/hooks/use-order-quote-polling.ts
|
|
1788
|
+
import { useQuery } from "react-query";
|
|
1789
|
+
var useOrderQuotePolling = (orderQuoteId) => {
|
|
1790
|
+
const {
|
|
1791
|
+
data: orderQuote,
|
|
1792
|
+
error,
|
|
1793
|
+
status
|
|
1794
|
+
} = useQuery(
|
|
1795
|
+
["getOrderQuote", orderQuoteId],
|
|
1796
|
+
() => getOrderQuote(orderQuoteId),
|
|
1797
|
+
{
|
|
1798
|
+
enabled: !!orderQuoteId,
|
|
1799
|
+
refetchInterval: (data) => {
|
|
1800
|
+
if (data?.is_completed || data?.has_error) {
|
|
1801
|
+
return false;
|
|
1802
|
+
}
|
|
1803
|
+
return 4e3;
|
|
1804
|
+
},
|
|
1805
|
+
refetchIntervalInBackground: true,
|
|
1806
|
+
retry: false
|
|
1807
|
+
}
|
|
1808
|
+
);
|
|
1809
|
+
return {
|
|
1810
|
+
status: status === "loading" ? "loading" : status === "error" ? "error" : "success",
|
|
1811
|
+
data: orderQuote ?? null,
|
|
1812
|
+
error: error instanceof Error ? error : null
|
|
1813
|
+
};
|
|
1814
|
+
};
|
|
1815
|
+
|
|
1757
1816
|
// lib/components/OrderDialog/InitialOrder.tsx
|
|
1758
1817
|
import { jsx as jsx19, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
1759
1818
|
var InitialOrderScreen = ({
|
|
1760
1819
|
onCancel,
|
|
1761
1820
|
packageReleaseId
|
|
1762
1821
|
}) => {
|
|
1763
|
-
const [quotes, setQuotes] = useState5([]);
|
|
1764
|
-
const [loading, setLoading] = useState5(true);
|
|
1765
1822
|
const [selectedVendorIdx, setSelectedVendorIdx] = useState5(
|
|
1766
1823
|
null
|
|
1767
1824
|
);
|
|
1768
1825
|
const [selectedShippingIdx, setSelectedShippingIdx] = useState5(
|
|
1769
1826
|
null
|
|
1770
1827
|
);
|
|
1771
|
-
const
|
|
1772
|
-
const
|
|
1773
|
-
const
|
|
1774
|
-
const { order_quote_id } = await registryKy.post("order_quotes/create", {
|
|
1775
|
-
json: {
|
|
1776
|
-
package_release_id: packageReleaseId,
|
|
1777
|
-
vendor_name: "jlcpcb"
|
|
1778
|
-
// TODO: Remove this once we have more vendor
|
|
1779
|
-
}
|
|
1780
|
-
}).json();
|
|
1781
|
-
return order_quote_id;
|
|
1782
|
-
};
|
|
1783
|
-
const getOrderQuotes = async (orderQuoteId) => {
|
|
1784
|
-
const { order_quote } = await registryKy.get(`order_quotes/get`, {
|
|
1785
|
-
searchParams: {
|
|
1786
|
-
order_quote_id: orderQuoteId
|
|
1787
|
-
}
|
|
1788
|
-
}).json();
|
|
1789
|
-
return order_quote;
|
|
1790
|
-
};
|
|
1791
|
-
const pollToGetOrderQuotes = async (orderQuoteId, maxAttempts = 10) => {
|
|
1792
|
-
let attempts = 0;
|
|
1793
|
-
while (attempts < maxAttempts) {
|
|
1794
|
-
try {
|
|
1795
|
-
const orderQuote = await getOrderQuotes(orderQuoteId);
|
|
1796
|
-
if (orderQuote.is_completed) {
|
|
1797
|
-
setOrderQuoteReceived(orderQuote);
|
|
1798
|
-
return orderQuote;
|
|
1799
|
-
}
|
|
1800
|
-
if (orderQuote.has_error) {
|
|
1801
|
-
throw new Error(orderQuote.error?.message ?? "Unknown error");
|
|
1802
|
-
}
|
|
1803
|
-
attempts++;
|
|
1804
|
-
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
1805
|
-
} catch (error) {
|
|
1806
|
-
attempts++;
|
|
1807
|
-
console.error("Error polling order quote:", error);
|
|
1808
|
-
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
throw new Error("Polling timed out after maximum attempts");
|
|
1812
|
-
};
|
|
1813
|
-
const redirectToStripeCheckout = async (orderQuoteId) => {
|
|
1828
|
+
const { mutate: createOrderQuote2, data: orderQuoteId } = useCreateOrderQuote();
|
|
1829
|
+
const { status, data: orderQuote, error } = useOrderQuotePolling(orderQuoteId);
|
|
1830
|
+
const redirectToStripeCheckout = async (orderQuoteId2) => {
|
|
1814
1831
|
const stripeCheckoutBaseUrl = getWindowVar(
|
|
1815
1832
|
"TSCIRCUIT_STRIPE_CHECKOUT_BASE_URL"
|
|
1816
1833
|
);
|
|
1817
|
-
window.location.href = `${stripeCheckoutBaseUrl}?client_reference_id=${
|
|
1834
|
+
window.location.href = `${stripeCheckoutBaseUrl}?client_reference_id=${orderQuoteId2}`;
|
|
1818
1835
|
};
|
|
1819
|
-
useEffect3(() => {
|
|
1820
|
-
const fetchQuotes = async () => {
|
|
1821
|
-
setLoading(true);
|
|
1822
|
-
setQuotes([]);
|
|
1823
|
-
setFetchError(null);
|
|
1824
|
-
const orderQuoteId = await createOrderQuotes();
|
|
1825
|
-
if (!orderQuoteId) {
|
|
1826
|
-
toast.error("Failed to create order quote.");
|
|
1827
|
-
setLoading(false);
|
|
1828
|
-
return;
|
|
1829
|
-
}
|
|
1830
|
-
try {
|
|
1831
|
-
const orderQuote = await pollToGetOrderQuotes(orderQuoteId);
|
|
1832
|
-
setQuotes([orderQuote]);
|
|
1833
|
-
setLoading(false);
|
|
1834
|
-
} catch (error) {
|
|
1835
|
-
console.error(error);
|
|
1836
|
-
toast.error("Failed to fetch order quotes.");
|
|
1837
|
-
setLoading(false);
|
|
1838
|
-
}
|
|
1839
|
-
};
|
|
1840
|
-
fetchQuotes();
|
|
1841
|
-
}, []);
|
|
1842
1836
|
useEffect3(() => {
|
|
1843
1837
|
setSelectedShippingIdx(null);
|
|
1844
1838
|
}, [selectedVendorIdx]);
|
|
1839
|
+
useEffect3(() => {
|
|
1840
|
+
createOrderQuote2(packageReleaseId);
|
|
1841
|
+
}, [packageReleaseId, createOrderQuote2]);
|
|
1845
1842
|
return /* @__PURE__ */ jsxs15("div", { className: "rf-max-w-lg rf-mx-auto rf-bg-white rf-rounded-2xl rf-p-8 rf-flex rf-flex-col rf-gap-3", children: [
|
|
1846
1843
|
/* @__PURE__ */ jsx19("h2", { className: "rf-text-3xl rf-font-bold rf-text-center rf-mb-8", children: "Order PCB \u2013 Choose a Vendor" }),
|
|
1847
1844
|
/* @__PURE__ */ jsx19("div", { className: "rf-mb-4 rf-text-gray-700 rf-text-center", children: "Select a quote from below, then pick a shipping method." }),
|
|
1848
|
-
loading ? /* @__PURE__ */ jsxs15("div", { className: "rf-flex rf-flex-col rf-items-center rf-gap-2 rf-my-12", children: [
|
|
1845
|
+
status === "loading" ? /* @__PURE__ */ jsxs15("div", { className: "rf-flex rf-flex-col rf-items-center rf-gap-2 rf-my-12", children: [
|
|
1849
1846
|
/* @__PURE__ */ jsx19(Loader22, { className: "rf-animate-spin rf-w-8 rf-h-8 rf-text-gray-400" }),
|
|
1850
1847
|
/* @__PURE__ */ jsx19("p", { className: "rf-text-gray-600", children: "Fetching quotes..." })
|
|
1851
|
-
] }) :
|
|
1848
|
+
] }) : status === "error" ? /* @__PURE__ */ jsx19("div", { className: "rf-text-red-600 rf-text-center rf-py-12", children: error?.message || "Failed to fetch quotes" }) : !orderQuote ? /* @__PURE__ */ jsx19("div", { className: "rf-text-red-600 rf-text-center rf-py-12", children: "No quotes available." }) : /* @__PURE__ */ jsx19(
|
|
1852
1849
|
VendorQuoteCard,
|
|
1853
1850
|
{
|
|
1854
|
-
vendor:
|
|
1855
|
-
isActive: selectedVendorIdx ===
|
|
1856
|
-
onSelect: () => setSelectedVendorIdx(
|
|
1857
|
-
selectedShippingIdx: selectedVendorIdx ===
|
|
1851
|
+
vendor: orderQuote,
|
|
1852
|
+
isActive: selectedVendorIdx === 0,
|
|
1853
|
+
onSelect: () => setSelectedVendorIdx(0),
|
|
1854
|
+
selectedShippingIdx: selectedVendorIdx === 0 ? selectedShippingIdx : null,
|
|
1858
1855
|
onSelectShipping: setSelectedShippingIdx
|
|
1859
1856
|
},
|
|
1860
|
-
|
|
1861
|
-
)
|
|
1857
|
+
orderQuote.order_quote_id
|
|
1858
|
+
),
|
|
1862
1859
|
/* @__PURE__ */ jsxs15("div", { className: "rf-flex rf-justify-between rf-mt-5 rf-gap-4", children: [
|
|
1863
1860
|
/* @__PURE__ */ jsx19(
|
|
1864
1861
|
Button,
|
|
@@ -1875,16 +1872,14 @@ var InitialOrderScreen = ({
|
|
|
1875
1872
|
{
|
|
1876
1873
|
type: "button",
|
|
1877
1874
|
className: "rf-w-1/2 rf-bg-blue-600 rf-hover:bg-blue-700",
|
|
1878
|
-
disabled: selectedVendorIdx === null ||
|
|
1879
|
-
loading,
|
|
1875
|
+
disabled: selectedVendorIdx === null || status === "loading",
|
|
1880
1876
|
onClick: () => {
|
|
1881
|
-
if (selectedVendorIdx === null ||
|
|
1882
|
-
loading) {
|
|
1877
|
+
if (selectedVendorIdx === null || status === "loading") {
|
|
1883
1878
|
toast.error("Please select a vendor and shipping option.");
|
|
1884
1879
|
return;
|
|
1885
1880
|
}
|
|
1886
|
-
if (
|
|
1887
|
-
redirectToStripeCheckout(
|
|
1881
|
+
if (orderQuote) {
|
|
1882
|
+
redirectToStripeCheckout(orderQuote.order_quote_id);
|
|
1888
1883
|
}
|
|
1889
1884
|
},
|
|
1890
1885
|
children: "Continue"
|
package/dist/preview.js
CHANGED
package/dist/runner.js
CHANGED