mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat(editor): improve api for store, and add docs (#10941)
This commit is contained in:
@@ -162,7 +162,7 @@ function addAIChatBlock(
|
||||
|
||||
const { doc } = host;
|
||||
const surfaceBlock = doc
|
||||
.getStore()
|
||||
.getAllModels()
|
||||
.find(block => block.flavour === 'affine:surface');
|
||||
if (!surfaceBlock) {
|
||||
return;
|
||||
@@ -520,7 +520,7 @@ const CREATE_AS_LINKED_DOC = {
|
||||
|
||||
const { doc } = host;
|
||||
const surfaceBlock = doc
|
||||
.getStore()
|
||||
.getAllModels()
|
||||
.find(block => block.flavour === 'affine:surface');
|
||||
if (!surfaceBlock) {
|
||||
return false;
|
||||
|
||||
@@ -236,7 +236,7 @@ function getEdgelessContentBound(host: EditorHost) {
|
||||
|
||||
const elements = (
|
||||
host.doc
|
||||
.getStore()
|
||||
.getAllModels()
|
||||
.filter(
|
||||
model =>
|
||||
model instanceof GfxBlockElementModel &&
|
||||
|
||||
@@ -106,7 +106,7 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
|
||||
const doc = collection.createDoc({ id: 'doc:home' }).load();
|
||||
const rootId = doc.addBlock('affine:page', {});
|
||||
const surfaceId = doc.addBlock('affine:surface', {}, rootId);
|
||||
const surface = doc.getBlockById(surfaceId) as SurfaceBlockModel;
|
||||
const surface = doc.getModelById(surfaceId) as SurfaceBlockModel;
|
||||
doc.resetHistory();
|
||||
|
||||
return {
|
||||
|
||||
@@ -163,7 +163,7 @@ export class AIChatBlockPeekView extends LitElement {
|
||||
const { doc } = this.host;
|
||||
// create a new AI chat block
|
||||
const surfaceBlock = doc
|
||||
.getStore()
|
||||
.getAllModels()
|
||||
.find(block => block.flavour === 'affine:surface');
|
||||
if (!surfaceBlock) {
|
||||
return;
|
||||
|
||||
@@ -44,7 +44,7 @@ function processSnapshot(
|
||||
text: TextSelection,
|
||||
host: EditorHost
|
||||
) {
|
||||
const model = host.doc.getBlockById(snapshot.id);
|
||||
const model = host.doc.getModelById(snapshot.id);
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ export function useReferenceLinkHelper(docCollection: Workspace) {
|
||||
},
|
||||
},
|
||||
] as DeltaInsert<AffineTextAttributes>[]);
|
||||
const [frame] = page.getBlockByFlavour('affine:note');
|
||||
const [frame] = page.getModelsByFlavour('affine:note');
|
||||
|
||||
frame && page.addBlock('affine:paragraph', { text }, frame.id);
|
||||
},
|
||||
|
||||
@@ -44,12 +44,12 @@ describe('useBlockSuitePagePreview', () => {
|
||||
{
|
||||
text: new Text('Hello, world!'),
|
||||
},
|
||||
page.getBlockByFlavour('affine:note')[0].id
|
||||
page.getModelsByFlavour('affine:note')[0].id
|
||||
);
|
||||
const hook = renderHook(() => useAtomValue(useBlockSuitePagePreview(page)));
|
||||
expect(hook.result.current).toBe('Hello, world!');
|
||||
page.transact(() => {
|
||||
page.getBlockById(id)!.text!.insert('Test', 0);
|
||||
page.getModelById(id)!.text!.insert('Test', 0);
|
||||
});
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
hook.rerender();
|
||||
@@ -61,7 +61,7 @@ describe('useBlockSuitePagePreview', () => {
|
||||
{
|
||||
text: new Text('First block!'),
|
||||
},
|
||||
page.getBlockByFlavour('affine:note')[0].id,
|
||||
page.getModelsByFlavour('affine:note')[0].id,
|
||||
0
|
||||
);
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
Reference in New Issue
Block a user