mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 15:26:59 +08:00
fix(editor): get block props (#11807)
Closes: [BS-3184](https://linear.app/affine-design/issue/BS-3184/duplicate-图片,一直在loading)
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
|||||||
type ToolbarModuleConfig,
|
type ToolbarModuleConfig,
|
||||||
ToolbarModuleExtension,
|
ToolbarModuleExtension,
|
||||||
} from '@blocksuite/affine-shared/services';
|
} from '@blocksuite/affine-shared/services';
|
||||||
|
import { getBlockProps } from '@blocksuite/affine-shared/utils';
|
||||||
import { Bound } from '@blocksuite/global/gfx';
|
import { Bound } from '@blocksuite/global/gfx';
|
||||||
import {
|
import {
|
||||||
CaptionIcon,
|
CaptionIcon,
|
||||||
@@ -35,7 +36,6 @@ import { keyed } from 'lit/directives/keyed.js';
|
|||||||
import { AttachmentBlockComponent } from '../attachment-block';
|
import { AttachmentBlockComponent } from '../attachment-block';
|
||||||
import { RenameModal } from '../components/rename-model';
|
import { RenameModal } from '../components/rename-model';
|
||||||
import { AttachmentEmbedProvider } from '../embed';
|
import { AttachmentEmbedProvider } from '../embed';
|
||||||
import { cloneAttachmentProperties } from '../utils';
|
|
||||||
|
|
||||||
const trackBaseProps = {
|
const trackBaseProps = {
|
||||||
category: 'attachment',
|
category: 'attachment',
|
||||||
@@ -219,7 +219,7 @@ const builtinToolbarConfig = {
|
|||||||
ctx.store.addSiblingBlocks(model, [
|
ctx.store.addSiblingBlocks(model, [
|
||||||
{
|
{
|
||||||
flavour: model.flavour,
|
flavour: model.flavour,
|
||||||
...cloneAttachmentProperties(model),
|
...getBlockProps(model),
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import type {
|
|||||||
AttachmentBlockModel,
|
AttachmentBlockModel,
|
||||||
AttachmentBlockProps,
|
AttachmentBlockProps,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import { defaultAttachmentProps } from '@blocksuite/affine-model';
|
|
||||||
import {
|
import {
|
||||||
EMBED_CARD_HEIGHT,
|
EMBED_CARD_HEIGHT,
|
||||||
EMBED_CARD_WIDTH,
|
EMBED_CARD_WIDTH,
|
||||||
@@ -20,18 +19,6 @@ import type { BlockModel } from '@blocksuite/store';
|
|||||||
|
|
||||||
import type { AttachmentBlockComponent } from './attachment-block.js';
|
import type { AttachmentBlockComponent } from './attachment-block.js';
|
||||||
|
|
||||||
export function cloneAttachmentProperties(model: AttachmentBlockModel) {
|
|
||||||
const clonedProps = {} as AttachmentBlockProps;
|
|
||||||
for (const cur in defaultAttachmentProps) {
|
|
||||||
const key = cur as keyof AttachmentBlockProps;
|
|
||||||
// @ts-expect-error it's safe because we just cloned the props simply
|
|
||||||
clonedProps[key] = model[
|
|
||||||
key
|
|
||||||
] as AttachmentBlockProps[keyof AttachmentBlockProps];
|
|
||||||
}
|
|
||||||
return clonedProps;
|
|
||||||
}
|
|
||||||
|
|
||||||
const attachmentUploads = new Set<string>();
|
const attachmentUploads = new Set<string>();
|
||||||
export function setAttachmentUploading(blockId: string) {
|
export function setAttachmentUploading(blockId: string) {
|
||||||
attachmentUploads.add(blockId);
|
attachmentUploads.add(blockId);
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import type { BlockModel } from '@blocksuite/store';
|
import type { BlockModel } from '@blocksuite/store';
|
||||||
|
|
||||||
export function getBlockProps(model: BlockModel): Record<string, unknown> {
|
export function getBlockProps(model: BlockModel): Record<string, unknown> {
|
||||||
const keys = model.keys as (keyof typeof model)[];
|
const keys = model.keys as (keyof typeof model.props)[];
|
||||||
const values = keys.map(key => model[key]);
|
return Object.fromEntries(keys.map(key => [key, model.props[key]]));
|
||||||
const blockProps = Object.fromEntries(keys.map((key, i) => [key, values[i]]));
|
|
||||||
return blockProps;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,3 +370,35 @@ test('should clear selection when switching doc mode', async ({ page }) => {
|
|||||||
|
|
||||||
await expect(toolbar).toBeHidden();
|
await expect(toolbar).toBeHidden();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.describe('Toolbar More Actions', () => {
|
||||||
|
test('should duplicate block', async ({ page }) => {
|
||||||
|
await page.keyboard.press('Enter');
|
||||||
|
|
||||||
|
await importImage(page, 'large-image.png');
|
||||||
|
const images = page.locator('affine-page-image');
|
||||||
|
|
||||||
|
const firstImage = images.first();
|
||||||
|
const firstImageUrl = await firstImage.locator('img').getAttribute('src');
|
||||||
|
|
||||||
|
await firstImage.hover();
|
||||||
|
|
||||||
|
const toolbar = locateToolbar(page);
|
||||||
|
const moreMenu = toolbar.getByLabel('More menu');
|
||||||
|
await moreMenu.click();
|
||||||
|
|
||||||
|
const duplicateButton = toolbar.getByTestId('duplicate');
|
||||||
|
await duplicateButton.click();
|
||||||
|
|
||||||
|
await expect(images).toHaveCount(2);
|
||||||
|
|
||||||
|
const secondImage = images.nth(1);
|
||||||
|
const secondImageUrl = await secondImage.locator('img').getAttribute('src');
|
||||||
|
|
||||||
|
expect(firstImageUrl).not.toBeNull();
|
||||||
|
expect(firstImageUrl!.startsWith('blob:')).toBe(true);
|
||||||
|
|
||||||
|
expect(secondImageUrl).not.toBeNull();
|
||||||
|
expect(secondImageUrl!.startsWith('blob:')).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user