mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 18:46:19 +08:00
init: the first public commit for AFFiNE
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { BaseView } from '@toeverything/framework/virgo';
|
||||
import { Protocol } from '@toeverything/datasource/db-service';
|
||||
import { RefLinkView } from './ref-link-view';
|
||||
|
||||
export class RefLinkBlock extends BaseView {
|
||||
type = Protocol.Block.Type.reference;
|
||||
View = RefLinkView;
|
||||
|
||||
override onTagging(content: any): string[] {
|
||||
return [
|
||||
`reference:${this.get_decoration<string>(content, 'reference')}`,
|
||||
];
|
||||
}
|
||||
|
||||
// TODO: html2block block2html
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { FC, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { InlineRefLink } from '@toeverything/components/common';
|
||||
import { CreateView } from '@toeverything/framework/virgo';
|
||||
|
||||
type RefLinkView = CreateView;
|
||||
|
||||
export const RefLinkView: FC<RefLinkView> = ({ block, editor }) => {
|
||||
const page_id = useMemo(() => block.getProperty('reference'), [block]);
|
||||
|
||||
const [block_content, set_block] =
|
||||
useState<Awaited<ReturnType<typeof editor.search>>[number]>();
|
||||
|
||||
useEffect(() => {
|
||||
editor
|
||||
.search({ tag: `id:${page_id}` })
|
||||
.then(block => set_block(block[0]));
|
||||
}, [editor, page_id]);
|
||||
|
||||
return <InlineRefLink block={block_content} pageId={page_id} />;
|
||||
};
|
||||
Reference in New Issue
Block a user