feat: remember pane sizes (#2556)
Co-authored-by: Sagar <sagar@Sagars-MacBook-Pro.local>
This commit is contained in:
@@ -6,21 +6,26 @@
|
|||||||
'!flex-row-reverse': SIDEBAR_ON_LEFT && mdAndLarger,
|
'!flex-row-reverse': SIDEBAR_ON_LEFT && mdAndLarger,
|
||||||
}"
|
}"
|
||||||
:horizontal="!mdAndLarger"
|
:horizontal="!mdAndLarger"
|
||||||
|
@resize="setPaneEvent($event, 'vertical')"
|
||||||
>
|
>
|
||||||
<Pane
|
<Pane
|
||||||
size="75"
|
:size="PANE_MAIN_SIZE"
|
||||||
min-size="65"
|
min-size="65"
|
||||||
class="hide-scrollbar !overflow-auto flex flex-col"
|
class="hide-scrollbar !overflow-auto flex flex-col"
|
||||||
>
|
>
|
||||||
<Splitpanes class="smart-splitter" :horizontal="COLUMN_LAYOUT">
|
<Splitpanes
|
||||||
|
class="smart-splitter"
|
||||||
|
:horizontal="COLUMN_LAYOUT"
|
||||||
|
@resize="setPaneEvent($event, 'horizontal')"
|
||||||
|
>
|
||||||
<Pane
|
<Pane
|
||||||
:size="COLUMN_LAYOUT ? 45 : 50"
|
:size="PANE_MAIN_TOP_SIZE"
|
||||||
class="hide-scrollbar !overflow-auto flex flex-col"
|
class="hide-scrollbar !overflow-auto flex flex-col"
|
||||||
>
|
>
|
||||||
<slot name="primary" />
|
<slot name="primary" />
|
||||||
</Pane>
|
</Pane>
|
||||||
<Pane
|
<Pane
|
||||||
:size="COLUMN_LAYOUT ? 65 : 50"
|
:size="PANE_MAIN_BOTTOM_SIZE"
|
||||||
class="flex flex-col hide-scrollbar !overflow-auto"
|
class="flex flex-col hide-scrollbar !overflow-auto"
|
||||||
>
|
>
|
||||||
<slot name="secondary" />
|
<slot name="secondary" />
|
||||||
@@ -29,7 +34,7 @@
|
|||||||
</Pane>
|
</Pane>
|
||||||
<Pane
|
<Pane
|
||||||
v-if="SIDEBAR && hasSidebar"
|
v-if="SIDEBAR && hasSidebar"
|
||||||
size="25"
|
:size="PANE_SIDEBAR_SIZE"
|
||||||
min-size="20"
|
min-size="20"
|
||||||
class="hide-scrollbar !overflow-auto flex flex-col"
|
class="hide-scrollbar !overflow-auto flex flex-col"
|
||||||
>
|
>
|
||||||
@@ -42,8 +47,9 @@
|
|||||||
import { Splitpanes, Pane } from "splitpanes"
|
import { Splitpanes, Pane } from "splitpanes"
|
||||||
import "splitpanes/dist/splitpanes.css"
|
import "splitpanes/dist/splitpanes.css"
|
||||||
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
|
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"
|
||||||
import { computed, useSlots } from "@nuxtjs/composition-api"
|
import { computed, useSlots, ref } from "@nuxtjs/composition-api"
|
||||||
import { useSetting } from "~/newstore/settings"
|
import { useSetting } from "~/newstore/settings"
|
||||||
|
import { setLocalConfig, getLocalConfig } from "~/newstore/localpersistence"
|
||||||
|
|
||||||
const SIDEBAR_ON_LEFT = useSetting("SIDEBAR_ON_LEFT")
|
const SIDEBAR_ON_LEFT = useSetting("SIDEBAR_ON_LEFT")
|
||||||
|
|
||||||
@@ -57,4 +63,60 @@ const SIDEBAR = useSetting("SIDEBAR")
|
|||||||
const slots = useSlots()
|
const slots = useSlots()
|
||||||
|
|
||||||
const hasSidebar = computed(() => !!slots.sidebar)
|
const hasSidebar = computed(() => !!slots.sidebar)
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
layoutId: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
type PaneEvent = {
|
||||||
|
max: number
|
||||||
|
min: number
|
||||||
|
size: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const PANE_SIDEBAR_SIZE = ref(25)
|
||||||
|
const PANE_MAIN_SIZE = ref(75)
|
||||||
|
const PANE_MAIN_TOP_SIZE = ref(45)
|
||||||
|
const PANE_MAIN_BOTTOM_SIZE = ref(65)
|
||||||
|
|
||||||
|
if (!COLUMN_LAYOUT.value) {
|
||||||
|
PANE_MAIN_TOP_SIZE.value = 50
|
||||||
|
PANE_MAIN_BOTTOM_SIZE.value = 50
|
||||||
|
}
|
||||||
|
|
||||||
|
function setPaneEvent(event: PaneEvent[], type: "vertical" | "horizontal") {
|
||||||
|
if (!props.layoutId) return
|
||||||
|
const storageKey = `${props.layoutId}-pane-config-${type}`
|
||||||
|
setLocalConfig(storageKey, JSON.stringify(event))
|
||||||
|
}
|
||||||
|
|
||||||
|
function populatePaneEvent() {
|
||||||
|
if (!props.layoutId) return
|
||||||
|
|
||||||
|
const verticalPaneData = getPaneData("vertical")
|
||||||
|
if (verticalPaneData) {
|
||||||
|
const [mainPane, sidebarPane] = verticalPaneData
|
||||||
|
PANE_MAIN_SIZE.value = mainPane?.size
|
||||||
|
PANE_SIDEBAR_SIZE.value = sidebarPane?.size
|
||||||
|
}
|
||||||
|
|
||||||
|
const horizontalPaneData = getPaneData("horizontal")
|
||||||
|
if (horizontalPaneData) {
|
||||||
|
const [mainTopPane, mainBottomPane] = horizontalPaneData
|
||||||
|
PANE_MAIN_TOP_SIZE.value = mainTopPane?.size
|
||||||
|
PANE_MAIN_BOTTOM_SIZE.value = mainBottomPane?.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPaneData(type: "vertical" | "horizontal"): PaneEvent[] | null {
|
||||||
|
const storageKey = `${props.layoutId}-pane-config-${type}`
|
||||||
|
const paneEvent = getLocalConfig(storageKey)
|
||||||
|
if (!paneEvent) return null
|
||||||
|
return JSON.parse(paneEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
populatePaneEvent()
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<AppPaneLayout>
|
<AppPaneLayout layout-id="docs">
|
||||||
<template #primary>
|
<template #primary>
|
||||||
<div class="flex items-start justify-between p-4">
|
<div class="flex items-start justify-between p-4">
|
||||||
<label>
|
<label>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<AppPaneLayout>
|
<AppPaneLayout layout-id="graphql">
|
||||||
<template #primary>
|
<template #primary>
|
||||||
<GraphqlRequest :conn="gqlConn" />
|
<GraphqlRequest :conn="gqlConn" />
|
||||||
<GraphqlRequestOptions :conn="gqlConn" />
|
<GraphqlRequestOptions :conn="gqlConn" />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<AppPaneLayout>
|
<AppPaneLayout layout-id="http">
|
||||||
<template #primary>
|
<template #primary>
|
||||||
<HttpRequest />
|
<HttpRequest />
|
||||||
<HttpRequestOptions />
|
<HttpRequestOptions />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<AppPaneLayout>
|
<AppPaneLayout layout-id="mqtt">
|
||||||
<template #primary>
|
<template #primary>
|
||||||
<div
|
<div
|
||||||
class="sticky top-0 z-10 flex flex-shrink-0 p-4 overflow-x-auto space-x-2 bg-primary hide-scrollbar"
|
class="sticky top-0 z-10 flex flex-shrink-0 p-4 overflow-x-auto space-x-2 bg-primary hide-scrollbar"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<AppPaneLayout>
|
<AppPaneLayout layout-id="socketio">
|
||||||
<template #primary>
|
<template #primary>
|
||||||
<div
|
<div
|
||||||
class="sticky top-0 z-10 flex flex-shrink-0 p-4 overflow-x-auto space-x-2 bg-primary hide-scrollbar"
|
class="sticky top-0 z-10 flex flex-shrink-0 p-4 overflow-x-auto space-x-2 bg-primary hide-scrollbar"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<AppPaneLayout>
|
<AppPaneLayout layout-id="sse">
|
||||||
<template #primary>
|
<template #primary>
|
||||||
<div
|
<div
|
||||||
class="sticky top-0 z-10 flex flex-shrink-0 p-4 overflow-x-auto space-x-2 bg-primary hide-scrollbar"
|
class="sticky top-0 z-10 flex flex-shrink-0 p-4 overflow-x-auto space-x-2 bg-primary hide-scrollbar"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<AppPaneLayout>
|
<AppPaneLayout layout-id="websocket">
|
||||||
<template #primary>
|
<template #primary>
|
||||||
<div
|
<div
|
||||||
class="sticky top-0 z-10 flex flex-shrink-0 p-4 overflow-x-auto space-x-2 bg-primary hide-scrollbar"
|
class="sticky top-0 z-10 flex flex-shrink-0 p-4 overflow-x-auto space-x-2 bg-primary hide-scrollbar"
|
||||||
|
|||||||
Reference in New Issue
Block a user