@bbki.ng/site 1.8.3 → 1.8.5
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/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bbki.ng/site",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.5",
|
|
4
4
|
"description": "code behind bbki.ng",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@extism/extism": "2.0.0-rc11",
|
|
20
|
-
"@bbki.ng/components": "workspace:2.6.
|
|
20
|
+
"@bbki.ng/components": "workspace:2.6.4",
|
|
21
21
|
"@supabase/supabase-js": "^1.35.4",
|
|
22
22
|
"classnames": "2.3.1",
|
|
23
23
|
"react": "^18.0.0",
|
|
@@ -1,25 +1,47 @@
|
|
|
1
1
|
import { ArticlePage, ArticlePageProps } from "@/components/article";
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useCallback, useEffect } from "react";
|
|
3
3
|
import { threeColWrapper } from "@/components/with_wrapper";
|
|
4
4
|
import { useParams } from "react-router-dom";
|
|
5
5
|
import { usePluginOutput } from "@/components/plugin/hooks/usePluginOutput";
|
|
6
6
|
import { PluginManager } from "@/plugin/PluginManager";
|
|
7
|
+
import { PluginConfig } from "@extism/extism";
|
|
8
|
+
import { PluginEvent } from "@/plugin/PluginEvent";
|
|
7
9
|
|
|
8
10
|
type PluginContentPageProps = Omit<ArticlePageProps, "children">;
|
|
9
11
|
|
|
10
12
|
const ContentPage = (props: PluginContentPageProps) => {
|
|
11
13
|
const { pluginRoute } = useParams();
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
15
|
+
const [c, setC] = React.useState<string>("");
|
|
16
16
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const onInstall = useCallback((plugin: PluginConfig) => {
|
|
18
|
+
if (plugin.route !== pluginRoute) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
PluginManager.instance.run(plugin.id).then((result) => {
|
|
23
|
+
setC(result);
|
|
24
|
+
});
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
PluginManager.addEventListener<PluginConfig>(
|
|
29
|
+
PluginEvent.INSTALL,
|
|
30
|
+
onInstall
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return () => {
|
|
34
|
+
PluginManager.removeEventListener<PluginConfig>(
|
|
35
|
+
PluginEvent.INSTALL,
|
|
36
|
+
onInstall
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
const plugin = PluginManager.instance?.getPluginByRoute(pluginRoute || "");
|
|
42
|
+
|
|
43
|
+
const content = usePluginOutput(plugin?.config.id) || c;
|
|
21
44
|
|
|
22
|
-
const content = usePluginOutput(plugin.config.id);
|
|
23
45
|
return (
|
|
24
46
|
<ArticlePage {...props} title={plugin?.config.route || ""}>
|
|
25
47
|
<div dangerouslySetInnerHTML={{ __html: content }} />
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginManager } from "@/plugin/PluginManager";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
|
|
4
|
-
export const usePluginOutput = (pluginId
|
|
4
|
+
export const usePluginOutput = (pluginId?: number): string => {
|
|
5
5
|
const [output, setOutput] = useState<string>("");
|
|
6
6
|
|
|
7
7
|
useEffect(() => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Plugin, PluginConfig
|
|
1
|
+
import { Plugin, PluginConfig } from "./Plugin";
|
|
2
2
|
import { Dependencies } from "@/plugin/Dependencies";
|
|
3
3
|
import { PluginManagerPayload } from "@/plugin/PluginManagerPayload";
|
|
4
|
+
import { PluginEvent } from "@/plugin/PluginEvent";
|
|
4
5
|
|
|
5
6
|
export class PluginManager {
|
|
6
7
|
private readonly dependencies: Dependencies;
|
|
@@ -46,6 +47,22 @@ export class PluginManager {
|
|
|
46
47
|
|
|
47
48
|
static instance: PluginManager;
|
|
48
49
|
|
|
50
|
+
static dispatchEvent<T>(evt: PluginEvent, data: T) {
|
|
51
|
+
window.dispatchEvent(new CustomEvent(evt, { detail: data }));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static addEventListener<T>(evt: PluginEvent, cb: (data: T) => void) {
|
|
55
|
+
window.addEventListener(evt, (e) => {
|
|
56
|
+
cb((e as CustomEvent<T>).detail);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static removeEventListener<T>(evt: PluginEvent, cb: (data: T) => void) {
|
|
61
|
+
window.removeEventListener(evt, (e) => {
|
|
62
|
+
cb((e as CustomEvent<T>).detail);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
49
66
|
static async init(dependencies: Dependencies) {
|
|
50
67
|
if (PluginManager.instance) {
|
|
51
68
|
return;
|
|
@@ -56,7 +73,8 @@ export class PluginManager {
|
|
|
56
73
|
await PluginManager.instance.fetchPluginConfig();
|
|
57
74
|
await PluginManager.instance.restoreInstalledPlugins();
|
|
58
75
|
dependencies.loading(false);
|
|
59
|
-
dependencies.toast("Plugin manager initialized");
|
|
76
|
+
// dependencies.toast("Plugin manager initialized");
|
|
77
|
+
PluginManager.dispatchEvent<null>(PluginEvent.INIT, null);
|
|
60
78
|
|
|
61
79
|
// @ts-ignore
|
|
62
80
|
// expose plugin manager to window for debugging
|
|
@@ -78,6 +96,9 @@ export class PluginManager {
|
|
|
78
96
|
this.dependencies.toast("Plugin installed");
|
|
79
97
|
}
|
|
80
98
|
|
|
99
|
+
// dispatch event
|
|
100
|
+
PluginManager.dispatchEvent<PluginConfig>(PluginEvent.INSTALL, config);
|
|
101
|
+
|
|
81
102
|
this.saveInfo();
|
|
82
103
|
}
|
|
83
104
|
|
|
@@ -93,6 +114,9 @@ export class PluginManager {
|
|
|
93
114
|
this.plugins.delete(id);
|
|
94
115
|
this.dependencies.toast("Plugin uninstalled");
|
|
95
116
|
|
|
117
|
+
// dispatch event
|
|
118
|
+
PluginManager.dispatchEvent<PluginConfig>(PluginEvent.UNINSTALL, plugin);
|
|
119
|
+
|
|
96
120
|
this.saveInfo();
|
|
97
121
|
}
|
|
98
122
|
|