<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Documents now automatically track and display "created by" and "updated by" user information. - Document creation and update timestamps are now managed and shown more accurately. - Workspace and document metadata (name, avatar) updates are more responsive and reliable. - Document creation supports middleware for customizing properties and behavior. - **Improvements** - Simplified and unified event handling for document list updates, reducing redundant event subscriptions. - Enhanced integration of editor and theme settings into the document creation process. - Explicit Yjs document initialization for improved workspace stability and reliability. - Consolidated journal-related metadata display in document icons and titles for clarity. - **Bug Fixes** - Fixed inconsistencies in how workspace and document names are set and updated. - Improved accuracy of "last updated" indicators by handling timestamps automatically. - **Refactor** - Removed deprecated event subjects and direct metadata manipulation in favor of more robust, reactive patterns. - Streamlined document creation logic across various features (quick search, journal, recording, etc.). - Simplified user avatar display components and removed cloud metadata dependencies. - Removed legacy editor setting and theme service dependencies from multiple modules. - **Chores** - Updated internal APIs and interfaces to support new metadata and event handling mechanisms. - Cleaned up unused code and dependencies related to editor settings and theme services. - Skipped flaky end-to-end test to improve test suite stability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
// the following import is used to ensure the block suite editor effects are run
|
|
import '../blocksuite/block-suite-editor';
|
|
|
|
import { DebugLogger } from '@affine/debug';
|
|
import { DEFAULT_WORKSPACE_NAME } from '@affine/env/constant';
|
|
import onboardingUrl from '@affine/templates/onboarding.zip';
|
|
import { ZipTransformer } from '@blocksuite/affine/widgets/linked-doc';
|
|
|
|
import { DocsService } from '../modules/doc';
|
|
import { OrganizeService } from '../modules/organize';
|
|
import {
|
|
getAFFiNEWorkspaceSchema,
|
|
type WorkspacesService,
|
|
} from '../modules/workspace';
|
|
|
|
export async function buildShowcaseWorkspace(
|
|
workspacesService: WorkspacesService,
|
|
flavour: string,
|
|
workspaceName: string
|
|
) {
|
|
const meta = await workspacesService.create(flavour, async docCollection => {
|
|
docCollection.meta.initialize();
|
|
docCollection.doc.getMap('meta').set('name', workspaceName);
|
|
const blob = await (await fetch(onboardingUrl)).blob();
|
|
|
|
await ZipTransformer.importDocs(
|
|
docCollection,
|
|
getAFFiNEWorkspaceSchema(),
|
|
blob
|
|
);
|
|
});
|
|
|
|
const { workspace, dispose } = workspacesService.open({ metadata: meta });
|
|
|
|
await workspace.engine.doc.waitForDocReady(workspace.id);
|
|
|
|
const docsService = workspace.scope.get(DocsService);
|
|
|
|
// should jump to "Getting Started"
|
|
const defaultDoc = docsService.list.docs$.value.find(p =>
|
|
p.title$.value.startsWith('Getting Started')
|
|
);
|
|
const folderTutorialDoc = docsService.list.docs$.value.find(p =>
|
|
p.title$.value.startsWith('How to use folder and Tags')
|
|
);
|
|
|
|
// create default organize
|
|
if (folderTutorialDoc) {
|
|
const organizeService = workspace.scope.get(OrganizeService);
|
|
const folderId = organizeService.folderTree.rootFolder.createFolder(
|
|
'First Folder',
|
|
organizeService.folderTree.rootFolder.indexAt('after')
|
|
);
|
|
const firstFolderNode =
|
|
organizeService.folderTree.folderNode$(folderId).value;
|
|
firstFolderNode?.createLink(
|
|
'doc',
|
|
folderTutorialDoc.id,
|
|
firstFolderNode.indexAt('after')
|
|
);
|
|
}
|
|
|
|
dispose();
|
|
|
|
return { meta, defaultDocId: defaultDoc?.id };
|
|
}
|
|
|
|
const logger = new DebugLogger('createFirstAppData');
|
|
|
|
export async function createFirstAppData(workspacesService: WorkspacesService) {
|
|
if (localStorage.getItem('is-first-open') !== null) {
|
|
return;
|
|
}
|
|
localStorage.setItem('is-first-open', 'false');
|
|
const { meta, defaultDocId } = await buildShowcaseWorkspace(
|
|
workspacesService,
|
|
'local',
|
|
DEFAULT_WORKSPACE_NAME
|
|
);
|
|
logger.info('create first workspace', defaultDocId);
|
|
return { meta, defaultPageId: defaultDocId };
|
|
}
|