Skip to content

Commit 75272c6

Browse files
add mode two tab
1 parent 2516bb8 commit 75272c6

File tree

4 files changed

+180
-7
lines changed

4 files changed

+180
-7
lines changed

src/components/sketch/SideBar/components/Dialog-SettingLayout.vue

Lines changed: 116 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,42 @@
55
<div class="text-subtitle1">Setting Layout</div>
66
</q-card-section>
77
<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+
832
<section class="row">
933
<div
1034
v-for="(_, value) in ModeSize"
1135
:key="value"
12-
v-memo="[value === mode]"
36+
v-memo="[value === mode, settingsStore.isModeDisabled(value)]"
1337
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+
"
1544
>
1645
<div
1746
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,21 +63,26 @@
3463
<div class="text-subtitle1">Preview</div>
3564
<!-- frame preview -->
3665
<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">
3971
<q-select
4072
v-model="area1"
4173
dense
4274
:options="options"
75+
:option-disable="optionDisable"
4376
:option-label="optionLabel"
4477
/>
4578
</div>
4679
<div class="group">
47-
<div class="area_2">
80+
<div v-if="countAreaActive > 2" class="area_2">
4881
<q-select
4982
v-model="area2"
5083
dense
5184
:options="options"
85+
:option-disable="optionDisable"
5286
:option-label="optionLabel"
5387
/>
5488
</div>
@@ -57,6 +91,7 @@
5791
v-model="area3"
5892
dense
5993
:options="options"
94+
:option-disable="optionDisable"
6095
:option-label="optionLabel"
6196
/>
6297
</div>
@@ -83,6 +118,7 @@
83118

84119
<script lang="ts" setup>
85120
import {
121+
Area,
86122
AreaComponent,
87123
AreaComponentSize,
88124
Mode,
@@ -91,10 +127,16 @@ import {
91127
92128
const settingsStore = useSettingsStore()
93129
130+
const areaActive = reactive<Record<AreaComponent, boolean>>({
131+
[AreaComponent.Console]: true,
132+
[AreaComponent.Editor]: true,
133+
[AreaComponent.Preview]: false,
134+
})
94135
const options: AreaComponent[] = Array(AreaComponentSize)
95136
.fill(0)
96137
.map((_, index) => index)
97138
const optionLabel = (index: AreaComponent) => AreaComponent[index]
139+
const optionDisable = (index: AreaComponent) => !areaActive[index]
98140
99141
const mode = ref(settingsStore.mode)
100142
watch(
@@ -142,6 +184,74 @@ watch([area2, area3], ([area2, area3]) => {
142184
}
143185
})
144186
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+
145255
// =============== setup ui done ==============
146256
function apply() {
147257
settingsStore.mode = mode.value
@@ -150,6 +260,7 @@ function apply() {
150260
area_2: area2.value,
151261
area_3: area3.value,
152262
}
263+
Object.assign(settingsStore.areaActive, areaActive)
153264
}
154265
</script>
155266

src/components/sketch/SketchMain/SketchMain.styles.scss

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
border-bottom-width: 1px;
2727
}
2828
}
29+
30+
&.active-2 {
31+
.area_1 {
32+
@apply h-1/2 flex-none;
33+
border-bottom-width: 1px;
34+
}
35+
.group .area_3 {
36+
@apply h-full flex-1;
37+
}
38+
}
2939
}
3040
&.rows {
3141
&,
@@ -47,6 +57,16 @@
4757
border-right-width: 1px;
4858
}
4959
}
60+
61+
&.active-2 {
62+
.area_1 {
63+
@apply w-1/2 flex-none;
64+
border-right-width: 1px;
65+
}
66+
.group .area_3 {
67+
@apply w-full flex-1;
68+
}
69+
}
5070
}
5171
&.bottom {
5272
@apply flex flex-col flex-nowrap;
@@ -141,4 +161,10 @@
141161
}
142162
}
143163
}
164+
165+
&.active-1 {
166+
.area_1 {
167+
@apply fit;
168+
}
169+
}
144170
}

src/components/sketch/SketchMain/SketchMain.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<template>
22
<div
33
class="container overflow-hidden max-w-full"
4-
:class="Mode[settingsStore.mode]"
4+
:class="[
5+
Mode[settingsStore.mode],
6+
`active-${settingsStore.countAreaActive}`,
7+
]"
58
>
69
<Resizable
10+
v-if="settingsStore.countAreaActive > 1"
711
class="area_1"
812
:enable="{
913
top: mode === Mode.bottom,
@@ -30,6 +34,7 @@
3034
</Resizable>
3135
<div class="group min-w-0">
3236
<Resizable
37+
v-if="settingsStore.countAreaActive > 2"
3338
class="area_2"
3439
:enable="{
3540
top: false,

src/stores/settings.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ import { defineStore } from "pinia"
77

88
export const useSettingsStore = defineStore("settings", () => {
99
const mode = ref<Mode>(Mode.top)
10+
11+
const areaActive = reactive<Record<AreaComponent, boolean>>({
12+
[AreaComponent.Console]: true,
13+
[AreaComponent.Editor]: true,
14+
[AreaComponent.Preview]: true,
15+
})
16+
const countAreaActive = computed(() => {
17+
// eslint-disable-next-line functional/no-let
18+
let count = 0
19+
for (const val of Object.values(areaActive)) if (val) count++
20+
return count
21+
})
1022
// bottom reverse
1123
// right reverse
1224

@@ -38,5 +50,24 @@ export const useSettingsStore = defineStore("settings", () => {
3850
}
3951
}
4052

41-
return { mode, mapTargetTo, getMapTargetDefault }
53+
function isModeDisabled(mode: Mode, count = countAreaActive.value): boolean {
54+
// if (mode === Mode.left)
55+
switch (count) {
56+
case 3:
57+
return false
58+
case 2:
59+
return mode !== Mode.columns && mode !== Mode.rows
60+
default:
61+
return true
62+
}
63+
}
64+
65+
return {
66+
mode,
67+
countAreaActive,
68+
mapTargetTo,
69+
getMapTargetDefault,
70+
areaActive,
71+
isModeDisabled,
72+
}
4273
})

0 commit comments

Comments
 (0)