mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 16:46:22 +08:00
feat(plugin): migrate plugin runner to rxjs
This commit is contained in:
@@ -3,30 +3,10 @@ import {
|
||||
styled,
|
||||
} from '@toeverything/components/ui';
|
||||
import { Protocol } from '@toeverything/datasource/db-service';
|
||||
import type {
|
||||
AsyncBlock,
|
||||
PluginHooks,
|
||||
Virgo,
|
||||
} from '@toeverything/framework/virgo';
|
||||
import {
|
||||
createContext,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
type CSSProperties,
|
||||
} from 'react';
|
||||
import type { AsyncBlock, Virgo } from '@toeverything/framework/virgo';
|
||||
import { useEffect, useState, type CSSProperties } from 'react';
|
||||
|
||||
export type Store =
|
||||
| {
|
||||
editor: Virgo;
|
||||
hooks: PluginHooks;
|
||||
}
|
||||
| Record<string, never>;
|
||||
|
||||
export const StoreContext = createContext<Store>({});
|
||||
|
||||
export const MenuApp = () => {
|
||||
const { editor } = useContext(StoreContext);
|
||||
export const MenuApp = ({ editor }: { editor: Virgo }) => {
|
||||
const [show, setShow] = useState<boolean>(false);
|
||||
const [style, setStyle] = useState<CSSProperties>();
|
||||
const [selectedNodes, setSelectedNodes] = useState<AsyncBlock[]>([]);
|
||||
|
||||
+7
-11
@@ -1,7 +1,7 @@
|
||||
import { StrictMode } from 'react';
|
||||
import { BasePlugin } from '../../base-plugin';
|
||||
import { PluginRenderRoot } from '../../utils';
|
||||
import { MenuApp, StoreContext } from './MenuApp';
|
||||
import { MenuApp } from './MenuApp';
|
||||
|
||||
const PLUGIN_NAME = 'selection-group';
|
||||
|
||||
@@ -10,27 +10,23 @@ export class SelectionGroupPlugin extends BasePlugin {
|
||||
return PLUGIN_NAME;
|
||||
}
|
||||
|
||||
private root: PluginRenderRoot | undefined;
|
||||
private _root: PluginRenderRoot | undefined;
|
||||
|
||||
protected override _onRender() {
|
||||
this.root = new PluginRenderRoot({
|
||||
this._root = new PluginRenderRoot({
|
||||
name: SelectionGroupPlugin.pluginName,
|
||||
render: this.editor.reactRenderRoot?.render,
|
||||
});
|
||||
this.root.mount();
|
||||
this.root.render(
|
||||
this._root.mount();
|
||||
this._root.render(
|
||||
<StrictMode>
|
||||
<StoreContext.Provider
|
||||
value={{ editor: this.editor, hooks: this.hooks }}
|
||||
>
|
||||
<MenuApp />
|
||||
</StoreContext.Provider>
|
||||
<MenuApp editor={this.editor} />
|
||||
</StrictMode>
|
||||
);
|
||||
}
|
||||
|
||||
public override dispose() {
|
||||
this.root?.unmount();
|
||||
this._root?.unmount();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user