feat(plugin): 插件系统 - 新增插件中心与可展开配置

This commit is contained in:
QAyong
2026-08-21 19:13:34 +08:00
parent 3b706ffdcc
commit b54e001425
12 changed files with 2659 additions and 16 deletions

View File

@@ -0,0 +1,20 @@
import { localForageStorageForScope } from "@/lib/localforage-storage";
export function createPluginStorage(pluginId: string) {
const storage = localForageStorageForScope();
const keyFor = (key: string) => `infinite-canvas:plugin:${pluginId}:${key}`;
return {
get: async <T>(key: string) => {
const value = await storage.getItem(keyFor(key));
if (!value) return null;
try {
return JSON.parse(value) as T;
} catch {
throw new Error(`插件 ${pluginId} 的配置数据损坏`);
}
},
set: async <T>(key: string, value: T) => storage.setItem(keyFor(key), JSON.stringify(value)),
remove: (key: string) => storage.removeItem(keyFor(key)),
};
}