Skip to content

Commit

Permalink
refactor: rename page to doc (toeverything#6290)
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushAgrawal-A2 authored Feb 27, 2024
1 parent f8f6883 commit fb79e2f
Show file tree
Hide file tree
Showing 539 changed files with 4,859 additions and 4,873 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ BlockSuite is a toolkit for building editors and collaborative applications. It
You can consider BlockSuite as a [UI component library](https://blocksuite.io/components/overview.html) for building various editors, based on a minimized vanilla framework as their runtime. With BlockSuite, you can:

- Reuse multiple first-party BlockSuite editors:
- [**`DocEditor`**](https://blocksuite.io/components/editors/doc-editor.html): A comprehensive block-based document editor, offering extensive customization and flexibility.
- [**`EdgelessEditor`**](https://blocksuite.io/components/editors/edgeless-editor.html): A graphics editor with opt-in canvas rendering support, but also shares the same rich-text capabilities with the `DocEditor`.
- [**`PageEditor`**](https://blocksuite.io/components/editors/page-editor.html): A comprehensive block-based document editor, offering extensive customization and flexibility.
- [**`EdgelessEditor`**](https://blocksuite.io/components/editors/edgeless-editor.html): A graphics editor with opt-in canvas rendering support, but also shares the same rich-text capabilities with the `PageEditor`.
- Customize, extend and enhance these editors with a rich set of [BlockSuite components](https://blocksuite.io/components/overview.html). All BlockSuite components (including editors) are native web components, making them framework-agnostic and easy to interop with popular frameworks.
- Or, build new editors from scratch based on the underlying vallina framework.
- Or, build new editors from scratch based on the underlying vanilla framework.

> 🚧 BlockSuite is currently in its early stage, with components and extension capabilities still under refinement. Hope you can stay tuned, try it out, or share your feedback!
Expand Down Expand Up @@ -108,7 +108,7 @@ To that end, the BlockSuite project is structured around key packages that are c
</tr>
<tr>
<td><code>@blocksuite/presets</code></td>
<td>Plug-and-play editable components including <i>editors</i> (<code>DocEditor</code> / <code>EdgelessEditor</code>) and auxiliary UI components named <i>fragments</i> (<code>CopilotPanel</code>, <code>DocTitle</code>...).</td>
<td>Plug-and-play editable components including <i>editors</i> (<code>PageEditor</code> / <code>EdgelessEditor</code>) and auxiliary UI components named <i>fragments</i> (<code>CopilotPanel</code>, <code>DocTitle</code>...).</td>
</tr>
</table>

Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/__tests__/adapters/html.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const template = (html: string) =>
</style>
</head>
<body>
<div style="width: 70vw; margin: 60px auto;"><!--BlockSuitePageTitlePlaceholder-->
<div style="width: 70vw; margin: 60px auto;"><!--BlockSuiteDocTitlePlaceholder-->
<!--HtmlTemplate-->
</div>
</body>
Expand Down
52 changes: 26 additions & 26 deletions packages/blocks/src/__tests__/database/database.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import '../../database-block/kanban/define.js';
import '../../database-block/table/define.js';

import type { BlockModel, Page } from '@blocksuite/store';
import type { BlockModel, Doc } from '@blocksuite/store';
import { Generator, Schema, Workspace } from '@blocksuite/store';
import { beforeEach, describe, expect, test } from 'vitest';

Expand All @@ -13,13 +13,13 @@ import type { DatabaseBlockModel } from '../../database-block/database-model.js'
import { DatabaseBlockSchema } from '../../database-block/database-model.js';
import type { Cell, Column } from '../../database-block/types.js';
import { NoteBlockSchema } from '../../note-block/note-model.js';
import { PageBlockSchema } from '../../page-block/page-model.js';
import { ParagraphBlockSchema } from '../../paragraph-block/paragraph-model.js';
import { RootBlockSchema } from '../../root-block/root-model.js';

const AffineSchemas = [
ParagraphBlockSchema,
PageBlockSchema,
RootBlockSchema,
NoteBlockSchema,
ParagraphBlockSchema,
DatabaseBlockSchema,
];

Expand All @@ -30,19 +30,19 @@ function createTestOptions() {
return { id: 'test-workspace', idGenerator, schema };
}

function createTestPage(pageId = 'page0') {
function createTestDoc(docId = 'doc0') {
const options = createTestOptions();
const workspace = new Workspace(options);
const page = workspace.createPage({ id: pageId });
page.load();
return page;
const doc = workspace.createDoc({ id: docId });
doc.load();
return doc;
}

describe('DatabaseManager', () => {
let page: Page;
let doc: Doc;
let db: DatabaseBlockModel;

let pageBlockId: BlockModel['id'];
let rootId: BlockModel['id'];
let noteBlockId: BlockModel['id'];
let databaseBlockId: BlockModel['id'];
let p1: BlockModel['id'];
Expand All @@ -58,14 +58,14 @@ describe('DatabaseManager', () => {
];

beforeEach(() => {
page = createTestPage();
doc = createTestDoc();

pageBlockId = page.addBlock('affine:page', {
title: new page.Text('database test'),
rootId = doc.addBlock('affine:page', {
title: new doc.Text('database test'),
});
noteBlockId = page.addBlock('affine:note', {}, pageBlockId);
noteBlockId = doc.addBlock('affine:note', {}, rootId);

databaseBlockId = page.addBlock(
databaseBlockId = doc.addBlock(
'affine:database' as BlockSuite.ModelKeys,
{
columns: [],
Expand All @@ -74,7 +74,7 @@ describe('DatabaseManager', () => {
noteBlockId
);

const databaseModel = page.getBlockById(
const databaseModel = doc.getBlockById(
databaseBlockId
) as DatabaseBlockModel;
db = databaseModel;
Expand All @@ -86,21 +86,21 @@ describe('DatabaseManager', () => {
);
col3 = db.addColumn('end', richTextPureColumnConfig.create('Rich Text'));

page.updateBlock(databaseModel, {
doc.updateBlock(databaseModel, {
columns: [col1, col2, col3],
});

p1 = page.addBlock(
p1 = doc.addBlock(
'affine:paragraph',
{
text: new page.Text('text1'),
text: new doc.Text('text1'),
},
databaseBlockId
);
p2 = page.addBlock(
p2 = doc.addBlock(
'affine:paragraph',
{
text: new page.Text('text2'),
text: new doc.Text('text2'),
},
databaseBlockId
);
Expand Down Expand Up @@ -148,10 +148,10 @@ describe('DatabaseManager', () => {
});

test('getCell', () => {
const modelId = page.addBlock(
const modelId = doc.addBlock(
'affine:paragraph',
{
text: new page.Text('paragraph'),
text: new doc.Text('paragraph'),
},
noteBlockId
);
Expand All @@ -167,7 +167,7 @@ describe('DatabaseManager', () => {
db.addColumn('end', column);
db.updateCell(modelId, cell);

const model = page.getBlockById(modelId);
const model = doc.getBlockById(modelId);

expect(model).not.toBeNull();

Expand All @@ -177,10 +177,10 @@ describe('DatabaseManager', () => {
});

test('updateCell', () => {
const newRowId = page.addBlock(
const newRowId = doc.addBlock(
'affine:paragraph',
{
text: new page.Text('text3'),
text: new doc.Text('text3'),
},
databaseBlockId
);
Expand Down
12 changes: 6 additions & 6 deletions packages/blocks/src/__tests__/migration/migration.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { DatabaseBlockSchema } from '../../database-block/database-model.js';
import { FrameBlockSchema } from '../../frame-block/frame-model.js';
import { ListBlockSchema } from '../../list-block/list-model.js';
import { NoteBlockSchema } from '../../note-block/note-model.js';
import { PageBlockSchema } from '../../page-block/page-model.js';
import { ParagraphBlockSchema } from '../../paragraph-block/paragraph-model.js';
import { RootBlockSchema } from '../../root-block/root-model.js';
import { SurfaceBlockSchema } from '../../surface-block/surface-model.js';

async function loadBinary(name: string) {
Expand All @@ -27,7 +27,7 @@ async function loadBinary(name: string) {

const schema = new Schema();
schema.register([
PageBlockSchema,
RootBlockSchema,
SurfaceBlockSchema,
NoteBlockSchema,
ParagraphBlockSchema,
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('block migration', () => {
assert.isUndefined(shape.get('bold'));
assert.isUndefined(shape.get('italic'));

schema.upgradePage(
schema.upgradeDoc(
0,
{
'affine:page': 1,
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('block migration', () => {

assert.exists(connector);

schema.upgradePage(
schema.upgradeDoc(
0,
{
'affine:list': 1,
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('block migration', () => {
.get('value') as Y.Map<unknown>;
assert.exists(surfaceElements.get('2'));

schema.upgradePage(
schema.upgradeDoc(
0,
{
'affine:surface': 5,
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('block migration', () => {
).toBeUndefined();
expect(databaseBlock['prop:views'].length).toBe(2);

schema.upgradePage(
schema.upgradeDoc(
0,
{
'affine:page': 1,
Expand Down
20 changes: 10 additions & 10 deletions packages/blocks/src/_common/adapters/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import type { AssetsManager } from '@blocksuite/store';
import {
BaseAdapter,
type BlockSnapshot,
type DocSnapshot,
type FromBlockSnapshotPayload,
type FromBlockSnapshotResult,
type FromPageSnapshotPayload,
type FromPageSnapshotResult,
type FromDocSnapshotPayload,
type FromDocSnapshotResult,
type FromSliceSnapshotPayload,
type FromSliceSnapshotResult,
nanoid,
type PageSnapshot,
sha,
type SliceSnapshot,
type ToBlockSnapshotPayload,
type ToPageSnapshotPayload,
type ToDocSnapshotPayload,
} from '@blocksuite/store';

export type Attachment = File[];
Expand All @@ -29,9 +29,9 @@ type AttachmentToSliceSnapshotPayload = {
};

export class AttachmentAdapter extends BaseAdapter<Attachment> {
override fromPageSnapshot(
_payload: FromPageSnapshotPayload
): Promise<FromPageSnapshotResult<Attachment>> {
override fromDocSnapshot(
_payload: FromDocSnapshotPayload
): Promise<FromDocSnapshotResult<Attachment>> {
throw new Error('Method not implemented.');
}
override fromBlockSnapshot(
Expand Down Expand Up @@ -59,9 +59,9 @@ export class AttachmentAdapter extends BaseAdapter<Attachment> {
}
return Promise.resolve({ file: attachments, assetsIds: [] });
}
override toPageSnapshot(
_payload: ToPageSnapshotPayload<Attachment>
): Promise<PageSnapshot> {
override toDocSnapshot(
_payload: ToDocSnapshotPayload<Attachment>
): Promise<DocSnapshot> {
throw new Error('Method not implemented.');
}
override toBlockSnapshot(
Expand Down
24 changes: 12 additions & 12 deletions packages/blocks/src/_common/adapters/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import type { DeltaInsert } from '@blocksuite/inline';
import type {
FromBlockSnapshotPayload,
FromBlockSnapshotResult,
FromPageSnapshotPayload,
FromPageSnapshotResult,
FromDocSnapshotPayload,
FromDocSnapshotResult,
FromSliceSnapshotPayload,
FromSliceSnapshotResult,
ToBlockSnapshotPayload,
ToPageSnapshotPayload,
ToDocSnapshotPayload,
} from '@blocksuite/store';
import {
type AssetsManager,
Expand All @@ -20,7 +20,7 @@ import {
import { ASTWalker, BaseAdapter } from '@blocksuite/store';
import {
type BlockSnapshot,
type PageSnapshot,
type DocSnapshot,
type SliceSnapshot,
} from '@blocksuite/store';
import type { ElementContent, Root, Text } from 'hast';
Expand Down Expand Up @@ -60,16 +60,16 @@ type HtmlToSliceSnapshotPayload = {
};

export class HtmlAdapter extends BaseAdapter<Html> {
override async fromPageSnapshot(
payload: FromPageSnapshotPayload
): Promise<FromPageSnapshotResult<string>> {
override async fromDocSnapshot(
payload: FromDocSnapshotPayload
): Promise<FromDocSnapshotResult<string>> {
const { file, assetsIds } = await this.fromBlockSnapshot({
snapshot: payload.snapshot.blocks,
assets: payload.assets,
});
return {
file: file.replace(
'<!--BlockSuitePageTitlePlaceholder-->',
'<!--BlockSuiteDocTitlePlaceholder-->',
`<h1>${payload.snapshot.meta.title}</h1>`
),
assetsIds,
Expand Down Expand Up @@ -120,9 +120,9 @@ export class HtmlAdapter extends BaseAdapter<Html> {
assetsIds: sliceAssetsIds,
};
}
override async toPageSnapshot(
payload: ToPageSnapshotPayload<string>
): Promise<PageSnapshot> {
override async toDocSnapshot(
payload: ToDocSnapshotPayload<string>
): Promise<DocSnapshot> {
const htmlAst = this._htmlToAst(payload.file);
const titleAst = hastQuerySelector(htmlAst, 'title');
const blockSnapshotRoot = {
Expand Down Expand Up @@ -346,7 +346,7 @@ export class HtmlAdapter extends BaseAdapter<Html> {
)
.openNode({
type: 'comment',
value: 'BlockSuitePageTitlePlaceholder',
value: 'BlockSuiteDocTitlePlaceholder',
})
.closeNode();
break;
Expand Down
20 changes: 10 additions & 10 deletions packages/blocks/src/_common/adapters/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import type { AssetsManager } from '@blocksuite/store';
import {
BaseAdapter,
type BlockSnapshot,
type DocSnapshot,
type FromBlockSnapshotPayload,
type FromBlockSnapshotResult,
type FromPageSnapshotPayload,
type FromPageSnapshotResult,
type FromDocSnapshotPayload,
type FromDocSnapshotResult,
type FromSliceSnapshotPayload,
type FromSliceSnapshotResult,
nanoid,
type PageSnapshot,
sha,
type SliceSnapshot,
type ToBlockSnapshotPayload,
type ToPageSnapshotPayload,
type ToDocSnapshotPayload,
} from '@blocksuite/store';

export type Image = File[];
Expand All @@ -29,9 +29,9 @@ type ImageToSliceSnapshotPayload = {
};

export class ImageAdapter extends BaseAdapter<Image> {
override fromPageSnapshot(
_payload: FromPageSnapshotPayload
): Promise<FromPageSnapshotResult<Image>> {
override fromDocSnapshot(
_payload: FromDocSnapshotPayload
): Promise<FromDocSnapshotResult<Image>> {
throw new Error('Method not implemented.');
}
override fromBlockSnapshot(
Expand Down Expand Up @@ -59,9 +59,9 @@ export class ImageAdapter extends BaseAdapter<Image> {
}
return Promise.resolve({ file: images, assetsIds: [] });
}
override toPageSnapshot(
_payload: ToPageSnapshotPayload<Image>
): Promise<PageSnapshot> {
override toDocSnapshot(
_payload: ToDocSnapshotPayload<Image>
): Promise<DocSnapshot> {
throw new Error('Method not implemented.');
}
override toBlockSnapshot(
Expand Down
Loading

1 comment on commit fb79e2f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size Report

Bundles

Entry Size Gzip Brotli
examples/basic 13.8 MB (+1.52 kB) 2.86 MB (+1.09 kB) 1.78 MB (+739 B)

Packages

Name Size Gzip Brotli
blocks 2.18 MB (-816 B) 507 kB (+398 B) 370 kB (-80 B)
editor 84 B 89 B 63 B
store 83 B 88 B 63 B
inline 84 B 88 B 63 B

Please sign in to comment.