mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
feat: init new plugin system (#3323)
This commit is contained in:
17
plugins/hello-world/src/app.tsx
Normal file
17
plugins/hello-world/src/app.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
26
plugins/hello-world/src/index.ts
Normal file
26
plugins/hello-world/src/index.ts
Normal 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');
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user