|
@@ -1,7 +1,8 @@
|
|
import { css } from "@linaria/core";
|
|
import { css } from "@linaria/core";
|
|
import { defineComponent, onMounted, ref } from "vue";
|
|
import { defineComponent, onMounted, ref } from "vue";
|
|
import { string } from "vue-types";
|
|
import { string } from "vue-types";
|
|
-import { useEditor } from "../../..";
|
|
|
|
|
|
+import { useEditor } from "../../../..";
|
|
|
|
+import RingBtns from "./RingBtns";
|
|
|
|
|
|
export const Transfer = defineComponent({
|
|
export const Transfer = defineComponent({
|
|
props: {
|
|
props: {
|
|
@@ -21,18 +22,13 @@ export const Transfer = defineComponent({
|
|
};
|
|
};
|
|
|
|
|
|
const comp = store.designData.compMap[props.compId];
|
|
const comp = store.designData.compMap[props.compId];
|
|
- let parentCompEl: HTMLElement;
|
|
|
|
|
|
+ let compEl: HTMLElement;
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
if (!resizeRef.value || !moveRef.value) return;
|
|
if (!resizeRef.value || !moveRef.value) return;
|
|
resizeRef.value.addEventListener("mousedown", startDrag);
|
|
resizeRef.value.addEventListener("mousedown", startDrag);
|
|
moveRef.value.addEventListener("mousedown", startMove);
|
|
moveRef.value.addEventListener("mousedown", startMove);
|
|
- const parentContentEl = getClosestParentWithClass(
|
|
|
|
- resizeRef.value,
|
|
|
|
- "view_content"
|
|
|
|
- );
|
|
|
|
- if (!parentContentEl) return;
|
|
|
|
- parentCompEl = parentContentEl;
|
|
|
|
|
|
+ compEl = moveRef.value.parentElement as HTMLElement;
|
|
});
|
|
});
|
|
|
|
|
|
function startMove(e: MouseEvent) {
|
|
function startMove(e: MouseEvent) {
|
|
@@ -43,7 +39,7 @@ export const Transfer = defineComponent({
|
|
document.addEventListener("mouseup", stopMove);
|
|
document.addEventListener("mouseup", stopMove);
|
|
}
|
|
}
|
|
function move(e: MouseEvent) {
|
|
function move(e: MouseEvent) {
|
|
- const viewEl = parentCompEl.parentElement;
|
|
|
|
|
|
+ const viewEl = compEl.parentElement;
|
|
if (!viewEl) return;
|
|
if (!viewEl) return;
|
|
start.offsetX = e.clientX - start.x;
|
|
start.offsetX = e.clientX - start.x;
|
|
start.offsetY = e.clientY - start.y;
|
|
start.offsetY = e.clientY - start.y;
|
|
@@ -65,20 +61,21 @@ export const Transfer = defineComponent({
|
|
function startDrag(e: MouseEvent) {
|
|
function startDrag(e: MouseEvent) {
|
|
start.x = e.clientX;
|
|
start.x = e.clientX;
|
|
start.y = e.clientY;
|
|
start.y = e.clientY;
|
|
- start.width = comp.layout.size?.[0] || 0;
|
|
|
|
- start.height = comp.layout.size?.[1] || 0;
|
|
|
|
|
|
+ start.width = comp.layout.size?.[0] || compEl.clientWidth * 2;
|
|
|
|
+ start.height = comp.layout.size?.[1] || compEl.clientHeight * 2;
|
|
|
|
|
|
document.addEventListener("mousemove", drag);
|
|
document.addEventListener("mousemove", drag);
|
|
document.addEventListener("mouseup", stopDrag);
|
|
document.addEventListener("mouseup", stopDrag);
|
|
}
|
|
}
|
|
|
|
|
|
function drag(e: MouseEvent) {
|
|
function drag(e: MouseEvent) {
|
|
|
|
+ console.log(e.clientX, e.clientY);
|
|
start.offsetX = e.clientX - start.x;
|
|
start.offsetX = e.clientX - start.x;
|
|
start.offsetY = e.clientY - start.y;
|
|
start.offsetY = e.clientY - start.y;
|
|
- parentCompEl.style.width = helper.designToNaturalSize(
|
|
|
|
|
|
+ compEl.style.width = helper.designToNaturalSize(
|
|
start.width + start.offsetX * 2
|
|
start.width + start.offsetX * 2
|
|
);
|
|
);
|
|
- parentCompEl.style.height = helper.designToNaturalSize(
|
|
|
|
|
|
+ compEl.style.height = helper.designToNaturalSize(
|
|
start.height + start.offsetY * 2
|
|
start.height + start.offsetY * 2
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -93,35 +90,37 @@ export const Transfer = defineComponent({
|
|
|
|
|
|
return () => (
|
|
return () => (
|
|
<>
|
|
<>
|
|
- <div ref={resizeRef} class={resizeStyle}></div>
|
|
|
|
- <div ref={moveRef} class={moveStyle}></div>
|
|
|
|
|
|
+ <div class={borderStyle}></div>
|
|
|
|
+ <div ref={resizeRef} class={[resizeStyle, "drag-disable"]}></div>
|
|
|
|
+ <div ref={moveRef} class={[moveStyle, "drag-disable"]}></div>
|
|
|
|
+ <RingBtns class={offsetStyle} />
|
|
</>
|
|
</>
|
|
);
|
|
);
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
|
|
-function getClosestParentWithClass(element: HTMLElement, className: string) {
|
|
|
|
- let parent = element.parentElement;
|
|
|
|
-
|
|
|
|
- while (parent) {
|
|
|
|
- if (parent.classList.contains(className)) {
|
|
|
|
- return parent;
|
|
|
|
- }
|
|
|
|
- parent = parent.parentElement;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return null;
|
|
|
|
-}
|
|
|
|
|
|
+const borderStyle = css`
|
|
|
|
+ position: absolute;
|
|
|
|
+ top: 0;
|
|
|
|
+ left: 0;
|
|
|
|
+ width: 100%;
|
|
|
|
+ height: 100%;
|
|
|
|
+ outline: 2px solid @inf-primary-color;
|
|
|
|
+ pointer-events: none;
|
|
|
|
+ z-index: 9;
|
|
|
|
+`;
|
|
|
|
|
|
const resizeStyle = css`
|
|
const resizeStyle = css`
|
|
position: absolute;
|
|
position: absolute;
|
|
bottom: 0;
|
|
bottom: 0;
|
|
right: 0;
|
|
right: 0;
|
|
- width: 8px;
|
|
|
|
- height: 8px;
|
|
|
|
- border-bottom: 4px solid;
|
|
|
|
- border-right: 4px solid;
|
|
|
|
- border-color: @inf-primary-fade-color;
|
|
|
|
|
|
+ width: 16px;
|
|
|
|
+ height: 16px;
|
|
|
|
+ border-radius: 50%;
|
|
|
|
+ background-color: #fff;
|
|
|
|
+ z-index: 9;
|
|
|
|
+ transform: translate(50%, 50%);
|
|
|
|
+ box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.2);
|
|
cursor: nwse-resize;
|
|
cursor: nwse-resize;
|
|
&:hover {
|
|
&:hover {
|
|
border-color: @inf-primary-color;
|
|
border-color: @inf-primary-color;
|
|
@@ -133,14 +132,19 @@ const moveStyle = css`
|
|
bottom: 0;
|
|
bottom: 0;
|
|
left: 50%;
|
|
left: 50%;
|
|
width: 40px;
|
|
width: 40px;
|
|
- height: 4px;
|
|
|
|
- transform: translate(-50%, 50%);
|
|
|
|
- background-color: @inf-primary-color;
|
|
|
|
- border-radius: 4px;
|
|
|
|
|
|
+ height: 8px;
|
|
|
|
+ transform: translate(-50%, 5px);
|
|
|
|
+ background-color: #fff;
|
|
|
|
+ border-radius: 8px;
|
|
|
|
+ box-shadow: 0 0 2px 1px rgba(0, 0, 0, 0.2);
|
|
|
|
+ z-index: 9;
|
|
cursor: all-scroll;
|
|
cursor: all-scroll;
|
|
- &:hover {
|
|
|
|
- border-color: #fff;
|
|
|
|
- box-shadow: 0 0 3px 2px rgba(0, 0, 0, 0.5);
|
|
|
|
- outline: 2px solid #fff;
|
|
|
|
- }
|
|
|
|
|
|
+`;
|
|
|
|
+
|
|
|
|
+const offsetStyle = css`
|
|
|
|
+ position: absolute;
|
|
|
|
+ bottom: 0;
|
|
|
|
+ left: 50%;
|
|
|
|
+ transform: translate(-50%, 60px);
|
|
|
|
+ z-index: 9;
|
|
`;
|
|
`;
|