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

View File

@@ -0,0 +1,17 @@
import { IconButton, Tooltip } from '@affine/component';
import { AffineLogoSBlue2_1Icon } from '@blocksuite/icons';
import { useCallback } from 'react';
export const HeaderItem = () => {
return (
<Tooltip content="Plugin Enabled">
<IconButton
onClick={useCallback(() => {
console.log('clicked hello world!');
}, [])}
>
<AffineLogoSBlue2_1Icon />
</IconButton>
</Tooltip>
);
};

View File

@@ -0,0 +1,26 @@
import type { PluginContext } from '@toeverything/plugin-infra/entry';
import {
currentWorkspaceIdAtom,
rootStore,
} from '@toeverything/plugin-infra/manager';
import { createElement } from 'react';
import { createRoot } from 'react-dom/client';
import { HeaderItem } from './app';
export const entry = (context: PluginContext) => {
console.log('register');
console.log('hello, world!');
console.log(rootStore.get(currentWorkspaceIdAtom));
context.register('headerItem', div => {
const root = createRoot(div);
root.render(createElement(HeaderItem));
return () => {
root.unmount();
};
});
return () => {
console.log('unregister');
};
};