Skip to content

Commit e9d4913

Browse files
authored
Merge pull request #312 from pathsim/refactor/pyodide-hidden-categories
Hide backend-incompatible block categories on Pyodide
2 parents 31522f7 + 2ffea5c commit e9d4913

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/lib/components/panels/NodeLibrary.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { onDestroy } from 'svelte';
33
import { nodeRegistry, blockConfig, registryVersion, type NodeCategory, type NodeTypeDefinition } from '$lib/nodes';
44
import { NODE_TYPES } from '$lib/constants/nodeTypes';
5+
import { PYODIDE_HIDDEN_CATEGORIES } from '$lib/constants/python';
6+
import { getBackendType } from '$lib/pyodide/backend';
57
import { createHoverDetail } from '$lib/actions/hoverDetail.svelte';
68
import NodePreview from '$lib/components/nodes/NodePreview.svelte';
79
import Icon from '$lib/components/icons/Icon.svelte';
@@ -71,6 +73,13 @@
7173
void registryTick;
7274
let nodes = nodeRegistry.getAll().filter((node) => node.type !== NODE_TYPES.INTERFACE);
7375
76+
// Hide backend-incompatible categories (e.g. FMI on the Pyodide backend:
77+
// FMU blocks need the native FMI runtime, not available in the browser).
78+
if (getBackendType() === 'pyodide' && PYODIDE_HIDDEN_CATEGORIES.length > 0) {
79+
const hidden = new Set(PYODIDE_HIDDEN_CATEGORIES);
80+
nodes = nodes.filter((node) => !hidden.has(node.category));
81+
}
82+
7483
if (!searchQuery.trim()) return nodes;
7584
const query = searchQuery.toLowerCase();
7685
return nodes.filter(

src/lib/constants/python.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,29 @@ export const CODE_SECTIONS = {
2727
export const BLOCK_CATEGORY_ORDER: string[] = [
2828
'Sources',
2929
'Dynamic',
30+
'DAE',
3031
'Algebraic',
3132
'Logic',
3233
'Discrete',
34+
'FMI',
3335
'Recording',
3436
'Subsystem'
3537
];
3638

39+
/**
40+
* Block categories hidden when running on the Pyodide (in-browser) backend,
41+
* configurable per distribution via `VITE_PYODIDE_HIDDEN_CATEGORIES`
42+
* (comma-separated). Empty by default. Use this for categories whose blocks
43+
* can't work in the browser sandbox (e.g. FMI/FMU blocks that drive an external
44+
* .fmu through a native runtime) so they're only offered on a native backend.
45+
*/
46+
export const PYODIDE_HIDDEN_CATEGORIES: string[] = (
47+
(import.meta.env.VITE_PYODIDE_HIDDEN_CATEGORIES as string | undefined) ?? ''
48+
)
49+
.split(',')
50+
.map((c) => c.trim())
51+
.filter(Boolean);
52+
3753
/**
3854
* Timeout constants for Pyodide operations (in milliseconds)
3955
*/

0 commit comments

Comments
 (0)