feat: bump blocksuite (#5953)

This commit is contained in:
regischen 2024-02-29 14:33:50 +08:00 committed by GitHub
parent fa534869e1
commit d1e6b23e1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
121 changed files with 665 additions and 674 deletions

View File

@ -3,8 +3,8 @@
"private": true,
"type": "module",
"devDependencies": {
"@blocksuite/global": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/store": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/global": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/store": "0.12.0-canary-202402271448-6d3a709",
"react": "18.2.0",
"react-dom": "18.2.0",
"vitest": "1.3.1"

View File

@ -17,9 +17,9 @@
"@affine/debug": "workspace:*",
"@affine/env": "workspace:*",
"@affine/templates": "workspace:*",
"@blocksuite/blocks": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/global": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/store": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/blocks": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/global": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/store": "0.12.0-canary-202402271448-6d3a709",
"foxact": "^0.2.31",
"jotai": "^2.6.5",
"jotai-effect": "^0.5.0",
@ -33,8 +33,8 @@
"devDependencies": {
"@affine-test/fixtures": "workspace:*",
"@affine/templates": "workspace:*",
"@blocksuite/lit": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/presets": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/lit": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/presets": "0.12.0-canary-202402271448-6d3a709",
"@testing-library/react": "^14.2.1",
"async-call-rpc": "^6.4.0",
"react": "^18.2.0",

View File

@ -30,7 +30,7 @@ export async function migratePages(
spaces.forEach((space: YDoc) => {
try {
// Catch page upgrade error to avoid blocking the whole workspace migration.
schema.upgradePage(0, oldVersions, space);
schema.upgradeDoc(0, oldVersions, space);
} catch (e) {
console.error(e);
}

View File

@ -28,7 +28,7 @@ export function checkWorkspaceCompatibility(
}
// exit if no pages
if (!workspace.meta.pages?.length) {
if (!workspace.meta.docs?.length) {
return null;
}
@ -55,7 +55,7 @@ export function checkWorkspaceCompatibility(
// TODO: Catch compatibility error from blocksuite to show upgrade page.
// Temporarily follow the check logic of blocksuite.
if ((workspace.meta.pages?.length ?? 0) <= 1) {
if ((workspace.meta.docs?.length ?? 0) <= 1) {
try {
workspace.meta.validateVersion(workspace);
} catch (e) {

View File

@ -1,8 +1,8 @@
import type { WorkspaceFlavour } from '@affine/env/workspace';
import type {
Doc,
DocSnapshot,
JobMiddleware,
Page,
PageSnapshot,
WorkspaceInfoSnapshot,
} from '@blocksuite/store';
import { Job } from '@blocksuite/store';
@ -13,7 +13,7 @@ import { PageRecordList } from '../page';
import type { WorkspaceManager } from '../workspace';
import { replaceIdMiddleware } from './middleware';
export function initEmptyPage(page: Page, title?: string) {
export function initEmptyPage(page: Doc, title?: string) {
page.load(() => {
const pageBlockId = page.addBlock('affine:page', {
title: new page.Text(title ?? ''),
@ -44,7 +44,7 @@ export async function buildShowcaseWorkspace(
const migrationMiddleware: JobMiddleware = ({ slots, workspace }) => {
slots.afterImport.on(payload => {
if (payload.type === 'page') {
workspace.schema.upgradePage(
workspace.schema.upgradeDoc(
info?.pageVersion ?? 0,
{},
payload.page.spaceDoc
@ -65,15 +65,15 @@ export async function buildShowcaseWorkspace(
// @ts-expect-error - rethinking API
job._assetsManager.writeToBlob = async () => {};
const pageSnapshots: PageSnapshot[] = Object.entries(onboarding)
const docSnapshots: DocSnapshot[] = Object.entries(onboarding)
.filter(([key]) => {
return key.endsWith('snapshot.json');
})
.map(([_, value]) => value as unknown as PageSnapshot);
.map(([_, value]) => value as unknown as DocSnapshot);
await Promise.all(
pageSnapshots.map(snapshot => {
return job.snapshotToPage(snapshot);
docSnapshots.map(snapshot => {
return job.snapshotToDoc(snapshot);
})
);

View File

@ -1,10 +1,10 @@
import type { Page as BlockSuitePage } from '@blocksuite/store';
import type { Doc as BlockSuiteDoc } from '@blocksuite/store';
import { createIdentifier, type ServiceCollection } from '../di';
import type { PageRecord } from './record';
import { PageScope } from './service-scope';
export const BlockSuitePageContext = createIdentifier<BlockSuitePage>(
export const BlockSuitePageContext = createIdentifier<BlockSuiteDoc>(
'BlockSuitePageContext'
);
@ -13,7 +13,7 @@ export const PageRecordContext =
export function configurePageContext(
services: ServiceCollection,
blockSuitePage: BlockSuitePage,
blockSuitePage: BlockSuiteDoc,
pageRecord: PageRecord
) {
services

View File

@ -9,7 +9,7 @@ import { CleanupService } from '../lifecycle';
import { Workspace, WorkspaceLocalState, WorkspaceScope } from '../workspace';
import { BlockSuitePageContext, PageRecordContext } from './context';
import { PageManager } from './manager';
import { Page } from './page';
import { Doc } from './page';
import { PageRecordList } from './record-list';
import { PageScope } from './service-scope';
@ -22,5 +22,5 @@ export function configurePageServices(services: ServiceCollection) {
services
.scope(PageScope)
.add(CleanupService)
.add(Page, [PageRecordContext, BlockSuitePageContext, ServiceProvider]);
.add(Doc, [PageRecordContext, BlockSuitePageContext, ServiceProvider]);
}

View File

@ -3,11 +3,11 @@ import { ObjectPool } from '../utils/object-pool';
import type { Workspace } from '../workspace';
import type { PageRecordList } from '.';
import { configurePageContext } from './context';
import { Page } from './page';
import { Doc } from './page';
import { PageScope } from './service-scope';
export class PageManager {
pool = new ObjectPool<string, Page>({});
pool = new ObjectPool<string, Doc>({});
constructor(
private readonly workspace: Workspace,
@ -20,7 +20,7 @@ export class PageManager {
if (!pageRecord) {
throw new Error('Page record not found');
}
const blockSuitePage = this.workspace.blockSuiteWorkspace.getPage(pageId);
const blockSuitePage = this.workspace.blockSuiteWorkspace.getDoc(pageId);
if (!blockSuitePage) {
throw new Error('Page not found');
}
@ -41,7 +41,7 @@ export class PageManager {
this.serviceProvider
);
const page = provider.get(Page);
const page = provider.get(Doc);
const { obj, release } = this.pool.put(pageId, page);

View File

@ -1,12 +1,12 @@
import type { Page as BlockSuitePage } from '@blocksuite/store';
import type { Doc as BlockSuiteDoc } from '@blocksuite/store';
import type { ServiceProvider } from '@toeverything/infra/di';
import type { PageMode, PageRecord } from './record';
export class Page {
export class Doc {
constructor(
public readonly record: PageRecord,
public readonly blockSuitePage: BlockSuitePage,
public readonly blockSuiteDoc: BlockSuiteDoc,
public readonly services: ServiceProvider
) {}

View File

@ -18,7 +18,7 @@ export class PageRecordList {
new Observable(subscriber => {
const emit = () => {
subscriber.next(
this.workspace.blockSuiteWorkspace.meta.pageMetas.map(
this.workspace.blockSuiteWorkspace.meta.docMetas.map(
v => new PageRecord(v.id, this.workspace, this.localState)
)
);
@ -27,9 +27,7 @@ export class PageRecordList {
emit();
const dispose =
this.workspace.blockSuiteWorkspace.meta.pageMetasUpdated.on(
emit
).dispose;
this.workspace.blockSuiteWorkspace.meta.docMetaUpdated.on(emit).dispose;
return () => {
dispose();
};

View File

@ -1,4 +1,4 @@
import type { PageMeta } from '@blocksuite/store';
import type { DocMeta } from '@blocksuite/store';
import { Observable } from 'rxjs';
import { LiveData } from '../livedata';
@ -13,10 +13,10 @@ export class PageRecord {
private readonly localState: WorkspaceLocalState
) {}
meta = LiveData.from<PageMeta>(
meta = LiveData.from<DocMeta>(
new Observable(subscriber => {
const emit = () => {
const meta = this.workspace.blockSuiteWorkspace.meta.pageMetas.find(
const meta = this.workspace.blockSuiteWorkspace.meta.docMetas.find(
page => page.id === this.id
);
if (meta === undefined) {
@ -28,9 +28,7 @@ export class PageRecord {
emit();
const dispose =
this.workspace.blockSuiteWorkspace.meta.pageMetasUpdated.on(
emit
).dispose;
this.workspace.blockSuiteWorkspace.meta.docMetaUpdated.on(emit).dispose;
return () => {
dispose();
};
@ -43,8 +41,8 @@ export class PageRecord {
}
);
setMeta(meta: Partial<PageMeta>): void {
this.workspace.blockSuiteWorkspace.setPageMeta(this.id, meta);
setMeta(meta: Partial<DocMeta>): void {
this.workspace.blockSuiteWorkspace.setDocMeta(this.id, meta);
}
mode: LiveData<PageMode> = LiveData.from(

View File

@ -22,7 +22,7 @@ describe('Workspace System', () => {
expect(workspaceListService.workspaceList.value.length).toBe(1);
const page = workspace.blockSuiteWorkspace.createPage({
const page = workspace.blockSuiteWorkspace.createDoc({
id: 'page0',
});
page.load();
@ -30,7 +30,7 @@ describe('Workspace System', () => {
title: new page.Text('test-page'),
});
expect(workspace.blockSuiteWorkspace.pages.size).toBe(1);
expect(workspace.blockSuiteWorkspace.docs.size).toBe(1);
expect(
(page!.getBlockByFlavour('affine:page')[0] as any).title.toString()
).toBe('test-page');

View File

@ -42,7 +42,7 @@ describe('SyncEngine', () => {
);
syncEngine.start();
const page = workspace.createPage({
const page = workspace.createDoc({
id: 'page0',
});
page.load();

View File

@ -35,7 +35,7 @@ describe('SyncPeer', () => {
);
await syncPeer.waitForLoaded();
const page = workspace.createPage({
const page = workspace.createDoc({
id: 'page0',
});
page.load();
@ -85,7 +85,7 @@ describe('SyncPeer', () => {
await syncPeer.waitForSynced();
expect(syncPeer.status.step).toBe(SyncPeerStep.Synced);
const page = workspace.createPage({
const page = workspace.createDoc({
id: 'page0',
});
expect(syncPeer.status.step).toBe(SyncPeerStep.LoadingSubDoc);

View File

@ -32,14 +32,14 @@
}
},
"dependencies": {
"@blocksuite/global": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/global": "0.12.0-canary-202402271448-6d3a709",
"idb": "^8.0.0",
"nanoid": "^5.0.6",
"y-provider": "workspace:*"
},
"devDependencies": {
"@blocksuite/blocks": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/store": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/blocks": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/store": "0.12.0-canary-202402271448-6d3a709",
"fake-indexeddb": "^5.0.2",
"vite": "^5.1.4",
"vite-plugin-dts": "3.7.3",

View File

@ -7,12 +7,12 @@ import { setTimeout } from 'node:timers/promises';
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
import { assertExists } from '@blocksuite/global/utils';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import { Schema, Workspace } from '@blocksuite/store';
import { openDB } from 'idb';
import { nanoid } from 'nanoid';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import { applyUpdate, Doc, encodeStateAsUpdate } from 'yjs';
import { applyUpdate, Doc as YDoc, encodeStateAsUpdate } from 'yjs';
import type { WorkspacePersist } from '../index';
import {
@ -27,7 +27,7 @@ import {
setMergeCount,
} from '../index';
function initEmptyPage(page: Page) {
function initEmptyPage(page: Doc) {
const pageBlockId = page.addBlock('affine:page', {
title: new page.Text(''),
});
@ -99,9 +99,9 @@ describe('indexeddb provider', () => {
},
],
});
const page = workspace.createPage({ id: 'page0' });
page.waitForLoaded();
const pageBlockId = page.addBlock('affine:page', { title: '' });
const page = workspace.createDoc({ id: 'page0' });
page.load();
const pageBlockId = page.addBlock('affine:page', {});
const frameId = page.addBlock('affine:note', {}, pageBlockId);
page.addBlock('affine:paragraph', {}, frameId);
}
@ -129,7 +129,7 @@ describe('indexeddb provider', () => {
| WorkspacePersist
| undefined;
assertExists(data);
testWorkspace.getPage('page0')?.waitForLoaded();
testWorkspace.getDoc('page0')?.load();
data.updates.forEach(({ update }) => {
Workspace.Y.applyUpdate(subPage, update);
});
@ -147,9 +147,9 @@ describe('indexeddb provider', () => {
provider.disconnect();
expect(provider.connected).toBe(false);
{
const page = workspace.createPage({ id: 'page0' });
page.waitForLoaded();
const pageBlockId = page.addBlock('affine:page', { title: '' });
const page = workspace.createDoc({ id: 'page0' });
page.load();
const pageBlockId = page.addBlock('affine:page');
const frameId = page.addBlock('affine:note', {}, pageBlockId);
page.addBlock('affine:paragraph', {}, frameId);
}
@ -202,9 +202,9 @@ describe('indexeddb provider', () => {
const provider = createIndexedDBProvider(workspace.doc, rootDBName);
provider.connect();
{
const page = workspace.createPage({ id: 'page0' });
page.waitForLoaded();
const pageBlockId = page.addBlock('affine:page', { title: '' });
const page = workspace.createDoc({ id: 'page0' });
page.load();
const pageBlockId = page.addBlock('affine:page');
const frameId = page.addBlock('affine:note', {}, pageBlockId);
for (let i = 0; i < 99; i++) {
page.addBlock('affine:paragraph', {}, frameId);
@ -250,7 +250,7 @@ describe('indexeddb provider', () => {
expect(event).toBe('beforeunload');
return oldRemoveEventListener(event, fn, options);
});
const doc = new Doc({
const doc = new YDoc({
guid: '1',
});
const provider = createIndexedDBProvider(doc);
@ -270,7 +270,7 @@ describe('indexeddb provider', () => {
describe('milestone', () => {
test('milestone', async () => {
const doc = new Doc();
const doc = new YDoc();
const map = doc.getMap('map');
const array = doc.getArray('array');
map.set('1', 1);
@ -281,7 +281,7 @@ describe('milestone', () => {
expect(milestones).toBeDefined();
expect(Object.keys(milestones).length).toBe(1);
expect(milestones.test1).toBeInstanceOf(Uint8Array);
const snapshot = new Doc();
const snapshot = new YDoc();
applyUpdate(snapshot, milestones.test1);
{
const map = snapshot.getMap('map');
@ -316,7 +316,7 @@ describe('milestone', () => {
expect(fn).toBeCalled();
const doc2 = new Doc();
const doc2 = new YDoc();
applyUpdate(doc2, encodeStateAsUpdate(doc));
revertUpdate(doc2, milestones.test1, key =>
@ -333,11 +333,11 @@ describe('subDoc', () => {
test('basic', async () => {
let json1: any, json2: any;
{
const doc = new Doc({
const doc = new YDoc({
guid: 'test',
});
const map = doc.getMap();
const subDoc = new Doc();
const subDoc = new YDoc();
subDoc.load();
map.set('1', subDoc);
map.set('2', 'test');
@ -348,14 +348,14 @@ describe('subDoc', () => {
json1 = doc.toJSON();
}
{
const doc = new Doc({
const doc = new YDoc({
guid: 'test',
});
const provider = createIndexedDBProvider(doc);
provider.connect();
await setTimeout(200);
const map = doc.getMap();
const subDoc = map.get('1') as Doc;
const subDoc = map.get('1') as YDoc;
subDoc.load();
provider.disconnect();
json2 = doc.toJSON();
@ -366,17 +366,17 @@ describe('subDoc', () => {
});
test('blocksuite', async () => {
const page0 = workspace.createPage({
const page0 = workspace.createDoc({
id: 'page0',
});
page0.waitForLoaded();
page0.load();
const { paragraphBlockId: paragraphBlockIdPage1 } = initEmptyPage(page0);
const provider = createIndexedDBProvider(workspace.doc, rootDBName);
provider.connect();
const page1 = workspace.createPage({
const page1 = workspace.createDoc({
id: 'page1',
});
page1.waitForLoaded();
page1.load();
const { paragraphBlockId: paragraphBlockIdPage2 } = initEmptyPage(page1);
await setTimeout(200);
provider.disconnect();
@ -389,15 +389,15 @@ describe('subDoc', () => {
const provider = createIndexedDBProvider(newWorkspace.doc, rootDBName);
provider.connect();
await setTimeout(200);
const page0 = newWorkspace.getPage('page0') as Page;
page0.waitForLoaded();
const page0 = newWorkspace.getDoc('page0') as Doc;
page0.load();
await setTimeout(200);
{
const block = page0.getBlockById(paragraphBlockIdPage1);
assertExists(block);
}
const page1 = newWorkspace.getPage('page1') as Page;
page1.waitForLoaded();
const page1 = newWorkspace.getDoc('page1') as Doc;
page1.load();
await setTimeout(200);
{
const block = page1.getBlockById(paragraphBlockIdPage2);
@ -409,8 +409,8 @@ describe('subDoc', () => {
describe('utils', () => {
test('download binary', async () => {
const page = workspace.createPage({ id: 'page0' });
page.waitForLoaded();
const page = workspace.createDoc({ id: 'page0' });
page.load();
initEmptyPage(page);
const provider = createIndexedDBProvider(workspace.doc, rootDBName);
provider.connect();
@ -437,7 +437,7 @@ describe('utils', () => {
});
test('overwrite binary', async () => {
const doc = new Doc();
const doc = new YDoc();
const map = doc.getMap();
map.set('1', 1);
await overwriteBinary('test', new Uint8Array(encodeStateAsUpdate(doc)));

View File

@ -24,7 +24,7 @@
"build": "vite build"
},
"devDependencies": {
"@blocksuite/store": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/store": "0.12.0-canary-202402271448-6d3a709",
"vite": "^5.1.4",
"vite-plugin-dts": "3.7.3",
"vitest": "1.3.1",

View File

@ -72,12 +72,12 @@
"uuid": "^9.0.1"
},
"devDependencies": {
"@blocksuite/blocks": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/global": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/blocks": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/global": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/icons": "2.1.44",
"@blocksuite/lit": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/presets": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/store": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/lit": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/presets": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/store": "0.12.0-canary-202402271448-6d3a709",
"@storybook/addon-actions": "^7.6.17",
"@storybook/addon-essentials": "^7.6.17",
"@storybook/addon-interactions": "^7.6.17",

View File

@ -25,14 +25,14 @@
"@affine/i18n": "workspace:*",
"@affine/templates": "workspace:*",
"@affine/workspace-impl": "workspace:*",
"@blocksuite/block-std": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/blocks": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/global": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/block-std": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/blocks": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/global": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/icons": "2.1.44",
"@blocksuite/inline": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/lit": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/presets": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/store": "0.12.0-canary-202402220729-0868ac6",
"@blocksuite/inline": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/lit": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/presets": "0.12.0-canary-202402271448-6d3a709",
"@blocksuite/store": "0.12.0-canary-202402271448-6d3a709",
"@dnd-kit/core": "^6.1.0",
"@dnd-kit/modifiers": "^7.0.0",
"@dnd-kit/sortable": "^8.0.0",

View File

@ -24,8 +24,8 @@ export async function createFirstAppData(workspaceManager: WorkspaceManager) {
WorkspaceFlavour.LOCAL,
async workspace => {
workspace.meta.setName(DEFAULT_WORKSPACE_NAME);
const page = workspace.createPage();
workspace.setPageMeta(page.id, {
const page = workspace.createDoc();
workspace.setDocMeta(page.id, {
jumpOnce: true,
});
initEmptyPage(page);

View File

@ -238,8 +238,8 @@ export const CreateWorkspaceModal = ({
workspaceFlavour,
async workspace => {
workspace.meta.setName(name);
const page = workspace.createPage();
workspace.setPageMeta(page.id, {
const page = workspace.createDoc();
workspace.setDocMeta(page.id, {
jumpOnce: true,
});
initEmptyPage(page);

View File

@ -1,4 +1,4 @@
import { usePageMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteWorkspacePage } from '@affine/core/hooks/use-block-suite-workspace-page';
import { timestampToLocalDate } from '@affine/core/utils';
import { DebugLogger } from '@affine/debug';
@ -27,7 +27,7 @@ const logger = new DebugLogger('page-history');
type DocHistory = ListHistoryQuery['workspace']['histories'][number];
export const usePageSnapshotList = (workspaceId: string, pageDocId: string) => {
export const useDocSnapshotList = (workspaceId: string, pageDocId: string) => {
const pageSize = 10;
const { data, loadingMore, loadMore } = useQueryInfinite({
query: listHistoryQuery,
@ -154,16 +154,16 @@ export const useSnapshotPage = (
}
const pageId = pageDocId + '-' + ts;
const historyShellWorkspace = getOrCreateShellWorkspace(workspace.id);
let page = historyShellWorkspace.getPage(pageId);
let page = historyShellWorkspace.getDoc(pageId);
if (!page && snapshot) {
page = historyShellWorkspace.createPage({
page = historyShellWorkspace.createDoc({
id: pageId,
});
page.awarenessStore.setReadonly(page, true);
const spaceDoc = page.spaceDoc;
page.load(() => {
applyUpdate(spaceDoc, new Uint8Array(snapshot));
historyShellWorkspace.schema.upgradePage(0, {}, spaceDoc);
historyShellWorkspace.schema.upgradeDoc(0, {}, spaceDoc);
}); // must load before applyUpdate
}
return page ?? undefined;
@ -197,7 +197,7 @@ export const useRestorePage = (workspace: Workspace, pageId: string) => {
const { trigger: recover, isMutating } = useMutation({
mutation: recoverDocMutation,
});
const { getPageMeta, setPageTitle } = usePageMetaHelper(workspace);
const { getDocMeta, setDocTitle } = useDocMetaHelper(workspace);
const onRestore = useMemo(() => {
return async (version: string, update: Uint8Array) => {
@ -211,10 +211,10 @@ export const useRestorePage = (workspace: Workspace, pageId: string) => {
});
// should also update the page title, since it may be changed in the history
const title = page.meta.title;
const title = page.meta?.title ?? '';
if (getPageMeta(pageId)?.title !== title) {
setPageTitle(pageId, title);
if (getDocMeta(pageId)?.title !== title) {
setDocTitle(pageId, title);
}
await recover({
@ -232,12 +232,12 @@ export const useRestorePage = (workspace: Workspace, pageId: string) => {
logger.info('Page restored', pageDocId, version);
};
}, [
getPageMeta,
getDocMeta,
mutateQueryResource,
page,
pageId,
recover,
setPageTitle,
setDocTitle,
workspace.id,
]);

View File

@ -10,11 +10,11 @@ import { useWorkspaceQuota } from '@affine/core/hooks/use-workspace-quota';
import { Trans } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { CloseIcon, ToggleCollapseIcon } from '@blocksuite/icons';
import type { Page as BlockSuitePage } from '@blocksuite/store';
import type { Doc as BlockSuiteDoc } from '@blocksuite/store';
import { type Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
import * as Collapsible from '@radix-ui/react-collapsible';
import type { DialogContentProps } from '@radix-ui/react-dialog';
import { Page, type PageMode, Workspace } from '@toeverything/infra';
import { Doc, type PageMode, Workspace } from '@toeverything/infra';
import { useService } from '@toeverything/infra/di';
import { atom, useAtom, useSetAtom } from 'jotai';
import {
@ -39,7 +39,7 @@ import {
import { AffineErrorBoundary } from '../affine-error-boundary';
import {
historyListGroupByDay,
usePageSnapshotList,
useDocSnapshotList,
useRestorePage,
useSnapshotPage,
} from './data';
@ -90,7 +90,7 @@ const ModalContainer = ({
interface HistoryEditorPreviewProps {
ts?: string;
snapshotPage?: BlockSuitePage;
snapshotPage?: BlockSuiteDoc;
mode: PageMode;
onModeChange: (mode: PageMode) => void;
title: string;
@ -251,7 +251,7 @@ const PageHistoryList = ({
activeVersion?: string;
onVersionChange: (version: string) => void;
}) => {
const [historyList, loadMore, loadingMore] = usePageSnapshotList(
const [historyList, loadMore, loadingMore] = useDocSnapshotList(
workspaceId,
pageDocId
);
@ -425,7 +425,7 @@ const PageHistoryManager = ({
const [activeVersion, setActiveVersion] = useState<string>();
const pageDocId = useMemo(() => {
return workspace.getPage(pageId)?.spaceDoc.guid ?? pageId;
return workspace.getDoc(pageId)?.spaceDoc.guid ?? pageId;
}, [pageId, workspace]);
const snapshotPage = useSnapshotPage(workspace, pageDocId, activeVersion);
@ -447,7 +447,7 @@ const PageHistoryManager = ({
[activeVersion, onClose, onRestore, snapshotPage]
);
const page = useService(Page);
const page = useService(Doc);
const [mode, setMode] = useState<PageMode>(page.mode.value);
const title = useBlockSuiteWorkspacePageTitle(workspace, pageId);

View File

@ -124,7 +124,7 @@ export class PagePropertiesMetaManager {
// returns page schema properties -> related page
getPropertyStatistics() {
const mapping = new Map<string, Set<string>>();
for (const page of this.adapter.workspace.blockSuiteWorkspace.pages.values()) {
for (const page of this.adapter.workspace.blockSuiteWorkspace.docs.values()) {
const properties = this.adapter.getPageProperties(page.id);
for (const id of Object.keys(properties.custom)) {
if (!mapping.has(id)) mapping.set(id, new Set());
@ -169,7 +169,7 @@ export class PagePropertiesManager {
}
get page() {
return this.adapter.workspace.blockSuiteWorkspace.getPage(this.pageId);
return this.adapter.workspace.blockSuiteWorkspace.getDoc(this.pageId);
}
get intrinsicMeta() {

View File

@ -1,5 +1,5 @@
import { Checkbox, DatePicker, Menu } from '@affine/component';
import { useAllBlockSuitePageMeta } from '@affine/core/hooks/use-all-block-suite-page-meta';
import { useAllBlockSuiteDocMeta } from '@affine/core/hooks/use-all-block-suite-page-meta';
import { WorkspaceLegacyProperties } from '@affine/core/modules/workspace';
import type {
PageInfoCustomProperty,
@ -9,7 +9,7 @@ import type {
import { timestampToLocalDate } from '@affine/core/utils';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { assertExists } from '@blocksuite/global/utils';
import { Page, useLiveData, useService, Workspace } from '@toeverything/infra';
import { Doc, useLiveData, useService, Workspace } from '@toeverything/infra';
import { noop } from 'lodash-es';
import {
type ChangeEventHandler,
@ -176,9 +176,9 @@ export const NumberValue = ({ property }: PropertyRowValueProps) => {
export const TagsValue = () => {
const workspace = useService(Workspace);
const page = useService(Page);
const page = useService(Doc);
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
const pageMetas = useAllBlockSuitePageMeta(blockSuiteWorkspace);
const pageMetas = useAllBlockSuiteDocMeta(blockSuiteWorkspace);
const legacyProperties = useService(WorkspaceLegacyProperties);
const options = useLiveData(legacyProperties.tagOptions$);
@ -199,7 +199,7 @@ export const TagsValue = () => {
placeholder={t['com.affine.page-properties.property-value-placeholder']()}
value={tagIds}
options={options}
readonly={page.blockSuitePage.readonly}
readonly={page.blockSuiteDoc.readonly}
onChange={onChange}
onOptionsChange={legacyProperties.updateTagOptions}
/>

View File

@ -27,7 +27,7 @@ import {
ToggleExpandIcon,
ViewIcon,
} from '@blocksuite/icons';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import {
DndContext,
type DragEndEvent,
@ -1027,7 +1027,7 @@ const PagePropertiesTableInner = () => {
);
};
const usePagePropertiesManager = (page: Page) => {
const usePagePropertiesManager = (page: Doc) => {
// the workspace properties adapter adapter is reactive,
// which means it's reference will change when any of the properties change
// also it will trigger a re-render of the component
@ -1040,7 +1040,7 @@ const usePagePropertiesManager = (page: Page) => {
// this is the main component that renders the page properties table at the top of the page below
// the page title
export const PagePropertiesTable = ({ page }: { page: Page }) => {
export const PagePropertiesTable = ({ page }: { page: Doc }) => {
const manager = usePagePropertiesManager(page);
// if the given page is not in the current workspace, then we don't render anything

View File

@ -1,4 +1,4 @@
import { usePageMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useJournalHelper } from '@affine/core/hooks/use-journal';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { LinkedPageIcon, TodayIcon } from '@blocksuite/icons';
@ -10,7 +10,7 @@ import * as styles from './styles.css';
export interface PageReferenceRendererOptions {
pageId: string;
pageMetaHelper: ReturnType<typeof usePageMetaHelper>;
pageMetaHelper: ReturnType<typeof useDocMetaHelper>;
journalHelper: ReturnType<typeof useJournalHelper>;
t: ReturnType<typeof useAFFiNEI18N>;
}
@ -22,7 +22,7 @@ export function pageReferenceRenderer({
t,
}: PageReferenceRendererOptions) {
const { isPageJournal, getLocalizedJournalDateString } = journalHelper;
const referencedPage = pageMetaHelper.getPageMeta(pageId);
const referencedPage = pageMetaHelper.getDocMeta(pageId);
let title =
referencedPage?.title ?? t['com.affine.editor.reference-not-found']();
let icon = <LinkedPageIcon className={styles.pageReferenceIcon} />;
@ -35,7 +35,9 @@ export function pageReferenceRenderer({
return (
<>
{icon}
<span className="affine-reference-title">{title}</span>
<span className="affine-reference-title">
{title ? title : 'Untitled'}
</span>
</>
);
}
@ -49,7 +51,7 @@ export function AffinePageReference({
pageId: string;
wrapper?: React.ComponentType<PropsWithChildren>;
}) {
const pageMetaHelper = usePageMetaHelper(workspace);
const pageMetaHelper = useDocMetaHelper(workspace);
const journalHelper = useJournalHelper(workspace);
const t = useAFFiNEI18N();
const el = pageReferenceRenderer({

View File

@ -1,6 +1,6 @@
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { WorkspaceFlavour } from '@affine/env/workspace';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import { type Workspace, WorkspaceManager } from '@toeverything/infra';
import { useService } from '@toeverything/infra';
import { useState } from 'react';
@ -11,7 +11,7 @@ import { ShareMenu } from './share-menu';
type SharePageModalProps = {
workspace: Workspace;
page: Page;
page: Doc;
isJournal?: boolean;
};

View File

@ -4,7 +4,7 @@ import { ExportMenuItems } from '@affine/core/components/page-list';
import { WorkspaceFlavour } from '@affine/env/workspace';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { LinkIcon } from '@blocksuite/icons';
import { Page, useLiveData } from '@toeverything/infra';
import { Doc, useLiveData } from '@toeverything/infra';
import { useService } from '@toeverything/infra/di';
import { useExportPage } from '../../../../hooks/affine/use-export-page';
@ -17,7 +17,7 @@ export const ShareExport = ({
currentPage,
}: ShareMenuProps) => {
const t = useAFFiNEI18N();
const page = useService(Page);
const page = useService(Doc);
const workspaceId = workspace.id;
const pageId = currentPage.id;
const { sharingUrl, onClickCopyLink } = useSharingUrl({

View File

@ -4,7 +4,7 @@ import { Menu } from '@affine/component/ui/menu';
import { WorkspaceFlavour } from '@affine/env/workspace';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { WebIcon } from '@blocksuite/icons';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import type { WorkspaceMetadata } from '@toeverything/infra';
import clsx from 'clsx';
@ -15,7 +15,7 @@ import { SharePage } from './share-page';
export interface ShareMenuProps {
workspaceMetadata: WorkspaceMetadata;
currentPage: Page;
currentPage: Doc;
isJournal?: boolean;
onEnableAffineCloud: () => void;
}

View File

@ -15,7 +15,7 @@ import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { ArrowRightSmallIcon } from '@blocksuite/icons';
import { useService } from '@toeverything/infra';
import { useLiveData } from '@toeverything/infra';
import { Page, type PageMode } from '@toeverything/infra';
import { Doc, type PageMode } from '@toeverything/infra';
import { useMemo, useState } from 'react';
import { useCallback } from 'react';
@ -56,7 +56,7 @@ export const AffineSharePage = (props: ShareMenuProps) => {
currentPage,
} = props;
const pageId = currentPage.id;
const page = useService(Page);
const page = useService(Doc);
const [showDisable, setShowDisable] = useState(false);
const {
isSharedPage,

View File

@ -1,10 +1,10 @@
import type { BlockElement } from '@blocksuite/lit';
import type {
AffineEditorContainer,
DocEditor,
EdgelessEditor,
PageEditor,
} from '@blocksuite/presets';
import { type Page, Slot } from '@blocksuite/store';
import { type Doc, Slot } from '@blocksuite/store';
import type { PageMode } from '@toeverything/infra';
import clsx from 'clsx';
import type React from 'react';
@ -37,7 +37,7 @@ function forwardSlot<T extends Record<string, Slot<any>>>(
}
interface BlocksuiteEditorContainerProps {
page: Page;
page: Doc;
mode: PageMode;
className?: string;
style?: React.CSSProperties;
@ -48,7 +48,7 @@ interface BlocksuiteEditorContainerProps {
// mimic the interface of the webcomponent and expose slots & host
type BlocksuiteEditorContainerRef = Pick<
(typeof AffineEditorContainer)['prototype'],
'mode' | 'page' | 'slots' | 'host'
'mode' | 'doc' | 'slots' | 'host'
> &
HTMLDivElement;
@ -100,14 +100,14 @@ export const BlocksuiteEditorContainer = forwardRef<
ref
) {
const rootRef = useRef<HTMLDivElement>(null);
const docRef = useRef<DocEditor>(null);
const docRef = useRef<PageEditor>(null);
const edgelessRef = useRef<EdgelessEditor>(null);
const slots: BlocksuiteEditorContainerRef['slots'] = useMemo(() => {
return {
pageLinkClicked: new Slot(),
pageModeSwitched: new Slot(),
pageUpdated: new Slot(),
docLinkClicked: new Slot(),
editorModeSwitched: new Slot(),
docUpdated: new Slot(),
tagClicked: new Slot(),
};
}, []);
@ -115,11 +115,10 @@ export const BlocksuiteEditorContainer = forwardRef<
// forward the slot to the webcomponent
useLayoutEffect(() => {
requestAnimationFrame(() => {
const docPage = rootRef.current?.querySelector('affine-doc-page');
const docPage = rootRef.current?.querySelector('affine-page-root');
const edgelessPage = rootRef.current?.querySelector(
'affine-edgeless-page'
'affine-edgeless-root'
);
('affine-edgeless-page');
if (docPage) {
forwardSlot(docPage.slots, slots);
}
@ -131,12 +130,12 @@ export const BlocksuiteEditorContainer = forwardRef<
}, [page, slots]);
useLayoutEffect(() => {
slots.pageUpdated.emit({ newPageId: page.id });
}, [page, slots.pageUpdated]);
slots.docUpdated.emit({ newDocId: page.id });
}, [page, slots.docUpdated]);
useLayoutEffect(() => {
slots.pageModeSwitched.emit(mode);
}, [mode, slots.pageModeSwitched]);
slots.editorModeSwitched.emit(mode);
}, [mode, slots.editorModeSwitched]);
/**
* mimic an AffineEditorContainer using proxy

View File

@ -1,10 +1,10 @@
import { EditorLoading } from '@affine/component/page-detail-skeleton';
import { usePageMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useJournalHelper } from '@affine/core/hooks/use-journal';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { assertExists } from '@blocksuite/global/utils';
import type { AffineEditorContainer } from '@blocksuite/presets';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import { use } from 'foxact/use';
import type { CSSProperties, ReactElement } from 'react';
import {
@ -30,7 +30,7 @@ export type ErrorBoundaryProps = {
};
export type EditorProps = {
page: Page;
page: Doc;
mode: 'page' | 'edgeless';
defaultSelectedBlockId?: string;
// on Editor instance instantiated
@ -39,7 +39,7 @@ export type EditorProps = {
className?: string;
};
function usePageRoot(page: Page) {
function usePageRoot(page: Doc) {
if (!page.ready) {
page.load();
}
@ -81,7 +81,7 @@ const customRenderersFactory: (
* TODO: Define error to unexpected state together in the future.
*/
export class NoPageRootError extends Error {
constructor(public page: Page) {
constructor(public page: Doc) {
super('Page root not found when render editor!');
// Log info to let sentry collect more message
@ -138,7 +138,7 @@ const BlockSuiteEditorImpl = forwardRef<AffineEditorContainer, EditorProps>(
};
}, []);
const pageMetaHelper = usePageMetaHelper(page.workspace);
const pageMetaHelper = useDocMetaHelper(page.workspace);
const journalHelper = useJournalHelper(page.workspace);
const t = useAFFiNEI18N();

View File

@ -1,10 +1,10 @@
import { useJournalInfoHelper } from '@affine/core/hooks/use-journal';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import * as styles from './styles.css';
export const BlocksuiteEditorJournalDocTitle = ({ page }: { page: Page }) => {
export const BlocksuiteEditorJournalDocTitle = ({ page }: { page: Doc }) => {
const { localizedJournalDate, isTodayJournal, journalDate } =
useJournalInfoHelper(page.workspace, page.id);
const t = useAFFiNEI18N();

View File

@ -1,14 +1,13 @@
import { createReactComponentFromLit } from '@affine/component';
import { useJournalInfoHelper } from '@affine/core/hooks/use-journal';
import type { DocPageService } from '@blocksuite/blocks';
import {
BiDirectionalLinkPanel,
DocEditor,
DocMetaTags,
DocTitle,
EdgelessEditor,
PageMetaTags,
PageEditor,
} from '@blocksuite/presets';
import { type Page } from '@blocksuite/store';
import { type Doc } from '@blocksuite/store';
import clsx from 'clsx';
import React, {
forwardRef,
@ -32,7 +31,7 @@ import * as styles from './styles.css';
const adapted = {
DocEditor: createReactComponentFromLit({
react: React,
elementClass: DocEditor,
elementClass: PageEditor,
}),
DocTitle: createReactComponentFromLit({
react: React,
@ -40,7 +39,7 @@ const adapted = {
}),
PageMetaTags: createReactComponentFromLit({
react: React,
elementClass: PageMetaTags,
elementClass: DocMetaTags,
}),
EdgelessEditor: createReactComponentFromLit({
react: React,
@ -53,23 +52,23 @@ const adapted = {
};
interface BlocksuiteDocEditorProps {
page: Page;
page: Doc;
customRenderers?: InlineRenderers;
// todo: add option to replace docTitle with custom component (e.g., for journal page)
}
export const BlocksuiteDocEditor = forwardRef<
DocEditor,
PageEditor,
BlocksuiteDocEditorProps
>(function BlocksuiteDocEditor({ page, customRenderers }, ref) {
const titleRef = useRef<DocTitle>(null);
const docRef = useRef<DocEditor | null>(null);
const docRef = useRef<PageEditor | null>(null);
const [docPage, setDocPage] =
useState<HTMLElementTagNameMap['affine-doc-page']>();
useState<HTMLElementTagNameMap['affine-page-root']>();
const { isJournal } = useJournalInfoHelper(page.workspace, page.id);
const onDocRef = useCallback(
(el: DocEditor) => {
(el: PageEditor) => {
docRef.current = el;
if (ref) {
if (typeof ref === 'function') {
@ -89,7 +88,7 @@ export const BlocksuiteDocEditor = forwardRef<
useEffect(() => {
// auto focus the title
setTimeout(() => {
const docPage = docRef.current?.querySelector('affine-doc-page');
const docPage = docRef.current?.querySelector('affine-page-root');
if (docPage) {
setDocPage(docPage);
}
@ -105,11 +104,11 @@ export const BlocksuiteDocEditor = forwardRef<
return (
<div className={styles.docEditorRoot}>
<div
className={clsx('affine-doc-viewport', styles.affineDocViewport)}
className={clsx('affine-page-viewport', styles.affineDocViewport)}
data-doc-viewport={true}
>
{!isJournal ? (
<adapted.DocTitle page={page} ref={titleRef} />
<adapted.DocTitle doc={page} ref={titleRef} />
) : (
<BlocksuiteEditorJournalDocTitle page={page} />
)}
@ -117,7 +116,7 @@ export const BlocksuiteDocEditor = forwardRef<
<adapted.DocEditor
className={styles.docContainer}
ref={onDocRef}
page={page}
doc={page}
specs={specs}
hasViewport={false}
/>
@ -125,14 +124,12 @@ export const BlocksuiteDocEditor = forwardRef<
<div
className={styles.docEditorGap}
onClick={() => {
(
docPage.std.spec.getService('affine:page') as DocPageService
).appendParagraph();
docPage.std.spec.getService('affine:page').appendParagraph();
}}
></div>
) : null}
{docPage ? (
<adapted.BiDirectionalLinkPanel page={page} docPageBlock={docPage} />
<adapted.BiDirectionalLinkPanel doc={page} pageRoot={docPage} />
) : null}
</div>
</div>
@ -146,5 +143,5 @@ export const BlocksuiteEdgelessEditor = forwardRef<
const specs = useMemo(() => {
return patchSpecs(edgelessModeSpecs, customRenderers);
}, [customRenderers]);
return <adapted.EdgelessEditor ref={ref} page={page} specs={specs} />;
return <adapted.EdgelessEditor ref={ref} doc={page} specs={specs} />;
});

View File

@ -1,12 +1,12 @@
import type { BlockSpec } from '@blocksuite/block-std';
import type { PageService, ParagraphService } from '@blocksuite/blocks';
import type { ParagraphService, RootService } from '@blocksuite/blocks';
import {
AttachmentService,
CanvasTextFonts,
DocEditorBlockSpecs,
DocPageService,
EdgelessEditorBlockSpecs,
EdgelessPageService,
EdgelessRootService,
PageEditorBlockSpecs,
PageRootService,
} from '@blocksuite/blocks';
import bytes from 'bytes';
import { html, unsafeStatic } from 'lit/static-html.js';
@ -20,7 +20,7 @@ class CustomAttachmentService extends AttachmentService {
}
}
function customLoadFonts(service: PageService): void {
function customLoadFonts(service: RootService): void {
const officialDomains = new Set(['app.affine.pro', 'affine.fail']);
if (!officialDomains.has(window.location.host)) {
const fonts = CanvasTextFonts.map(font => ({
@ -34,12 +34,12 @@ function customLoadFonts(service: PageService): void {
}
}
class CustomDocPageService extends DocPageService {
class CustomDocPageService extends PageRootService {
override loadFonts(): void {
customLoadFonts(this);
}
}
class CustomEdgelessPageService extends EdgelessPageService {
class CustomEdgelessPageService extends EdgelessRootService {
override loadFonts(): void {
customLoadFonts(this);
}
@ -97,7 +97,7 @@ export function patchSpecs(
return newSpecs;
}
export const docModeSpecs = DocEditorBlockSpecs.map(spec => {
export const docModeSpecs = PageEditorBlockSpecs.map(spec => {
if (spec.schema.model.flavour === 'affine:attachment') {
return {
...spec,

View File

@ -5,7 +5,7 @@ export const docEditorRoot = style({
background: cssVar('backgroundPrimaryColor'),
});
// brings styles of .affine-doc-viewport from blocksuite
// brings styles of .affine-page-viewport from blocksuite
export const affineDocViewport = style({
display: 'flex',
flexDirection: 'column',

View File

@ -1,6 +1,6 @@
import { FavoriteTag } from '@affine/core/components/page-list';
import { useBlockSuiteMetaHelper } from '@affine/core/hooks/affine/use-block-suite-meta-helper';
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { toast } from '@affine/core/utils';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { assertExists } from '@blocksuite/global/utils';
@ -16,10 +16,10 @@ export const useFavorite = (pageId: string) => {
const t = useAFFiNEI18N();
const workspace = useService(Workspace);
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
const currentPage = blockSuiteWorkspace.getPage(pageId);
const currentPage = blockSuiteWorkspace.getDoc(pageId);
assertExists(currentPage);
const pageMeta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
const pageMeta = useBlockSuiteDocMeta(blockSuiteWorkspace).find(
meta => meta.id === pageId
);
const favorite = pageMeta?.favorite ?? false;

View File

@ -4,13 +4,13 @@ import {
useJournalRouteHelper,
} from '@affine/core/hooks/use-journal';
import type { BlockSuiteWorkspace } from '@affine/core/shared';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import dayjs from 'dayjs';
import { useEffect, useRef, useState } from 'react';
export interface JournalWeekDatePickerProps {
workspace: BlockSuiteWorkspace;
page: Page;
page: Doc;
}
const weekStyle = { maxWidth: 800, width: '100%' };

View File

@ -11,7 +11,7 @@ import { Export, MoveToTrash } from '@affine/core/components/page-list';
import { useBlockSuiteMetaHelper } from '@affine/core/hooks/affine/use-block-suite-meta-helper';
import { useExportPage } from '@affine/core/hooks/affine/use-export-page';
import { useTrashModalHelper } from '@affine/core/hooks/affine/use-trash-modal-helper';
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { WorkspaceFlavour } from '@affine/env/workspace';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { assertExists } from '@blocksuite/global/utils';
@ -25,7 +25,7 @@ import {
ImportIcon,
PageIcon,
} from '@blocksuite/icons';
import { Page, useLiveData, useService, Workspace } from '@toeverything/infra';
import { Doc, useLiveData, useService, Workspace } from '@toeverything/infra';
import { useSetAtom } from 'jotai';
import { useCallback, useState } from 'react';
@ -48,13 +48,13 @@ export const PageHeaderMenuButton = ({
const workspace = useService(Workspace);
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
const currentPage = blockSuiteWorkspace.getPage(pageId);
const currentPage = blockSuiteWorkspace.getDoc(pageId);
assertExists(currentPage);
const pageMeta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
const pageMeta = useBlockSuiteDocMeta(blockSuiteWorkspace).find(
meta => meta.id === pageId
);
const page = useService(Page);
const page = useService(Doc);
const currentMode = useLiveData(page.mode);
const { favorite, toggleFavorite } = useFavorite(pageId);

View File

@ -1,7 +1,7 @@
import { InlineEdit, type InlineEditProps } from '@affine/component';
import {
useBlockSuitePageMeta,
usePageMetaHelper,
useBlockSuiteDocMeta,
useDocMetaHelper,
} from '@affine/core/hooks/use-block-suite-page-meta';
import type { BlockSuiteWorkspace } from '@affine/core/shared';
import type { HTMLAttributes } from 'react';
@ -27,18 +27,18 @@ export const BlocksuiteHeaderTitle = (props: BlockSuiteHeaderTitleProps) => {
isPublic,
inputHandleRef,
} = props;
const currentPage = workspace.getPage(pageId);
const pageMeta = useBlockSuitePageMeta(workspace).find(
const currentPage = workspace.getDoc(pageId);
const pageMeta = useBlockSuiteDocMeta(workspace).find(
meta => meta.id === currentPage?.id
);
const title = pageMeta?.title;
const { setPageTitle } = usePageMetaHelper(workspace);
const { setDocTitle } = useDocMetaHelper(workspace);
const onChange = useCallback(
(v: string) => {
setPageTitle(currentPage?.id || '', v);
setDocTitle(currentPage?.id || '', v);
},
[currentPage?.id, setPageTitle]
[currentPage?.id, setDocTitle]
);
return (

View File

@ -1,8 +1,8 @@
import { Tooltip } from '@affine/component/ui/tooltip';
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import {
Page,
Doc,
type PageMode,
useLiveData,
useService,
@ -42,11 +42,11 @@ export const EditorModeSwitch = ({
publicMode,
}: EditorModeSwitchProps) => {
const t = useAFFiNEI18N();
const pageMeta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
const pageMeta = useBlockSuiteDocMeta(blockSuiteWorkspace).find(
meta => meta.id === pageId
);
const trash = pageMeta?.trash ?? false;
const page = useService(Page);
const page = useService(Doc);
const currentMode = useLiveData(page.mode);

View File

@ -1,6 +1,6 @@
import { toast } from '@affine/component';
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { usePageMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteWorkspaceHelper } from '@affine/core/hooks/use-block-suite-workspace-helper';
import { WorkspaceSubPath } from '@affine/core/shared';
import { useService } from '@toeverything/infra';
@ -13,8 +13,8 @@ import type { BlockSuiteWorkspace } from '../../../shared';
export const usePageHelper = (blockSuiteWorkspace: BlockSuiteWorkspace) => {
const { openPage, jumpToSubPath } = useNavigateHelper();
const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
const { createDoc } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
const { setDocMeta } = useDocMetaHelper(blockSuiteWorkspace);
const pageRecordList = useService(PageRecordList);
const isPreferredEdgeless = useCallback(
@ -25,13 +25,13 @@ export const usePageHelper = (blockSuiteWorkspace: BlockSuiteWorkspace) => {
const createPageAndOpen = useCallback(
(mode?: 'page' | 'edgeless') => {
const page = createPage();
const page = createDoc();
initEmptyPage(page);
pageRecordList.record(page.id).value?.setMode(mode || 'page');
openPage(blockSuiteWorkspace.id, page.id);
return page;
},
[blockSuiteWorkspace.id, createPage, openPage, pageRecordList]
[blockSuiteWorkspace.id, createDoc, openPage, pageRecordList]
);
const createEdgelessAndOpen = useCallback(() => {
@ -64,7 +64,7 @@ export const usePageHelper = (blockSuiteWorkspace: BlockSuiteWorkspace) => {
async (pageId: string) => {
const page = createPageAndOpen();
page.load();
const parentPage = blockSuiteWorkspace.getPage(pageId);
const parentPage = blockSuiteWorkspace.getDoc(pageId);
if (parentPage) {
parentPage.load();
const text = parentPage.Text.fromDelta([
@ -80,10 +80,10 @@ export const usePageHelper = (blockSuiteWorkspace: BlockSuiteWorkspace) => {
]);
const [frame] = parentPage.getBlockByFlavour('affine:note');
frame && parentPage.addBlock('affine:paragraph', { text }, frame.id);
setPageMeta(page.id, {});
setDocMeta(page.id, {});
}
},
[blockSuiteWorkspace, createPageAndOpen, setPageMeta]
[blockSuiteWorkspace, createPageAndOpen, setDocMeta]
);
return useMemo(() => {

View File

@ -1,7 +1,7 @@
import { Button } from '@affine/component/ui/button';
import { useActiveBlocksuiteEditor } from '@affine/core/hooks/use-block-suite-editor';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { EdgelessPageService } from '@blocksuite/blocks';
import type { EdgelessRootService } from '@blocksuite/blocks';
import { PresentationIcon } from '@blocksuite/icons';
import { useCallback, useEffect, useState } from 'react';
@ -18,18 +18,18 @@ export const PresentButton = () => {
// TODO: use surfaceService subAtom
const enterPresentationMode = () => {
const edgelessPageService = editorHost.spec.getService(
const edgelessRootService = editorHost.spec.getService(
'affine:page'
) as EdgelessPageService;
) as EdgelessRootService;
if (
!edgelessPageService ||
edgelessPageService.tool.edgelessTool.type === 'frameNavigator'
!edgelessRootService ||
edgelessRootService.tool.edgelessTool.type === 'frameNavigator'
) {
return;
}
edgelessPageService.tool.setEdgelessTool({ type: 'frameNavigator' });
edgelessRootService.tool.setEdgelessTool({ type: 'frameNavigator' });
};
enterPresentationMode();
@ -42,7 +42,7 @@ export const PresentButton = () => {
const editorHost = editor?.host;
if (!editorHost) return;
const edgelessPage = editorHost?.querySelector('affine-edgeless-page');
const edgelessPage = editorHost?.querySelector('affine-edgeless-root');
if (!edgelessPage) return;
edgelessPage.slots.edgelessToolUpdated.on(() => {

View File

@ -96,7 +96,7 @@ const ImagePreviewModalImpl = (
if (!hasPlayedAnimation) {
setHasPlayedAnimation(true);
}
const page = workspace.getPage(props.pageId);
const page = workspace.getDoc(props.pageId);
assertExists(page);
const block = page.getBlockById(blockId);
assertExists(block);
@ -116,7 +116,7 @@ const ImagePreviewModalImpl = (
(blockId: string | null) => {
assertExists(blockId);
const workspace = props.workspace;
const page = workspace.getPage(props.pageId);
const page = workspace.getDoc(props.pageId);
assertExists(page);
const block = page.getBlockById(blockId);
assertExists(block);
@ -137,7 +137,7 @@ const ImagePreviewModalImpl = (
(blockId: string) => {
const { pageId, workspace, onClose } = props;
const page = workspace.getPage(pageId);
const page = workspace.getDoc(pageId);
assertExists(page);
const block = page.getBlockById(blockId);
assertExists(block);
@ -186,7 +186,7 @@ const ImagePreviewModalImpl = (
const downloadHandler = useCallback(
async (blockId: string | null) => {
const workspace = props.workspace;
const page = workspace.getPage(props.pageId);
const page = workspace.getDoc(props.pageId);
assertExists(page);
if (typeof blockId === 'string') {
const block = page.getBlockById(blockId) as ImageBlockModel;
@ -240,14 +240,14 @@ const ImagePreviewModalImpl = (
[props.pageId, props.workspace]
);
const [caption, setCaption] = useState(() => {
const page = props.workspace.getPage(props.pageId);
const page = props.workspace.getDoc(props.pageId);
assertExists(page);
const block = page.getBlockById(props.blockId) as ImageBlockModel;
assertExists(block);
return block?.caption;
});
useEffect(() => {
const page = props.workspace.getPage(props.pageId);
const page = props.workspace.getDoc(props.pageId);
assertExists(page);
const block = page.getBlockById(props.blockId) as ImageBlockModel;
assertExists(block);
@ -257,7 +257,7 @@ const ImagePreviewModalImpl = (
['workspace', 'image', props.pageId, props.blockId],
{
fetcher: ([_, __, pageId, blockId]) => {
const page = props.workspace.getPage(pageId);
const page = props.workspace.getDoc(pageId);
assertExists(page);
const block = page.getBlockById(blockId) as ImageBlockModel;
assertExists(block);
@ -510,7 +510,7 @@ export const ImagePreviewModal = (
const workspace = props.workspace;
const page = workspace.getPage(props.pageId);
const page = workspace.getDoc(props.pageId);
assertExists(page);
const block = page.getBlockById(blockId);
assertExists(block);

View File

@ -11,7 +11,7 @@ export const editor = style({
},
});
globalStyle(
`${editor} .affine-doc-viewport:not(.affine-embed-synced-doc-editor)`,
`${editor} .affine-page-viewport:not(.affine-embed-synced-doc-editor)`,
{
paddingBottom: '150px',
}

View File

@ -5,9 +5,9 @@ import { useBlockSuiteWorkspacePage } from '@affine/core/hooks/use-block-suite-w
import { assertExists, DisposableGroup } from '@blocksuite/global/utils';
import type { AffineEditorContainer } from '@blocksuite/presets';
import type { Workspace } from '@blocksuite/store';
import type { Page as BlockSuitePage } from '@blocksuite/store';
import type { Doc as BlockSuiteDoc } from '@blocksuite/store';
import {
Page,
Doc,
type PageMode,
useLiveData,
useService,
@ -28,7 +28,7 @@ declare global {
}
export type OnLoadEditor = (
page: BlockSuitePage,
page: BlockSuiteDoc,
editor: AffineEditorContainer
) => () => void;
@ -49,8 +49,8 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({
onLoad,
isPublic,
publishMode,
}: PageDetailEditorProps & { page: BlockSuitePage }) {
const currentMode = useLiveData(useService(Page).mode);
}: PageDetailEditorProps & { page: BlockSuiteDoc }) {
const currentMode = useLiveData(useService(Doc).mode);
const mode = useMemo(() => {
const shareMode = publishMode || currentMode;
@ -81,7 +81,7 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({
const disposableGroup = new DisposableGroup();
disposableGroup.add(
page.slots.blockUpdated.once(() => {
page.workspace.setPageMeta(page.id, {
page.workspace.setDocMeta(page.id, {
updatedDate: Date.now(),
});
})

View File

@ -5,7 +5,7 @@ import 'fake-indexeddb/auto';
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
import { assertExists } from '@blocksuite/global/utils';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import { Schema, Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
import { renderHook } from '@testing-library/react';
import { useAtomValue } from 'jotai';
@ -21,8 +21,8 @@ schema.register(AffineSchemas).register(__unstableSchemas);
beforeEach(async () => {
vi.useFakeTimers({ toFake: ['requestIdleCallback'] });
blockSuiteWorkspace = new BlockSuiteWorkspace({ id: 'test', schema });
const initPage = async (page: Page) => {
page.waitForLoaded();
const initPage = async (page: Doc) => {
page.load();
expect(page).not.toBeNull();
assertExists(page);
const pageBlockId = page.addBlock('affine:page', {
@ -31,12 +31,12 @@ beforeEach(async () => {
const frameId = page.addBlock('affine:note', {}, pageBlockId);
page.addBlock('affine:paragraph', {}, frameId);
};
await initPage(blockSuiteWorkspace.createPage({ id: 'page0' }));
await initPage(blockSuiteWorkspace.createDoc({ id: 'page0' }));
});
describe('useBlockSuitePagePreview', () => {
test('basic', async () => {
const page = blockSuiteWorkspace.getPage('page0') as Page;
const page = blockSuiteWorkspace.getDoc('page0') as Doc;
const id = page.addBlock(
'affine:paragraph',
{

View File

@ -1,11 +1,11 @@
import { toast } from '@affine/component';
import { useBlockSuiteMetaHelper } from '@affine/core/hooks/affine/use-block-suite-meta-helper';
import { useTrashModalHelper } from '@affine/core/hooks/affine/use-trash-modal-helper';
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import type { Collection, Filter } from '@affine/env/filter';
import { Trans } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { PageMeta, Tag } from '@blocksuite/store';
import type { DocMeta, Tag } from '@blocksuite/store';
import { useService } from '@toeverything/infra';
import { Workspace } from '@toeverything/infra';
import { useCallback, useMemo, useRef, useState } from 'react';
@ -37,7 +37,7 @@ const usePageOperationsRenderer = () => {
const t = useAFFiNEI18N();
const pageOperationsRenderer = useCallback(
(page: PageMeta) => {
(page: DocMeta) => {
const onDisablePublicSharing = () => {
toast('Successfully disabled', {
portal: document.body,
@ -90,14 +90,14 @@ export const VirtualizedPageList = ({
collection?: Collection;
filters?: Filter[];
config?: AllPageListConfig;
listItem?: PageMeta[];
listItem?: DocMeta[];
setHideHeaderCreateNewPage?: (hide: boolean) => void;
}) => {
const listRef = useRef<ItemListHandle>(null);
const [showFloatingToolbar, setShowFloatingToolbar] = useState(false);
const [selectedPageIds, setSelectedPageIds] = useState<string[]>([]);
const currentWorkspace = useService(Workspace);
const pageMetas = useBlockSuitePageMeta(currentWorkspace.blockSuiteWorkspace);
const pageMetas = useBlockSuiteDocMeta(currentWorkspace.blockSuiteWorkspace);
const pageOperations = usePageOperationsRenderer();
const { isPreferredEdgeless } = usePageHelper(
currentWorkspace.blockSuiteWorkspace
@ -125,7 +125,7 @@ export const VirtualizedPageList = ({
const pageOperationRenderer = useCallback(
(item: ListItem) => {
const page = item as PageMeta;
const page = item as DocMeta;
return pageOperations(page);
},
[pageOperations]

View File

@ -10,7 +10,7 @@ import {
ToggleCollapseIcon,
ViewLayersIcon,
} from '@blocksuite/icons';
import type { PageMeta, Workspace } from '@blocksuite/store';
import type { DocMeta, Workspace } from '@blocksuite/store';
import * as Collapsible from '@radix-ui/react-collapsible';
import clsx from 'clsx';
import { selectAtom } from 'jotai/utils';
@ -223,7 +223,7 @@ const listsPropsAtom = selectAtom(
export const PageListItemRenderer = (item: ListItem) => {
const props = useAtomValue(listsPropsAtom);
const { selectionActive } = useAtomValue(selectionStateAtom);
const page = item as PageMeta;
const page = item as DocMeta;
return (
<PageListItem
{...pageMetaToListItemProp(page, {
@ -294,8 +294,8 @@ const UnifiedPageIcon = ({
};
function pageMetaToListItemProp(
item: PageMeta,
props: RequiredProps<PageMeta>
item: DocMeta,
props: RequiredProps<DocMeta>
): PageListItemProps {
const toggleSelection = props.onSelectedIdsChange
? () => {

View File

@ -1,9 +1,9 @@
import type { Collection, Tag } from '@affine/env/filter';
import type { PageMeta, Workspace } from '@blocksuite/store';
import type { DocMeta, Workspace } from '@blocksuite/store';
import type { PropsWithChildren, ReactNode } from 'react';
import type { To } from 'react-router-dom';
export type ListItem = PageMeta | CollectionMeta | TagMeta;
export type ListItem = DocMeta | CollectionMeta | TagMeta;
export interface CollectionMeta extends Collection {
title: string;

View File

@ -1,13 +1,13 @@
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import type { Atom } from 'jotai';
import { atom } from 'jotai';
const MAX_PREVIEW_LENGTH = 150;
const MAX_SEARCH_BLOCK_COUNT = 30;
const weakMap = new WeakMap<Page, Atom<string>>();
const weakMap = new WeakMap<Doc, Atom<string>>();
export const getPagePreviewText = (page: Page) => {
export const getPagePreviewText = (page: Doc) => {
const pageRoot = page.root;
if (!pageRoot) {
return '';
@ -56,7 +56,7 @@ export const getPagePreviewText = (page: Page) => {
const emptyAtom = atom<string>('');
export function useBlockSuitePagePreview(page: Page | null): Atom<string> {
export function useBlockSuitePagePreview(page: Doc | null): Atom<string> {
if (page === null) {
return emptyAtom;
} else if (weakMap.has(page)) {

View File

@ -1,26 +1,26 @@
import { DisposableGroup } from '@blocksuite/global/utils';
import type { Page, Workspace } from '@blocksuite/store';
import type { Doc, Workspace } from '@blocksuite/store';
import { useEffect, useState } from 'react';
export function useBlockSuiteWorkspacePage(
blockSuiteWorkspace: Workspace,
pageId: string | null
): Page | null {
): Doc | null {
const [page, setPage] = useState(
pageId ? blockSuiteWorkspace.getPage(pageId) : null
pageId ? blockSuiteWorkspace.getDoc(pageId) : null
);
useEffect(() => {
const group = new DisposableGroup();
group.add(
blockSuiteWorkspace.slots.pageAdded.on(id => {
blockSuiteWorkspace.slots.docAdded.on(id => {
if (pageId === id) {
setPage(blockSuiteWorkspace.getPage(id));
setPage(blockSuiteWorkspace.getDoc(id));
}
})
);
group.add(
blockSuiteWorkspace.slots.pageRemoved.on(id => {
blockSuiteWorkspace.slots.docRemoved.on(id => {
if (pageId === id) {
setPage(null);
}
@ -39,7 +39,7 @@ export function useBlockSuiteWorkspacePage(
useEffect(() => {
if (page?.id !== pageId) {
setPage(pageId ? blockSuiteWorkspace.getPage(pageId) : null);
setPage(pageId ? blockSuiteWorkspace.getDoc(pageId) : null);
}
}, [blockSuiteWorkspace, page?.id, pageId]);

View File

@ -1,5 +1,5 @@
import type { Collection, Filter, VariableMap } from '@affine/env/filter';
import type { PageMeta } from '@blocksuite/store';
import type { DocMeta } from '@blocksuite/store';
import { evalFilterList } from './filter';
@ -20,7 +20,7 @@ export const filterByFilterList = (filterList: Filter[], varMap: VariableMap) =>
evalFilterList(filterList, varMap);
export type PageDataForFilter = {
meta: PageMeta;
meta: DocMeta;
publicMode: undefined | 'page' | 'edgeless';
};

View File

@ -1,5 +1,5 @@
import type { Collection, Filter } from '@affine/env/filter';
import type { PageMeta } from '@blocksuite/store';
import type { DocMeta } from '@blocksuite/store';
import type { Workspace } from '@toeverything/infra';
import { useMemo } from 'react';
@ -8,7 +8,7 @@ import { filterPage, filterPageByRules } from './use-collection-manager';
export const useFilteredPageMetas = (
workspace: Workspace,
pageMetas: PageMeta[],
pageMetas: DocMeta[],
options: {
trash?: boolean;
filters?: Filter[];

View File

@ -1,14 +1,11 @@
import type { PageMeta, Tag, Workspace } from '@blocksuite/store';
import type { DocMeta, Tag, Workspace } from '@blocksuite/store';
import { useCallback, useMemo } from 'react';
interface TagUsageCounts {
[key: string]: number;
}
export function useTagMetas(
currentWorkspace: Workspace,
pageMetas: PageMeta[]
) {
export function useTagMetas(currentWorkspace: Workspace, pageMetas: DocMeta[]) {
const tags = useMemo(() => {
return currentWorkspace.meta.properties.tags?.options || [];
}, [currentWorkspace]);

View File

@ -6,7 +6,7 @@ import {
} from '@affine/component';
import type { Collection } from '@affine/env/filter';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { PageMeta, Workspace } from '@blocksuite/store';
import type { DocMeta, Workspace } from '@blocksuite/store';
import type { DialogContentProps } from '@radix-ui/react-dialog';
import { type ReactNode, useCallback, useMemo, useState } from 'react';
@ -198,13 +198,13 @@ export const EditCollection = ({
};
export type AllPageListConfig = {
allPages: PageMeta[];
allPages: DocMeta[];
workspace: Workspace;
isEdgeless: (id: string) => boolean;
/**
* Return `undefined` if the page is not public
*/
getPublicMode: (id: string) => undefined | 'page' | 'edgeless';
getPage: (id: string) => PageMeta | undefined;
favoriteRender: (page: PageMeta) => ReactNode;
getPage: (id: string) => DocMeta | undefined;
favoriteRender: (page: DocMeta) => ReactNode;
};

View File

@ -2,7 +2,7 @@ import { Menu } from '@affine/component';
import type { Collection } from '@affine/env/filter';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { FilterIcon } from '@blocksuite/icons';
import type { PageMeta } from '@blocksuite/store';
import type { DocMeta } from '@blocksuite/store';
import clsx from 'clsx';
import { type ReactNode, useCallback } from 'react';
@ -56,7 +56,7 @@ export const PagesMode = ({
}, [collection, updateCollection]);
const pageOperationsRenderer = useCallback(
(item: ListItem) => {
const page = item as PageMeta;
const page = item as DocMeta;
return allPageListConfig.favoriteRender(page);
},
[allPageListConfig]

View File

@ -8,7 +8,7 @@ import {
PlusIcon,
ToggleCollapseIcon,
} from '@blocksuite/icons';
import type { PageMeta } from '@blocksuite/store';
import type { DocMeta } from '@blocksuite/store';
import clsx from 'clsx';
import { type ReactNode, useCallback, useEffect, useState } from 'react';
@ -38,8 +38,8 @@ export const RulesMode = ({
}) => {
const t = useAFFiNEI18N();
const [showPreview, setShowPreview] = useState(true);
const allowListPages: PageMeta[] = [];
const rulesPages: PageMeta[] = [];
const allowListPages: DocMeta[] = [];
const rulesPages: DocMeta[] = [];
const [showTips, setShowTips] = useState(false);
useEffect(() => {
setShowTips(!localStorage.getItem('hide-rules-mode-include-page-tips'));
@ -85,7 +85,7 @@ export const RulesMode = ({
);
const operationsRenderer = useCallback(
(item: ListItem) => {
const page = item as PageMeta;
const page = item as DocMeta;
return allPageListConfig.favoriteRender(page);
},
[allPageListConfig]

View File

@ -2,7 +2,7 @@ import { Button, Menu } from '@affine/component';
import { Trans } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { FilterIcon } from '@blocksuite/icons';
import type { PageMeta } from '@blocksuite/store';
import type { DocMeta } from '@blocksuite/store';
import clsx from 'clsx';
import { useCallback, useState } from 'react';
@ -53,7 +53,7 @@ export const SelectPage = ({
const operationsRenderer = useCallback(
(item: ListItem) => {
const page = item as PageMeta;
const page = item as DocMeta;
return allPageListConfig.favoriteRender(page);
},
[allPageListConfig]

View File

@ -1,7 +1,7 @@
import type { PageMeta } from '@blocksuite/store';
import type { DocMeta } from '@blocksuite/store';
import { useState } from 'react';
export const useSearch = (list: PageMeta[]) => {
export const useSearch = (list: DocMeta[]) => {
const [value, onChange] = useState('');
return {
searchText: value,

View File

@ -1,6 +1,6 @@
import {
useBlockSuitePageMeta,
usePageMetaHelper,
useBlockSuiteDocMeta,
useDocMetaHelper,
} from '@affine/core/hooks/use-block-suite-page-meta';
import { useGetBlockSuiteWorkspacePageTitle } from '@affine/core/hooks/use-block-suite-workspace-page-title';
import { useJournalHelper } from '@affine/core/hooks/use-journal';
@ -14,9 +14,9 @@ import {
TodayIcon,
ViewLayersIcon,
} from '@blocksuite/icons';
import type { PageMeta } from '@blocksuite/store';
import type { DocMeta } from '@blocksuite/store';
import {
Page,
Doc,
PageRecordList,
useLiveData,
Workspace,
@ -79,7 +79,7 @@ function getAllCommand(context: CommandContext) {
const useWorkspacePages = () => {
const workspace = useService(Workspace);
const pages = useBlockSuitePageMeta(workspace.blockSuiteWorkspace);
const pages = useBlockSuiteDocMeta(workspace.blockSuiteWorkspace);
return pages;
};
@ -92,13 +92,13 @@ const useRecentPages = () => {
const page = pages.find(page => page.id === pageId);
return page;
})
.filter((p): p is PageMeta => !!p);
.filter((p): p is DocMeta => !!p);
}, [recentPageIds, pages]);
};
export const pageToCommand = (
category: CommandCategory,
page: PageMeta,
page: DocMeta,
navigationHelper: ReturnType<typeof useNavigateHelper>,
getPageTitle: ReturnType<typeof useGetBlockSuiteWorkspacePageTitle>,
isPageJournal: (pageId: string) => boolean,
@ -152,7 +152,7 @@ export const usePageCommands = () => {
const pages = useWorkspacePages();
const workspace = useService(Workspace);
const pageHelper = usePageHelper(workspace.blockSuiteWorkspace);
const pageMetaHelper = usePageMetaHelper(workspace.blockSuiteWorkspace);
const pageMetaHelper = useDocMetaHelper(workspace.blockSuiteWorkspace);
const query = useAtomValue(cmdkQueryAtom);
const navigationHelper = useNavigateHelper();
const journalHelper = useJournalHelper(workspace.blockSuiteWorkspace);
@ -260,7 +260,7 @@ export const usePageCommands = () => {
run: async () => {
const page = pageHelper.createPage();
page.load();
pageMetaHelper.setPageTitle(page.id, query);
pageMetaHelper.setDocTitle(page.id, query);
},
icon: <PageIcon />,
});
@ -275,7 +275,7 @@ export const usePageCommands = () => {
run: async () => {
const page = pageHelper.createEdgeless();
page.load();
pageMetaHelper.setPageTitle(page.id, query);
pageMetaHelper.setDocTitle(page.id, query);
},
icon: <EdgelessIcon />,
});
@ -357,7 +357,7 @@ export const useCMDKCommandGroups = () => {
const pageCommands = usePageCommands();
const collectionCommands = useCollectionsCommands();
const currentPage = useServiceOptional(Page);
const currentPage = useServiceOptional(Doc);
const currentPageMode = useLiveData(currentPage?.mode);
const affineCommands = useMemo(() => {
return getAllCommand({

View File

@ -3,7 +3,7 @@ import { formatDate } from '@affine/core/components/page-list';
import { useSyncEngineStatus } from '@affine/core/hooks/affine/use-sync-engine-status';
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { PageMeta } from '@blocksuite/store';
import type { DocMeta } from '@blocksuite/store';
import { SyncEngineStep } from '@toeverything/infra';
import type { CommandCategory } from '@toeverything/infra/command';
import clsx from 'clsx';
@ -155,7 +155,7 @@ export const CMDKContainer = ({
open: boolean;
className?: string;
query: string;
pageMeta?: PageMeta;
pageMeta?: DocMeta;
groups: ReturnType<typeof useCMDKCommandGroups>;
onQueryChange: (query: string) => void;
}>) => {
@ -235,7 +235,7 @@ const CMDKQuickSearchModalInner = ({
pageMeta,
open,
...props
}: CMDKModalProps & { pageMeta?: PageMeta }) => {
}: CMDKModalProps & { pageMeta?: DocMeta }) => {
const [query, setQuery] = useAtom(cmdkQueryAtom);
useLayoutEffect(() => {
if (open) {
@ -261,7 +261,7 @@ export const CMDKQuickSearchModal = ({
pageMeta,
open,
...props
}: CMDKModalProps & { pageMeta?: PageMeta }) => {
}: CMDKModalProps & { pageMeta?: DocMeta }) => {
return (
<CMDKModal open={open} {...props}>
<Suspense fallback={<Command.Loading />}>

View File

@ -2,7 +2,7 @@ import { Tooltip } from '@affine/component/ui/tooltip';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { CloseIcon, NewIcon } from '@blocksuite/icons';
import { useLiveData, useServiceOptional } from '@toeverything/infra';
import { Page } from '@toeverything/infra';
import { Doc } from '@toeverything/infra';
import { useSetAtom } from 'jotai/react';
import { useCallback, useState } from 'react';
@ -28,7 +28,7 @@ type IslandItemNames = 'whatNew' | 'contact' | 'shortcuts';
const showList = environment.isDesktop ? DESKTOP_SHOW_LIST : DEFAULT_SHOW_LIST;
export const HelpIsland = () => {
const page = useServiceOptional(Page);
const page = useServiceOptional(Doc);
const pageId = page?.id;
const mode = useLiveData(page?.mode);
const setOpenSettingModalAtom = useSetAtom(openSettingModalAtom);

View File

@ -1,7 +1,7 @@
import { Button } from '@affine/component/ui/button';
import { ConfirmModal } from '@affine/component/ui/modal';
import { Tooltip } from '@affine/component/ui/tooltip';
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { assertExists } from '@blocksuite/global/utils';
import { DeleteIcon, ResetIcon } from '@blocksuite/icons';
@ -23,7 +23,7 @@ export const TrashPageFooter = ({ pageId }: { pageId: string }) => {
);
assertExists(workspace);
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
const pageMeta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
const pageMeta = useBlockSuiteDocMeta(blockSuiteWorkspace).find(
meta => meta.id === pageId
);
assertExists(pageMeta);
@ -45,7 +45,7 @@ export const TrashPageFooter = ({ pageId }: { pageId: string }) => {
const onConfirmDelete = useCallback(() => {
jumpToSubPath(workspace.id, WorkspaceSubPath.ALL);
blockSuiteWorkspace.removePage(pageId);
blockSuiteWorkspace.removeDoc(pageId);
toast(t['com.affine.toastMessage.permanentlyDeleted']());
}, [blockSuiteWorkspace, jumpToSubPath, pageId, workspace.id, t]);

View File

@ -11,7 +11,7 @@ import { CollectionService } from '@affine/core/modules/collection';
import type { Collection, DeleteCollectionInfo } from '@affine/env/filter';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { MoreHorizontalIcon, ViewLayersIcon } from '@blocksuite/icons';
import type { PageMeta, Workspace } from '@blocksuite/store';
import type { DocMeta, Workspace } from '@blocksuite/store';
import { useDroppable } from '@dnd-kit/core';
import * as Collapsible from '@radix-ui/react-collapsible';
import { useService } from '@toeverything/infra';
@ -20,7 +20,7 @@ import { useCallback, useMemo, useState } from 'react';
import { useAllPageListConfig } from '../../../../hooks/affine/use-all-page-list-config';
import { getDropItemId } from '../../../../hooks/affine/use-sidebar-drag';
import { useBlockSuitePageMeta } from '../../../../hooks/use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '../../../../hooks/use-block-suite-page-meta';
import { Workbench } from '../../../../modules/workbench';
import { WorkbenchLink } from '../../../../modules/workbench/workbench-link';
import type { CollectionsListProps } from '../index';
@ -34,7 +34,7 @@ const CollectionRenderer = ({
info,
}: {
collection: Collection;
pages: PageMeta[];
pages: DocMeta[];
workspace: Workspace;
info: DeleteCollectionInfo;
}) => {
@ -173,7 +173,7 @@ export const CollectionsList = ({
info,
onCreate,
}: CollectionsListProps) => {
const metas = useBlockSuitePageMeta(workspace);
const metas = useBlockSuiteDocMeta(workspace);
const collections = useLiveData(useService(CollectionService).collections);
const t = useAFFiNEI18N();
if (collections.length === 0) {

View File

@ -2,7 +2,7 @@ import { MenuItem as CollectionItem } from '@affine/component/app-sidebar';
import { useBlockSuitePageReferences } from '@affine/core/hooks/use-block-suite-page-references';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
import type { PageMeta, Workspace } from '@blocksuite/store';
import type { DocMeta, Workspace } from '@blocksuite/store';
import { useDraggable } from '@dnd-kit/core';
import * as Collapsible from '@radix-ui/react-collapsible';
import { PageRecordList, useLiveData, useService } from '@toeverything/infra';
@ -23,11 +23,11 @@ export const Page = ({
inAllowList,
removeFromAllowList,
}: {
page: PageMeta;
page: DocMeta;
inAllowList: boolean;
removeFromAllowList: (id: string) => void;
workspace: Workspace;
allPageMeta: Record<string, PageMeta>;
allPageMeta: Record<string, DocMeta>;
}) => {
const [collapsed, setCollapsed] = React.useState(true);
const params = useParams();

View File

@ -1,6 +1,6 @@
import { toast } from '@affine/component';
import { RenameModal } from '@affine/component/rename-modal';
import { usePageMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { Workspace } from '@blocksuite/store';
import { useCallback, useState } from 'react';
@ -23,15 +23,15 @@ export const PostfixItem = ({ ...props }: PostfixItemProps) => {
const { workspace, pageId, pageTitle } = props;
const t = useAFFiNEI18N();
const [open, setOpen] = useState(false);
const { setPageTitle } = usePageMetaHelper(workspace);
const { setDocTitle } = useDocMetaHelper(workspace);
const handleRename = useCallback(
(newName: string) => {
setPageTitle(pageId, newName);
setDocTitle(pageId, newName);
setOpen(false);
toast(t['com.affine.toastMessage.rename']());
},
[pageId, setPageTitle, t]
[pageId, setDocTitle, t]
);
return (

View File

@ -2,7 +2,7 @@ import { MenuLinkItem } from '@affine/component/app-sidebar';
import { useBlockSuitePageReferences } from '@affine/core/hooks/use-block-suite-page-references';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
import { type PageMeta, type Workspace } from '@blocksuite/store';
import { type DocMeta, type Workspace } from '@blocksuite/store';
import * as Collapsible from '@radix-ui/react-collapsible';
import { PageRecordList, useLiveData, useService } from '@toeverything/infra';
import { useMemo, useState } from 'react';
@ -13,7 +13,7 @@ import { PostfixItem } from './postfix-item';
export interface ReferencePageProps {
workspace: Workspace;
pageId: string;
metaMapping: Record<string, PageMeta>;
metaMapping: Record<string, DocMeta>;
parentIds: Set<string>;
}

View File

@ -1,6 +1,6 @@
import { IconButton } from '@affine/component/ui/button';
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { usePageMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { PlusIcon } from '@blocksuite/icons';
import type { Workspace } from '@blocksuite/store';
@ -16,7 +16,7 @@ export const AddFavouriteButton = ({
pageId,
}: AddFavouriteButtonProps) => {
const { createPage, createLinkedPage } = usePageHelper(workspace);
const { setPageMeta } = usePageMetaHelper(workspace);
const { setDocMeta } = useDocMetaHelper(workspace);
const handleAddFavorite = useAsyncCallback(
async e => {
if (pageId) {
@ -26,10 +26,10 @@ export const AddFavouriteButton = ({
} else {
const page = createPage();
page.load();
setPageMeta(page.id, { favorite: true });
setDocMeta(page.id, { favorite: true });
}
},
[pageId, createLinkedPage, createPage, setPageMeta]
[pageId, createLinkedPage, createPage, setDocMeta]
);
return (

View File

@ -1,5 +1,5 @@
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import type { PageMeta } from '@blocksuite/store';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import type { DocMeta } from '@blocksuite/store';
import { useDroppable } from '@dnd-kit/core';
import { useMemo } from 'react';
@ -12,7 +12,7 @@ import * as styles from './styles.css';
const emptyPageIdSet = new Set<string>();
export const FavoriteList = ({ workspace }: FavoriteListProps) => {
const metas = useBlockSuitePageMeta(workspace);
const metas = useBlockSuiteDocMeta(workspace);
const dropItemId = getDropItemId('favorites');
const favoriteList = useMemo(
@ -27,7 +27,7 @@ export const FavoriteList = ({ workspace }: FavoriteListProps) => {
acc[meta.id] = meta;
return acc;
},
{} as Record<string, PageMeta>
{} as Record<string, DocMeta>
),
[metas]
);

View File

@ -17,7 +17,7 @@ import { CollectionService } from '@affine/core/modules/collection';
import { apis, events } from '@affine/electron-api';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { FolderIcon, SettingsIcon } from '@blocksuite/icons';
import { type Page } from '@blocksuite/store';
import { type Doc } from '@blocksuite/store';
import { useDroppable } from '@dnd-kit/core';
import { useLiveData, useService, type Workspace } from '@toeverything/infra';
import { useAtom, useAtomValue } from 'jotai';
@ -57,7 +57,7 @@ export type RootAppSidebarProps = {
onOpenSettingModal: () => void;
currentWorkspace: Workspace;
openPage: (pageId: string) => void;
createPage: () => Page;
createPage: () => Doc;
paths: {
all: (workspaceId: string) => string;
trash: (workspaceId: string) => string;
@ -114,7 +114,7 @@ export const RootAppSidebar = ({
const onClickNewPage = useAsyncCallback(async () => {
const page = createPage();
page.waitForLoaded();
page.load();
openPage(page.id);
}, [createPage, openPage]);

View File

@ -6,7 +6,7 @@ import {
import type { BlockSuiteWorkspace } from '@affine/core/shared';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { TodayIcon, TomorrowIcon, YesterdayIcon } from '@blocksuite/icons';
import { Page, useServiceOptional } from '@toeverything/infra';
import { Doc, useServiceOptional } from '@toeverything/infra';
import { useParams } from 'react-router-dom';
interface AppSidebarJournalButtonProps {
@ -17,7 +17,7 @@ export const AppSidebarJournalButton = ({
workspace,
}: AppSidebarJournalButtonProps) => {
const t = useAFFiNEI18N();
const currentPage = useServiceOptional(Page);
const currentPage = useServiceOptional(Doc);
const { openToday } = useJournalRouteHelper(workspace);
const { journalDate, isJournal } = useJournalInfoHelper(
workspace,

View File

@ -10,16 +10,15 @@ import { initEmptyPage, ServiceProviderContext } from '@toeverything/infra';
import type { PropsWithChildren } from 'react';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import { useBlockSuitePageMeta } from '../use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '../use-block-suite-page-meta';
import { useBlockSuiteWorkspaceHelper } from '../use-block-suite-workspace-helper';
const configureTestingWorkspace = async () => {
const { workspace } = await configureTestingEnvironment();
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
// await initEmptyPage(blockSuiteWorkspace.createPage({ id: 'page-0' }));
initEmptyPage(blockSuiteWorkspace.createPage({ id: 'page1' }));
initEmptyPage(blockSuiteWorkspace.createPage({ id: 'page2' }));
initEmptyPage(blockSuiteWorkspace.createDoc({ id: 'page1' }));
initEmptyPage(blockSuiteWorkspace.createDoc({ id: 'page2' }));
return workspace;
};
@ -43,7 +42,7 @@ describe('useBlockSuiteWorkspaceHelper', () => {
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
const Wrapper = getWrapper(workspace);
expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(3);
expect(blockSuiteWorkspace.meta.docMetas.length).toBe(3);
const helperHook = renderHook(
() => useBlockSuiteWorkspaceHelper(blockSuiteWorkspace),
{
@ -51,17 +50,17 @@ describe('useBlockSuiteWorkspaceHelper', () => {
}
);
const pageMetaHook = renderHook(
() => useBlockSuitePageMeta(blockSuiteWorkspace),
() => useBlockSuiteDocMeta(blockSuiteWorkspace),
{
wrapper: Wrapper,
}
);
await new Promise(resolve => setTimeout(resolve));
expect(pageMetaHook.result.current.length).toBe(3);
expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(3);
const page = helperHook.result.current.createPage('page4');
expect(blockSuiteWorkspace.meta.docMetas.length).toBe(3);
const page = helperHook.result.current.createDoc('page4');
expect(page.id).toBe('page4');
expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(4);
expect(blockSuiteWorkspace.meta.docMetas.length).toBe(4);
pageMetaHook.rerender();
expect(pageMetaHook.result.current.length).toBe(4);
});

View File

@ -43,7 +43,7 @@ describe('useBlockSuiteWorkspacePageTitle', () => {
</ServiceProviderContext.Provider>
);
expect(await findByText('title: Untitled')).toBeDefined();
workspace.blockSuiteWorkspace.setPageMeta(page.id, { title: '1' });
workspace.blockSuiteWorkspace.setDocMeta(page.id, { title: '1' });
rerender(
<ServiceProviderContext.Provider value={page.services}>
<Provider store={store}>

View File

@ -3,9 +3,9 @@ import {
type AllPageListConfig,
FavoriteTag,
} from '@affine/core/components/page-list';
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { PageMeta } from '@blocksuite/store';
import type { DocMeta } from '@blocksuite/store';
import { Workspace } from '@toeverything/infra';
import { useService } from '@toeverything/infra/di';
import { useCallback, useMemo } from 'react';
@ -18,7 +18,7 @@ export const useAllPageListConfig = () => {
const currentWorkspace = useService(Workspace);
const { getPublicMode } = usePublicPages(currentWorkspace);
const workspace = currentWorkspace.blockSuiteWorkspace;
const pageMetas = useBlockSuitePageMeta(workspace);
const pageMetas = useBlockSuiteDocMeta(workspace);
const { isPreferredEdgeless } = usePageHelper(workspace);
const pageMap = useMemo(
() => Object.fromEntries(pageMetas.map(page => [page.id, page])),
@ -29,7 +29,7 @@ export const useAllPageListConfig = () => {
);
const t = useAFFiNEI18N();
const onToggleFavoritePage = useCallback(
(page: PageMeta) => {
(page: DocMeta) => {
const status = page.favorite;
toggleFavorite(page.id);
toast(

View File

@ -1,5 +1,5 @@
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { usePageMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteWorkspaceHelper } from '@affine/core/hooks/use-block-suite-workspace-helper';
import { CollectionService } from '@affine/core/modules/collection';
import { PageRecordList, useService } from '@toeverything/infra';
@ -13,76 +13,76 @@ import { useReferenceLinkHelper } from './use-reference-link-helper';
export function useBlockSuiteMetaHelper(
blockSuiteWorkspace: BlockSuiteWorkspace
) {
const { setPageMeta, getPageMeta, setPageReadonly, setPageTitle } =
usePageMetaHelper(blockSuiteWorkspace);
const { setDocMeta, getDocMeta, setDocReadonly, setDocTitle } =
useDocMetaHelper(blockSuiteWorkspace);
const { addReferenceLink } = useReferenceLinkHelper(blockSuiteWorkspace);
const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
const { createDoc } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
const { openPage } = useNavigateHelper();
const collectionService = useService(CollectionService);
const pageRecordList = useService(PageRecordList);
const addToFavorite = useCallback(
(pageId: string) => {
setPageMeta(pageId, {
setDocMeta(pageId, {
favorite: true,
});
},
[setPageMeta]
[setDocMeta]
);
const removeFromFavorite = useCallback(
(pageId: string) => {
setPageMeta(pageId, {
setDocMeta(pageId, {
favorite: false,
});
},
[setPageMeta]
[setDocMeta]
);
const toggleFavorite = useCallback(
(pageId: string) => {
const { favorite } = getPageMeta(pageId) ?? {};
setPageMeta(pageId, {
const { favorite } = getDocMeta(pageId) ?? {};
setDocMeta(pageId, {
favorite: !favorite,
});
},
[getPageMeta, setPageMeta]
[getDocMeta, setDocMeta]
);
// TODO-Doma
// "Remove" may cause ambiguity here. Consider renaming as "moveToTrash".
const removeToTrash = useCallback(
(pageId: string) => {
setPageMeta(pageId, {
setDocMeta(pageId, {
trash: true,
trashDate: Date.now(),
trashRelate: undefined,
});
setPageReadonly(pageId, true);
setDocReadonly(pageId, true);
collectionService.deletePagesFromCollections([pageId]);
},
[collectionService, setPageMeta, setPageReadonly]
[collectionService, setDocMeta, setDocReadonly]
);
const restoreFromTrash = useCallback(
(pageId: string) => {
const { trashRelate } = getPageMeta(pageId) ?? {};
const { trashRelate } = getDocMeta(pageId) ?? {};
if (trashRelate) {
addReferenceLink(trashRelate, pageId);
}
setPageMeta(pageId, {
setDocMeta(pageId, {
trash: false,
trashDate: undefined,
trashRelate: undefined,
});
setPageReadonly(pageId, false);
setDocReadonly(pageId, false);
},
[addReferenceLink, getPageMeta, setPageMeta, setPageReadonly]
[addReferenceLink, getDocMeta, setDocMeta, setDocReadonly]
);
const permanentlyDeletePage = useCallback(
(pageId: string) => {
blockSuiteWorkspace.removePage(pageId);
blockSuiteWorkspace.removeDoc(pageId);
},
[blockSuiteWorkspace]
);
@ -92,11 +92,11 @@ export function useBlockSuiteMetaHelper(
*/
const publicPage = useCallback(
(pageId: string) => {
setPageMeta(pageId, {
setDocMeta(pageId, {
isPublic: true,
});
},
[setPageMeta]
[setDocMeta]
);
/**
@ -104,21 +104,21 @@ export function useBlockSuiteMetaHelper(
*/
const cancelPublicPage = useCallback(
(pageId: string) => {
setPageMeta(pageId, {
setDocMeta(pageId, {
isPublic: false,
});
},
[setPageMeta]
[setDocMeta]
);
const duplicate = useAsyncCallback(
async (pageId: string, openPageAfterDuplication: boolean = true) => {
const currentPageMode = pageRecordList.record(pageId).value?.mode.value;
const currentPageMeta = getPageMeta(pageId);
const newPage = createPage();
const currentPage = blockSuiteWorkspace.getPage(pageId);
const currentPageMeta = getDocMeta(pageId);
const newPage = createDoc();
const currentPage = blockSuiteWorkspace.getDoc(pageId);
newPage.waitForLoaded();
newPage.load();
if (!currentPageMeta || !currentPage) {
return;
}
@ -126,7 +126,7 @@ export function useBlockSuiteMetaHelper(
const update = encodeStateAsUpdate(currentPage.spaceDoc);
applyUpdate(newPage.spaceDoc, update);
setPageMeta(newPage.id, {
setDocMeta(newPage.id, {
tags: currentPageMeta.tags,
favorite: currentPageMeta.favorite,
});
@ -141,17 +141,17 @@ export function useBlockSuiteMetaHelper(
pageRecordList
.record(newPage.id)
.value?.setMode(currentPageMode || 'page');
setPageTitle(newPage.id, newPageTitle);
setDocTitle(newPage.id, newPageTitle);
openPageAfterDuplication && openPage(blockSuiteWorkspace.id, newPage.id);
},
[
blockSuiteWorkspace,
createPage,
getPageMeta,
createDoc,
getDocMeta,
openPage,
pageRecordList,
setPageMeta,
setPageTitle,
setDocMeta,
setDocTitle,
]
);

View File

@ -5,13 +5,13 @@ import {
import { pushNotificationAtom } from '@affine/component/notification-center';
import { apis } from '@affine/electron-api';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { PageService } from '@blocksuite/blocks';
import type { PageRootService } from '@blocksuite/blocks';
import {
HtmlTransformer,
MarkdownTransformer,
type PageBlockModel,
type RootBlockModel,
} from '@blocksuite/blocks';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import { useSetAtom } from 'jotai';
import { nanoid } from 'nanoid';
import { useCallback } from 'react';
@ -19,27 +19,27 @@ import { useCallback } from 'react';
type ExportType = 'pdf' | 'html' | 'png' | 'markdown';
interface ExportHandlerOptions {
page: Page;
page: Doc;
type: ExportType;
}
async function exportHandler({ page, type }: ExportHandlerOptions) {
const editorRoot = document.querySelector('editor-host');
let pageService: PageService | null = null;
let pageService: PageRootService | null = null;
if (editorRoot) {
pageService = editorRoot.spec.getService('affine:page') as PageService;
pageService = editorRoot.spec.getService<PageRootService>('affine:page');
}
switch (type) {
case 'html':
await HtmlTransformer.exportPage(page);
await HtmlTransformer.exportDoc(page);
break;
case 'markdown':
await MarkdownTransformer.exportPage(page);
await MarkdownTransformer.exportDoc(page);
break;
case 'pdf':
if (environment.isDesktop && page.meta.mode === 'page') {
if (environment.isDesktop && page.meta?.mode === 'page') {
await apis?.export.savePDFFileAs(
(page.root as PageBlockModel).title.toString()
(page.root as RootBlockModel).title.toString()
);
} else {
if (!pageService) return;
@ -54,7 +54,7 @@ async function exportHandler({ page, type }: ExportHandlerOptions) {
}
}
export const useExportPage = (page: Page) => {
export const useExportPage = (page: Doc) => {
const pushNotification = useSetAtom(pushNotificationAtom);
const pushGlobalLoadingEvent = useSetAtom(pushGlobalLoadingEventAtom);
const resolveGlobalLoadingEvent = useSetAtom(resolveGlobalLoadingEventAtom);

View File

@ -7,7 +7,7 @@ export function useReferenceLinkHelper(
) {
const addReferenceLink = useCallback(
(pageId: string, referenceId: string) => {
const page = blockSuiteWorkspace?.getPage(pageId);
const page = blockSuiteWorkspace?.getDoc(pageId);
if (!page) {
return;
}

View File

@ -1,10 +1,10 @@
import { toast } from '@affine/component';
import { usePageMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { WorkspaceFlavour } from '@affine/env/workspace';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { assertExists } from '@blocksuite/global/utils';
import { EdgelessIcon, HistoryIcon, PageIcon } from '@blocksuite/icons';
import { Page, useLiveData, Workspace } from '@toeverything/infra';
import { Doc, useLiveData, Workspace } from '@toeverything/infra';
import {
PreconditionStrategy,
registerAffineCommand,
@ -19,16 +19,16 @@ import { useExportPage } from './use-export-page';
import { useTrashModalHelper } from './use-trash-modal-helper';
export function useRegisterBlocksuiteEditorCommands() {
const page = useService(Page);
const page = useService(Doc);
const pageId = page.id;
const mode = useLiveData(page.mode);
const t = useAFFiNEI18N();
const workspace = useService(Workspace);
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
const { getPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
const currentPage = blockSuiteWorkspace.getPage(pageId);
const { getDocMeta } = useDocMetaHelper(blockSuiteWorkspace);
const currentPage = blockSuiteWorkspace.getDoc(pageId);
assertExists(currentPage);
const pageMeta = getPageMeta(pageId);
const pageMeta = getDocMeta(pageId);
assertExists(pageMeta);
const favorite = pageMeta.favorite ?? false;
const trash = pageMeta.trash ?? false;

View File

@ -1,6 +1,6 @@
import { toast } from '@affine/component';
import type { DraggableTitleCellData } from '@affine/core/components/page-list';
import { usePageMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { DragEndEvent, UniqueIdentifier } from '@dnd-kit/core';
import { Workspace } from '@toeverything/infra';
@ -74,7 +74,7 @@ export const useSidebarDrag = () => {
const { setTrashModal } = useTrashModalHelper(workspace);
const { addToFavorite, removeFromFavorite } =
useBlockSuiteMetaHelper(workspace);
const { getPageMeta } = usePageMetaHelper(workspace);
const { getDocMeta } = useDocMetaHelper(workspace);
const isDropArea = useCallback(
(id: UniqueIdentifier | undefined, prefix: string) => {
@ -109,7 +109,7 @@ export const useSidebarDrag = () => {
const processMoveToTrashDrag = useCallback(
(e: DragEndEvent) => {
const { pageId } = e.active.data.current as DraggableTitleCellData;
const pageTitle = getPageMeta(pageId)?.title ?? t['Untitled']();
const pageTitle = getDocMeta(pageId)?.title ?? t['Untitled']();
processDrag(e, DropPrefix.SidebarTrash, pageId => {
setTrashModal({
open: true,
@ -118,13 +118,13 @@ export const useSidebarDrag = () => {
});
});
},
[getPageMeta, processDrag, setTrashModal, t]
[getDocMeta, processDrag, setTrashModal, t]
);
const processFavouritesDrag = useCallback(
(e: DragEndEvent) => {
const { pageId } = e.active.data.current as DraggableTitleCellData;
const isFavourited = getPageMeta(pageId)?.favorite;
const isFavourited = getDocMeta(pageId)?.favorite;
const isFavouriteDrag = String(e.over?.id).startsWith(
DropPrefix.SidebarFavorites
);
@ -136,7 +136,7 @@ export const useSidebarDrag = () => {
toast(t['com.affine.cmdk.affine.editor.add-to-favourites']());
});
},
[getPageMeta, processDrag, addToFavorite, t]
[getDocMeta, processDrag, addToFavorite, t]
);
const processRemoveDrag = useCallback(

View File

@ -20,7 +20,7 @@ const useReactiveAdapter = (adapter: WorkspacePropertiesAdapter) => {
}
const disposables: (() => void)[] = [];
disposables.push(
adapter.workspace.blockSuiteWorkspace.meta.pageMetasUpdated.on(observe)
adapter.workspace.blockSuiteWorkspace.meta.docMetaUpdated.on(observe)
.dispose
);
adapter.properties.observeDeep(observe);

View File

@ -1,25 +1,25 @@
import type { PageMeta, Workspace } from '@blocksuite/store';
import type { DocMeta, Workspace } from '@blocksuite/store';
import type { Atom } from 'jotai';
import { atom, useAtomValue } from 'jotai';
const weakMap = new WeakMap<Workspace, Atom<PageMeta[]>>();
const weakMap = new WeakMap<Workspace, Atom<DocMeta[]>>();
// this hook is extracted from './use-block-suite-page-meta.ts' to avoid circular dependency
export function useAllBlockSuitePageMeta(
export function useAllBlockSuiteDocMeta(
blockSuiteWorkspace: Workspace
): PageMeta[] {
): DocMeta[] {
if (!weakMap.has(blockSuiteWorkspace)) {
const baseAtom = atom<PageMeta[]>(blockSuiteWorkspace.meta.pageMetas);
const baseAtom = atom<DocMeta[]>(blockSuiteWorkspace.meta.docMetas);
weakMap.set(blockSuiteWorkspace, baseAtom);
baseAtom.onMount = set => {
set(blockSuiteWorkspace.meta.pageMetas);
const dispose = blockSuiteWorkspace.meta.pageMetasUpdated.on(() => {
set(blockSuiteWorkspace.meta.pageMetas);
set(blockSuiteWorkspace.meta.docMetas);
const dispose = blockSuiteWorkspace.meta.docMetaUpdated.on(() => {
set(blockSuiteWorkspace.meta.docMetas);
});
return () => {
dispose.dispose();
};
};
}
return useAtomValue(weakMap.get(blockSuiteWorkspace) as Atom<PageMeta[]>);
return useAtomValue(weakMap.get(blockSuiteWorkspace) as Atom<DocMeta[]>);
}

View File

@ -1,17 +1,17 @@
import type { Page, Workspace } from '@blocksuite/store';
import type { Doc, Workspace } from '@blocksuite/store';
import { type Atom, atom, useAtomValue } from 'jotai';
import { useBlockSuiteWorkspacePage } from './use-block-suite-workspace-page';
const weakMap = new WeakMap<Page, Atom<string[]>>();
function getPageBacklinks(page: Page): string[] {
const weakMap = new WeakMap<Doc, Atom<string[]>>();
function getPageBacklinks(page: Doc): string[] {
return page.workspace.indexer.backlink
.getBacklink(page.id)
.map(linkNode => linkNode.pageId)
.filter(id => id !== page.id);
}
const getPageBacklinksAtom = (page: Page | null) => {
const getPageBacklinksAtom = (page: Doc | null) => {
if (!page) {
return atom([]);
}

View File

@ -1,9 +1,9 @@
import type { PageBlockModel } from '@blocksuite/blocks';
import type { RootBlockModel } from '@blocksuite/blocks';
import { assertExists } from '@blocksuite/global/utils';
import type { PageMeta, Workspace } from '@blocksuite/store';
import type { DocMeta, Workspace } from '@blocksuite/store';
import { useMemo } from 'react';
import { useAllBlockSuitePageMeta } from './use-all-block-suite-page-meta';
import { useAllBlockSuiteDocMeta } from './use-all-block-suite-page-meta';
import { useJournalHelper } from './use-journal';
/**
@ -11,8 +11,8 @@ import { useJournalHelper } from './use-journal';
* If you want to get all pageMetas, use `useAllBlockSuitePageMeta` instead
* @returns
*/
export function useBlockSuitePageMeta(blocksuiteWorkspace: Workspace) {
const pageMetas = useAllBlockSuitePageMeta(blocksuiteWorkspace);
export function useBlockSuiteDocMeta(blocksuiteWorkspace: Workspace) {
const pageMetas = useAllBlockSuiteDocMeta(blocksuiteWorkspace);
const { isPageJournal } = useJournalHelper(blocksuiteWorkspace);
return useMemo(
() =>
@ -23,32 +23,32 @@ export function useBlockSuitePageMeta(blocksuiteWorkspace: Workspace) {
);
}
export function usePageMetaHelper(blockSuiteWorkspace: Workspace) {
export function useDocMetaHelper(blockSuiteWorkspace: Workspace) {
return useMemo(
() => ({
setPageTitle: (pageId: string, newTitle: string) => {
const page = blockSuiteWorkspace.getPage(pageId);
setDocTitle: (docId: string, newTitle: string) => {
const page = blockSuiteWorkspace.getDoc(docId);
assertExists(page);
const pageBlock = page
.getBlockByFlavour('affine:page')
.at(0) as PageBlockModel;
.at(0) as RootBlockModel;
assertExists(pageBlock);
page.transact(() => {
pageBlock.title.delete(0, pageBlock.title.length);
pageBlock.title.insert(newTitle, 0);
});
blockSuiteWorkspace.meta.setPageMeta(pageId, { title: newTitle });
blockSuiteWorkspace.meta.setDocMeta(docId, { title: newTitle });
},
setPageReadonly: (pageId: string, readonly: boolean) => {
const page = blockSuiteWorkspace.getPage(pageId);
setDocReadonly: (docId: string, readonly: boolean) => {
const page = blockSuiteWorkspace.getDoc(docId);
assertExists(page);
page.awarenessStore.setReadonly(page, readonly);
},
setPageMeta: (pageId: string, pageMeta: Partial<PageMeta>) => {
blockSuiteWorkspace.meta.setPageMeta(pageId, pageMeta);
setDocMeta: (docId: string, docMeta: Partial<DocMeta>) => {
blockSuiteWorkspace.meta.setDocMeta(docId, docMeta);
},
getPageMeta: (pageId: string) => {
return blockSuiteWorkspace.meta.getPageMeta(pageId);
getDocMeta: (docId: string) => {
return blockSuiteWorkspace.meta.getDocMeta(docId);
},
}),
[blockSuiteWorkspace]

View File

@ -1,16 +1,16 @@
import type { Page, Workspace } from '@blocksuite/store';
import type { Doc, Workspace } from '@blocksuite/store';
import { type Atom, atom, useAtomValue } from 'jotai';
import { useBlockSuiteWorkspacePage } from './use-block-suite-workspace-page';
const weakMap = new WeakMap<Page, Atom<string[]>>();
function getPageReferences(page: Page): string[] {
const weakMap = new WeakMap<Doc, Atom<string[]>>();
function getPageReferences(page: Doc): string[] {
return Object.values(
page.workspace.indexer.backlink.linkIndexMap[page.id] ?? {}
).flatMap(linkNodes => linkNodes.map(linkNode => linkNode.pageId));
}
const getPageReferencesAtom = (page: Page | null) => {
const getPageReferencesAtom = (page: Doc | null) => {
if (!page) {
return atom([]);
}

View File

@ -1,11 +1,11 @@
import type { Page, Workspace } from '@blocksuite/store';
import type { Doc, Workspace } from '@blocksuite/store';
import { useMemo } from 'react';
export function useBlockSuiteWorkspaceHelper(blockSuiteWorkspace: Workspace) {
return useMemo(
() => ({
createPage: (pageId?: string): Page => {
return blockSuiteWorkspace.createPage({ id: pageId });
createDoc: (pageId?: string): Doc => {
return blockSuiteWorkspace.createDoc({ id: pageId });
},
}),
[blockSuiteWorkspace]

View File

@ -15,11 +15,11 @@ function getAtom(w: Workspace, pageId: string): Atom<string> {
const map = weakMap.get(w);
assertExists(map);
if (!map.has(pageId)) {
const baseAtom = atom<string>(w.getPage(pageId)?.meta.title || 'Untitled');
const baseAtom = atom<string>(w.getDoc(pageId)?.meta?.title || 'Untitled');
baseAtom.onMount = set => {
const disposable = w.meta.pageMetasUpdated.on(() => {
const page = w.getPage(pageId);
set(page?.meta.title || 'Untitled');
const disposable = w.meta.docMetaUpdated.on(() => {
const page = w.getDoc(pageId);
set(page?.meta?.title || 'Untitled');
});
return () => {
disposable.dispose();
@ -56,7 +56,7 @@ export function useGetBlockSuiteWorkspacePageTitle(
(pageId: string) => {
return (
getLocalizedJournalDateString(pageId) ||
blockSuiteWorkspace.getPage(pageId)?.meta.title
blockSuiteWorkspace.getDoc(pageId)?.meta?.title
);
},
[blockSuiteWorkspace, getLocalizedJournalDateString]

View File

@ -1,26 +1,26 @@
import { DisposableGroup } from '@blocksuite/global/utils';
import type { Page, Workspace } from '@blocksuite/store';
import type { Doc, Workspace } from '@blocksuite/store';
import { useEffect, useState } from 'react';
export function useBlockSuiteWorkspacePage(
blockSuiteWorkspace: Workspace,
pageId: string | null
): Page | null {
): Doc | null {
const [page, setPage] = useState(
pageId ? blockSuiteWorkspace.getPage(pageId) : null
pageId ? blockSuiteWorkspace.getDoc(pageId) : null
);
useEffect(() => {
const group = new DisposableGroup();
group.add(
blockSuiteWorkspace.slots.pageAdded.on(id => {
blockSuiteWorkspace.slots.docAdded.on(id => {
if (pageId === id) {
setPage(blockSuiteWorkspace.getPage(id));
setPage(blockSuiteWorkspace.getDoc(id));
}
})
);
group.add(
blockSuiteWorkspace.slots.pageRemoved.on(id => {
blockSuiteWorkspace.slots.docRemoved.on(id => {
if (pageId === id) {
setPage(null);
}

View File

@ -32,9 +32,9 @@ export const useJournalHelper = (workspace: BlockSuiteWorkspace) => {
const _createJournal = useCallback(
(maybeDate: MaybeDate) => {
const title = dayjs(maybeDate).format(JOURNAL_DATE_FORMAT);
const page = bsWorkspaceHelper.createPage();
const page = bsWorkspaceHelper.createDoc();
// set created date to match the journal date
page.workspace.setPageMeta(page.id, {
page.workspace.setDocMeta(page.id, {
createDate: dayjs(maybeDate).toDate().getTime(),
});
initEmptyPage(page, title);
@ -57,16 +57,16 @@ export const useJournalHelper = (workspace: BlockSuiteWorkspace) => {
const getJournalsByDate = useCallback(
(maybeDate: MaybeDate) => {
const day = dayjs(maybeDate);
return Array.from(workspace.pages.values()).filter(page => {
return Array.from(workspace.docs.values()).filter(page => {
const pageId = page.id;
if (!isPageJournal(pageId)) return false;
if (page.meta.trash) return false;
if (page.meta?.trash) return false;
const journalDate = adapter.getJournalPageDateString(page.id);
if (!journalDate) return false;
return day.isSame(journalDate, 'day');
});
},
[adapter, isPageJournal, workspace.pages]
[adapter, isPageJournal, workspace.docs]
);
/**

View File

@ -3,7 +3,7 @@ import {
appSidebarResizingAtom,
} from '@affine/component/app-sidebar';
import { MainContainer, WorkspaceFallback } from '@affine/component/workspace';
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useWorkspaceStatus } from '@affine/core/hooks/use-workspace-status';
import { assertExists } from '@blocksuite/global/utils';
import {
@ -58,7 +58,7 @@ export const QuickSearch = () => {
const currentWorkspace = useService(Workspace);
const { pageId } = useParams();
const blockSuiteWorkspace = currentWorkspace.blockSuiteWorkspace;
const pageMeta = useBlockSuitePageMeta(
const pageMeta = useBlockSuiteDocMeta(
currentWorkspace.blockSuiteWorkspace
).find(meta => meta.id === pageId);

View File

@ -1,4 +1,4 @@
import type { PagesPropertiesMeta, Tag } from '@blocksuite/store';
import type { DocsPropertiesMeta, Tag } from '@blocksuite/store';
import { LiveData } from '@toeverything/infra/livedata';
import type { Workspace } from '@toeverything/infra/workspace';
import { Observable } from 'rxjs';
@ -20,18 +20,18 @@ export class WorkspaceLegacyProperties {
return this.properties.tags?.options ?? [];
}
updateProperties = (properties: PagesPropertiesMeta) => {
updateProperties = (properties: DocsPropertiesMeta) => {
this.workspace.blockSuiteWorkspace.meta.setProperties(properties);
};
subscribe(cb: () => void) {
const disposable =
this.workspace.blockSuiteWorkspace.meta.pageMetasUpdated.on(cb);
this.workspace.blockSuiteWorkspace.meta.docMetaUpdated.on(cb);
return disposable.dispose;
}
properties$ = LiveData.from(
new Observable<PagesPropertiesMeta>(sub => {
new Observable<DocsPropertiesMeta>(sub => {
return this.subscribe(() => sub.next(this.properties));
}),
this.properties
@ -61,11 +61,11 @@ export class WorkspaceLegacyProperties {
this.workspace.blockSuiteWorkspace.doc.transact(() => {
this.updateTagOptions(this.tagOptions.filter(o => o.id !== id));
// need to remove tag from all pages
this.workspace.blockSuiteWorkspace.pages.forEach(page => {
const tags = page.meta.tags ?? [];
this.workspace.blockSuiteWorkspace.docs.forEach(doc => {
const tags = doc.meta?.tags ?? [];
if (tags.includes(id)) {
this.updatePageTags(
page.id,
doc.id,
tags.filter(t => t !== id)
);
}
@ -74,7 +74,7 @@ export class WorkspaceLegacyProperties {
};
updatePageTags = (pageId: string, tags: string[]) => {
this.workspace.blockSuiteWorkspace.setPageMeta(pageId, {
this.workspace.blockSuiteWorkspace.setDocMeta(pageId, {
tags,
});
};

View File

@ -10,7 +10,7 @@ import {
StaticBlobStorage,
} from '@affine/workspace-impl';
import { Logo1Icon } from '@blocksuite/icons';
import type { Page } from '@toeverything/infra';
import type { Doc } from '@toeverything/infra';
import {
EmptyBlobStorage,
LocalBlobStorage,
@ -130,7 +130,7 @@ export const Component = () => {
const currentWorkspace = useService(CurrentWorkspaceService);
const t = useAFFiNEI18N();
const [page, setPage] = useState<Page | null>(null);
const [page, setPage] = useState<Doc | null>(null);
useEffect(() => {
// create a workspace for share page
@ -163,7 +163,7 @@ export const Component = () => {
const { page } = workspace.services.get(PageManager).open(pageId);
workspace.blockSuiteWorkspace.awarenessStore.setReadonly(
page.blockSuitePage,
page.blockSuiteDoc,
true
);
@ -200,14 +200,14 @@ export const Component = () => {
<ShareHeader
pageId={page.id}
publishMode={publishMode}
blockSuiteWorkspace={page.blockSuitePage.workspace}
blockSuiteWorkspace={page.blockSuiteDoc.workspace}
/>
<Scrollable.Root>
<Scrollable.Viewport className={styles.editorContainer}>
<PageDetailEditor
isPublic
publishMode={publishMode}
workspace={page.blockSuitePage.workspace}
workspace={page.blockSuiteDoc.workspace}
pageId={page.id}
onLoad={() => noop}
/>

View File

@ -4,7 +4,7 @@ import {
useFilteredPageMetas,
VirtualizedPageList,
} from '@affine/core/components/page-list';
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useNavigateHelper } from '@affine/core/hooks/use-navigate-helper';
import { performanceRenderLogger } from '@affine/core/shared';
import type { Filter } from '@affine/env/filter';
@ -18,7 +18,7 @@ import { AllPageHeader } from './all-page-header';
export const AllPage = () => {
const currentWorkspace = useService(Workspace);
const pageMetas = useBlockSuitePageMeta(currentWorkspace.blockSuiteWorkspace);
const pageMetas = useBlockSuiteDocMeta(currentWorkspace.blockSuiteWorkspace);
const [hideHeaderCreateNew, setHideHeaderCreateNew] = useState(true);
const [filters, setFilters] = useState<Filter[]>([]);
@ -58,10 +58,10 @@ export const Component = () => {
useEffect(() => {
function checkJumpOnce() {
for (const [pageId] of currentWorkspace.blockSuiteWorkspace.pages) {
const page = currentWorkspace.blockSuiteWorkspace.getPage(pageId);
if (page && page.meta.jumpOnce) {
currentWorkspace.blockSuiteWorkspace.meta.setPageMeta(page.id, {
for (const [pageId] of currentWorkspace.blockSuiteWorkspace.docs) {
const page = currentWorkspace.blockSuiteWorkspace.getDoc(pageId);
if (page && page.meta?.jumpOnce) {
currentWorkspace.blockSuiteWorkspace.meta.setDocMeta(page.id, {
jumpOnce: false,
});
navigateHelper.jumpToPage(currentWorkspace.id, pageId);
@ -69,7 +69,7 @@ export const Component = () => {
}
}
checkJumpOnce();
return currentWorkspace.blockSuiteWorkspace.slots.pagesUpdated.on(
return currentWorkspace.blockSuiteWorkspace.slots.docUpdated.on(
checkJumpOnce
).dispose;
}, [

View File

@ -4,7 +4,7 @@ import {
TagListHeader,
VirtualizedTagList,
} from '@affine/core/components/page-list/tags';
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useService } from '@toeverything/infra';
import { Workspace } from '@toeverything/infra';
@ -14,7 +14,7 @@ import { AllTagHeader } from './header';
export const AllTag = () => {
const currentWorkspace = useService(Workspace);
const pageMetas = useBlockSuitePageMeta(currentWorkspace.blockSuiteWorkspace);
const pageMetas = useBlockSuiteDocMeta(currentWorkspace.blockSuiteWorkspace);
const { tags, tagMetas, deleteTags } = useTagMetas(
currentWorkspace.blockSuiteWorkspace,

View File

@ -12,7 +12,7 @@ import { PageHeaderMenuButton } from '@affine/core/components/blocksuite/block-s
import { EditorModeSwitch } from '@affine/core/components/blocksuite/block-suite-mode-switch';
import { useJournalInfoHelper } from '@affine/core/hooks/use-journal';
import { RightSidebarIcon } from '@blocksuite/icons';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import type { Workspace } from '@toeverything/infra';
import { useAtomValue, useSetAtom } from 'jotai';
import { useCallback, useRef } from 'react';
@ -104,7 +104,7 @@ function Header({
}
interface PageHeaderProps {
page: Page;
page: Doc;
workspace: Workspace;
showSidebarSwitch?: boolean;
}
@ -178,7 +178,7 @@ export function NormalPageHeader({
export function DetailPageHeader(props: PageHeaderProps) {
const { page } = props;
const { isJournal } = useJournalInfoHelper(page.workspace, page.id);
const isInTrash = page.meta.trash;
const isInTrash = page.meta?.trash;
return isJournal && !isInTrash ? (
<JournalPageHeader {...props} />
@ -189,7 +189,7 @@ export function DetailPageHeader(props: PageHeaderProps) {
interface SidebarHeaderProps {
workspace: Workspace;
page: Page;
page: Doc;
}
function WindowsSidebarHeader(props: SidebarHeaderProps) {
return (

View File

@ -1,8 +1,7 @@
import { Scrollable } from '@affine/component';
import { PageDetailSkeleton } from '@affine/component/page-detail-skeleton';
import { ResizePanel } from '@affine/component/resize-panel';
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import type { PageService } from '@blocksuite/blocks';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import {
BookmarkService,
customImageProxyMiddleware,
@ -12,10 +11,10 @@ import {
ImageService,
} from '@blocksuite/blocks';
import type { AffineEditorContainer } from '@blocksuite/presets';
import type { Page as BlockSuitePage } from '@blocksuite/store';
import type { Doc as BlockSuiteDoc } from '@blocksuite/store';
import {
Doc,
globalBlockSuiteSchema,
Page,
PageManager,
PageRecordList,
ServiceProviderContext,
@ -109,14 +108,14 @@ const DetailPageLayout = ({
};
const DetailPageImpl = memo(function DetailPageImpl() {
const page = useService(Page);
const page = useService(Doc);
const pageRecordList = useService(PageRecordList);
const currentPageId = page.id;
const { openPage, jumpToTag } = useNavigateHelper();
const currentWorkspace = useService(Workspace);
const blockSuiteWorkspace = currentWorkspace.blockSuiteWorkspace;
const pageMeta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
const pageMeta = useBlockSuiteDocMeta(blockSuiteWorkspace).find(
meta => meta.id === page.id
);
@ -128,7 +127,7 @@ const DetailPageImpl = memo(function DetailPageImpl() {
usePageDocumentTitle(title);
const onLoad = useCallback(
(bsPage: BlockSuitePage, editor: AffineEditorContainer) => {
(bsPage: BlockSuiteDoc, editor: AffineEditorContainer) => {
try {
// todo(joooye34): improve the following migration code
const surfaceBlock = bsPage.getBlockByFlavour('affine:surface')[0];
@ -139,7 +138,7 @@ const DetailPageImpl = memo(function DetailPageImpl() {
'type'
) !== '$blocksuite:internal:native$'
) {
globalBlockSuiteSchema.upgradePage(
globalBlockSuiteSchema.upgradeDoc(
0,
{
'affine:surface': 3,
@ -165,12 +164,10 @@ const DetailPageImpl = memo(function DetailPageImpl() {
EmbedLoomService.setLinkPreviewEndpoint(runtimeConfig.linkPreviewUrl);
// provide page mode and updated date to blocksuite
const pageService = editorHost.std.spec.getService(
'affine:page'
) as PageService;
pageService.getPageMode = (pageId: string) =>
const pageService = editorHost.std.spec.getService('affine:page');
pageService.getEditorMode = (pageId: string) =>
pageRecordList.record(pageId).value?.mode.value ?? 'page';
pageService.getPageUpdatedAt = (pageId: string) => {
pageService.getDocUpdatedAt = (pageId: string) => {
const linkedPage = pageRecordList.record(pageId).value;
if (!linkedPage) return new Date();
@ -181,8 +178,8 @@ const DetailPageImpl = memo(function DetailPageImpl() {
page.setMode(mode);
// fixme: it seems pageLinkClicked is not triggered sometimes?
const dispose = editor.slots.pageLinkClicked.on(({ pageId }) => {
return openPage(blockSuiteWorkspace.id, pageId);
const dispose = editor.slots.docLinkClicked.on(({ docId }) => {
return openPage(blockSuiteWorkspace.id, docId);
});
const disposeTagClick = editor.slots.tagClicked.on(({ tagId }) => {
jumpToTag(currentWorkspace.id, tagId);
@ -209,7 +206,7 @@ const DetailPageImpl = memo(function DetailPageImpl() {
header={
<>
<DetailPageHeader
page={page.blockSuitePage}
page={page.blockSuiteDoc}
workspace={currentWorkspace}
showSidebarSwitch={!isInTrash}
/>
@ -238,11 +235,11 @@ const DetailPageImpl = memo(function DetailPageImpl() {
<div className={styles.sidebarContainerInner}>
<RightSidebarHeader
workspace={currentWorkspace}
page={page.blockSuitePage}
page={page.blockSuiteDoc}
/>
<EditorSidebar
workspace={blockSuiteWorkspace}
page={page.blockSuitePage}
page={page.blockSuiteDoc}
/>
</div>
) : null
@ -271,7 +268,7 @@ export const DetailPage = ({ pageId }: { pageId: string }): ReactElement => {
const pageManager = useService(PageManager);
const [page, setPage] = useState<Page | null>(null);
const [page, setPage] = useState<Doc | null>(null);
useEffect(() => {
if (!pageRecord) {

View File

@ -2,7 +2,7 @@ import { IconButton } from '@affine/component';
import { useJournalInfoHelper } from '@affine/core/hooks/use-journal';
import { useWorkspaceEnabledFeatures } from '@affine/core/hooks/use-workspace-features';
import { FeatureType } from '@affine/graphql';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
import type { Workspace } from '@toeverything/infra';
import { assignInlineVars } from '@vanilla-extract/dynamic';
import { useAtom, useAtomValue } from 'jotai';
@ -16,7 +16,7 @@ import * as styles from './extensions.css';
export interface ExtensionTabsProps {
workspace: Workspace;
page: Page;
page: Doc;
}
// provide a switcher for active extensions

View File

@ -7,7 +7,7 @@ import {
} from '@affine/component';
import { MoveToTrash } from '@affine/core/components/page-list';
import { useTrashModalHelper } from '@affine/core/hooks/affine/use-trash-modal-helper';
import { useBlockSuitePageMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteWorkspacePageTitle } from '@affine/core/hooks/use-block-suite-workspace-page-title';
import {
useJournalHelper,
@ -23,7 +23,7 @@ import {
PageIcon,
TodayIcon,
} from '@blocksuite/icons';
import type { Page, PageMeta } from '@blocksuite/store';
import type { Doc, DocMeta } from '@blocksuite/store';
import { assignInlineVars } from '@vanilla-extract/dynamic';
import clsx from 'clsx';
import dayjs from 'dayjs';
@ -44,7 +44,7 @@ const CountDisplay = ({
return <span {...attrs}>{count > max ? `${max}+` : count}</span>;
};
interface PageItemProps extends HTMLAttributes<HTMLDivElement> {
pageMeta: PageMeta;
pageMeta: DocMeta;
workspace: BlockSuiteWorkspace;
right?: ReactNode;
}
@ -156,7 +156,7 @@ const EditorJournalPanel = (props: EditorExtensionProps) => {
};
const sortPagesByDate = (
pages: PageMeta[],
pages: DocMeta[],
field: 'updatedDate' | 'createDate',
order: 'asc' | 'desc' = 'desc'
) => {
@ -180,7 +180,7 @@ const JournalDailyCountBlock = ({ workspace, date }: JournalBlockProps) => {
const nodeRef = useRef<HTMLDivElement>(null);
const t = useAFFiNEI18N();
const [activeItem, setActiveItem] = useState<NavItemName>('createdToday');
const pageMetas = useBlockSuitePageMeta(workspace);
const pageMetas = useBlockSuiteDocMeta(workspace);
const navigateHelper = useNavigateHelper();
@ -289,7 +289,7 @@ interface ConflictListProps
extends JournalBlockProps,
PropsWithChildren,
HTMLAttributes<HTMLDivElement> {
pages: Page[];
pages: Doc[];
}
const ConflictList = ({
page: currentPage,
@ -303,7 +303,7 @@ const ConflictList = ({
const { setTrashModal } = useTrashModalHelper(workspace);
const handleOpenTrashModal = useCallback(
(page: Page) => {
(page: Doc) => {
if (!page.meta) return;
setTrashModal({
open: true,
@ -320,9 +320,9 @@ const ConflictList = ({
const isCurrent = page.id === currentPage.id;
return (
<PageItem
aria-label={page.meta.title}
aria-label={page.meta?.title}
aria-selected={isCurrent}
pageMeta={page.meta}
pageMeta={page.meta as DocMeta}
workspace={workspace}
key={page.id}
right={

View File

@ -1,11 +1,11 @@
import type { BlockSuiteWorkspace } from '@affine/core/shared';
import type { Page } from '@blocksuite/store';
import type { Doc } from '@blocksuite/store';
export type EditorExtensionName = 'outline' | 'frame' | 'copilot' | 'journal';
export interface EditorExtensionProps {
workspace: BlockSuiteWorkspace;
page: Page;
page: Doc;
}
export interface EditorExtension {

Some files were not shown because too many files have changed in this diff Show More