@bbki.ng/site 5.5.18 → 5.5.19
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 +8 -0
- package/index.d.ts +7 -6
- package/package.json +3 -3
- package/src/core/pluginManager.ts +14 -5
- package/src/core/registry.ts +25 -11
- package/src/plugins/sticker/components/StickerCom.tsx +6 -8
- package/src/plugins/xwy/components/logo.tsx +6 -2
- package/src/types/hostApi.ts +3 -3
- package/src/types/slots.ts +4 -0
- package/tsconfig.json +2 -4
package/CHANGELOG.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
declare const GLOBAL_COMMIT_HASH: string;
|
|
5
|
-
interface ImportMeta {
|
|
6
|
-
glob: (pattern: string) => Record<string, () => Promise<unknown>>;
|
|
7
|
-
}
|
|
3
|
+
import type React from 'react';
|
|
8
4
|
|
|
9
5
|
declare global {
|
|
6
|
+
const GLOBAL_BBKING_VERSION: string;
|
|
7
|
+
const GLOBAL_COMMIT_HASH: string;
|
|
8
|
+
|
|
10
9
|
namespace JSX {
|
|
11
10
|
interface IntrinsicElements {
|
|
12
11
|
'bb-img': React.DetailedHTMLProps<
|
|
@@ -16,3 +15,5 @@ declare global {
|
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
}
|
|
18
|
+
|
|
19
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bbki.ng/site",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.19",
|
|
4
4
|
"description": "code behind bbki.ng",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"react-dom": "^18.0.0",
|
|
15
15
|
"react-router-dom": "6",
|
|
16
16
|
"swr": "^2.2.5",
|
|
17
|
-
"@bbki.ng/ui": "0.2.
|
|
17
|
+
"@bbki.ng/ui": "0.2.13"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@eslint/compat": "^1.0.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"vite-plugin-mdx": "^3.5.8",
|
|
58
58
|
"vite-plugin-pwa": "0.19",
|
|
59
59
|
"workbox-window": "^6.3.0",
|
|
60
|
-
"@bbki.ng/config": "1.0.
|
|
60
|
+
"@bbki.ng/config": "1.0.9"
|
|
61
61
|
},
|
|
62
62
|
"author": "bbbottle",
|
|
63
63
|
"license": "MIT",
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import { IHostContext } from '#/types/hostApi';
|
|
4
|
-
import {
|
|
5
|
-
import type { SlotName, HookPoint } from '#/types/slots';
|
|
4
|
+
import type { SlotName, HookPoint, IComPropsRegisteredToSlot } from '#/types/slots';
|
|
6
5
|
import { IPlugin } from '#/types/plugin';
|
|
7
6
|
import { getStableDeviceId } from '@/utils/fingerprints';
|
|
7
|
+
|
|
8
|
+
import { registry } from './registry';
|
|
9
|
+
|
|
8
10
|
const pluginModules = import.meta.glob('../plugins/*/index.ts');
|
|
9
11
|
|
|
10
12
|
class PluginManager {
|
|
@@ -13,13 +15,18 @@ class PluginManager {
|
|
|
13
15
|
private createHostContext(): IHostContext {
|
|
14
16
|
return {
|
|
15
17
|
api: {
|
|
16
|
-
registerMiddleware: (
|
|
18
|
+
registerMiddleware: <T>(
|
|
19
|
+
point: HookPoint,
|
|
20
|
+
fn: (data: T) => Promise<T> | T,
|
|
21
|
+
pluginId: string,
|
|
22
|
+
weight = 0
|
|
23
|
+
) => {
|
|
17
24
|
registry.registerMiddleware(point, fn, pluginId, weight);
|
|
18
25
|
},
|
|
19
26
|
getDeviceId: getStableDeviceId,
|
|
20
27
|
registerSlot: (
|
|
21
28
|
slotName: SlotName,
|
|
22
|
-
component: React.ComponentType<
|
|
29
|
+
component: React.ComponentType<IComPropsRegisteredToSlot>,
|
|
23
30
|
pluginId: string,
|
|
24
31
|
weight = 0
|
|
25
32
|
) => {
|
|
@@ -54,7 +61,9 @@ class PluginManager {
|
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
try {
|
|
57
|
-
const module = await moduleLoader()
|
|
64
|
+
const module = (await moduleLoader()) as {
|
|
65
|
+
default: IPlugin;
|
|
66
|
+
};
|
|
58
67
|
|
|
59
68
|
const p: IPlugin = module.default;
|
|
60
69
|
|
package/src/core/registry.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { SlotName, HookPoint, IComPropsRegisteredToSlot } from '#/types/slots';
|
|
2
4
|
|
|
3
5
|
export interface ISlotEntry {
|
|
4
6
|
id: string;
|
|
5
|
-
component: React.ComponentType<
|
|
7
|
+
component: React.ComponentType<IComPropsRegisteredToSlot>;
|
|
6
8
|
pluginId: string;
|
|
7
9
|
weight: number;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
export interface IMiddlewareEntry {
|
|
12
|
+
export interface IMiddlewareEntry<T> {
|
|
11
13
|
id: string;
|
|
12
|
-
fn:
|
|
14
|
+
fn: (data: T) => Promise<T> | T;
|
|
13
15
|
pluginId: string;
|
|
14
16
|
weight?: number;
|
|
15
17
|
}
|
|
@@ -19,7 +21,7 @@ export class Registry {
|
|
|
19
21
|
|
|
20
22
|
private listeners = new Set<() => void>();
|
|
21
23
|
|
|
22
|
-
private middlewares = new Map<HookPoint, IMiddlewareEntry[]>();
|
|
24
|
+
private middlewares = new Map<HookPoint, IMiddlewareEntry<unknown>[]>();
|
|
23
25
|
|
|
24
26
|
private broadcastChange() {
|
|
25
27
|
this.listeners.forEach(listener => listener());
|
|
@@ -30,7 +32,12 @@ export class Registry {
|
|
|
30
32
|
return () => this.listeners.delete(listener);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
registerComponent(
|
|
35
|
+
registerComponent(
|
|
36
|
+
slot: SlotName,
|
|
37
|
+
component: React.ComponentType<IComPropsRegisteredToSlot>,
|
|
38
|
+
pluginId: string,
|
|
39
|
+
weight = 0
|
|
40
|
+
) {
|
|
34
41
|
const existing = this.slots.get(slot) || [];
|
|
35
42
|
|
|
36
43
|
const newEntry: ISlotEntry = {
|
|
@@ -65,10 +72,15 @@ export class Registry {
|
|
|
65
72
|
this.broadcastChange();
|
|
66
73
|
}
|
|
67
74
|
|
|
68
|
-
registerMiddleware(
|
|
75
|
+
registerMiddleware<T>(
|
|
76
|
+
hookPoint: HookPoint,
|
|
77
|
+
fn: (data: T) => Promise<T> | T,
|
|
78
|
+
pluginId: string,
|
|
79
|
+
weight = 0
|
|
80
|
+
) {
|
|
69
81
|
const existing = this.middlewares.get(hookPoint) || [];
|
|
70
82
|
|
|
71
|
-
const newEntry: IMiddlewareEntry = {
|
|
83
|
+
const newEntry: IMiddlewareEntry<T> = {
|
|
72
84
|
id: `${pluginId}-${fn.name || 'middleware'}`,
|
|
73
85
|
pluginId,
|
|
74
86
|
fn,
|
|
@@ -76,11 +88,13 @@ export class Registry {
|
|
|
76
88
|
};
|
|
77
89
|
|
|
78
90
|
// 插入并按权重排序(权重大的在前)
|
|
79
|
-
const newList = [...existing, newEntry].sort(
|
|
91
|
+
const newList = [...existing, newEntry as IMiddlewareEntry<unknown>].sort(
|
|
92
|
+
(a, b) => (b.weight || 0) - (a.weight || 0)
|
|
93
|
+
);
|
|
80
94
|
this.middlewares.set(hookPoint, newList);
|
|
81
95
|
}
|
|
82
96
|
|
|
83
|
-
getComponents(slotName: SlotName): React.ComponentType<
|
|
97
|
+
getComponents(slotName: SlotName): React.ComponentType<IComPropsRegisteredToSlot>[] {
|
|
84
98
|
return (this.slots.get(slotName) || []).map(entry => entry.component);
|
|
85
99
|
}
|
|
86
100
|
|
|
@@ -88,7 +102,7 @@ export class Registry {
|
|
|
88
102
|
const fns = (this.middlewares.get(point) || []).map(entry => entry.fn);
|
|
89
103
|
let result = data;
|
|
90
104
|
for (const fn of fns) {
|
|
91
|
-
result = await fn(result);
|
|
105
|
+
result = (await fn(result)) as T;
|
|
92
106
|
}
|
|
93
107
|
return result;
|
|
94
108
|
}
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import { PathObj } from '@bbki.ng/ui';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { PathObj } from '@bbki.ng/ui';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { IComPropsRegisteredToSlot } from '#/types/slots';
|
|
5
5
|
|
|
6
|
-
export const StickerCom = ({ data }:
|
|
7
|
-
const
|
|
6
|
+
export const StickerCom = ({ data }: IComPropsRegisteredToSlot) => {
|
|
7
|
+
const paths = data as PathObj[];
|
|
8
8
|
|
|
9
|
-
if (
|
|
9
|
+
if (paths.length === 0) {
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const lastPath =
|
|
13
|
+
const lastPath = paths[paths.length - 1];
|
|
14
14
|
|
|
15
15
|
if (lastPath.name !== '~') {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
console.log(ctx.deviceId);
|
|
20
|
-
|
|
21
19
|
return (
|
|
22
20
|
<div className="fixed bottom-32 left-16">
|
|
23
21
|
<div className="-rotate-17 inline-flex">
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { useLocation } from 'react-router-dom';
|
|
3
3
|
|
|
4
|
+
import { IComPropsRegisteredToSlot } from '#/types/slots';
|
|
5
|
+
|
|
4
6
|
export const Crows = () => {
|
|
5
7
|
return (
|
|
6
8
|
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
@@ -13,9 +15,11 @@ export const Crows = () => {
|
|
|
13
15
|
);
|
|
14
16
|
};
|
|
15
17
|
|
|
16
|
-
export const XwyLogo = ({ data
|
|
18
|
+
export const XwyLogo = ({ data }: IComPropsRegisteredToSlot) => {
|
|
17
19
|
const location = useLocation();
|
|
18
20
|
|
|
21
|
+
const defaultLogo = data as React.ReactNode;
|
|
22
|
+
|
|
19
23
|
if (decodeURIComponent(location.pathname).includes('小乌鸦')) {
|
|
20
24
|
return <Crows />;
|
|
21
25
|
}
|
package/src/types/hostApi.ts
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { type FingerprintData } from '@/utils/fingerprints';
|
|
4
4
|
|
|
5
|
-
import { HookPoint, SlotName } from './slots';
|
|
5
|
+
import { HookPoint, IComPropsRegisteredToSlot, SlotName } from './slots';
|
|
6
6
|
|
|
7
7
|
export interface IHostApi {
|
|
8
8
|
getDeviceId: () => Promise<{ id: string; fp: FingerprintData }>;
|
|
@@ -12,9 +12,9 @@ export interface IHostApi {
|
|
|
12
12
|
pluginId: string,
|
|
13
13
|
weight?: number
|
|
14
14
|
) => void;
|
|
15
|
-
registerSlot:
|
|
15
|
+
registerSlot: (
|
|
16
16
|
slotName: SlotName,
|
|
17
|
-
component: React.ComponentType<
|
|
17
|
+
component: React.ComponentType<IComPropsRegisteredToSlot>,
|
|
18
18
|
pluginId: string,
|
|
19
19
|
weight?: number
|
|
20
20
|
) => void;
|
package/src/types/slots.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -5,11 +5,9 @@
|
|
|
5
5
|
"jsx": "react",
|
|
6
6
|
"noEmit": true,
|
|
7
7
|
"moduleResolution": "bundler",
|
|
8
|
-
"ignoreDeprecations": "6.0",
|
|
9
|
-
"baseUrl": ".",
|
|
10
8
|
"paths": {
|
|
11
|
-
"@/*": ["src/blog/*"],
|
|
12
|
-
"#/*": ["src/*"]
|
|
9
|
+
"@/*": ["./src/blog/*"],
|
|
10
|
+
"#/*": ["./src/*"]
|
|
13
11
|
}
|
|
14
12
|
},
|
|
15
13
|
"include": ["./src", "vite.config.js", "index.d.ts"]
|