Skip to content

Commit 6919477

Browse files
committed
输出框优化
修复bug,添加复制按钮
1 parent 42a0e53 commit 6919477

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

src/consts.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export function toOriginalDatum(items: InternalDatum[], forExport?: boolean) {
108108
delete (<any>item).graphType;
109109
}
110110
delete (<any>item).key;
111+
delete (<any>item).hidden;
111112
return item;
112113
}) as FunctionPlotDatum[];
113114
}
@@ -388,11 +389,19 @@ export const fnTypeArr = [
388389

389390
// Datum define
390391
import { defineStore } from "pinia";
391-
import { ref } from "vue";
392+
import { computed, ref } from "vue";
392393
export const useProfile = defineStore("profile", () => {
393394
const data = ref<InternalDatum[]>([
394395
{ fnType: "linear", graphType: "polyline", fn: "x^2", key: 1 },
395396
]);
396-
const getOriginalCopy = () => toOriginalDatum(data.value);
397+
const getOriginalCopy = (forExport?: boolean) => toOriginalDatum(data.value, forExport);
397398
return { data, getOriginalCopy };
398-
});
399+
});
400+
// Theme define
401+
export const useTheme = defineStore("theme", () => {
402+
const themeValues = ["auto", "dark", "light"] as const;
403+
const index = ref(0);
404+
const value = computed(() => themeValues[index.value]);
405+
const toogle = () => index.value = (index.value + 1) % themeValues.length
406+
return { index, value, toogle }
407+
})

src/editor/output.vue

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
></s-icon>
1010
{{ t(folded ? "buttons.expand" : "buttons.collapse") }}
1111
</s-button>
12+
13+
<s-tooltip align="right">
14+
<s-icon-button
15+
slot="trigger"
16+
@click="copyCode"
17+
>
18+
<SIconCopy />
19+
</s-icon-button>
20+
{{ t("buttons.copy") }}
21+
</s-tooltip>
1222
</div>
1323
<s-fold :folded="folded">
1424
<s-scroll-view id="formattedCode">
@@ -22,6 +32,8 @@
2232
import { useI18n } from "vue-i18n";
2333
const { t } = useI18n();
2434
35+
import SIconCopy from "@/ui/icons/copy.vue";
36+
2537
import JSON5 from "json5";
2638
import prettier from "prettier/standalone";
2739
import prettierPluginBabel from "prettier/plugins/babel";
@@ -35,7 +47,7 @@ watch(
3547
profile,
3648
() => {
3749
prettier
38-
.format(JSON5.stringify({ data: profile.data }), {
50+
.format(JSON5.stringify({ data: profile.getOriginalCopy(true) }), {
3951
parser: "json5",
4052
printWidth: 40,
4153
plugins: [prettierPluginBabel, prettierPluginEstree],
@@ -46,6 +58,15 @@ watch(
4658
);
4759
4860
const folded = ref(true);
61+
62+
import { Snackbar } from "sober";
63+
function copyCode() {
64+
navigator.clipboard.writeText(formatted.value);
65+
Snackbar.builder({
66+
text: t("title.copySuccess"),
67+
type: "success",
68+
});
69+
}
4970
</script>
5071

5172
<style>
@@ -78,12 +99,13 @@ const folded = ref(true);
7899
}
79100
80101
.plot-data.output pre {
81-
user-select: all;
102+
user-select: text;
103+
cursor: text;
82104
margin: 0;
83105
}
84106
85107
::selection {
86-
background-color: var(--s-color-primary);
87-
color: var(--s-color-scrim);
108+
background: var(--s-color-primary);
109+
color: var(--s-color-on-primary);
88110
}
89111
</style>

src/ui/icons/copy.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<s-icon>
3+
<svg viewBox="0 -960 960 960">
4+
<path
5+
d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"
6+
></path>
7+
</svg>
8+
</s-icon>
9+
</template>

0 commit comments

Comments
 (0)