From 0b346aabbf0981e626173bc93cd0880d57335108 Mon Sep 17 00:00:00 2001 From: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:20:57 +0200 Subject: [PATCH] decouple node inspector from right hand panel --- .../components/Common/DraggableSeparator.vue | 139 +++++++++++++++++ client/src/components/Panels/FlexPanel.vue | 143 ++---------------- .../src/components/Workflow/Editor/Index.vue | 13 +- .../Workflow/Editor/NodeInspector.vue | 41 +++++ .../Workflow/Editor/WorkflowGraph.vue | 1 + client/src/composables/eventEmitter.ts | 20 +++ 6 files changed, 216 insertions(+), 141 deletions(-) create mode 100644 client/src/components/Common/DraggableSeparator.vue create mode 100644 client/src/components/Workflow/Editor/NodeInspector.vue create mode 100644 client/src/composables/eventEmitter.ts diff --git a/client/src/components/Common/DraggableSeparator.vue b/client/src/components/Common/DraggableSeparator.vue new file mode 100644 index 000000000000..b722bb3c1802 --- /dev/null +++ b/client/src/components/Common/DraggableSeparator.vue @@ -0,0 +1,139 @@ + + + + + diff --git a/client/src/components/Panels/FlexPanel.vue b/client/src/components/Panels/FlexPanel.vue index 9d0031af395f..a01a8612b097 100644 --- a/client/src/components/Panels/FlexPanel.vue +++ b/client/src/components/Panels/FlexPanel.vue @@ -2,14 +2,9 @@ import { library } from "@fortawesome/fontawesome-svg-core"; import { faChevronLeft, faChevronRight } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; -import { useDebounce, useDraggable } from "@vueuse/core"; import { computed, ref, watch } from "vue"; -import { useTimeoutThrottle } from "@/composables/throttle"; - -import { determineWidth } from "./utilities"; - -const { throttle } = useTimeoutThrottle(10); +import DraggableSeparator from "../Common/DraggableSeparator.vue"; library.add(faChevronLeft, faChevronRight); @@ -28,26 +23,18 @@ const props = withDefaults(defineProps(), { defaultWidth: 300, }); -const draggable = ref(null); -const root = ref(null); - const panelWidth = ref(props.defaultWidth); -const show = ref(true); - -const { position, isDragging } = useDraggable(draggable, { - preventDefault: true, - exact: true, -}); -const hoverDraggable = ref(false); -const hoverDraggableDebounced = useDebounce(hoverDraggable, 100); -const showHover = computed(() => (hoverDraggable.value && hoverDraggableDebounced.value) || isDragging.value); +const root = ref(null); +const show = ref(true); const showToggle = ref(false); const hoverToggle = ref(false); -const hoverDraggableOrToggle = computed( - () => (hoverDraggableDebounced.value || hoverToggle.value) && !isDragging.value -); + +const isHoveringDragHandle = ref(false); +const isDragging = ref(false); + +const hoverDraggableOrToggle = computed(() => (isHoveringDragHandle.value || hoverToggle.value) && !isDragging.value); const toggleLinger = 500; const toggleShowDelay = 600; @@ -70,72 +57,6 @@ watch( } ); -/** Watch position changes and adjust width accordingly */ -watch(position, () => { - throttle(() => { - if (!root.value || !draggable.value) { - return; - } - - const rectRoot = root.value.getBoundingClientRect(); - const rectDraggable = draggable.value.getBoundingClientRect(); - panelWidth.value = determineWidth( - rectRoot, - rectDraggable, - props.minWidth, - props.maxWidth, - props.side, - position.value.x - ); - }); -}); - -/** If the `maxWidth` changes, prevent the panel from exceeding it */ -watch( - () => props.maxWidth, - (newVal) => { - if (newVal && panelWidth.value > newVal) { - panelWidth.value = props.maxWidth; - } - }, - { immediate: true } -); - -/** If the `minWidth` changes, ensure the panel width is at least the `minWidth` */ -watch( - () => props.minWidth, - (newVal) => { - if (newVal && panelWidth.value < newVal) { - panelWidth.value = newVal; - } - }, - { immediate: true } -); - -function onKeyLeft() { - if (props.side === "left") { - decreaseWidth(); - } else { - increaseWidth(); - } -} - -function onKeyRight() { - if (props.side === "left") { - increaseWidth(); - } else { - decreaseWidth(); - } -} - -function increaseWidth(by = 50) { - panelWidth.value = Math.min(panelWidth.value + by, props.maxWidth); -} - -function decreaseWidth(by = 50) { - panelWidth.value = Math.max(panelWidth.value - by, props.minWidth); -} - const sideClasses = computed(() => ({ left: props.side === "left", right: props.side === "right", @@ -148,19 +69,9 @@ const sideClasses = computed(() => ({ :id="side" ref="root" class="flex-panel" - :class="{ ...sideClasses, 'show-hover': showHover }" + :class="{ ...sideClasses }" :style="`--width: ${panelWidth}px`"> - +