feat: /l/:libId/:tool lib-scoped route + fix lib items for fileless launches
Add a deep-linkable, reload-safe route /l/<libId>/<tool> (LibToolPage) that boots the editor scoped to one backend library; the home page's lib chips become anchors to it (full nav → clean Emscripten). Local lib FILES stay in-place (bytes can't be URL-addressed). Fix empty lib trees against a registry server: fileless/lib-scoped launches use the placeholder projectId "local", which was sent as x-pcbjam-project — the closed server then scoped its (0005 mirror) lib resolution to a non-existent project and returned nothing. Suppress the project header for "local"; real backend projects keep sending their uuid and keep project-scoped resolution. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4b404f3771
commit
2f5d37993e
4 changed files with 66 additions and 24 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { Route, Routes } from "react-router-dom";
|
import { Route, Routes } from "react-router-dom";
|
||||||
import { HomePage } from "@/pages/HomePage";
|
import { HomePage } from "@/pages/HomePage";
|
||||||
|
import { LibToolPage } from "@/pages/LibToolPage";
|
||||||
import { ProjectView } from "@/pages/ProjectView";
|
import { ProjectView } from "@/pages/ProjectView";
|
||||||
import { ToolPage } from "@/pages/ToolPage";
|
import { ToolPage } from "@/pages/ToolPage";
|
||||||
|
|
||||||
|
|
@ -9,6 +10,7 @@ export default function App() {
|
||||||
<Route path="/" element={<HomePage />} />
|
<Route path="/" element={<HomePage />} />
|
||||||
<Route path="/p/:project" element={<ProjectView />} />
|
<Route path="/p/:project" element={<ProjectView />} />
|
||||||
<Route path="/p/:project/:tool/*" element={<ToolPage />} />
|
<Route path="/p/:project/:tool/*" element={<ToolPage />} />
|
||||||
|
<Route path="/l/:lib/:tool" element={<LibToolPage />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,12 +74,18 @@ export function libsOwner(): string {
|
||||||
|
|
||||||
export function libsSourceConfig(projectId?: string): LibsSource | null {
|
export function libsSourceConfig(projectId?: string): LibsSource | null {
|
||||||
const kind = import.meta.env.VITE_LIBS_SOURCE ?? "remote";
|
const kind = import.meta.env.VITE_LIBS_SOURCE ?? "remote";
|
||||||
|
// "local" is the placeholder id for launches with no real backend project
|
||||||
|
// (local folder, tool grid, lib-scoped open). It is NOT a project on the
|
||||||
|
// backend, so don't send it as the project header — a registry server would
|
||||||
|
// scope its lib resolution (project-pinned mirrors) to a non-existent project
|
||||||
|
// and return nothing. Real backend projects pass their uuid and keep scoping.
|
||||||
|
const project = projectId && projectId !== "local" ? projectId : undefined;
|
||||||
const base =
|
const base =
|
||||||
kind === "off"
|
kind === "off"
|
||||||
? null
|
? null
|
||||||
: kind === "static"
|
: kind === "static"
|
||||||
? staticLibsSource()
|
? staticLibsSource()
|
||||||
: remoteLibsSource(API_BASE_URL, libsOwner(), projectId);
|
: remoteLibsSource(API_BASE_URL, libsOwner(), project);
|
||||||
|
|
||||||
// 0004-A spike: `?libwrite=1` adds one in-memory writable user SYMBOL lib so the
|
// 0004-A spike: `?libwrite=1` adds one in-memory writable user SYMBOL lib so the
|
||||||
// editor save path works with no backend (a dev/test aid). The real remote
|
// editor save path works with no backend (a dev/test aid). The real remote
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ import { Link } from "react-router-dom";
|
||||||
import type { Lib, Tool } from "@pcbjam/shared";
|
import type { Lib, Tool } from "@pcbjam/shared";
|
||||||
import { FolderOpen, Library, Loader2, Package } from "lucide-react";
|
import { FolderOpen, Library, Loader2, Package } from "lucide-react";
|
||||||
import { useLibs, useProjects } from "@/lib/api";
|
import { useLibs, useProjects } from "@/lib/api";
|
||||||
import { libsSourceConfig } from "@/lib/config";
|
|
||||||
import { scopedLibsSource } from "@/wasm/libs/scoped-source";
|
|
||||||
import { localFileLibsSource } from "@/wasm/libs/local-file-source";
|
import { localFileLibsSource } from "@/wasm/libs/local-file-source";
|
||||||
import type { LibsSource } from "@/wasm/libs/source";
|
import type { LibsSource } from "@/wasm/libs/source";
|
||||||
import { downloadBytes } from "@/lib/download";
|
import { downloadBytes } from "@/lib/download";
|
||||||
|
|
@ -121,15 +119,6 @@ export function HomePage() {
|
||||||
libsSource?: LibsSource | null;
|
libsSource?: LibsSource | null;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
/** Open a backend library scoped to itself in its matching editor. */
|
|
||||||
const openScopedLib = (tool: Tool, lib: Lib) => {
|
|
||||||
const base = libsSourceConfig("local");
|
|
||||||
setLaunchedTool({
|
|
||||||
tool,
|
|
||||||
libsSource: base ? scopedLibsSource(base, lib.id) : undefined,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// <input webkitdirectory> is non-standard; set it imperatively.
|
// <input webkitdirectory> is non-standard; set it imperatively.
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (inputRef.current) inputRef.current.setAttribute("webkitdirectory", "");
|
if (inputRef.current) inputRef.current.setAttribute("webkitdirectory", "");
|
||||||
|
|
@ -299,13 +288,13 @@ export function HomePage() {
|
||||||
icon={<Library size={16} />}
|
icon={<Library size={16} />}
|
||||||
label="Symbols"
|
label="Symbols"
|
||||||
query={symbolLibs}
|
query={symbolLibs}
|
||||||
onOpen={(lib) => openScopedLib("symbol_editor", lib)}
|
tool="symbol_editor"
|
||||||
/>
|
/>
|
||||||
<LibGroup
|
<LibGroup
|
||||||
icon={<Package size={16} />}
|
icon={<Package size={16} />}
|
||||||
label="Footprints"
|
label="Footprints"
|
||||||
query={footprintLibs}
|
query={footprintLibs}
|
||||||
onOpen={(lib) => openScopedLib("footprint_editor", lib)}
|
tool="footprint_editor"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -314,21 +303,20 @@ export function HomePage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One backend-library group (Symbols / Footprints): clickable chips that launch
|
* One backend-library group (Symbols / Footprints): each lib is a deep-link to
|
||||||
* the matching editor to browse the library. The editor lists ALL libs of that
|
* `/l/<libId>/<tool>` (LibToolPage), which boots the editor scoped to that one
|
||||||
* kind in its own tree (lib-scoped open is a later iteration); clicking here
|
* library. A full navigation (anchor) gives Emscripten a clean page.
|
||||||
* just opens the right tool.
|
|
||||||
*/
|
*/
|
||||||
function LibGroup({
|
function LibGroup({
|
||||||
icon,
|
icon,
|
||||||
label,
|
label,
|
||||||
query,
|
query,
|
||||||
onOpen,
|
tool,
|
||||||
}: {
|
}: {
|
||||||
icon: React.ReactNode;
|
icon: React.ReactNode;
|
||||||
label: string;
|
label: string;
|
||||||
query: ReturnType<typeof useLibs>;
|
query: ReturnType<typeof useLibs>;
|
||||||
onOpen: (lib: Lib) => void;
|
tool: Tool;
|
||||||
}) {
|
}) {
|
||||||
const { data: libs, isLoading, error } = query;
|
const { data: libs, isLoading, error } = query;
|
||||||
return (
|
return (
|
||||||
|
|
@ -352,10 +340,9 @@ function LibGroup({
|
||||||
{libs && libs.length > 0 && (
|
{libs && libs.length > 0 && (
|
||||||
<div className="flex flex-wrap gap-2">
|
<div className="flex flex-wrap gap-2">
|
||||||
{libs.map((lib) => (
|
{libs.map((lib) => (
|
||||||
<button
|
<a
|
||||||
key={lib.id}
|
key={lib.id}
|
||||||
type="button"
|
href={`/l/${encodeURIComponent(lib.id)}/${tool}`}
|
||||||
onClick={() => onOpen(lib)}
|
|
||||||
title={lib.description ?? undefined}
|
title={lib.description ?? undefined}
|
||||||
className="inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-sm hover:bg-accent"
|
className="inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-sm hover:bg-accent"
|
||||||
>
|
>
|
||||||
|
|
@ -365,7 +352,7 @@ function LibGroup({
|
||||||
{lib.itemCount}
|
{lib.itemCount}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</button>
|
</a>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
47
web/standalone/src/pages/LibToolPage.tsx
Normal file
47
web/standalone/src/pages/LibToolPage.tsx
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import { toolSchema } from "@pcbjam/shared";
|
||||||
|
import { libsSourceConfig } from "@/lib/config";
|
||||||
|
import { scopedLibsSource } from "@/wasm/libs/scoped-source";
|
||||||
|
import { WasmTool } from "@/components/WasmTool";
|
||||||
|
import { PreflightGate } from "@/preflight/PreflightGate";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open one BACKEND library scoped to itself in its editor, addressed by URL:
|
||||||
|
* /l/<libId>/<tool> e.g. /l/Diode/symbol_editor
|
||||||
|
*
|
||||||
|
* Deep-linkable + reload-safe (unlike the home page's in-place lib launch). The
|
||||||
|
* editor boots with no project/files and a `scopedLibsSource` so its lib tree
|
||||||
|
* shows exactly this one library. (Local lib FILES can't be URL-addressed — they
|
||||||
|
* stay an in-place launch on the home page.)
|
||||||
|
*/
|
||||||
|
export function LibToolPage() {
|
||||||
|
const params = useParams();
|
||||||
|
const libId = params.lib ?? "";
|
||||||
|
const parsedTool = toolSchema.safeParse(params.tool);
|
||||||
|
|
||||||
|
if (!parsedTool.success) {
|
||||||
|
return (
|
||||||
|
<div className="container py-10 text-destructive">
|
||||||
|
Unknown tool: {params.tool}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const base = libsSourceConfig("local");
|
||||||
|
const libsSource = base ? scopedLibsSource(base, libId) : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PreflightGate>
|
||||||
|
<WasmTool
|
||||||
|
tool={parsedTool.data}
|
||||||
|
slug="local"
|
||||||
|
projectId="local"
|
||||||
|
files={[]}
|
||||||
|
libsSource={libsSource}
|
||||||
|
fetchBytes={async (relPath) => {
|
||||||
|
throw new Error(`no project file to fetch: ${relPath}`);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</PreflightGate>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue