init: the first public commit for AFFiNE

This commit is contained in:
DarkSky
2022-07-22 15:49:21 +08:00
commit e3e3741393
1451 changed files with 108124 additions and 0 deletions

View File

@@ -0,0 +1 @@
export { PluginRenderRoot } from './plugin-render-root';

View File

@@ -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;
}
}