@archilogic/plugin-container 0.0.0-20240209180426 → 0.0.0-20240212115958
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/index.html +26 -12
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Plugin Container
|
|
2
|
+
|
|
3
|
+
This package hosts an HTML file which can be used to load plugins by URL. It is published to the npm registry alongside the plugin packages so that it can be served via CDN.
|
|
4
|
+
|
|
5
|
+
## Local usage
|
|
6
|
+
|
|
7
|
+
Start the dev server:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm run dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Open a browser and visit: `http://localhost:5173/?pluginUrl=<pluginUrl>&pluginName=<pluginName>`
|
|
14
|
+
|
|
15
|
+
## Usage via ESM CDN
|
|
16
|
+
|
|
17
|
+
Open a browser and visit: `https://esm.sh/@archilogic/plugin-container/index.html?pluginUrl=<pluginUrl>`
|
|
18
|
+
|
|
19
|
+
## Query params
|
|
20
|
+
|
|
21
|
+
- `?pluginUrl` (required): the JS entry point for a plugin
|
|
22
|
+
- `?pluginName` (optional): the name of the plugin
|
package/index.html
CHANGED
|
@@ -10,25 +10,39 @@
|
|
|
10
10
|
<script type="module">
|
|
11
11
|
const queries = new URLSearchParams(window.location.search)
|
|
12
12
|
const url = queries.get('pluginUrl')
|
|
13
|
-
const name = queries.get('pluginName')
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
14
|
+
if (!url) {
|
|
15
|
+
const exampleUrl = `${
|
|
16
|
+
window.location.href.split('?')[0]
|
|
17
|
+
}?pluginUrl=https://esm.sh/@archilogic/editor-plugin-graph`
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
document.getElementById('app').innerHTML =
|
|
20
|
+
`Please provide a plugin URL as a query parameter, e.g. <a href="${exampleUrl}">${exampleUrl}</a>`
|
|
21
|
+
|
|
22
|
+
throw new Error('No plugin URL provided')
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
const name = queries.get('pluginName') ?? url.split('/').pop()
|
|
26
|
+
|
|
23
27
|
try {
|
|
24
|
-
console.info(`${name}:
|
|
25
|
-
|
|
26
|
-
import(url).then(pluginModule => {
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
console.info(`${name}: Loading plugin from ${url}`)
|
|
29
|
+
|
|
30
|
+
import(/* @vite-ignore */ url).then(pluginModule => {
|
|
31
|
+
if (typeof pluginModule.runPlugin !== 'function') {
|
|
32
|
+
throw new Error(`${name}: Could not find plugin method 'runPlugin' in ${url}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.info(`${name}: Loaded plugin from ${url}`)
|
|
36
|
+
|
|
37
|
+
pluginModule.runPlugin({
|
|
38
|
+
pluginModule,
|
|
39
|
+
container: document.getElementById('app'),
|
|
40
|
+
url,
|
|
41
|
+
name
|
|
42
|
+
})
|
|
29
43
|
})
|
|
30
44
|
} catch (error) {
|
|
31
|
-
console.error(`${name}:
|
|
45
|
+
console.error(`${name}: Error loading plugin from ${url}`, error)
|
|
32
46
|
}
|
|
33
47
|
</script>
|
|
34
48
|
</body>
|
package/package.json
CHANGED