99 </select >
1010 <select v-model =" dataItem.graphType" v-if =" dataItem.graphType !== 'text'" >
1111 <option
12- v-if =" !getFnType(dataItem. fnType) .notAllowedInInterval"
12+ v-if =" !fnType.notAllowedInInterval"
1313 :value =" undefined"
1414 >
1515 {{ graphTypeArr[0].label }}
3333 </div >
3434
3535 <div class =" inputs" >
36- <div v-for =" input in getFnType(dataItem.fnType).inputs" class =" input-box" >
37- <span class =" input-title" >{{ input.title }}</span >
38- <input
39- type =" text"
40- v-model =" dataItem[input.value]"
41- :placeholder =" input.placeholder"
42- />
43- </div >
44- <template v-if =" getFnType (dataItem .fnType ).coord " >
45- <div
46- v-for =" input in getFnType(dataItem.fnType).coord?.filter(
47- ({ folded }) => !(folded && blockFolded)
48- )"
49- class =" input-box coord"
50- :class =" { optional: input.optional }"
51- >
52- <span class =" coord-label" >{{ input.label }}</span >
53- <input
54- type =" number"
55- @input =" handleCoordInput(dataItem!, input, 0, $event)"
56- :placeholder =" input.placeholder[0]"
57- />
58- <span class =" coord-label" >{{ input.sep }}</span >
59- <input
60- type =" number"
61- @input =" handleCoordInput(dataItem!, input, 1, $event)"
62- :placeholder =" input.placeholder[1]"
63- />
64- <span class =" coord-label" >{{ input.fin }}</span >
65- </div >
66- </template >
67-
68- <template v-if =" getFnType (dataItem .fnType ).switches " >
69- <div
70- v-for =" input in getFnType(dataItem.fnType).switches?.filter(
71- ({ folded }) => !(folded && blockFolded)
72- )"
73- class =" input-box switches"
74- @click ="
75- dataItem[input.value]
76- ? delete dataItem[input.value]
77- : (dataItem[input.value] = true)
78- "
79- >
80- <span
81- class =" switch"
82- :class =" dataItem[input.value] ? 'on' : 'off'"
83- ></span >
84- {{ input.label }}
85- </div >
86- </template >
36+ <StrInputs
37+ :dataItem =" dataItem"
38+ :fnType =" fnType"
39+ :blockFolded =" blockFolded"
40+ />
41+ <CoordInputs
42+ :dataItem =" dataItem"
43+ :fnType =" fnType"
44+ :blockFolded =" blockFolded"
45+ />
46+ <SwitchInputs
47+ :dataItem =" dataItem"
48+ :fnType =" fnType"
49+ :blockFolded =" blockFolded"
50+ />
8751 </div >
8852 </div >
8953</template >
9054<script setup lang="ts">
9155import type { FunctionPlotDatum } from " function-plot" ;
9256import { fnTypeArr , graphTypeArr , inputTypeArr , getFnType } from " ../consts" ;
93- import type { CoordType } from " ../consts" ;
94- import { ref } from " vue" ;
57+ import { ref , computed } from " vue" ;
58+ import StrInputs from " ./dataBlockInner/strInputs.vue" ;
59+ import CoordInputs from " ./dataBlockInner/coordInputs.vue" ;
60+ import SwitchInputs from " ./dataBlockInner/switchInputs.vue" ;
61+
9562const emit = defineEmits ([" delete" ]);
9663const dataItem = defineModel <FunctionPlotDatum >();
9764const block = ref <HTMLDivElement >();
@@ -109,34 +76,14 @@ function fnTypeChange(
10976 } else {
11077 if (dataItem .graphType === " text" || dataItem .fnType === " implicit" )
11178 delete dataItem .graphType ;
112- if (getFnType ( dataItem . fnType ) .notAllowedInInterval && ! dataItem .graphType )
79+ if (fnType . value .notAllowedInInterval && ! dataItem .graphType )
11380 dataItem .graphType = " polyline" ;
11481 if (dataItem .fnType === " vector" ) dataItem .vector = [0 , 0 ];
11582 if (block .value )
11683 block .value .querySelectorAll (" input" ).forEach ((ele ) => (ele .value = " " ));
11784 }
11885}
119- function handleCoordInput(
120- dataItem : FunctionPlotDatum ,
121- input : CoordType ,
122- index : 0 | 1 ,
123- event : Event
124- ) {
125- const raw = (<HTMLInputElement >event .target ).value ;
126- const newVal = Number (raw );
127- const key = input .value ,
128- defaultVal = input .defaultVal ?? [0 , 0 ];
129- if (! dataItem [key ]) {
130- const coord: [number , number ] = [... defaultVal ];
131- coord [index ] = newVal ;
132- dataItem [key ] = coord ;
133- } else {
134- if (raw !== " " ) dataItem [key ][index ] = newVal ;
135- else if (dataItem [key ][1 - index ] !== defaultVal [1 - index ])
136- dataItem [key ][index ] = defaultVal [index ];
137- else delete dataItem [key ];
138- }
139- }
86+ const fnType = computed (() => getFnType (dataItem .value ?.fnType ));
14087 </script >
14188
14289<style >
@@ -187,110 +134,4 @@ function handleCoordInput(
187134.selectors select :focus {
188135 border-color : var (--c-accent );
189136}
190- .inputs {
191- display : flex ;
192- flex-direction : column ;
193- gap : 10px ;
194- }
195- .inputs .input-box {
196- position : relative ;
197- display : flex ;
198- }
199- .inputs .input-box .input-title {
200- font-style : italic ;
201- letter-spacing : 5px ;
202- font-size : 20px ;
203- font-weight : bold ;
204- margin : auto 5px ;
205- height : fit-content ;
206- }
207- .inputs input {
208- color : var (--c-text );
209- background : var (--c-bk1 );
210- border : var (--c-border ) 1px solid ;
211- height : 100% ;
212- font-size : 20px ;
213- border-radius : 5px ;
214- display : block ;
215- width : 100% ;
216- text-indent : 10px ;
217- padding : 10px 0 ;
218- }
219- .inputs :not (.optional ) input :placeholder-shown {
220- border-color : var (--c-red );
221- }
222- .inputs input :focus {
223- border-color : var (--c-accent );
224- }
225-
226- .input-box.coord {
227- display : flex ;
228- }
229- .input-box.coord.optional {
230- color : #bbb ;
231- }
232- .input-box.coord span {
233- font-size : 18px ;
234- margin : auto 5px ;
235- flex-shrink : 0 ;
236- }
237- .input-box.coord input {
238- max-width : 8em ;
239- min-width : 3em ;
240- padding : 6px 0 ;
241- font-size : 18px ;
242- flex-shrink : 1 ;
243- }
244-
245- .input-box.switches {
246- align-items : center ;
247- gap : 10px ;
248- padding-left : 5px ;
249- cursor : default ;
250- }
251-
252- .switch :before ,
253- .switch :after {
254- position : absolute ;
255- transition : all 0.2s cubic-bezier (0 , 0.48 , 0.27 , 0.98 );
256- }
257-
258- .switch {
259- width : 40px ;
260- height : 20px ;
261- border-radius : 5px ;
262- position : relative ;
263- border-radius : 10px ;
264- }
265-
266- .switch.on {
267- background : var (--c-accent );
268- }
269-
270- .switch.off {
271- background : var (--c-border );
272- }
273- .switch :after {
274- content : " " ;
275- background : #fff ;
276- width : 12px ;
277- height : 12px ;
278- border-radius : 50% ;
279- top : 0 ;
280- bottom : 0 ;
281- margin : auto 0 ;
282- }
283- .switch.off :after {
284- left : 4px ;
285- }
286- .switch.on :after {
287- left : 24px ;
288- }
289- .switch :hover {
290- filter : brightness (110% );
291- }
292-
293- .switch :active {
294- filter : brightness (90% );
295- }
296137 </style >
0 commit comments