mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
To close: [BS-2843](https://linear.app/affine-design/issue/BS-2843/iframe-embed-block-占位态) [BS-2844](https://linear.app/affine-design/issue/BS-2844/iframe-embed-block-create-modal-ui-调整) [BS-2880](https://linear.app/affine-design/issue/BS-2880/spotify-选中时圆角有问题) [BS-2881](https://linear.app/affine-design/issue/BS-2881/miro-圆角有问题-点击-see-the-board-加载之后就好了)
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import type { EmbedIframeBlockProps } from '@blocksuite/affine-model';
|
|
import type { Command } from '@blocksuite/block-std';
|
|
import type { BlockModel } from '@blocksuite/store';
|
|
|
|
import type { EmbedLinkInputPopupOptions } from '../components/embed-iframe-link-input-popup';
|
|
import { EmbedIframeBlockComponent } from '../embed-iframe-block';
|
|
|
|
export const insertEmptyEmbedIframeCommand: Command<
|
|
{
|
|
place?: 'after' | 'before';
|
|
removeEmptyLine?: boolean;
|
|
selectedModels?: BlockModel[];
|
|
linkInputPopupOptions?: EmbedLinkInputPopupOptions;
|
|
},
|
|
{
|
|
insertedEmbedIframeBlockId: Promise<string>;
|
|
}
|
|
> = (ctx, next) => {
|
|
const { selectedModels, place, removeEmptyLine, std, linkInputPopupOptions } =
|
|
ctx;
|
|
if (!selectedModels?.length) return;
|
|
|
|
const targetModel =
|
|
place === 'before'
|
|
? selectedModels[0]
|
|
: selectedModels[selectedModels.length - 1];
|
|
|
|
const embedIframeBlockProps: Partial<EmbedIframeBlockProps> & {
|
|
flavour: 'affine:embed-iframe';
|
|
} = {
|
|
flavour: 'affine:embed-iframe',
|
|
};
|
|
|
|
const result = std.store.addSiblingBlocks(
|
|
targetModel,
|
|
[embedIframeBlockProps],
|
|
place
|
|
);
|
|
if (result.length === 0) return;
|
|
|
|
if (removeEmptyLine && targetModel.text?.length === 0) {
|
|
std.store.deleteBlock(targetModel);
|
|
}
|
|
|
|
next({
|
|
insertedEmbedIframeBlockId: std.host.updateComplete.then(async () => {
|
|
const blockComponent = std.view.getBlock(result[0]);
|
|
if (blockComponent instanceof EmbedIframeBlockComponent) {
|
|
await blockComponent.updateComplete;
|
|
blockComponent.toggleLinkInputPopup(linkInputPopupOptions);
|
|
}
|
|
return result[0];
|
|
}),
|
|
});
|
|
};
|