@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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 5.5.19
4
+
5
+ ### Patch Changes
6
+
7
+ - 3edea98: fix base url config
8
+ - Updated dependencies [3edea98]
9
+ - @bbki.ng/ui@0.2.13
10
+
3
11
  ## 5.5.18
4
12
 
5
13
  ### Patch Changes
package/index.d.ts CHANGED
@@ -1,12 +1,11 @@
1
- import React from 'react';
1
+ /// <reference types="vite/client" />
2
2
 
3
- declare const GLOBAL_BBKING_VERSION: string;
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.18",
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.12"
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.8"
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 { registry } from './registry';
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: (point: HookPoint, fn: Function, pluginId: string, weight = 0) => {
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<any>,
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
 
@@ -1,15 +1,17 @@
1
- import type { SlotName, HookPoint } from 'src/types/slots';
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<any>;
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: Function;
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(slot: SlotName, component: React.ComponentType, pluginId: string, weight = 0) {
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(hookPoint: HookPoint, fn: Function, pluginId: string, weight = 0) {
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((a, b) => (b.weight || 0) - (a.weight || 0));
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<any>[] {
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 { StickerCtx } from '../context';
4
+ import { IComPropsRegisteredToSlot } from '#/types/slots';
5
5
 
6
- export const StickerCom = ({ data }: { data: PathObj[] }) => {
7
- const ctx = StickerCtx.useCtx();
6
+ export const StickerCom = ({ data }: IComPropsRegisteredToSlot) => {
7
+ const paths = data as PathObj[];
8
8
 
9
- if (data.length === 0) {
9
+ if (paths.length === 0) {
10
10
  return null;
11
11
  }
12
12
 
13
- const lastPath = data[data.length - 1];
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, { ReactNode } from '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: defaultLogo }: { data: ReactNode }) => {
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
  }
@@ -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: <T>(
15
+ registerSlot: (
16
16
  slotName: SlotName,
17
- component: React.ComponentType<T>,
17
+ component: React.ComponentType<IComPropsRegisteredToSlot>,
18
18
  pluginId: string,
19
19
  weight?: number
20
20
  ) => void;
@@ -1,2 +1,6 @@
1
1
  export type SlotName = 'leftCol' | 'rightCol' | 'articleActionRow' | 'logo';
2
2
  export type HookPoint = 'filterPosts' | 'transformPostContent' | 'transformTitleList';
3
+
4
+ export interface IComPropsRegisteredToSlot {
5
+ data: unknown;
6
+ }
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"]