refactor(core): move block collection to affine and implement as doc (#9514)
This commit is contained in:
@@ -64,11 +64,11 @@ test(scoped`basic init with external text`, async ({ page }) => {
|
||||
await page.evaluate(() => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text('hello'),
|
||||
title: new window.$blocksuite.store.Text('hello'),
|
||||
});
|
||||
const note = doc.addBlock('affine:note', {}, rootId);
|
||||
|
||||
const text = new doc.Text('world');
|
||||
const text = new window.$blocksuite.store.Text('world');
|
||||
doc.addBlock('affine:paragraph', { text }, note);
|
||||
|
||||
const delta = [
|
||||
@@ -78,7 +78,7 @@ test(scoped`basic init with external text`, async ({ page }) => {
|
||||
doc.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new doc.Text(delta as DeltaInsert[]),
|
||||
text: new window.$blocksuite.store.Text(delta as DeltaInsert[]),
|
||||
},
|
||||
note
|
||||
);
|
||||
|
||||
@@ -628,7 +628,7 @@ test.fixme(
|
||||
const { doc } = window;
|
||||
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
doc.addBlock('affine:surface', {}, rootId);
|
||||
|
||||
@@ -637,7 +637,7 @@ test.fixme(
|
||||
doc.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new doc.Text(text),
|
||||
text: new window.$blocksuite.store.Text(text),
|
||||
},
|
||||
noteId
|
||||
);
|
||||
|
||||
@@ -554,7 +554,7 @@ test('press backspace at the start of first line when edgeless text exist', asyn
|
||||
await page.evaluate(() => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
doc.addBlock('affine:surface', {}, rootId);
|
||||
doc.addBlock('affine:note', {}, rootId);
|
||||
|
||||
@@ -140,7 +140,7 @@ test.describe('Embed synced doc', () => {
|
||||
await page.evaluate(() => {
|
||||
const { doc, collection } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
|
||||
const noteId = doc.addBlock('affine:note', {}, rootId);
|
||||
@@ -149,14 +149,14 @@ test.describe('Embed synced doc', () => {
|
||||
const doc2 = collection.createDoc({ id: 'doc2' });
|
||||
doc2.load();
|
||||
const rootId2 = doc2.addBlock('affine:page', {
|
||||
title: new doc.Text('Doc 2'),
|
||||
title: new window.$blocksuite.store.Text('Doc 2'),
|
||||
});
|
||||
|
||||
const noteId2 = doc2.addBlock('affine:note', {}, rootId2);
|
||||
doc2.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new doc.Text('Hello from Doc 2'),
|
||||
text: new window.$blocksuite.store.Text('Hello from Doc 2'),
|
||||
},
|
||||
noteId2
|
||||
);
|
||||
@@ -164,14 +164,14 @@ test.describe('Embed synced doc', () => {
|
||||
const doc3 = collection.createDoc({ id: 'doc3' });
|
||||
doc3.load();
|
||||
const rootId3 = doc3.addBlock('affine:page', {
|
||||
title: new doc.Text('Doc 3'),
|
||||
title: new window.$blocksuite.store.Text('Doc 3'),
|
||||
});
|
||||
|
||||
const noteId3 = doc3.addBlock('affine:note', {}, rootId3);
|
||||
doc3.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new doc.Text('Hello from Doc 3'),
|
||||
text: new window.$blocksuite.store.Text('Hello from Doc 3'),
|
||||
},
|
||||
noteId3
|
||||
);
|
||||
@@ -232,7 +232,7 @@ test.describe('Embed synced doc', () => {
|
||||
const databaseId = doc2.addBlock(
|
||||
'affine:database',
|
||||
{
|
||||
title: new doc2.Text('Database 1'),
|
||||
title: new window.$blocksuite.store.Text('Database 1'),
|
||||
},
|
||||
noteId
|
||||
);
|
||||
|
||||
@@ -453,10 +453,10 @@ test('should format quick bar position correct at the start of second line', asy
|
||||
await page.evaluate(() => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
const note = doc.addBlock('affine:note', {}, rootId);
|
||||
const text = new doc.Text('a'.repeat(100));
|
||||
const text = new window.$blocksuite.store.Text('a'.repeat(100));
|
||||
const paragraphId = doc.addBlock('affine:paragraph', { text }, note);
|
||||
return paragraphId;
|
||||
});
|
||||
@@ -715,7 +715,7 @@ test('should format bar style active correctly', async ({ page }) => {
|
||||
await page.evaluate(() => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
const note = doc.addBlock('affine:note', {}, rootId);
|
||||
const delta = [
|
||||
@@ -723,7 +723,7 @@ test('should format bar style active correctly', async ({ page }) => {
|
||||
{ insert: '2', attributes: { bold: true, underline: true } },
|
||||
{ insert: '3', attributes: { bold: true, code: true } },
|
||||
];
|
||||
const text = new doc.Text(delta as DeltaInsert[]);
|
||||
const text = new window.$blocksuite.store.Text(delta as DeltaInsert[]);
|
||||
doc.addBlock('affine:paragraph', { text }, note);
|
||||
});
|
||||
|
||||
@@ -869,7 +869,7 @@ test('should update the format quick bar state when there is a change in keyboar
|
||||
await page.evaluate(() => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
const note = doc.addBlock('affine:note', {}, rootId);
|
||||
const delta = [
|
||||
@@ -877,7 +877,7 @@ test('should update the format quick bar state when there is a change in keyboar
|
||||
{ insert: '2', attributes: { bold: true } },
|
||||
{ insert: '3', attributes: { bold: false } },
|
||||
];
|
||||
const text = new doc.Text(delta as DeltaInsert[]);
|
||||
const text = new window.$blocksuite.store.Text(delta as DeltaInsert[]);
|
||||
doc.addBlock('affine:paragraph', { text }, note);
|
||||
});
|
||||
await focusTitle(page);
|
||||
|
||||
@@ -121,11 +121,11 @@ async function createLinkBlock(page: Page, str: string, link: string) {
|
||||
([str, link]) => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text('title'),
|
||||
title: new window.$blocksuite.store.Text('title'),
|
||||
});
|
||||
const noteId = doc.addBlock('affine:note', {}, rootId);
|
||||
|
||||
const text = new doc.Text([
|
||||
const text = new window.$blocksuite.store.Text([
|
||||
{ insert: 'Hello' },
|
||||
{ insert: str, attributes: { link } },
|
||||
]);
|
||||
|
||||
@@ -825,20 +825,20 @@ test('press arrow down should move caret to the start of line', async ({
|
||||
await page.evaluate(() => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
const note = doc.addBlock('affine:note', {}, rootId);
|
||||
doc.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new doc.Text('0'.repeat(100)),
|
||||
text: new window.$blocksuite.store.Text('0'.repeat(100)),
|
||||
},
|
||||
note
|
||||
);
|
||||
doc.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new doc.Text('1'),
|
||||
text: new window.$blocksuite.store.Text('1'),
|
||||
},
|
||||
note
|
||||
);
|
||||
@@ -860,7 +860,7 @@ test('press arrow up in the second line should move caret to the first line', as
|
||||
await page.evaluate(() => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
const note = doc.addBlock('affine:note', {}, rootId);
|
||||
const delta = Array.from({ length: 150 }, (_, i) => {
|
||||
@@ -868,7 +868,7 @@ test('press arrow up in the second line should move caret to the first line', as
|
||||
? { insert: 'i', attributes: { italic: true } }
|
||||
: { insert: 'b', attributes: { bold: true } };
|
||||
}) as DeltaInsert[];
|
||||
const text = new doc.Text(delta);
|
||||
const text = new window.$blocksuite.store.Text(delta);
|
||||
doc.addBlock('affine:paragraph', { text }, note);
|
||||
doc.addBlock('affine:paragraph', {}, note);
|
||||
});
|
||||
@@ -912,7 +912,7 @@ test('press arrow down in indent line should not move caret to the start of line
|
||||
await page.evaluate(() => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
const note = doc.addBlock('affine:note', {}, rootId);
|
||||
const p1 = doc.addBlock('affine:paragraph', {}, note);
|
||||
@@ -921,7 +921,7 @@ test('press arrow down in indent line should not move caret to the start of line
|
||||
doc.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new doc.Text('0'),
|
||||
text: new window.$blocksuite.store.Text('0'),
|
||||
},
|
||||
note
|
||||
);
|
||||
@@ -1003,20 +1003,22 @@ test.describe('press ArrowDown when cursor is at the last line of a block', () =
|
||||
await page.evaluate(() => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
const note = doc.addBlock('affine:note', {}, rootId);
|
||||
doc.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new doc.Text('This is the 2nd last block.'),
|
||||
text: new window.$blocksuite.store.Text(
|
||||
'This is the 2nd last block.'
|
||||
),
|
||||
},
|
||||
note
|
||||
);
|
||||
doc.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new doc.Text('This is the last block.'),
|
||||
text: new window.$blocksuite.store.Text('This is the last block.'),
|
||||
},
|
||||
note
|
||||
);
|
||||
@@ -1172,7 +1174,7 @@ test('delete at the start of paragraph (multiple notes)', async ({ page }) => {
|
||||
const { doc } = window;
|
||||
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
doc.addBlock('affine:surface', {}, rootId);
|
||||
|
||||
@@ -1181,7 +1183,7 @@ test('delete at the start of paragraph (multiple notes)', async ({ page }) => {
|
||||
doc.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new doc.Text(text),
|
||||
text: new window.$blocksuite.store.Text(text),
|
||||
},
|
||||
noteId
|
||||
);
|
||||
|
||||
@@ -413,7 +413,7 @@ export async function enterPlaygroundWithList(
|
||||
({ contents, type }: { contents: string[]; type: ListType }) => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
const noteId = doc.addBlock('affine:note', {}, rootId);
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
||||
@@ -421,7 +421,7 @@ export async function enterPlaygroundWithList(
|
||||
doc.addBlock(
|
||||
'affine:list',
|
||||
contents.length > 0
|
||||
? { text: new doc.Text(contents[i]), type }
|
||||
? { text: new window.$blocksuite.store.Text(contents[i]), type }
|
||||
: { type },
|
||||
noteId
|
||||
);
|
||||
@@ -439,7 +439,7 @@ export async function initEmptyParagraphState(page: Page, rootId?: string) {
|
||||
doc.captureSync();
|
||||
if (!rootId) {
|
||||
rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -464,7 +464,7 @@ export async function initMultipleNoteWithParagraphState(
|
||||
doc.captureSync();
|
||||
if (!rootId) {
|
||||
rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -490,7 +490,7 @@ export async function initEmptyEdgelessState(page: Page) {
|
||||
const ids = await page.evaluate(() => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
doc.addBlock('affine:surface', {}, rootId);
|
||||
const noteId = doc.addBlock('affine:note', {}, rootId);
|
||||
@@ -509,14 +509,14 @@ export async function initEmptyDatabaseState(page: Page, rootId?: string) {
|
||||
doc.captureSync();
|
||||
if (!rootId) {
|
||||
rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
}
|
||||
const noteId = doc.addBlock('affine:note', {}, rootId);
|
||||
const databaseId = doc.addBlock(
|
||||
'affine:database',
|
||||
{
|
||||
title: new doc.Text('Database 1'),
|
||||
title: new window.$blocksuite.store.Text('Database 1'),
|
||||
},
|
||||
noteId
|
||||
);
|
||||
@@ -553,14 +553,14 @@ export async function initKanbanViewState(
|
||||
doc.captureSync();
|
||||
if (!rootId) {
|
||||
rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
}
|
||||
const noteId = doc.addBlock('affine:note', {}, rootId);
|
||||
const databaseId = doc.addBlock(
|
||||
'affine:database',
|
||||
{
|
||||
title: new doc.Text('Database 1'),
|
||||
title: new window.$blocksuite.store.Text('Database 1'),
|
||||
},
|
||||
noteId
|
||||
);
|
||||
@@ -572,7 +572,7 @@ export async function initKanbanViewState(
|
||||
const rowIds = config.rows.map(rowText => {
|
||||
const rowId = doc.addBlock(
|
||||
'affine:paragraph',
|
||||
{ type: 'text', text: new doc.Text(rowText) },
|
||||
{ type: 'text', text: new window.$blocksuite.store.Text(rowText) },
|
||||
databaseId
|
||||
);
|
||||
return rowId;
|
||||
@@ -590,7 +590,7 @@ export async function initKanbanViewState(
|
||||
columnId,
|
||||
value:
|
||||
column.type === 'rich-text'
|
||||
? new doc.Text(value as string)
|
||||
? new window.$blocksuite.store.Text(value as string)
|
||||
: value,
|
||||
});
|
||||
}
|
||||
@@ -619,14 +619,14 @@ export async function initEmptyDatabaseWithParagraphState(
|
||||
doc.captureSync();
|
||||
if (!rootId) {
|
||||
rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
}
|
||||
const noteId = doc.addBlock('affine:note', {}, rootId);
|
||||
const databaseId = doc.addBlock(
|
||||
'affine:database',
|
||||
{
|
||||
title: new doc.Text('Database 1'),
|
||||
title: new window.$blocksuite.store.Text('Database 1'),
|
||||
},
|
||||
noteId
|
||||
);
|
||||
@@ -1326,7 +1326,7 @@ export async function initImageState(page: Page, prependParagraph = false) {
|
||||
await page.evaluate(async prepend => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
const noteId = doc.addBlock('affine:note', {}, rootId);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
} from '@blocksuite/block-std';
|
||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import type { StarterDebugMenu } from '@playground/apps/_common/components/starter-debug-menu.js';
|
||||
import type { BlockModel, Doc, Job, Workspace } from '@store/index.js';
|
||||
import type { BlockModel, Blocks, Job, Workspace } from '@store/index.js';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -38,7 +38,7 @@ declare global {
|
||||
};
|
||||
collection: Workspace;
|
||||
blockSchema: Record<string, typeof BlockModel>;
|
||||
doc: Doc;
|
||||
doc: Blocks;
|
||||
debugMenu: StarterDebugMenu;
|
||||
editor: AffineEditorContainer;
|
||||
host: EditorHost;
|
||||
|
||||
@@ -44,7 +44,7 @@ test(
|
||||
await page.evaluate(() => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
const note = doc.addBlock('affine:note', {}, rootId);
|
||||
doc.addBlock('affine:code', {}, note);
|
||||
@@ -71,7 +71,7 @@ test(
|
||||
async ({ bookMarkUrl, embedUrl }) => {
|
||||
const { doc } = window;
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
title: new window.$blocksuite.store.Text(),
|
||||
});
|
||||
const note = doc.addBlock('affine:note', {}, rootId);
|
||||
doc.addBlock('affine:code', {}, note);
|
||||
|
||||
Reference in New Issue
Block a user