Skip to content

Commit 826bf06

Browse files
committed
使用自定义组件替代 s-fold
减少额外 DOM,提升性能
1 parent 685f479 commit 826bf06

File tree

10 files changed

+76
-30
lines changed

10 files changed

+76
-30
lines changed

src/editor/inputs/implicit.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
/>
99
<span class="label styled"> =0 </span>
1010
</div>
11-
<s-fold :folded="props.folded">
11+
<AnimatedFold :folded="props.folded">
1212
<s-divider>{{ t("title.moreOptions") }}</s-divider>
1313
<p>
1414
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Tempora ab hic
1515
accusamus iure natus expedita laborum ea nam, reiciendis obcaecati animi
1616
voluptatem nisi assumenda ipsam nihil fuga minima? Id, ab?
1717
</p>
18-
</s-fold>
18+
</AnimatedFold>
1919
</div>
2020
</template>
2121

@@ -27,6 +27,8 @@ import { I18nSchema } from "@/i18n";
2727
const { t } = useI18n<{ message: I18nSchema }>();
2828
2929
import FilledTextfield from "@/editor/inputs/subblocks/function.vue";
30+
import AnimatedFold from "@/ui/animated/animatedFold.vue";
31+
3032
3133
const props = defineProps<{
3234
folded: boolean;

src/editor/inputs/inputs.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222
}
2323

24-
& > s-fold {
24+
& > .fold {
2525
margin: -8px -15px 0 -15px;
2626
}
2727
s-divider {

src/editor/inputs/linear.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<span class="label styled">y=</span>
55
<filledTextfield class="styled fn" label="f(x)" v-model="self.fn" />
66
</div>
7-
<s-fold :folded="props.folded">
7+
<AnimatedFold :folded="props.folded" class="fold">
88
<s-divider>{{ t("data.more.dividerTitle") }}</s-divider>
99
<div class="input-inner-optional">
1010
<div class="fields">
@@ -53,7 +53,7 @@
5353
</s-checkbox>
5454
</div>
5555
</div>
56-
</s-fold>
56+
</AnimatedFold>
5757
</div>
5858
</template>
5959

@@ -76,5 +76,6 @@ import HelpIcon from "./subblocks/helpIcon.vue";
7676
import ColorPicker from "./subblocks/colorPicker.vue";
7777
import Domain from "./subblocks/domain.vue";
7878
import DerivatePane from "./subblocks/derivatePane.vue";
79+
import AnimatedFold from "@/ui/animated/animatedFold.vue";
7980
import "./inputs.scss";
8081
</script>

src/editor/inputs/parametric.vue

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@
88
<span class="label styled">y=</span>
99
<FilledTextfield class="styled fn" label="g(t)" v-model="self.y" />
1010
</div>
11-
<s-fold :folded="props.folded">
12-
<s-divider>{{ t("title.moreOptions") }}</s-divider>
13-
<p>
14-
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Tempora ab hic
15-
accusamus iure natus expedita laborum ea nam, reiciendis obcaecati animi
16-
voluptatem nisi assumenda ipsam nihil fuga minima? Id, ab?
17-
</p>
18-
</s-fold>
11+
1912
</div>
2013
</template>
2114

src/editor/inputs/polar.vue

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@
1010
/>
1111
</div>
1212
</div>
13-
<s-fold :folded="props.folded">
14-
<s-divider>{{ t("title.moreOptions") }}</s-divider>
15-
<p>
16-
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Tempora ab hic
17-
accusamus iure natus expedita laborum ea nam, reiciendis obcaecati animi
18-
voluptatem nisi assumenda ipsam nihil fuga minima? Id, ab?
19-
</p>
20-
</s-fold>
13+
2114
</template>
2215

2316
<script setup lang="ts">

src/editor/inputs/subblocks/derivatePane.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
</s-segmented-button-item>
5353
</s-segmented-button>
5454
</div>
55-
<s-fold :folded="derivFollowMouse" class="derivate-x-coord-fold">
55+
<AnimatedFold :folded="derivFollowMouse" class="derivate-x-coord-fold">
5656
<div class="field x-coord-field">
5757
<div class="label">{{ t("data.derivate.sepcify") }}</div>
5858
<s-text-field
@@ -62,7 +62,7 @@
6262
v-model="derivateX"
6363
></s-text-field>
6464
</div>
65-
</s-fold>
65+
</AnimatedFold>
6666
</div>
6767

6868
<!-- secant -->
@@ -133,6 +133,7 @@ import FunctionField from "./function.vue";
133133
import AnimatedList from "@/ui/animated/animatedList.vue";
134134
import AnimatedListItem from "@/ui/animated/animatedListItem.vue";
135135
import SIconDelete from "@/ui/icons/delete.vue";
136+
import AnimatedFold from "@/ui/animated/animatedFold.vue";
136137
137138
import { useI18n } from "vue-i18n";
138139
import { I18nSchema } from "@/i18n";

src/editor/output.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
{{ t("output.copy.tip") }}
1818
</s-tooltip>
1919
</div>
20-
<s-fold :folded="folded">
20+
<AnimatedFold :folded="folded">
2121
<s-scroll-view id="formattedCode">
2222
<pre ref="formattedCodePre">{{ formatted }}</pre>
2323
</s-scroll-view>
24-
</s-fold>
24+
</AnimatedFold>
2525
</div>
2626
</template>
2727

@@ -43,6 +43,8 @@ import { ref, watch } from "vue";
4343
import { useProfile } from "@/states";
4444
const profile = useProfile();
4545
46+
import AnimatedFold from "@/ui/animated/animatedFold.vue";
47+
4648
import { FunctionPlotOptions } from "function-plot";
4749
const formatted = ref("");
4850
watch(

src/graph/graph.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,26 @@ onMounted(async () => {
7474
while (!shellRef.value) await waitForTruthy(plotRef);
7575
const handleUpdate = throttle(() => {
7676
const target = plotRef.value;
77-
7877
try {
7978
if (!target) throw new Error("plotRef is null");
79+
if (
80+
profile.datum.some((data) => {
81+
const isEmpty = (str: string) => str === undefined || str === "";
82+
const someEmpty = (...strs: string[]) => strs.some(isEmpty);
83+
switch (data.fnType) {
84+
case "linear":
85+
case "implicit":
86+
return someEmpty(data.fn);
87+
case "parametric":
88+
return someEmpty(data.x, data.y);
89+
case "polar":
90+
return someEmpty(data.r);
91+
default:
92+
return false;
93+
}
94+
})
95+
)
96+
throw new Error("Empty data found");
8097
const data = profile.getPublicDatum();
8198
const annotations = profile.getPublicAnnotations();
8299
const options = profile.getPublicOptions();

src/ui/animated/animatedFold.vue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<template>
2+
<Transition name="fold-trans">
3+
<div class="fold-shell" :class="props.class" v-if="!props.folded">
4+
<div class="fold-shell-inner">
5+
<slot></slot>
6+
</div>
7+
</div>
8+
</Transition>
9+
</template>
10+
11+
<script lang="ts" setup>
12+
const props = defineProps<{
13+
class?: string;
14+
folded?: boolean;
15+
}>();
16+
</script>
17+
18+
<style lang="scss" scoped>
19+
.fold-shell {
20+
display: grid;
21+
grid-template-rows: 1fr;
22+
overflow: hidden;
23+
transition: grid-template-rows var(--s-motion-duration-short4, 0.2s)
24+
var(--s-motion-easing-emphasized, cubic-bezier(0.2, 0, 0, 1));
25+
}
26+
.fold-shell-inner {
27+
min-height: 0;
28+
}
29+
.fold-trans {
30+
&-enter-from,
31+
&-leave-to {
32+
grid-template-rows: 0fr;
33+
}
34+
}
35+
</style>

src/ui/animated/animatedListItem.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const props = defineProps<{
1313
}>();
1414
</script>
1515

16-
<style>
16+
<style lang="scss" scoped>
1717
.animatedListItem {
1818
display: grid;
1919
grid-template-rows: 1fr;
@@ -24,8 +24,10 @@ const props = defineProps<{
2424
.animatedListItemInner {
2525
min-height: 0;
2626
}
27-
.list-trans-enter-from,
28-
.list-trans-leave-to {
29-
grid-template-rows: 0fr;
27+
.list-trans {
28+
&-enter-from,
29+
&-leave-to {
30+
grid-template-rows: 0fr;
31+
}
3032
}
3133
</style>

0 commit comments

Comments
 (0)