mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-29 16:19:43 +08:00
refactor(editor): add mock notes creator (#10109)
Further features should be validated using multiple notes. <img width="806" alt="image" src="https://github.com/user-attachments/assets/ad2bf934-bebe-479a-bec0-a0a28001b08d" />
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { Text } from '@blocksuite/store';
|
||||
|
||||
import { doc } from './editor.js';
|
||||
|
||||
function addParagraph(noteId: string, content: string) {
|
||||
const props = { text: new Text(content) };
|
||||
doc.addBlock('affine:paragraph', props, noteId);
|
||||
}
|
||||
|
||||
function addSampleNote(noteId: string, i: number) {
|
||||
addParagraph(noteId, `Note ${i + 1}`);
|
||||
addParagraph(noteId, 'Hello World!');
|
||||
addParagraph(
|
||||
noteId,
|
||||
'Hello World! Lorem ipsum dolor sit amet. Consectetur adipiscing elit. Sed do eiusmod tempor incididunt.'
|
||||
);
|
||||
addParagraph(
|
||||
noteId,
|
||||
'你好这是测试,这是一个为了换行而写的中文段落。这个段落会自动换行。'
|
||||
);
|
||||
}
|
||||
|
||||
export function addSampleNotes(n: number) {
|
||||
const cols = Math.ceil(Math.sqrt(n));
|
||||
const NOTE_WIDTH = 500;
|
||||
const NOTE_HEIGHT = 250;
|
||||
const SPACING = 50;
|
||||
|
||||
const rootId = doc.addBlock('affine:page', {});
|
||||
doc.addBlock('affine:surface', {}, rootId);
|
||||
|
||||
for (let i = 0; i < n; i++) {
|
||||
const row = Math.floor(i / cols);
|
||||
const col = i % cols;
|
||||
const x = col * (NOTE_WIDTH + SPACING);
|
||||
const y = row * (NOTE_HEIGHT + SPACING);
|
||||
|
||||
const xywh = `[${x},${y},${NOTE_WIDTH},${NOTE_HEIGHT}]`;
|
||||
const noteId = doc.addBlock('affine:note', { xywh }, rootId);
|
||||
addSampleNote(noteId, i);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user