mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
init: the first public commit for AFFiNE
This commit is contained in:
1
libs/components/editor-plugins/src/utils/index.ts
Normal file
1
libs/components/editor-plugins/src/utils/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { PluginRenderRoot } from './plugin-render-root';
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import type { PatchNode, UnPatchNode } from '@toeverything/components/ui';
|
||||
|
||||
interface PluginRenderRootProps {
|
||||
name: string;
|
||||
render: PatchNode;
|
||||
}
|
||||
export class PluginRenderRoot {
|
||||
readonly name: string;
|
||||
readonly patch: PatchNode;
|
||||
private un_patch: UnPatchNode;
|
||||
private root: ReactNode;
|
||||
public isMounted = false;
|
||||
|
||||
constructor({ name, render }: PluginRenderRootProps) {
|
||||
this.name = name;
|
||||
this.patch = render;
|
||||
}
|
||||
|
||||
render(node?: ReactNode) {
|
||||
this.root = node;
|
||||
if (this.isMounted) {
|
||||
this.mount();
|
||||
}
|
||||
}
|
||||
|
||||
mount() {
|
||||
this.un_patch = this.patch(this.name, this.root);
|
||||
this.isMounted = true;
|
||||
}
|
||||
|
||||
unmount() {
|
||||
this.un_patch?.();
|
||||
this.isMounted = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user