feat(editor): make height of edgeless embed doc to fit content (#12089)

Close [BS-3388](https://linear.app/affine-design/issue/BS-3388/embed-doc-拖入后的初始高度不要超过800,不要限制用户随后的调整空间)

This PR impl a extension which initialize the height of added `affine-embed-edgeless-synced-doc-block` to fit its content

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Improved handling of embedded synced document block height to better fit content within edgeless mode.
- **Tests**
  - Added an end-to-end test to verify correct height adjustment for embedded synced documents in edgeless mode.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
L-Sun
2025-04-30 18:48:54 +00:00
parent 83e55fad1e
commit e0308c5815
5 changed files with 151 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import type { AffineReference } from '@blocksuite/affine/inlines/reference';
import type { EmbedSyncedDocBlockProps } from '@blocksuite/affine/model';
import { expect, type Page } from '@playwright/test';
import { clickView } from '../utils/actions/click.js';
@@ -12,7 +13,7 @@ import {
isIntersected,
switchEditorMode,
} from '../utils/actions/edgeless';
import { pressEscape } from '../utils/actions/keyboard.js';
import { pressBackspace, pressEscape } from '../utils/actions/keyboard.js';
import { enterPlaygroundRoom, waitNextFrame } from '../utils/actions/misc';
import { test } from '../utils/playwright';
import { initEmbedSyncedDocState } from './utils';
@@ -75,6 +76,65 @@ test.describe('Embed synced doc in edgeless mode', () => {
}
);
test('new edgeless embed synced doc should fit in height', async ({
page,
}) => {
const [_, embedDocId] = await initEmbedSyncedDocState(page, [
{ title: 'Root Doc', content: 'hello root doc' },
{ title: 'Page 1', content: '1\n2\n3\n4\n5\n6\n7' },
]);
await switchEditorMode(page);
const paragraphHeight = (
await page
.locator('affine-embed-synced-doc-block affine-paragraph')
.boundingBox()
)?.height;
if (!paragraphHeight) {
test.fail();
return;
}
const createEmbedDocWithHeight = async (height: number) => {
await page.evaluate(
({ embedDocId, height }) => {
const std = window.editor.std;
const surface = std.store.getModelsByFlavour('affine:surface')[0];
std.store.addBlock(
'affine:embed-synced-doc',
{
pageId: embedDocId,
xywh: `[0,100,370,${height}]`,
} satisfies Partial<EmbedSyncedDocBlockProps>,
surface.id
);
},
{ embedDocId, height }
);
};
const embedSyncedBlockInNote = page.locator(
'affine-embed-edgeless-synced-doc-block'
);
{
const initHeight = paragraphHeight - 50;
await createEmbedDocWithHeight(initHeight);
const embedSyncedBoxInNote = await embedSyncedBlockInNote.boundingBox();
expect(embedSyncedBoxInNote?.height).toBeGreaterThan(initHeight);
}
await embedSyncedBlockInNote.click();
await pressBackspace(page);
{
const initHeight = paragraphHeight + 50;
await createEmbedDocWithHeight(initHeight);
const embedSyncedBoxInNote = await embedSyncedBlockInNote.boundingBox();
expect(embedSyncedBoxInNote?.height).toBeLessThan(initHeight);
}
});
test.describe('edgeless element toolbar', () => {
test.beforeEach(async ({ page }) => {
await initEmbedSyncedDocState(page, [