@archilogic/plugin-container 0.0.0-20240209175834 → 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 +49 -0
- package/package.json +3 -4
- package/dist/assets/index-WgfBxxC8.js +0 -7
- package/dist/index.html +0 -12
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
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Archilogic Plugin Container</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module">
|
|
11
|
+
const queries = new URLSearchParams(window.location.search)
|
|
12
|
+
const url = queries.get('pluginUrl')
|
|
13
|
+
|
|
14
|
+
if (!url) {
|
|
15
|
+
const exampleUrl = `${
|
|
16
|
+
window.location.href.split('?')[0]
|
|
17
|
+
}?pluginUrl=https://esm.sh/@archilogic/editor-plugin-graph`
|
|
18
|
+
|
|
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')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const name = queries.get('pluginName') ?? url.split('/').pop()
|
|
26
|
+
|
|
27
|
+
try {
|
|
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
|
+
})
|
|
43
|
+
})
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error(`${name}: Error loading plugin from ${url}`, error)
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
</body>
|
|
49
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@archilogic/plugin-container",
|
|
3
3
|
"description": "An HTML container for Archilogic plugins",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-20240212115958",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
-
"
|
|
10
|
+
"index.html"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
-
"dev": "vite"
|
|
14
|
-
"build": "vite build"
|
|
13
|
+
"dev": "vite"
|
|
15
14
|
},
|
|
16
15
|
"devDependencies": {
|
|
17
16
|
"vite": "^5.1.0"
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
(function(){const i=document.createElement("link").relList;if(i&&i.supports&&i.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))s(e);new MutationObserver(e=>{for(const t of e)if(t.type==="childList")for(const r of t.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&s(r)}).observe(document,{childList:!0,subtree:!0});function o(e){const t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?t.credentials="include":e.crossOrigin==="anonymous"?t.credentials="omit":t.credentials="same-origin",t}function s(e){if(e.ep)return;e.ep=!0;const t=o(e);fetch(e.href,t)}})();const p="modulepreload",y=function(n){return"/"+n},m={},P=function(i,o,s){let e=Promise.resolve();if(o&&o.length>0){const t=document.getElementsByTagName("link");e=Promise.all(o.map(r=>{if(r=y(r),r in m)return;m[r]=!0;const c=r.endsWith(".css"),g=c?'[rel="stylesheet"]':"";if(!!s)for(let u=t.length-1;u>=0;u--){const f=t[u];if(f.href===r&&(!c||f.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${r}"]${g}`))return;const l=document.createElement("link");if(l.rel=c?"stylesheet":p,c||(l.as="script",l.crossOrigin=""),l.href=r,document.head.appendChild(l),c)return new Promise((u,f)=>{l.addEventListener("load",u),l.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${r}`)))})}))}return e.then(()=>i()).catch(t=>{const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=t,window.dispatchEvent(r),!r.defaultPrevented)throw t})},h=new URLSearchParams(window.location.search),a=h.get("pluginUrl"),d=h.get("pluginName"),v=({pluginModule:n,container:i,url:o,name:s})=>{if(typeof n.runPlugin!="function")throw new Error(`${s}: could not find plugin method ${pluginMethod} in ${o}`);n.runPlugin({pluginModule:n,container:i,url:o,name:s})};try{console.info(`${d}: loading plugin from ${a}`),P(()=>import(a),__vite__mapDeps([])).then(n=>{console.info(`${d}: loaded plugin from ${a}`),v({pluginModule:n,container:document.getElementById("app"),url:a,name:d})})}catch(n){console.error(`${d}: error loading plugin from ${a}`,n)}
|
|
2
|
-
function __vite__mapDeps(indexes) {
|
|
3
|
-
if (!__vite__mapDeps.viteFileDeps) {
|
|
4
|
-
__vite__mapDeps.viteFileDeps = []
|
|
5
|
-
}
|
|
6
|
-
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
7
|
-
}
|
package/dist/index.html
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<title>Archilogic Plugin Container</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-WgfBxxC8.js"></script>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="app"></div>
|
|
11
|
-
</body>
|
|
12
|
-
</html>
|