5
5
<div class =" text-subtitle1" >Setting Layout</div >
6
6
</q-card-section >
7
7
<q-card-section >
8
+ <section class =" row" >
9
+ <q-toggle
10
+ dense
11
+ size =" 35px"
12
+ class =" mr-5"
13
+ v-model =" areaActive[AreaComponent.Editor]"
14
+ label =" Editor"
15
+ />
16
+ <q-toggle
17
+ dense
18
+ size =" 35px"
19
+ class =" mr-5"
20
+ v-model =" areaActive[AreaComponent.Console]"
21
+ label =" Console"
22
+ />
23
+ <q-toggle
24
+ dense
25
+ size =" 35px"
26
+ class =" mr-5"
27
+ v-model =" areaActive[AreaComponent.Preview]"
28
+ label =" Preview"
29
+ />
30
+ </section >
31
+
8
32
<section class =" row" >
9
33
<div
10
34
v-for =" (_, value) in ModeSize"
11
35
:key =" value"
12
- v-memo =" [value === mode]"
36
+ v-memo =" [value === mode, settingsStore.isModeDisabled(value) ]"
13
37
class =" col-4 py-1 cursor-pointer"
14
- @click =" mode = value"
38
+ :class =" {
39
+ disabled: settingsStore.isModeDisabled(value),
40
+ }"
41
+ @click ="
42
+ settingsStore.isModeDisabled(value) ? false : (mode = value)
43
+ "
15
44
>
16
45
<div
17
46
class =" flex items-center hover:bg-gray-100 hover:bg-opacity-10 px-3 py-2 rounded-xl transition-bg duration-100 text-[rgba(200,200,200,0.3)] hover:text-[rgba(200,200,200,0.5)]"
34
63
<div class =" text-subtitle1" >Preview</div >
35
64
<!-- frame preview -->
36
65
<div class =" aspect-4/3 max-w-full w-340px text-center" >
37
- <div class =" container" :class =" Mode[mode]" >
38
- <div class =" area_1" >
66
+ <div
67
+ class =" container"
68
+ :class =" [Mode[mode], `active-${countAreaActive}`]"
69
+ >
70
+ <div v-if =" countAreaActive > 1" class =" area_1" >
39
71
<q-select
40
72
v-model =" area1"
41
73
dense
42
74
:options =" options"
75
+ :option-disable =" optionDisable"
43
76
:option-label =" optionLabel"
44
77
/>
45
78
</div >
46
79
<div class =" group" >
47
- <div class =" area_2" >
80
+ <div v-if = " countAreaActive > 2 " class =" area_2" >
48
81
<q-select
49
82
v-model =" area2"
50
83
dense
51
84
:options =" options"
85
+ :option-disable =" optionDisable"
52
86
:option-label =" optionLabel"
53
87
/>
54
88
</div >
57
91
v-model =" area3"
58
92
dense
59
93
:options =" options"
94
+ :option-disable =" optionDisable"
60
95
:option-label =" optionLabel"
61
96
/>
62
97
</div >
83
118
84
119
<script lang="ts" setup>
85
120
import {
121
+ Area ,
86
122
AreaComponent ,
87
123
AreaComponentSize ,
88
124
Mode ,
@@ -91,10 +127,16 @@ import {
91
127
92
128
const settingsStore = useSettingsStore ()
93
129
130
+ const areaActive = reactive <Record <AreaComponent , boolean >>({
131
+ [AreaComponent .Console ]: true ,
132
+ [AreaComponent .Editor ]: true ,
133
+ [AreaComponent .Preview ]: false ,
134
+ })
94
135
const options: AreaComponent [] = Array (AreaComponentSize )
95
136
.fill (0 )
96
137
.map ((_ , index ) => index )
97
138
const optionLabel = (index : AreaComponent ) => AreaComponent [index ]
139
+ const optionDisable = (index : AreaComponent ) => ! areaActive [index ]
98
140
99
141
const mode = ref (settingsStore .mode )
100
142
watch (
@@ -142,6 +184,74 @@ watch([area2, area3], ([area2, area3]) => {
142
184
}
143
185
})
144
186
187
+ const countAreaActive = computed (() => {
188
+ // eslint-disable-next-line functional/no-let
189
+ let count = 0
190
+ for (const val of Object .values (areaActive )) if (val ) count ++
191
+ return count
192
+ })
193
+ watchEffect (() => {
194
+ areaActive [AreaComponent .Console ] =
195
+ settingsStore .areaActive [AreaComponent .Console ]
196
+ areaActive [AreaComponent .Editor ] =
197
+ settingsStore .areaActive [AreaComponent .Editor ]
198
+ areaActive [AreaComponent .Preview ] =
199
+ settingsStore .areaActive [AreaComponent .Preview ]
200
+ })
201
+ watch (
202
+ countAreaActive ,
203
+ (value ) => {
204
+ if (settingsStore .isModeDisabled (mode .value , value )) {
205
+ mode .value = Mode .rows
206
+ }
207
+ },
208
+ { immediate: true }
209
+ )
210
+ const findNextAreaActive = (
211
+ start : AreaComponent ,
212
+ ignore : (AreaComponent | false )[]
213
+ ) => {
214
+ for (let i = start ; i < start + 3 ; i ++ ) {
215
+ const index = (i >= 3 ? i - 3 : i ) as AreaComponent
216
+ const val = areaActive [index ]
217
+
218
+ if (ignore .includes (index )) continue
219
+
220
+ if (val ) return index
221
+ }
222
+ }
223
+ watch (
224
+ areaActive ,
225
+ (areaActive ) => {
226
+ const a1 = countAreaActive .value > 1
227
+ const a2 = countAreaActive .value > 2
228
+ const a3 = true
229
+
230
+ if (countAreaActive .value > 1 && ! areaActive [area1 .value ]) {
231
+ area1 .value =
232
+ findNextAreaActive (area1 .value , [
233
+ a2 && area2 .value ,
234
+ a3 && area3 .value ,
235
+ ]) ?? area1 .value
236
+ }
237
+ if (countAreaActive .value > 2 && ! areaActive [area2 .value ]) {
238
+ area2 .value =
239
+ findNextAreaActive (area2 .value , [
240
+ a1 && area1 .value ,
241
+ a3 && area3 .value ,
242
+ ]) ?? area2 .value
243
+ }
244
+ if (! areaActive [area3 .value ]) {
245
+ area3 .value =
246
+ findNextAreaActive (area3 .value , [
247
+ a1 && area1 .value ,
248
+ a2 && area2 .value ,
249
+ ]) ?? area3 .value
250
+ }
251
+ },
252
+ { immediate: true , deep: true }
253
+ )
254
+
145
255
// =============== setup ui done ==============
146
256
function apply() {
147
257
settingsStore .mode = mode .value
@@ -150,6 +260,7 @@ function apply() {
150
260
area_2: area2 .value ,
151
261
area_3: area3 .value ,
152
262
}
263
+ Object .assign (settingsStore .areaActive , areaActive )
153
264
}
154
265
</script >
155
266
0 commit comments