Files
AFFiNE-Mirror/blocksuite/playground/apps/starter/data/empty.ts
Saul-Mirone d859c4252b refactor(editor): move history from doc to store (#12131)
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Undo/redo history management is now centralized in the workspace, providing more consistent and robust undo/redo behavior.
  - History update events are emitted at the workspace level, enabling better tracking of changes.

- **Bug Fixes**
  - Improved reliability of undo/redo actions by shifting history management from documents to the workspace.

- **Documentation**
  - Updated and clarified documentation for history-related APIs, including improved examples and clearer descriptions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-05-05 09:24:09 +00:00

30 lines
838 B
TypeScript

import { Text, type Workspace } from '@blocksuite/affine/store';
import type { InitFn } from './utils.js';
export const empty: InitFn = (collection: Workspace, id: string) => {
const doc = collection.getDoc(id) ?? collection.createDoc(id);
const store = doc.getStore();
doc.clear();
doc.load(() => {
// Add root block and surface block at root level
const rootId = store.addBlock('affine:page', {
title: new Text(),
});
store.addBlock('affine:surface', {}, rootId);
// Add note block inside root block
const noteId = store.addBlock('affine:note', {}, rootId);
// Add paragraph block inside note block
store.addBlock('affine:paragraph', {}, noteId);
});
store.resetHistory();
};
empty.id = 'empty';
empty.displayName = 'Empty Editor';
empty.description = 'Start from empty editor';