Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(schema-diagram): (experimental) copy exported png to clipboard (#4348)

Liu Jib7bfca31c6d5
diff --git a/frontend/src/components/SchemaDiagram/Canvas/DummyCanvas.vue b/frontend/src/components/SchemaDiagram/Canvas/DummyCanvas.vue
index 5f27110886..0c270dffc8 100644
--- a/frontend/src/components/SchemaDiagram/Canvas/DummyCanvas.vue
+++ b/frontend/src/components/SchemaDiagram/Canvas/DummyCanvas.vue
@@ -37,6 +37,7 @@
</template>
<script lang="ts" setup>
+import { pushNotification } from "@/store";
import { computed, defineComponent, nextTick, PropType, ref, VNode } from "vue";
import {
@@ -122,17 +123,29 @@ const capture = async (filename: string) => {
return;
}
- const [{ toPng }, { default: download }] = await Promise.all([
- import("html-to-image"),
- import("downloadjs"),
- ]);
- const dataUrl = await toPng(node, {
- pixelRatio: 1,
- quality: 0.9,
- });
- download(dataUrl, filename, `image/png`);
-
- isCapturing.value = false;
+ try {
+ const [{ toBlob }, { default: download }] = await Promise.all([
+ import("html-to-image"),
+ import("downloadjs"),
+ ]);
+ const blob = await toBlob(node, {
+ pixelRatio: 1,
+ quality: 0.9,
+ });
+ if (blob) {
+ download(blob, filename, blob.type);
+
+ const data = [new window.ClipboardItem({ [blob.type]: blob })];
+ await navigator.clipboard.write(data);
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: "Screenshot generated successfully and copied to the clipboard!",
+ });
+ }
+ } finally {
+ isCapturing.value = false;
+ }
};
provideSchemaDiagramContext({