feat(schema-diff): professional DDL diff view with deployment-aware colors and custom themes (#1112)
Co-authored-by: Sam <14344444@@qq.com>
This commit is contained in:
1 parent
2554ed95be
commit
ef5ed05ae7
41 files changed
+5695
-1215
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { ref, type Ref } from "vue";
|
||||
import type { DiffHunk } from "@/components/diff/DiffHunkBuilder";
|
||||
|
||||
export interface UseDiffScrollSyncOptions {
|
||||
container: Ref<HTMLElement | undefined>;
|
||||
leftPane: Ref<HTMLElement | undefined>;
|
||||
rightPane: Ref<HTMLElement | undefined>;
|
||||
hunks: Ref<DiffHunk[]>;
|
||||
}
|
||||
|
||||
export function useDiffScrollSync({ container, leftPane, rightPane, hunks }: UseDiffScrollSyncOptions) {
|
||||
const isSyncingScroll = ref(false);
|
||||
|
||||
function syncScroll(from: "left" | "right") {
|
||||
if (isSyncingScroll.value) return;
|
||||
const source = from === "left" ? leftPane.value : rightPane.value;
|
||||
const target = from === "left" ? rightPane.value : leftPane.value;
|
||||
if (!source || !target) return;
|
||||
isSyncingScroll.value = true;
|
||||
target.scrollTop = source.scrollTop;
|
||||
isSyncingScroll.value = false;
|
||||
}
|
||||
|
||||
function measureHunks() {
|
||||
const outer = container.value;
|
||||
const left = leftPane.value;
|
||||
const right = rightPane.value;
|
||||
if (!outer || !left || !right) return;
|
||||
|
||||
const outerRect = outer.getBoundingClientRect();
|
||||
|
||||
for (const hunk of hunks.value) {
|
||||
const leftEl = left.querySelector(`[data-hunk-id="${hunk.id}"]`) as HTMLElement | null;
|
||||
const rightEl = right.querySelector(`[data-hunk-id="${hunk.id}"]`) as HTMLElement | null;
|
||||
if (leftEl) {
|
||||
const rect = leftEl.getBoundingClientRect();
|
||||
hunk.leftTop = rect.top - outerRect.top;
|
||||
hunk.leftBottom = rect.bottom - outerRect.top;
|
||||
}
|
||||
if (rightEl) {
|
||||
const rect = rightEl.getBoundingClientRect();
|
||||
hunk.rightTop = rect.top - outerRect.top;
|
||||
hunk.rightBottom = rect.bottom - outerRect.top;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
syncScroll,
|
||||
measureHunks,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user