fix(embed): implement setLockComponents in store and fix asset fetch base paths
This commit is contained in:
parent
fcff4de4a5
commit
1397076dfd
|
|
@ -93,7 +93,7 @@ export const EditorPage: React.FC = () => {
|
|||
const setLockComponents = useSimulatorStore((s) => s.setLockComponents);
|
||||
|
||||
useEffect(() => {
|
||||
if (embedMode.lockComponents) {
|
||||
if (embedMode.lockComponents && typeof setLockComponents === 'function') {
|
||||
setLockComponents(true);
|
||||
}
|
||||
}, [embedMode.lockComponents, setLockComponents]);
|
||||
|
|
@ -102,12 +102,14 @@ export const EditorPage: React.FC = () => {
|
|||
if (!embedMode.enabled) return;
|
||||
const handler = (e: Event) => {
|
||||
const detail = (e as CustomEvent).detail || {};
|
||||
if (detail.lockComponents !== undefined) setLockComponents(detail.lockComponents);
|
||||
if (detail.lockComponents !== undefined && typeof setLockComponents === 'function') {
|
||||
setLockComponents(detail.lockComponents);
|
||||
}
|
||||
};
|
||||
window.addEventListener('velxio-embed-mode', handler);
|
||||
embedBridge.notifyReady();
|
||||
return () => window.removeEventListener('velxio-embed-mode', handler);
|
||||
}, [embedMode.enabled]);
|
||||
}, [embedMode.enabled, setLockComponents]);
|
||||
|
||||
const [editorWidthPct, setEditorWidthPct] = useState(45);
|
||||
// Desktop-only 3-way layout switch (code-only / circuit-only / both).
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ export class ComponentRegistry {
|
|||
// `cache: 'no-store'` so adding a new component (or rebuilding the JSON)
|
||||
// shows up after a single page refresh — without this, the browser keeps
|
||||
// serving the stale copy until you do a hard reload.
|
||||
const response = await fetch('/components-metadata.json', { cache: 'no-store' });
|
||||
const base = (typeof import.meta !== 'undefined' && import.meta.env?.BASE_URL ? import.meta.env.BASE_URL.replace(/\/+$/, '') : '');
|
||||
const response = await fetch(`${base}/components-metadata.json`, { cache: 'no-store' });
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load metadata: ${response.statusText}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -387,7 +387,8 @@ export class Esp32C3Simulator {
|
|||
// @ts-expect-error kept for future use when more peripherals are emulated
|
||||
private async _loadRom(): Promise<void> {
|
||||
try {
|
||||
const resp = await fetch('/boards/esp32c3-rom.bin');
|
||||
const base = (typeof import.meta !== 'undefined' && import.meta.env?.BASE_URL ? import.meta.env.BASE_URL.replace(/\/+$/, '') : '');
|
||||
const resp = await fetch(`${base}/boards/esp32c3-rom.bin`);
|
||||
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
||||
const buf = await resp.arrayBuffer();
|
||||
this._romData = new Uint8Array(buf);
|
||||
|
|
|
|||
|
|
@ -1146,6 +1146,8 @@ interface SimulatorState {
|
|||
dismissEsp32Crash: () => void;
|
||||
|
||||
// ── Components ──────────────────────────────────────────────────────────
|
||||
lockComponents: boolean;
|
||||
setLockComponents: (lock: boolean) => void;
|
||||
components: Component[];
|
||||
addComponent: (component: Component) => void;
|
||||
removeComponent: (id: string) => void;
|
||||
|
|
@ -3077,6 +3079,9 @@ export const useSimulatorStore = create<SimulatorState>((set, get) => {
|
|||
// named V_led-builtin_sense yields the wrong key in branchCurrents
|
||||
// and the LED's update() loop never sees the diode current — the
|
||||
// node voltage is correct (the user sees ~1.84V on the wire) but the
|
||||
lockComponents: false,
|
||||
setLockComponents: (lock: boolean) => set({ lockComponents: lock }),
|
||||
|
||||
// visual brightness stays at zero. Underscore is safe.
|
||||
components: [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -96,7 +96,8 @@ export const BREADBOARD_PINS: readonly BreadboardPin[] = PINS;
|
|||
let artPromise: Promise<string | null> | null = null;
|
||||
function fetchArt(): Promise<string | null> {
|
||||
if (!artPromise) {
|
||||
artPromise = fetch('/component-svgs/fritzing/breadboard-full.svg')
|
||||
const base = (typeof import.meta !== 'undefined' && import.meta.env?.BASE_URL ? import.meta.env.BASE_URL.replace(/\/+$/, '') : '');
|
||||
artPromise = fetch(`${base}/component-svgs/fritzing/breadboard-full.svg`)
|
||||
.then((r) => (r.ok ? r.text() : null))
|
||||
.catch(() => null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@ export const BREADBOARD_MINI_PINS: readonly BreadboardMiniPin[] = PINS;
|
|||
let artPromise: Promise<string | null> | null = null;
|
||||
function fetchArt(): Promise<string | null> {
|
||||
if (!artPromise) {
|
||||
artPromise = fetch('/component-svgs/fritzing/breadboard-mini.svg')
|
||||
const base = (typeof import.meta !== 'undefined' && import.meta.env?.BASE_URL ? import.meta.env.BASE_URL.replace(/\/+$/, '') : '');
|
||||
artPromise = fetch(`${base}/component-svgs/fritzing/breadboard-mini.svg`)
|
||||
.then((r) => (r.ok ? r.text() : null))
|
||||
.catch(() => null);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue