@bbki.ng/site 5.6.2 → 5.6.3
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 +6 -0
- package/package.json +1 -1
- package/src/core/hooks/use_plugins.ts +5 -1
- package/src/core/pluginManager.ts +7 -0
- package/src/plugins/fx/components/index.tsx +19 -10
- package/src/plugins/fx/context/index.ts +4 -0
- package/src/plugins/fx/index.ts +3 -0
- package/src/plugins/manifest.ts +2 -3
- package/src/plugins/store/components/storePage.tsx +19 -9
- package/src/types/hostApi.ts +4 -1
- package/src/types/plugin.ts +1 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -7,7 +7,11 @@ import { PluginID } from '#/types/plugin';
|
|
|
7
7
|
import { PluginStore } from '../pluginStore';
|
|
8
8
|
|
|
9
9
|
const usePluginsLoading = () => {
|
|
10
|
-
const { setGlobalLoading } = useGlobalLoading();
|
|
10
|
+
const { setGlobalLoading, isLoading } = useGlobalLoading();
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
pluginManager.notifySiteLoadingChanged(isLoading);
|
|
14
|
+
}, [isLoading]);
|
|
11
15
|
|
|
12
16
|
useEffect(() => {
|
|
13
17
|
let unregister: (() => void) | undefined;
|
|
@@ -30,6 +30,9 @@ class PluginManager {
|
|
|
30
30
|
setLoading: (id: PluginID, loading: boolean) => {
|
|
31
31
|
this.bus.emit('plugin:loading:changed', { id, loading });
|
|
32
32
|
},
|
|
33
|
+
onLoadingChanged: (listener: (payload: PluginEvents['site:loading:changed']) => void) => {
|
|
34
|
+
return this.bus.on('site:loading:changed', listener);
|
|
35
|
+
},
|
|
33
36
|
registerMiddleware: <T>(
|
|
34
37
|
point: HookPoint,
|
|
35
38
|
fn: (data: T) => Promise<T> | T,
|
|
@@ -58,6 +61,10 @@ class PluginManager {
|
|
|
58
61
|
|
|
59
62
|
private loading = new Set<string>();
|
|
60
63
|
|
|
64
|
+
notifySiteLoadingChanged(loading: boolean) {
|
|
65
|
+
this.bus.emit('site:loading:changed', loading);
|
|
66
|
+
}
|
|
67
|
+
|
|
61
68
|
subscribePluginLoading(listener: (payload: PluginEvents['plugin:loading:changed']) => void) {
|
|
62
69
|
return this.bus.on('plugin:loading:changed', listener);
|
|
63
70
|
}
|
|
@@ -1,30 +1,39 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
|
-
import { EffectLayer, grain, paper,
|
|
2
|
+
import { EffectLayer, grain, paper, spiral, watermark, Effect } from '@bbki.ng/ui';
|
|
3
3
|
|
|
4
4
|
import { IComPropsRegisteredToSlot } from '#/types/slots';
|
|
5
5
|
|
|
6
6
|
import { FxContext } from '../context';
|
|
7
7
|
|
|
8
|
+
const useLoadingState = () => {
|
|
9
|
+
const ctx = FxContext.useCtx();
|
|
10
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
11
|
+
|
|
12
|
+
React.useEffect(() => {
|
|
13
|
+
const unsubscribe = ctx.subscribeToLoading(setIsLoading);
|
|
14
|
+
return () => {
|
|
15
|
+
unsubscribe();
|
|
16
|
+
};
|
|
17
|
+
}, [ctx]);
|
|
18
|
+
|
|
19
|
+
return isLoading;
|
|
20
|
+
};
|
|
21
|
+
|
|
8
22
|
export const FxCom = (_: IComPropsRegisteredToSlot) => {
|
|
9
23
|
const ctx = FxContext.useCtx();
|
|
10
24
|
const hashStr = ctx.versionHash;
|
|
11
25
|
const deviceId = ctx.deviceId;
|
|
26
|
+
const isLoading = useLoadingState();
|
|
12
27
|
|
|
13
|
-
|
|
14
|
-
// const { deviceId } = useFingerprint();
|
|
28
|
+
console.log('is loading', isLoading);
|
|
15
29
|
|
|
16
30
|
const effects: Effect[] = useMemo(() => {
|
|
17
31
|
const wmLines = [hashStr];
|
|
18
32
|
if (deviceId) wmLines.push(deviceId);
|
|
19
33
|
wmLines.push('hello world');
|
|
20
34
|
|
|
21
|
-
return [
|
|
22
|
-
|
|
23
|
-
paper(),
|
|
24
|
-
// spiral({ active: isLoading }),
|
|
25
|
-
watermark({ lines: wmLines }),
|
|
26
|
-
];
|
|
27
|
-
}, [/*isLoading,*/ deviceId, hashStr]);
|
|
35
|
+
return [grain(), paper(), spiral({ active: isLoading }), watermark({ lines: wmLines })];
|
|
36
|
+
}, [isLoading, deviceId, hashStr]);
|
|
28
37
|
|
|
29
38
|
return <EffectLayer effects={effects} />;
|
|
30
39
|
};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { createPluginCtx } from '#/core/context';
|
|
2
|
+
import { PluginEvents } from '#/types/plugin';
|
|
2
3
|
|
|
3
4
|
export interface IFxContext {
|
|
4
5
|
versionHash: string;
|
|
5
6
|
deviceId: string;
|
|
7
|
+
subscribeToLoading: (
|
|
8
|
+
listener: (payload: PluginEvents['site:loading:changed']) => void
|
|
9
|
+
) => () => void;
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
export const FxContext = createPluginCtx<IFxContext>();
|
package/src/plugins/fx/index.ts
CHANGED
package/src/plugins/manifest.ts
CHANGED
|
@@ -25,14 +25,13 @@ export const PLUGIN_MANIFEST: Array<IPluginManifestEntry> = [
|
|
|
25
25
|
id: 'extra-cd',
|
|
26
26
|
version: '0.1.0',
|
|
27
27
|
description:
|
|
28
|
-
'
|
|
28
|
+
'提供额外的页面跳转链接。例如在标题列表末尾添加一个 "cd ~" 的选项,点击后跳转到主页',
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
name: '特效',
|
|
32
32
|
id: 'fx',
|
|
33
33
|
version: '0.1.0',
|
|
34
|
-
description:
|
|
35
|
-
'提供一些额外的视觉效果。此外,页面左下角会显示当前版本的哈希值和设备标识哈希水印。',
|
|
34
|
+
description: '提供一些额外的视觉效果。例如版本、设备信息水印,加载状态螺旋线、背景纹理等',
|
|
36
35
|
},
|
|
37
36
|
// {
|
|
38
37
|
// name: 'extra-entry',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { Button, Table, Link } from '@bbki.ng/ui';
|
|
3
4
|
|
|
4
5
|
import { IComPropsRegisteredToSlot } from '#/types/slots';
|
|
5
6
|
import { IPluginStoreEntry, PluginID } from '#/types/plugin';
|
|
@@ -163,13 +164,22 @@ export const StorePage = (_: IComPropsRegisteredToSlot) => {
|
|
|
163
164
|
}
|
|
164
165
|
|
|
165
166
|
return (
|
|
166
|
-
|
|
167
|
-
<
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
<>
|
|
168
|
+
<div className="prose">
|
|
169
|
+
<Table
|
|
170
|
+
className="w-full"
|
|
171
|
+
rowCount={plugins.length}
|
|
172
|
+
headerRenderer={headerRenderer}
|
|
173
|
+
rowRenderer={rowRenderer}
|
|
174
|
+
/>
|
|
175
|
+
</div>
|
|
176
|
+
<Link
|
|
177
|
+
className={classNames('w-fit relative transition-all duration-300 mt-16')}
|
|
178
|
+
to="/"
|
|
179
|
+
style={{ left: -4 }}
|
|
180
|
+
>
|
|
181
|
+
cd ..
|
|
182
|
+
</Link>
|
|
183
|
+
</>
|
|
174
184
|
);
|
|
175
185
|
};
|
package/src/types/hostApi.ts
CHANGED
|
@@ -4,12 +4,15 @@ import { type FingerprintData } from '@/utils/fingerprints';
|
|
|
4
4
|
import { PluginStore } from '#/core/pluginStore';
|
|
5
5
|
|
|
6
6
|
import { HookPoint, IComPropsRegisteredToSlot, SlotName } from './slots';
|
|
7
|
-
import { PluginID } from './plugin';
|
|
7
|
+
import { PluginEvents, PluginID } from './plugin';
|
|
8
8
|
|
|
9
9
|
export interface IHostApi {
|
|
10
10
|
getDeviceId: () => Promise<{ id: string; fp: FingerprintData }>;
|
|
11
11
|
getVersionHash: () => Promise<string> | string;
|
|
12
12
|
setLoading: (id: PluginID, loading: boolean) => void;
|
|
13
|
+
onLoadingChanged: (
|
|
14
|
+
listener: (payload: PluginEvents['site:loading:changed']) => void
|
|
15
|
+
) => () => void;
|
|
13
16
|
registerMiddleware: <T>(
|
|
14
17
|
point: HookPoint,
|
|
15
18
|
fn: (baseData: T) => T,
|