-
Notifications
You must be signed in to change notification settings - Fork 495
feat: preview state styles during canvas drags #684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,7 +46,7 @@ import type Block from "@/block"; | |||||||||||||||||||||
| import useBuilderStore from "@/stores/builderStore"; | ||||||||||||||||||||||
| import useCanvasStore from "@/stores/canvasStore"; | ||||||||||||||||||||||
| import blockController from "@/utils/blockController"; | ||||||||||||||||||||||
| import { addPxToNumber } from "@/utils/helpers"; | ||||||||||||||||||||||
| import { addPxToNumber, getNumberFromPx } from "@/utils/helpers"; | ||||||||||||||||||||||
| import { isReorderable, startBlockReorder } from "@/utils/useBlockReorder"; | ||||||||||||||||||||||
| import { Ref, computed, inject, nextTick, onMounted, ref, watch, watchEffect } from "vue"; | ||||||||||||||||||||||
| import setGuides from "../utils/guidesTracker"; | ||||||||||||||||||||||
|
|
@@ -100,6 +100,7 @@ const transforming = computed(() => resizing.value || rotating.value); | |||||||||||||||||||||
| const guides = setGuides(props.target, canvasProps); | ||||||||||||||||||||||
| const moving = ref(false); | ||||||||||||||||||||||
| const preventCLick = ref(false); | ||||||||||||||||||||||
| const hasStyleValue = (value: StyleValue) => value !== null && value !== undefined && value !== ""; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const showPaddingHandler = computed(() => { | ||||||||||||||||||||||
| return ( | ||||||||||||||||||||||
|
|
@@ -296,8 +297,14 @@ const handleMove = (ev: MouseEvent) => { | |||||||||||||||||||||
| const target = ev.target as HTMLElement; | ||||||||||||||||||||||
| const startX = ev.clientX; | ||||||||||||||||||||||
| const startY = ev.clientY; | ||||||||||||||||||||||
| const startLeft = (props.target as HTMLElement).offsetLeft || 0; | ||||||||||||||||||||||
| const startTop = (props.target as HTMLElement).offsetTop || 0; | ||||||||||||||||||||||
| const activeLeft = props.block.getActiveStyleValue("left"); | ||||||||||||||||||||||
| const activeTop = props.block.getActiveStyleValue("top"); | ||||||||||||||||||||||
| const startLeft = hasStyleValue(activeLeft) | ||||||||||||||||||||||
| ? getNumberFromPx(activeLeft) | ||||||||||||||||||||||
| : (props.target as HTMLElement).offsetLeft || 0; | ||||||||||||||||||||||
| const startTop = hasStyleValue(activeTop) | ||||||||||||||||||||||
| ? getNumberFromPx(activeTop) | ||||||||||||||||||||||
| : (props.target as HTMLElement).offsetTop || 0; | ||||||||||||||||||||||
|
Comment on lines
+300
to
+307
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| moving.value = true; | ||||||||||||||||||||||
| guides.showX(); | ||||||||||||||||||||||
|
|
@@ -314,15 +321,15 @@ const handleMove = (ev: MouseEvent) => { | |||||||||||||||||||||
| const movementY = (mouseMoveEvent.clientY - startY) / scale; | ||||||||||||||||||||||
| let finalLeft = startLeft + movementX; | ||||||||||||||||||||||
| let finalTop = startTop + movementY; | ||||||||||||||||||||||
| props.block.setStyle("left", addPxToNumber(finalLeft)); | ||||||||||||||||||||||
| props.block.setStyle("top", addPxToNumber(finalTop)); | ||||||||||||||||||||||
| props.block.setActiveStyle("left", addPxToNumber(finalLeft)); | ||||||||||||||||||||||
| props.block.setActiveStyle("top", addPxToNumber(finalTop)); | ||||||||||||||||||||||
| await nextTick(); | ||||||||||||||||||||||
| const { leftOffset, rightOffset } = guides.getPositionOffset(); | ||||||||||||||||||||||
| if (leftOffset !== 0) { | ||||||||||||||||||||||
| props.block.setStyle("left", addPxToNumber(finalLeft + leftOffset)); | ||||||||||||||||||||||
| props.block.setActiveStyle("left", addPxToNumber(finalLeft + leftOffset)); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| if (rightOffset !== 0) { | ||||||||||||||||||||||
| props.block.setStyle("left", addPxToNumber(finalLeft + rightOffset)); | ||||||||||||||||||||||
| props.block.setActiveStyle("left", addPxToNumber(finalLeft + rightOffset)); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| mouseMoveEvent.preventDefault(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasStyleValueis copy-pasted intoBorderRadiusHandler.vue,BoxResizer.vue, anduseSpacingHandler.ts; extract it to a shared util.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!