mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 05:29:08 +08:00
chore(editor): adjust size of synced doc (#12163)
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 -->
This commit is contained in:
+85
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
EmbedSyncedDocBlockSchema,
|
||||
SYNCED_MIN_HEIGHT,
|
||||
SYNCED_MIN_WIDTH,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { clamp } from '@blocksuite/global/gfx';
|
||||
import { GfxViewInteractionExtension } from '@blocksuite/std/gfx';
|
||||
|
||||
import type { EmbedEdgelessSyncedDocBlockComponent } from '../embed-edgeless-synced-doc-block';
|
||||
import { calcSyncedDocFullHeight } from '../utils';
|
||||
|
||||
export const EmbedSyncedDocInteraction =
|
||||
GfxViewInteractionExtension<EmbedEdgelessSyncedDocBlockComponent>(
|
||||
EmbedSyncedDocBlockSchema.model.flavour,
|
||||
{
|
||||
resizeConstraint: {
|
||||
minWidth: SYNCED_MIN_WIDTH,
|
||||
minHeight: SYNCED_MIN_HEIGHT,
|
||||
},
|
||||
|
||||
handleRotate: () => {
|
||||
return {
|
||||
beforeRotate(context) {
|
||||
context.set({
|
||||
rotatable: false,
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
handleResize: ({ view, model }) => {
|
||||
const initialScale = model.props.scale ?? 1;
|
||||
const initHeight = model.elementBound.h;
|
||||
const maxHeight = calcSyncedDocFullHeight(view);
|
||||
|
||||
return {
|
||||
beforeResize: context => {
|
||||
context.set({ maxHeight });
|
||||
},
|
||||
onResizeStart: context => {
|
||||
context.default(context);
|
||||
model.stash('scale');
|
||||
model.stash('preFoldHeight');
|
||||
},
|
||||
onResizeMove: context => {
|
||||
const { lockRatio, originalBound, constraint, newBound } = context;
|
||||
|
||||
let scale = initialScale;
|
||||
const realWidth = originalBound.w / initialScale;
|
||||
|
||||
if (lockRatio) {
|
||||
scale = newBound.w / realWidth;
|
||||
}
|
||||
|
||||
const newWidth = newBound.w / scale;
|
||||
|
||||
newBound.w =
|
||||
clamp(newWidth, constraint.minWidth, constraint.maxWidth) * scale;
|
||||
newBound.h =
|
||||
clamp(newBound.h, constraint.minHeight, constraint.maxHeight) *
|
||||
scale;
|
||||
|
||||
const newHeight = newBound.h / scale;
|
||||
|
||||
// only adjust height check the fold state
|
||||
if (originalBound.w === newBound.w) {
|
||||
let preFoldHeight = 0;
|
||||
if (newHeight === constraint.minHeight) {
|
||||
preFoldHeight = initHeight;
|
||||
}
|
||||
model.props.preFoldHeight = preFoldHeight;
|
||||
}
|
||||
|
||||
model.props.scale = scale;
|
||||
model.xywh = newBound.serialize();
|
||||
},
|
||||
onResizeEnd: context => {
|
||||
context.default(context);
|
||||
model.pop('scale');
|
||||
model.pop('preFoldHeight');
|
||||
},
|
||||
};
|
||||
},
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user