refactor(infra): remove old plugin system (#5411)

plugin system need redesign
This commit is contained in:
EYHN
2023-12-27 02:49:59 +00:00
parent 3903a1c1d6
commit 265ee81666
110 changed files with 46 additions and 4426 deletions

View File

@@ -12,8 +12,6 @@ export const blockSuiteFeatureFlags = z.object({
});
export const runtimeFlagsSchema = z.object({
enablePlugin: z.boolean(),
builtinPlugins: z.array(z.string()),
enableTestProperties: z.boolean(),
enableBroadcastChannelProvider: z.boolean(),
enableDebugPage: z.boolean(),

View File

@@ -61,7 +61,6 @@
"dependencies": {
"@affine/debug": "workspace:*",
"@affine/env": "workspace:*",
"@affine/sdk": "workspace:*",
"@blocksuite/blocks": "0.11.0-nightly-202312220916-e3abcbb",
"@blocksuite/global": "0.11.0-nightly-202312220916-e3abcbb",
"@blocksuite/store": "0.11.0-nightly-202312220916-e3abcbb",

View File

@@ -1,53 +0,0 @@
import type { CallbackMap } from '@affine/sdk/entry';
import { assertExists } from '@blocksuite/global/utils';
import { atomWithStorage } from 'jotai/utils';
import { atom } from 'jotai/vanilla';
import type { z } from 'zod';
import type { packageJsonOutputSchema } from '../type.js';
export const builtinPluginPaths = new Set(runtimeConfig.builtinPlugins);
const pluginCleanupMap = new Map<string, Set<() => void>>();
export function addCleanup(
pluginName: string,
cleanup: () => void
): () => void {
if (!pluginCleanupMap.has(pluginName)) {
pluginCleanupMap.set(pluginName, new Set());
}
const cleanupSet = pluginCleanupMap.get(pluginName);
assertExists(cleanupSet);
cleanupSet.add(cleanup);
return () => {
cleanupSet.delete(cleanup);
};
}
export function invokeCleanup(pluginName: string) {
pluginCleanupMap.get(pluginName)?.forEach(cleanup => cleanup());
pluginCleanupMap.delete(pluginName);
}
export const pluginPackageJson = atom<
z.infer<typeof packageJsonOutputSchema>[]
>([]);
export const enabledPluginAtom = atomWithStorage('affine-enabled-plugin', [
'@affine/image-preview-plugin',
]);
export const pluginHeaderItemAtom = atom<
Record<string, CallbackMap['headerItem']>
>({});
export const pluginSettingAtom = atom<Record<string, CallbackMap['setting']>>(
{}
);
export const pluginEditorAtom = atom<Record<string, CallbackMap['editor']>>({});
export const pluginWindowAtom = atom<
Record<string, (root: HTMLElement) => () => void>
>({});

View File

@@ -1,6 +1,2 @@
import { atom } from 'jotai';
export const loadedPluginNameAtom = atom<string[]>([]);
export * from './root-store';
export * from './settings';

View File

@@ -8,9 +8,6 @@
"outDir": "lib"
},
"references": [
{
"path": "../sdk"
},
{
"path": "../env"
},

View File

@@ -19,7 +19,6 @@ export default defineConfig({
'core/event-emitter': resolve(root, 'src/core/event-emitter.ts'),
'preload/electron': resolve(root, 'src/preload/electron.ts'),
'app-config-storage': resolve(root, 'src/app-config-storage.ts'),
'__internal__/plugin': resolve(root, 'src/__internal__/plugin.ts'),
},
formats: ['es', 'cjs'],
name: 'AffineInfra',

View File

@@ -1,4 +0,0 @@
src/entry.d.ts
src/entry.d.ts.map
src/entry.js
src/entry.js.map

View File

@@ -1,37 +0,0 @@
{
"name": "@affine/sdk",
"version": "0.11.0",
"type": "module",
"scripts": {
"build": "vite build",
"dev": "vite build --watch"
},
"exports": {
"./entry": {
"types": "./dist/src/entry.d.ts",
"import": "./dist/entry.js",
"require": "./dist/entry.cjs"
},
"./server": {
"types": "./dist/src/server.d.ts",
"import": "./dist/server.js",
"require": "./dist/server.cjs"
}
},
"files": [
"dist"
],
"dependencies": {
"@blocksuite/block-std": "0.11.0-nightly-202312220916-e3abcbb",
"@blocksuite/blocks": "0.11.0-nightly-202312220916-e3abcbb",
"@blocksuite/global": "0.11.0-nightly-202312220916-e3abcbb",
"@blocksuite/presets": "0.11.0-nightly-202312220916-e3abcbb",
"@blocksuite/store": "0.11.0-nightly-202312220916-e3abcbb",
"jotai": "^2.5.1",
"zod": "^3.22.4"
},
"devDependencies": {
"vite": "^5.0.6",
"vite-plugin-dts": "3.6.0"
}
}

View File

@@ -1,22 +0,0 @@
{
"name": "sdk",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"sourceRoot": "packages/common/sdk/src",
"targets": {
"build": {
"executor": "@nx/vite:build",
"options": {
"outputPath": "packages/common/sdk/dist"
}
},
"serve": {
"executor": "@nx/vite:build",
"options": {
"outputPath": "packages/common/sdk/dist",
"watch": true
}
}
},
"tags": ["infra"]
}

View File

@@ -1,64 +0,0 @@
import type { BaseSelection } from '@blocksuite/block-std';
import type { AffineEditorContainer } from '@blocksuite/presets';
import type { Page } from '@blocksuite/store';
import type { Workspace } from '@blocksuite/store';
import type { Atom, getDefaultStore } from 'jotai/vanilla';
import type { WritableAtom } from 'jotai/vanilla/atom';
import type { FunctionComponent } from 'react';
export type Part = 'headerItem' | 'editor' | 'setting' | 'formatBar';
export type CallbackMap = {
headerItem: (root: HTMLElement) => () => void;
editor: (root: HTMLElement, editor: AffineEditorContainer) => () => void;
setting: (root: HTMLElement) => () => void;
formatBar: (
root: HTMLElement,
page: Page,
getBlockRange: () => BaseSelection[]
) => () => void;
};
export interface PluginContext {
register: <T extends Part>(part: T, callback: CallbackMap[T]) => void;
utils: {
PluginProvider: FunctionComponent; // make more clear
};
}
export type LayoutDirection = 'horizontal' | 'vertical';
export type LayoutNode = LayoutParentNode | string;
export type LayoutParentNode = {
direction: LayoutDirection;
splitPercentage: number; // 0 - 100
first: string;
second: LayoutNode;
maxWidth?: (number | undefined)[];
};
export type ExpectedLayout =
| {
direction: 'horizontal';
// the first element is always the editor
first: 'editor';
second: LayoutNode;
// the percentage should be greater than 70
splitPercentage: number;
}
| 'editor';
export declare const pushLayoutAtom: WritableAtom<
null,
| [
string,
(div: HTMLDivElement) => () => void,
{
maxWidth: (number | undefined)[];
},
]
| [string, (div: HTMLDivElement) => () => void],
void
>;
export declare const deleteLayoutAtom: WritableAtom<null, [string], void>;
export declare const currentWorkspaceAtom: Atom<Promise<Workspace>>;
export declare const rootStore: ReturnType<typeof getDefaultStore>;

View File

@@ -1,4 +0,0 @@
export interface ServerContext {
registerCommand: (command: string, fn: (...args: any[]) => any) => void;
unregisterCommand: (command: string) => void;
}

View File

@@ -1,15 +0,0 @@
{
"extends": "../../../tsconfig.json",
"include": ["./src"],
"compilerOptions": {
"composite": true,
"noEmit": false,
"moduleResolution": "bundler",
"outDir": "lib"
},
"references": [
{
"path": "./tsconfig.node.json"
}
]
}

View File

@@ -1,12 +0,0 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"outDir": "lib",
"noEmit": false
},
"include": ["vite.config.ts"]
}

View File

@@ -1,23 +0,0 @@
import { resolve } from 'node:path';
import { fileURLToPath } from 'url';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
const root = fileURLToPath(new URL('.', import.meta.url));
export default defineConfig({
build: {
minify: false,
lib: {
entry: {
entry: resolve(root, 'src/entry.ts'),
server: resolve(root, 'src/server.ts'),
},
},
rollupOptions: {
external: [/^jotai/, /^@blocksuite/, 'zod'],
},
},
plugins: [dts()],
});