feat(tabletop): inject proxy handlers from web app

This commit is contained in:
2026-08-09 21:46:36 +08:00
parent eefce5487d
commit 521519ce3d
15 changed files with 670 additions and 0 deletions
+13
View File
@@ -1,7 +1,10 @@
import { useParams } from 'react-router-dom';
import { PartView, ErrorBoundary, TabletopProvider } from '@tts/tabletop';
import Breadcrumbs from '../components/Breadcrumbs';
import PackageMissing from '../components/PackageMissing';
import Scene from '../components/viewers/Scene';
import { findPackage } from './bgm';
import { tabletopHttp } from '../tabletopHttp';
/** Detail view for a single part within a package. */
export default function PartPage() {
@@ -35,6 +38,16 @@ export default function PartPage() {
{found.fillet ? ` · fillet ${found.fillet}mm` : ''}
</p>
</div>
{/* The boundary wraps the Canvas (Scene), not PartView, so its HTML
fallback renders outside the r3f namespace. The provider wires the
library's proxy calls to the web app's proxy. */}
<ErrorBoundary>
<TabletopProvider http={tabletopHttp}>
<Scene>
<PartView part={found} baseUrl={found.baseUrl} />
</Scene>
</TabletopProvider>
</ErrorBoundary>
<pre className="overflow-x-auto rounded-lg border border-zinc-800 bg-zinc-900 p-3 text-xs text-zinc-400">
{JSON.stringify(found, null, 2)}
</pre>
+13
View File
@@ -0,0 +1,13 @@
import type { TabletopHttp } from '@tts/tabletop';
import { traceImage as apiTraceImage } from './api';
import { assetUrl as viewerAssetUrl } from './components/viewers/assetUrl';
/**
* The tabletop library's HTTP handlers, wired to the web app's proxy. The
* library defaults to the conventional `/asset` and `/trace` paths, but the web
* app provides its own so the coupling is explicit and testable.
*/
export const tabletopHttp: TabletopHttp = {
assetUrl: viewerAssetUrl,
traceImage: apiTraceImage,
};