|
@@ -19,6 +19,8 @@ import {
|
|
|
useSetViewport,
|
|
useSetViewport,
|
|
|
useViewer,
|
|
useViewer,
|
|
|
useViewerDebounce,
|
|
useViewerDebounce,
|
|
|
|
|
+ useViewerInvertTransform,
|
|
|
|
|
+ useViewerTransform,
|
|
|
useViewerTransformConfig,
|
|
useViewerTransformConfig,
|
|
|
} from "./use-viewer.ts";
|
|
} from "./use-viewer.ts";
|
|
|
import { useGlobalResize, useListener } from "./use-event.ts";
|
|
import { useGlobalResize, useListener } from "./use-event.ts";
|
|
@@ -29,23 +31,33 @@ import { usePaste } from "./use-paste.ts";
|
|
|
import { useMouseShapesStatus } from "./use-mouse-status.ts";
|
|
import { useMouseShapesStatus } from "./use-mouse-status.ts";
|
|
|
import { Mode } from "@/constant/mode.ts";
|
|
import { Mode } from "@/constant/mode.ts";
|
|
|
import { ElMessageBox } from "element-plus";
|
|
import { ElMessageBox } from "element-plus";
|
|
|
-import { mergeFuns } from "@/utils/shared.ts";
|
|
|
|
|
|
|
+import { asyncTimeout, mergeFuns } from "@/utils/shared.ts";
|
|
|
import { getImage, isSvgString } from "@/utils/resource.ts";
|
|
import { getImage, isSvgString } from "@/utils/resource.ts";
|
|
|
import { useResourceHandler } from "./use-fetch.ts";
|
|
import { useResourceHandler } from "./use-fetch.ts";
|
|
|
import { useConfig } from "./use-config.ts";
|
|
import { useConfig } from "./use-config.ts";
|
|
|
import { useExcludeSelection, useSelectionRevise } from "./use-selection.ts";
|
|
import { useExcludeSelection, useSelectionRevise } from "./use-selection.ts";
|
|
|
import { useFormalLayer, useGetFormalChildren } from "./use-layer.ts";
|
|
import { useFormalLayer, useGetFormalChildren } from "./use-layer.ts";
|
|
|
-import { components } from "../components/index.ts";
|
|
|
|
|
|
|
+import { components, DrawItem, ShapeType } from "../components/index.ts";
|
|
|
import { useProportion } from "./use-proportion.ts";
|
|
import { useProportion } from "./use-proportion.ts";
|
|
|
import { useGetDXF } from "./use-dxf.ts";
|
|
import { useGetDXF } from "./use-dxf.ts";
|
|
|
import { getIconStyle } from "../components/icon/index.ts";
|
|
import { getIconStyle } from "../components/icon/index.ts";
|
|
|
import { useGetShapeBelong } from "./use-component.ts";
|
|
import { useGetShapeBelong } from "./use-component.ts";
|
|
|
|
|
+import { IRect } from "konva/lib/types";
|
|
|
|
|
+import { getBaseItem } from "../components/util.ts";
|
|
|
|
|
+import { Pos } from "@/utils/math.ts";
|
|
|
|
|
+import { Transform } from "konva/lib/Util";
|
|
|
|
|
+import { getCurrentNdx, getSerialFontW } from "../components/serial/index.ts";
|
|
|
|
|
|
|
|
// 自动粘贴服务
|
|
// 自动粘贴服务
|
|
|
export const useAutoPaste = () => {
|
|
export const useAutoPaste = () => {
|
|
|
const paste = usePaste();
|
|
const paste = usePaste();
|
|
|
const drawAPI = useInteractiveDrawShapeAPI();
|
|
const drawAPI = useInteractiveDrawShapeAPI();
|
|
|
const resourceHandler = useResourceHandler();
|
|
const resourceHandler = useResourceHandler();
|
|
|
|
|
+ const viewMat = useViewerTransform();
|
|
|
|
|
+ const viewInvMat = useViewerInvertTransform();
|
|
|
|
|
+ const store = useStore();
|
|
|
|
|
+ const history = useHistory();
|
|
|
|
|
+
|
|
|
paste.push({
|
|
paste.push({
|
|
|
["text/plain"]: {
|
|
["text/plain"]: {
|
|
|
async handler(pos, val) {
|
|
async handler(pos, val) {
|
|
@@ -57,7 +69,7 @@ export const useAutoPaste = () => {
|
|
|
{ ...style, fill: undefined, stroke: undefined },
|
|
{ ...style, fill: undefined, stroke: undefined },
|
|
|
pos,
|
|
pos,
|
|
|
true,
|
|
true,
|
|
|
- true
|
|
|
|
|
|
|
+ true,
|
|
|
);
|
|
);
|
|
|
} else {
|
|
} else {
|
|
|
drawAPI.addShape("text", { content: val }, pos, true, true);
|
|
drawAPI.addShape("text", { content: val }, pos, true, true);
|
|
@@ -69,13 +81,17 @@ export const useAutoPaste = () => {
|
|
|
async handler(pos, val, type) {
|
|
async handler(pos, val, type) {
|
|
|
const url = await resourceHandler(val, type);
|
|
const url = await resourceHandler(val, type);
|
|
|
if (type.includes("svg")) {
|
|
if (type.includes("svg")) {
|
|
|
- const style = await getIconStyle(window.platform.getResource(url), 100, 100);
|
|
|
|
|
|
|
+ const style = await getIconStyle(
|
|
|
|
|
+ window.platform.getResource(url),
|
|
|
|
|
+ 100,
|
|
|
|
|
+ 100,
|
|
|
|
|
+ );
|
|
|
drawAPI.addShape(
|
|
drawAPI.addShape(
|
|
|
"icon",
|
|
"icon",
|
|
|
{ ...style, fill: undefined, stroke: undefined },
|
|
{ ...style, fill: undefined, stroke: undefined },
|
|
|
pos,
|
|
pos,
|
|
|
true,
|
|
true,
|
|
|
- true
|
|
|
|
|
|
|
+ true,
|
|
|
);
|
|
);
|
|
|
} else {
|
|
} else {
|
|
|
const image = await getImage(window.platform.getResource(url));
|
|
const image = await getImage(window.platform.getResource(url));
|
|
@@ -84,12 +100,75 @@ export const useAutoPaste = () => {
|
|
|
{ url, width: image.width, height: image.height },
|
|
{ url, width: image.width, height: image.height },
|
|
|
pos,
|
|
pos,
|
|
|
true,
|
|
true,
|
|
|
- true
|
|
|
|
|
|
|
+ true,
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
type: "file",
|
|
type: "file",
|
|
|
},
|
|
},
|
|
|
|
|
+ ["draw-shape/json"]: {
|
|
|
|
|
+ handler(pos, val) {
|
|
|
|
|
+ const { center: oldCenter, items } = JSON.parse(val) as {
|
|
|
|
|
+ center: Pos;
|
|
|
|
|
+ items: {
|
|
|
|
|
+ rect: IRect;
|
|
|
|
|
+ type: ShapeType;
|
|
|
|
|
+ data: any;
|
|
|
|
|
+ }[];
|
|
|
|
|
+ };
|
|
|
|
|
+ const mouse = viewInvMat.value.point(pos);
|
|
|
|
|
+
|
|
|
|
|
+ const copy = () => {
|
|
|
|
|
+ for (const item of items) {
|
|
|
|
|
+ const base = getBaseItem();
|
|
|
|
|
+ const data = {
|
|
|
|
|
+ ...base,
|
|
|
|
|
+ ...item.data,
|
|
|
|
|
+ id: base.id,
|
|
|
|
|
+ createTime: base.createTime,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ switch (item.type) {
|
|
|
|
|
+ case "text":
|
|
|
|
|
+ data.mat[4] = mouse.x + item.rect.x;
|
|
|
|
|
+ data.mat[5] = mouse.y + item.rect.y;
|
|
|
|
|
+ store.addItem(item.type, data);
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case "serial":
|
|
|
|
|
+ data.content = getCurrentNdx(store);
|
|
|
|
|
+ const radius = (getSerialFontW(data) * Math.sqrt(2)) / 2;
|
|
|
|
|
+ data.radiusX = radius;
|
|
|
|
|
+ data.radiusY = radius;
|
|
|
|
|
+ case "image":
|
|
|
|
|
+ case "icon":
|
|
|
|
|
+ case "circle":
|
|
|
|
|
+ data.mat[4] = mouse.x + item.rect.x + item.rect.width / 2;
|
|
|
|
|
+ data.mat[5] = mouse.y + item.rect.y + item.rect.height / 2;
|
|
|
|
|
+ store.addItem(item.type, data);
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case "arrow":
|
|
|
|
|
+ case "triangle":
|
|
|
|
|
+ case "rectangle":
|
|
|
|
|
+ case "polygon":
|
|
|
|
|
+ data.points.forEach((p: Pos) => {
|
|
|
|
|
+ p.x = p.x - oldCenter.x + mouse.x;
|
|
|
|
|
+ p.y = p.y - oldCenter.y + mouse.y;
|
|
|
|
|
+ });
|
|
|
|
|
+ store.addItem(item.type, data);
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case 'table':
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ return history.onceTrack(copy);
|
|
|
|
|
+ },
|
|
|
|
|
+ type: "string",
|
|
|
|
|
+ },
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -98,7 +177,7 @@ export const useShortcutKey = () => {
|
|
|
// 自动退出添加模式
|
|
// 自动退出添加模式
|
|
|
const { quitDrawShape, enterDrawShape } = useInteractiveDrawShapeAPI();
|
|
const { quitDrawShape, enterDrawShape } = useInteractiveDrawShapeAPI();
|
|
|
const interactiveProps = useInteractiveProps();
|
|
const interactiveProps = useInteractiveProps();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
const store = useStore();
|
|
const store = useStore();
|
|
|
useListener(
|
|
useListener(
|
|
|
"contextmenu",
|
|
"contextmenu",
|
|
@@ -115,20 +194,20 @@ export const useShortcutKey = () => {
|
|
|
}, 10);
|
|
}, 10);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- document.documentElement
|
|
|
|
|
|
|
+ document.documentElement,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
const history = useHistory();
|
|
const history = useHistory();
|
|
|
const status = useMouseShapesStatus();
|
|
const status = useMouseShapesStatus();
|
|
|
const getChildren = useGetFormalChildren();
|
|
const getChildren = useGetFormalChildren();
|
|
|
const operMode = useOperMode();
|
|
const operMode = useOperMode();
|
|
|
- const getShapeBelong = useGetShapeBelong()
|
|
|
|
|
- const eSelection = useExcludeSelection()
|
|
|
|
|
|
|
+ const getShapeBelong = useGetShapeBelong();
|
|
|
|
|
+ const eSelection = useExcludeSelection();
|
|
|
useListener(
|
|
useListener(
|
|
|
"keydown",
|
|
"keydown",
|
|
|
(ev) => {
|
|
(ev) => {
|
|
|
if (ev.target !== document.body) return;
|
|
if (ev.target !== document.body) return;
|
|
|
- const key = ev.key.toLowerCase()
|
|
|
|
|
|
|
+ const key = ev.key.toLowerCase();
|
|
|
if (key === "z" && ev.ctrlKey) {
|
|
if (key === "z" && ev.ctrlKey) {
|
|
|
ev.preventDefault();
|
|
ev.preventDefault();
|
|
|
history.hasUndo.value && history.undo();
|
|
history.hasUndo.value && history.undo();
|
|
@@ -145,15 +224,17 @@ export const useShortcutKey = () => {
|
|
|
|
|
|
|
|
const isSelect = status.selects.length;
|
|
const isSelect = status.selects.length;
|
|
|
const shapes = isSelect ? status.selects : status.actives;
|
|
const shapes = isSelect ? status.selects : status.actives;
|
|
|
- const delItems = shapes
|
|
|
|
|
- .map(getShapeBelong)
|
|
|
|
|
- .filter((item) => !!item);
|
|
|
|
|
|
|
+ const delItems = shapes.map(getShapeBelong).filter((item) => !!item);
|
|
|
|
|
|
|
|
- history.onceTrack(() => {
|
|
|
|
|
|
|
+ history.onceTrack(() => {
|
|
|
delItems.forEach((belong) => {
|
|
delItems.forEach((belong) => {
|
|
|
- const compDelItem = components[belong.type].delItem
|
|
|
|
|
|
|
+ const compDelItem = components[belong.type].delItem;
|
|
|
if (compDelItem) {
|
|
if (compDelItem) {
|
|
|
- compDelItem(store, belong.item as any, belong.isSelf ? undefined : belong.curId)
|
|
|
|
|
|
|
+ compDelItem(
|
|
|
|
|
+ store,
|
|
|
|
|
+ belong.item as any,
|
|
|
|
|
+ belong.isSelf ? undefined : belong.curId,
|
|
|
|
|
+ );
|
|
|
} else if (belong.isSelf) {
|
|
} else if (belong.isSelf) {
|
|
|
store.delItem(belong.type, belong.id);
|
|
store.delItem(belong.type, belong.id);
|
|
|
}
|
|
}
|
|
@@ -171,12 +252,14 @@ export const useShortcutKey = () => {
|
|
|
if (status.selects.length) {
|
|
if (status.selects.length) {
|
|
|
status.selects = [];
|
|
status.selects = [];
|
|
|
} else {
|
|
} else {
|
|
|
- console.log('多选')
|
|
|
|
|
- status.selects = getChildren().filter(shape => !eSelection.value.includes(shape.id()));
|
|
|
|
|
|
|
+ console.log("多选");
|
|
|
|
|
+ status.selects = getChildren().filter(
|
|
|
|
|
+ (shape) => !eSelection.value.includes(shape.id()),
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- window
|
|
|
|
|
|
|
+ window,
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -192,7 +275,7 @@ export const useAutoService = () => {
|
|
|
|
|
|
|
|
watchEffect((onCleanup) => {
|
|
watchEffect((onCleanup) => {
|
|
|
if (operMode.value.freeView) {
|
|
if (operMode.value.freeView) {
|
|
|
- onCleanup(cursor.push('pointer'))
|
|
|
|
|
|
|
+ onCleanup(cursor.push("pointer"));
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
let style: string | null = null;
|
|
let style: string | null = null;
|
|
@@ -221,7 +304,7 @@ export const useAutoService = () => {
|
|
|
history.setLocalId(id);
|
|
history.setLocalId(id);
|
|
|
window.addEventListener("beforeunload", unloadHandler);
|
|
window.addEventListener("beforeunload", unloadHandler);
|
|
|
quitHooks.push(() =>
|
|
quitHooks.push(() =>
|
|
|
- window.removeEventListener("beforeunload", unloadHandler)
|
|
|
|
|
|
|
+ window.removeEventListener("beforeunload", unloadHandler),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
if (!history.hasLocal()) return quitHooks;
|
|
if (!history.hasLocal()) return quitHooks;
|