sharpie7 / circuitjs1

Electronic Circuit Simulator in the Browser
GNU General Public License v2.0
2.36k stars 644 forks source link

Feature Request: Subcircuit as Dependencies #970

Open by-justin opened 1 week ago

by-justin commented 1 week ago

Currently, subcircuits are kept in the browser cache after being defined by the user. To reuse a subcircuit on a different device, it must either be saved within a circuit file or individually reimported. This can become cumbersome, especially when dealing with many subcircuits, as users need to either store them all in one large file or manage multiple small files, which must be opened one by one to reload the subcircuits into the cache. Furthermore, when different circuit files share the same subcircuits, this leads to repetition.

As mentioned in #769, the goal is to keep everything in text files. One solution is to allow URL-based references for subcircuit definitions at the start of a circuit file. When loading the file, the subcircuits would be fetched and incorporated recursively into the current circuit. For example:

> https://url.to.subcircuit.1
> https://url.to.subcircuit.2
  ...
. subcircuit1 ...
  ...

Additionally, it would be helpful to add an option to export all directly defined (non-imported) subcircuits in the current file as separate files.

This approach would allow users to maintain a proper subcircuit library (as requested in #690) and would address any concerns about subcircuits across sessions by letting users save them as text files instead of relying on browser cache.