openscd / open-scd-core

Apache License 2.0
5 stars 8 forks source link

fix(plugging): import relative paths from origin #82

Closed ca-d closed 1 year ago

ca-d commented 1 year ago

Resolve src URLs for plugins relative to window.location.host to make the editor work as expected when a bundled open-scd.js is imported from a remote host.

JakobVogelsang commented 1 year ago

@ca-d how did you found this bug?

ca-d commented 1 year ago

@ca-d how did you found this bug?

This fix was basically needed for the scenario where open-scd.js is imported from a different place than the distribution, which is the case in the current open-scd/next "live" distribution which uses

import 'https://openscd.github.io/open-scd-core/open-scd.js';

in one of its script tags. In this scenario, when we import plugins with relative URLs like in the case of plugins included in a distribution, we want all "path only" plugin src URLs to resolve relative to the distribution's URL, not relative to the URL of whatever server and path I happened to load open-scd.js from. In our "live" distribution example, we want the AddPlugins.js plugin to be loaded from the openscd.github.io/open-scd/ directory rather than from the openscd.github.io/open-scd-core/ directory.

In my view, a regression test for this would ideally go into a distribution that hosts some local plugin.

JakobVogelsang commented 1 year ago

Now I got it, thank you :)