Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/DocFlow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"clean": "rm -rf .next .turbo node_modules"
},
"dependencies": {
"@syncflow/alert": "workspace:*",
"@syncflow/bilibili": "workspace:*",
"@azure/core-sse": "^2.3.0",
"@dnd-kit/core": "^6.3.1",
Expand Down
68 changes: 41 additions & 27 deletions apps/DocFlow/src/components/menus/TextMenu/BubbleMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,26 @@ export const CustomBubbleMenu: React.FC<CustomBubbleMenuProps> = ({
// 创建虚拟元素代表选区位置
const virtualElement = {
getBoundingClientRect: () => {
const start = view.coordsAtPos(from);
const end = view.coordsAtPos(to);

return {
top: Math.min(start.top, end.top),
bottom: Math.max(start.bottom, end.bottom),
left: Math.min(start.left, end.left),
right: Math.max(start.right, end.right),
width: Math.abs(end.right - start.left),
height: Math.abs(end.bottom - start.top),
x: Math.min(start.left, end.left),
y: Math.min(start.top, end.top),
};
try {
const docSize = state.doc.content.size;
const clampedFrom = Math.max(0, Math.min(from, docSize));
const clampedTo = Math.max(0, Math.min(to, docSize));
const start = view.coordsAtPos(clampedFrom);
const end = view.coordsAtPos(clampedTo);

return {
top: Math.min(start.top, end.top),
bottom: Math.max(start.bottom, end.bottom),
left: Math.min(start.left, end.left),
right: Math.max(start.right, end.right),
width: Math.abs(end.right - start.left),
height: Math.abs(end.bottom - start.top),
x: Math.min(start.left, end.left),
y: Math.min(start.top, end.top),
};
} catch {
return new DOMRect();
}
},
Comment on lines 93 to 114

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

updateMenu 方法中,getBoundingClientRect 的实现(L93-L113)与 autoUpdate 中的实现(L172-L195)几乎完全相同。这种代码重复会增加维护成本,当需要修改此逻辑时,可能需要在两个地方进行同步修改。

建议将这部分重复的逻辑提取到一个独立的辅助函数中,然后在两个地方调用它,以提高代码的可维护性和复用性。

};

Expand Down Expand Up @@ -163,22 +170,29 @@ export const CustomBubbleMenu: React.FC<CustomBubbleMenuProps> = ({
const cleanup = autoUpdate(
{
getBoundingClientRect: () => {
const { selection } = editor.state;

if (selection.empty) {
try {
const { selection } = editor.state;

if (selection.empty) {
return new DOMRect();
}

const { from, to } = selection;
const docSize = editor.state.doc.content.size;
const clampedFrom = Math.max(0, Math.min(from, docSize));
const clampedTo = Math.max(0, Math.min(to, docSize));
const start = editor.view.coordsAtPos(clampedFrom);
const end = editor.view.coordsAtPos(clampedTo);

return new DOMRect(
Math.min(start.left, end.left),
Math.min(start.top, end.top),
Math.abs(end.right - start.left),
Math.abs(end.bottom - start.top),
);
} catch {
return new DOMRect();
}

const { from, to } = selection;
const start = editor.view.coordsAtPos(from);
const end = editor.view.coordsAtPos(to);

return new DOMRect(
Math.min(start.left, end.left),
Math.min(start.top, end.top),
Math.abs(end.right - start.left),
Math.abs(end.bottom - start.top),
);
},
},
menuEl,
Expand Down
139 changes: 0 additions & 139 deletions apps/DocFlow/src/extensions/Alert/Alert.ts

This file was deleted.

84 changes: 0 additions & 84 deletions apps/DocFlow/src/extensions/Alert/AlertComponent.tsx

This file was deleted.

52 changes: 0 additions & 52 deletions apps/DocFlow/src/extensions/Alert/alert.css

This file was deleted.

3 changes: 0 additions & 3 deletions apps/DocFlow/src/extensions/Alert/index.ts

This file was deleted.

Loading
Loading