From 124627d724eb6ece23f405ba096477fb934e280d Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:26:35 +0800 Subject: [PATCH] refactor: wrapping element with drag and resize behavior as a standalone component --- frontend/src/AppContent.vue | 88 ++++--------- .../components/common/ResizeableWrapper.vue | 122 ++++++++++++++++++ .../components/content/ContentValueTab.vue | 12 +- frontend/src/langs/en.json | 2 +- frontend/src/langs/zh-cn.json | 2 +- 5 files changed, 152 insertions(+), 74 deletions(-) create mode 100644 frontend/src/components/common/ResizeableWrapper.vue diff --git a/frontend/src/AppContent.vue b/frontend/src/AppContent.vue index 3ffa147..d4b060e 100644 --- a/frontend/src/AppContent.vue +++ b/frontend/src/AppContent.vue @@ -16,6 +16,7 @@ import ToolbarControlWidget from '@/components/common/ToolbarControlWidget.vue' import { EventsOn, WindowIsFullscreen, WindowIsMaximised, WindowToggleMaximise } from 'wailsjs/runtime/runtime.js' import { isMacOS } from '@/utils/platform.js' import iconUrl from '@/assets/images/icon.png' +import ResizeableWrapper from '@/components/common/ResizeableWrapper.vue' const themeVars = useThemeVars() @@ -25,8 +26,6 @@ const props = defineProps({ const data = reactive({ navMenuWidth: 60, - hoverResize: false, - resizing: false, toolbarHeight: 45, }) @@ -38,33 +37,10 @@ const logPaneRef = ref(null) // provide('preferences', preferences) const saveSidebarWidth = debounce(prefStore.savePreferences, 1000, { trailing: true }) -const handleResize = (evt) => { - if (data.resizing) { - prefStore.setAsideWidth(Math.max(evt.clientX - data.navMenuWidth, 300)) - saveSidebarWidth() - } +const handleResize = () => { + saveSidebarWidth() } -const stopResize = () => { - data.resizing = false - document.removeEventListener('mousemove', handleResize) - document.removeEventListener('mouseup', stopResize) -} - -const startResize = () => { - data.resizing = true - document.addEventListener('mousemove', handleResize) - document.addEventListener('mouseup', stopResize) -} - -const asideWidthVal = computed(() => { - return prefStore.behavior.asideWidth + 'px' -}) - -const dragging = computed(() => { - return data.hoverResize || data.resizing -}) - watch( () => tabStore.nav, (nav) => { @@ -166,15 +142,6 @@ onMounted(async () => { -