feat: init new plugin system (#3323)

This commit is contained in:
Alex Yang
2023-07-20 18:52:29 +08:00
committed by GitHub
parent 604b53d9a4
commit 19055baa49
45 changed files with 768 additions and 389 deletions
+32 -30
View File
@@ -1,31 +1,33 @@
import { definePlugin } from '@toeverything/plugin-infra/manager';
import { ReleaseStage } from '@toeverything/plugin-infra/type';
import type { PluginContext } from '@toeverything/plugin-infra/entry';
import { createElement } from 'react';
import { createRoot } from 'react-dom/client';
definePlugin(
{
id: 'com.affine.copilot',
name: {
fallback: 'AFFiNE Copilot',
i18nKey: 'com.affine.copilot.name',
},
description: {
fallback:
'AFFiNE Copilot will help you with best writing experience on the World.',
},
publisher: {
name: {
fallback: 'AFFiNE',
},
link: 'https://affine.pro',
},
stage: ReleaseStage.NIGHTLY,
version: '0.0.1',
commands: [],
},
{
load: () => import('./UI/index'),
hotModuleReload: onHot =>
import.meta.webpackHot &&
import.meta.webpackHot.accept('./UI', () => onHot(import('./UI/index'))),
}
);
import { DetailContent } from './UI/detail-content';
import { HeaderItem } from './UI/header-item';
export const entry = (context: PluginContext) => {
context.register('headerItem', div => {
const root = createRoot(div);
root.render(
createElement(context.utils.PluginProvider, {}, createElement(HeaderItem))
);
return () => {
root.unmount();
};
});
context.register('window', div => {
const root = createRoot(div);
root.render(
createElement(
context.utils.PluginProvider,
{},
createElement(DetailContent)
)
);
return () => {
root.unmount();
};
});
return () => {};
};