mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-26 14:58:55 +08:00
3ebed1d5a8
Close [BS-3418](https://linear.app/affine-design/issue/BS-3418/折叠的embed-doc调整宽度时,会出现一个最小高度,不需要这个) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved resizing and folding interactions for embedded synced documents in edgeless mode, including dynamic height calculation and enhanced drag-handle styling. - **Bug Fixes** - Adjusted minimum height for synced document embeds to allow more compact display. - Ensured consistent width settings across embed cards. - **Tests** - Added end-to-end tests covering folding, unfolding, and resizing behaviors for edgeless synced document embeds. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { type Container, createIdentifier } from '@blocksuite/global/di';
|
|
import { type BlockStdScope, StdIdentifier } from '@blocksuite/std';
|
|
import { Extension, Slice, type SliceSnapshot } from '@blocksuite/store';
|
|
|
|
export const DndApiExtensionIdentifier = createIdentifier<DNDAPIExtension>(
|
|
'AffineDndApiIdentifier'
|
|
);
|
|
|
|
export class DNDAPIExtension extends Extension {
|
|
mimeType = 'application/x-blocksuite-dnd';
|
|
|
|
constructor(readonly std: BlockStdScope) {
|
|
super();
|
|
}
|
|
|
|
static override setup(di: Container) {
|
|
di.add(this, [StdIdentifier]);
|
|
|
|
di.addImpl(DndApiExtensionIdentifier, provider => provider.get(this));
|
|
}
|
|
|
|
decodeSnapshot(data: string): SliceSnapshot {
|
|
return JSON.parse(decodeURIComponent(data));
|
|
}
|
|
|
|
encodeSnapshot(json: SliceSnapshot) {
|
|
const snapshot = JSON.stringify(json);
|
|
return encodeURIComponent(snapshot);
|
|
}
|
|
|
|
fromEntity(options: {
|
|
docId: string;
|
|
flavour?: string;
|
|
blockId?: string;
|
|
props?: Record<string, unknown>;
|
|
}): SliceSnapshot | null {
|
|
const { docId, flavour = 'affine:embed-linked-doc', blockId } = options;
|
|
|
|
const slice = Slice.fromModels(this.std.store, []);
|
|
const job = this.std.store.getTransformer();
|
|
const snapshot = job.sliceToSnapshot(slice);
|
|
if (!snapshot) {
|
|
console.error('Failed to convert slice to snapshot');
|
|
return null;
|
|
}
|
|
const props = {
|
|
...options.props,
|
|
...(blockId ? { blockId } : {}),
|
|
pageId: docId,
|
|
style: flavour === 'affine:embed-synced-doc' ? 'syncedDoc' : 'vertical',
|
|
};
|
|
return {
|
|
...snapshot,
|
|
content: [
|
|
{
|
|
id: this.std.workspace.idGenerator(),
|
|
type: 'block',
|
|
flavour,
|
|
props,
|
|
children: [],
|
|
},
|
|
],
|
|
};
|
|
}
|
|
}
|