Skip to content

Commit 66d9082

Browse files
committed
feat(views): maximize a view on double click
1 parent 8b2b3ea commit 66d9082

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/components/LayoutGrid.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
>
77
<div v-for="(item, i) in items" :key="i" class="d-flex flex-equal">
88
<layout-grid v-if="item.type === 'layout'" :layout="(item as Layout)" />
9-
<div v-else class="layout-item">
9+
<div v-else class="layout-item" @dblclick="maximize(item.id)">
1010
<component
1111
:is="item.component"
1212
:key="item.id"
@@ -35,6 +35,9 @@ export default defineComponent({
3535
useViewStore().setActiveViewID(id);
3636
}
3737
},
38+
maximize(viewId: string) {
39+
useViewStore().toggleMaximizeView(viewId);
40+
},
3841
},
3942
props: {
4043
layout: {

src/store/views.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,22 @@ import {
99
View,
1010
} from '../io/state-file/schema';
1111

12+
function cloneLayout(layout: Layout): Layout {
13+
return {
14+
direction: layout.direction,
15+
items: layout.items.map((item) =>
16+
typeof item === 'string' ? item : cloneLayout(item)
17+
),
18+
...(layout.name && { name: layout.name }),
19+
};
20+
}
21+
1222
interface State {
1323
layout: Layout;
1424
viewSpecs: Record<string, ViewSpec>;
1525
activeViewID: string;
26+
maximizedViewID: string | null;
27+
originalLayout: Layout | null;
1628
}
1729

1830
export const useViewStore = defineStore('view', {
@@ -23,6 +35,8 @@ export const useViewStore = defineStore('view', {
2335
},
2436
viewSpecs: structuredClone(InitViewSpecs),
2537
activeViewID: '',
38+
maximizedViewID: null,
39+
originalLayout: null,
2640
}),
2741
getters: {
2842
viewIDs(state) {
@@ -44,6 +58,7 @@ export const useViewStore = defineStore('view', {
4458
}
4559
},
4660
setLayout(layout: Layout) {
61+
this.restoreLayout();
4762
this.layout = layout;
4863

4964
const layoutsToProcess = [layout];
@@ -59,6 +74,33 @@ export const useViewStore = defineStore('view', {
5974
});
6075
}
6176
},
77+
maximizeView(viewID: string) {
78+
if (this.maximizedViewID) {
79+
this.restoreLayout();
80+
}
81+
82+
this.originalLayout = cloneLayout(this.layout);
83+
this.maximizedViewID = viewID;
84+
85+
this.layout = {
86+
direction: LayoutDirection.H,
87+
items: [viewID],
88+
};
89+
},
90+
restoreLayout() {
91+
if (this.originalLayout) {
92+
this.layout = this.originalLayout;
93+
this.originalLayout = null;
94+
this.maximizedViewID = null;
95+
}
96+
},
97+
toggleMaximizeView(viewID: string) {
98+
if (this.maximizedViewID === viewID) {
99+
this.restoreLayout();
100+
} else {
101+
this.maximizeView(viewID);
102+
}
103+
},
62104
serialize(stateFile: StateFile) {
63105
const viewConfigStore = useViewConfigStore();
64106
const { manifest } = stateFile;

0 commit comments

Comments
 (0)