refactor(core): move block collection to affine and implement as doc (#9514)

This commit is contained in:
Saul-Mirone
2025-01-04 06:28:54 +00:00
parent 4cb186def2
commit dcf4993265
39 changed files with 595 additions and 192 deletions
@@ -5,7 +5,7 @@ import { DocModeProvider } from '@blocksuite/affine-shared/services';
import { getBlockProps } from '@blocksuite/affine-shared/utils';
import type { EditorHost } from '@blocksuite/block-std';
import { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
import { type BlockModel, type Blocks } from '@blocksuite/store';
import { type BlockModel, type Blocks, Text } from '@blocksuite/store';
import {
getElementProps,
@@ -43,7 +43,7 @@ export function createLinkedDocFromNote(
const linkedDoc = doc.collection.createDoc({});
linkedDoc.load(() => {
const rootId = linkedDoc.addBlock('affine:page', {
title: new doc.Text(docTitle),
title: new Text(docTitle),
});
linkedDoc.addBlock('affine:surface', {}, rootId);
const blockProps = getBlockProps(note);
@@ -74,7 +74,7 @@ export function createLinkedDocFromEdgelessElements(
const linkedDoc = host.doc.collection.createDoc({});
linkedDoc.load(() => {
const rootId = linkedDoc.addBlock('affine:page', {
title: new host.doc.Text(docTitle),
title: new Text(docTitle),
});
const surfaceId = linkedDoc.addBlock('affine:surface', {}, rootId);
const surface = getSurfaceBlock(linkedDoc);
@@ -53,7 +53,7 @@ import {
} from '@blocksuite/affine-shared/services';
import { getHostName, referenceToNode } from '@blocksuite/affine-shared/utils';
import { type BlockStdScope, WidgetComponent } from '@blocksuite/block-std';
import { type BlockModel } from '@blocksuite/store';
import { type BlockModel, Text } from '@blocksuite/store';
import { autoUpdate, computePosition, flip, offset } from '@floating-ui/dom';
import { html, nothing, type TemplateResult } from 'lit';
import { query, state } from 'lit/decorators.js';
@@ -619,7 +619,7 @@ export class EmbedCardToolbar extends WidgetComponent<
const insert = title || caption || url;
yText.insert(0, insert);
yText.format(0, insert.length, { link: url });
const text = new doc.Text(yText);
const text = new Text(yText);
doc.addBlock(
'affine:paragraph',
{
@@ -709,9 +709,7 @@ export const defaultSlashMenuConfig: SlashMenuConfig = {
model.flavour as never,
{
type: (model as ParagraphBlockModel).type,
text: new rootComponent.doc.Text(
model.text.toDelta() as DeltaInsert[]
),
text: new Text(model.text.toDelta() as DeltaInsert[]),
// @ts-expect-error FIXME: ts error
checked: model.checked,
},