|
@@ -1,101 +1,87 @@
|
|
|
+import { TransferCtrl } from "@/modules/editor/controllers/TransferCtrl";
|
|
|
import { css } from "@linaria/core";
|
|
|
import { defineComponent, onMounted, ref } from "vue";
|
|
|
-import { string } from "vue-types";
|
|
|
import { useEditor } from "../../../..";
|
|
|
-import RingBtns from "./RingBtns";
|
|
|
+import { string } from "vue-types";
|
|
|
+import { CompToolbars } from "@/modules/editor/objects/EditingCompTools";
|
|
|
+import { DesignComp } from "@/modules/editor/objects/DesignTemp/DesignComp";
|
|
|
+
|
|
|
+const btnStyles = {
|
|
|
+ top: {
|
|
|
+ top: 0,
|
|
|
+ left: "50%",
|
|
|
+ transform: "translate(-50%, -50%)",
|
|
|
+ },
|
|
|
+ bottom: {
|
|
|
+ bottom: 0,
|
|
|
+ left: "50%",
|
|
|
+ transform: "rotate(180deg) translate(50%, -50%)",
|
|
|
+ },
|
|
|
+ left: {
|
|
|
+ top: "50%",
|
|
|
+ left: 0,
|
|
|
+ transform: "rotate(-90deg) translate(50%, -50%)",
|
|
|
+ },
|
|
|
+ right: {
|
|
|
+ top: "50%",
|
|
|
+ right: 0,
|
|
|
+ transform: "rotate(90deg) translate(-50%, -50%)",
|
|
|
+ },
|
|
|
+};
|
|
|
|
|
|
export const Transfer = defineComponent({
|
|
|
props: {
|
|
|
compId: string().isRequired,
|
|
|
},
|
|
|
setup(props) {
|
|
|
- const { store, helper } = useEditor();
|
|
|
- const resizeRef = ref<HTMLElement>();
|
|
|
- const moveRef = ref<HTMLElement>();
|
|
|
- const start = {
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
- width: 0,
|
|
|
- height: 0,
|
|
|
- offsetX: 0,
|
|
|
- offsetY: 0,
|
|
|
- };
|
|
|
-
|
|
|
- const comp = store.designData.compMap[props.compId];
|
|
|
- let compEl: HTMLElement;
|
|
|
+ const transferRef = ref();
|
|
|
+ const editor = useEditor();
|
|
|
+ const transferCtrl = new TransferCtrl(editor);
|
|
|
|
|
|
onMounted(() => {
|
|
|
- if (!resizeRef.value || !moveRef.value) return;
|
|
|
- resizeRef.value.addEventListener("mousedown", startDrag);
|
|
|
- moveRef.value.addEventListener("mousedown", startMove);
|
|
|
- compEl = moveRef.value.parentElement as HTMLElement;
|
|
|
- });
|
|
|
-
|
|
|
- function startMove(e: MouseEvent) {
|
|
|
- start.x = e.clientX;
|
|
|
- start.y = e.clientY;
|
|
|
-
|
|
|
- document.addEventListener("mousemove", move);
|
|
|
- document.addEventListener("mouseup", stopMove);
|
|
|
- }
|
|
|
- function move(e: MouseEvent) {
|
|
|
- const viewEl = compEl.parentElement;
|
|
|
- if (!viewEl) return;
|
|
|
- start.offsetX = e.clientX - start.x;
|
|
|
- start.offsetY = e.clientY - start.y;
|
|
|
-
|
|
|
- viewEl.style.left = helper.designToNaturalSize(
|
|
|
- comp.value.position[0] + start.offsetX * 2
|
|
|
- );
|
|
|
- viewEl.style.top = helper.designToNaturalSize(
|
|
|
- comp.value.position[1] + start.offsetY * 2
|
|
|
+ transferCtrl.init(
|
|
|
+ transferRef.value.parentElement as HTMLElement,
|
|
|
+ props.compId
|
|
|
);
|
|
|
- }
|
|
|
- function stopMove(e: MouseEvent) {
|
|
|
- comp.value.position[0] += start.offsetX * 2;
|
|
|
- comp.value.position[1] += start.offsetY * 2;
|
|
|
- document.removeEventListener("mousemove", move);
|
|
|
- document.removeEventListener("mouseup", stopMove);
|
|
|
- }
|
|
|
-
|
|
|
- function startDrag(e: MouseEvent) {
|
|
|
- start.x = e.clientX;
|
|
|
- start.y = e.clientY;
|
|
|
- start.width = comp.layout.size?.[0] || compEl.clientWidth * 2;
|
|
|
- start.height = comp.layout.size?.[1] || compEl.clientHeight * 2;
|
|
|
-
|
|
|
- document.addEventListener("mousemove", drag);
|
|
|
- document.addEventListener("mouseup", stopDrag);
|
|
|
- }
|
|
|
+ });
|
|
|
|
|
|
- function drag(e: MouseEvent) {
|
|
|
- console.log(e.clientX, e.clientY);
|
|
|
- start.offsetX = e.clientX - start.x;
|
|
|
- start.offsetY = e.clientY - start.y;
|
|
|
- compEl.style.width = helper.designToNaturalSize(
|
|
|
- start.width + start.offsetX * 2
|
|
|
- );
|
|
|
- compEl.style.height = helper.designToNaturalSize(
|
|
|
- start.height + start.offsetY * 2
|
|
|
+ return () => {
|
|
|
+ const comp = editor.helper.findComp(props.compId) as DesignComp;
|
|
|
+ return (
|
|
|
+ <div ref={transferRef}>
|
|
|
+ <div class={toolbarStyle}>
|
|
|
+ {CompToolbars.default.map((item, i) => {
|
|
|
+ return (
|
|
|
+ <item.component
|
|
|
+ class="p-4px"
|
|
|
+ value={item.value?.(comp)}
|
|
|
+ onClick={() => item.onClick.call(editor, comp)}
|
|
|
+ />
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </div>
|
|
|
+ <div class={borderStyle}></div>
|
|
|
+ <div
|
|
|
+ class={[resizeStyle, "drag-disable"]}
|
|
|
+ onMousedown={(e) => transferCtrl.mousedown(e, "resize")}
|
|
|
+ ></div>
|
|
|
+ {Object.entries(btnStyles).map(([name, style]) => (
|
|
|
+ <div
|
|
|
+ class={[fanBtnStyle, "drag-disable"]}
|
|
|
+ style={style}
|
|
|
+ onMousedown={(e) =>
|
|
|
+ transferCtrl.mousedown(
|
|
|
+ e,
|
|
|
+ `offset_${name as keyof typeof btnStyles}`
|
|
|
+ )
|
|
|
+ }
|
|
|
+ >
|
|
|
+ ↑
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
);
|
|
|
- }
|
|
|
-
|
|
|
- function stopDrag() {
|
|
|
- comp.layout.size || (comp.layout.size = [0, 0]);
|
|
|
- comp.layout.size[0] = start.width + start.offsetX * 2;
|
|
|
- comp.layout.size[1] = start.height + start.offsetY * 2;
|
|
|
- document.removeEventListener("mousemove", drag);
|
|
|
- document.removeEventListener("mouseup", stopDrag);
|
|
|
- }
|
|
|
-
|
|
|
- return () => (
|
|
|
- <>
|
|
|
- <div class={borderStyle}></div>
|
|
|
- <div ref={resizeRef} class={[resizeStyle, "drag-disable"]}></div>
|
|
|
- <div ref={moveRef} class={[moveStyle, "drag-disable"]}></div>
|
|
|
- <RingBtns class={offsetStyle} />
|
|
|
- </>
|
|
|
- );
|
|
|
+ };
|
|
|
},
|
|
|
});
|
|
|
|
|
@@ -127,24 +113,27 @@ const resizeStyle = css`
|
|
|
}
|
|
|
`;
|
|
|
|
|
|
-const moveStyle = css`
|
|
|
+const fanBtnStyle = css`
|
|
|
position: absolute;
|
|
|
- bottom: 0;
|
|
|
- left: 50%;
|
|
|
- width: 40px;
|
|
|
- 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;
|
|
|
+ width: 30px;
|
|
|
+ height: 30px;
|
|
|
+ border-radius: 50%;
|
|
|
+ background-color: rgba(255, 255, 255, 0.3);
|
|
|
+ font-size: 12px;
|
|
|
+ text-align: center;
|
|
|
+ clip-path: polygon(0 0, 100% 0, 100% 50%, 0 50%);
|
|
|
+ cursor: grab;
|
|
|
+ z-index: 99;
|
|
|
+
|
|
|
+ &:hover {
|
|
|
+ background: @inf-primary-color;
|
|
|
+ }
|
|
|
`;
|
|
|
|
|
|
-const offsetStyle = css`
|
|
|
+const toolbarStyle = css`
|
|
|
+ @apply bg-white shadow rounded space-x-4px p-4px whitespace-nowrap;
|
|
|
position: absolute;
|
|
|
- bottom: 0;
|
|
|
+ top: 0;
|
|
|
left: 50%;
|
|
|
- transform: translate(-50%, 60px);
|
|
|
- z-index: 9;
|
|
|
+ transform: translate(-50%, -60px);
|
|
|
`;
|