|
@@ -12,8 +12,7 @@ import { Matrix } from "../../controllers/SelectCtrl/matrix";
|
|
import { nanoid } from "nanoid";
|
|
import { nanoid } from "nanoid";
|
|
import { string } from "vue-types";
|
|
import { string } from "vue-types";
|
|
|
|
|
|
-
|
|
|
|
-let ctrlcselected:string[] = [];
|
|
|
|
|
|
+let ctrlcselected: string[] = [];
|
|
|
|
|
|
export const editActions = EditorModule.action({
|
|
export const editActions = EditorModule.action({
|
|
pickComp(compId: string, selected = true) {
|
|
pickComp(compId: string, selected = true) {
|
|
@@ -118,30 +117,30 @@ export const editActions = EditorModule.action({
|
|
this.controls.cropCtrl.close();
|
|
this.controls.cropCtrl.close();
|
|
},
|
|
},
|
|
|
|
|
|
- // 通过点击添加组件到画布
|
|
|
|
- async clickCompUserToDesign(id: string, isSys) {
|
|
|
|
- if (!this.store.currStreamCardId) {
|
|
|
|
|
|
+ // 通过点击添加组件到画布
|
|
|
|
+ async clickCompUserToDesign(id: string, isSys) {
|
|
|
|
+ if (!this.store.currStreamCardId) {
|
|
queenApi.messageError("请先选中一个卡片");
|
|
queenApi.messageError("请先选中一个卡片");
|
|
return;
|
|
return;
|
|
- }
|
|
|
|
- const { result } = await this.https.getCompDetail(id, isSys);
|
|
|
|
-
|
|
|
|
- //先创建卡片
|
|
|
|
- // const currCardIndex = this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1;
|
|
|
|
- // const cardId = await this.store.insertDesignContent(
|
|
|
|
- // "Container",
|
|
|
|
- // currCardIndex
|
|
|
|
- // );
|
|
|
|
- // const currCard = this.helper.findComp(cardId) as DesignComp;
|
|
|
|
- const currCard = this.store.currStreamCard;
|
|
|
|
- const comp = this.store.addUserCard(result);
|
|
|
|
|
|
+ }
|
|
|
|
+ const { result } = await this.https.getCompDetail(id, isSys);
|
|
|
|
+
|
|
|
|
+ //先创建卡片
|
|
|
|
+ // const currCardIndex = this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1;
|
|
|
|
+ // const cardId = await this.store.insertDesignContent(
|
|
|
|
+ // "Container",
|
|
|
|
+ // currCardIndex
|
|
|
|
+ // );
|
|
|
|
+ // const currCard = this.helper.findComp(cardId) as DesignComp;
|
|
|
|
+ const currCard = this.store.currStreamCard;
|
|
|
|
+ const comp = this.store.addUserCard(result);
|
|
|
|
|
|
const compId = comp.id;
|
|
const compId = comp.id;
|
|
const childIds = [...(currCard.children.default || [])];
|
|
const childIds = [...(currCard.children.default || [])];
|
|
childIds.push(compId);
|
|
childIds.push(compId);
|
|
currCard.children.default = childIds;
|
|
currCard.children.default = childIds;
|
|
|
|
|
|
- this.store.setCompPid(compId, currCard.id);
|
|
|
|
|
|
+ this.store.setCompPid(compId, currCard.id);
|
|
|
|
|
|
const addedComp = this.store.compMap[compId];
|
|
const addedComp = this.store.compMap[compId];
|
|
addedComp.layout.position = "absolute";
|
|
addedComp.layout.position = "absolute";
|
|
@@ -151,21 +150,16 @@ export const editActions = EditorModule.action({
|
|
this.actions.pickComp(compId);
|
|
this.actions.pickComp(compId);
|
|
},
|
|
},
|
|
|
|
|
|
-
|
|
|
|
- initAddedCompPos(currId: string, addedId:string, cardId:string) {
|
|
|
|
-
|
|
|
|
|
|
+ initAddedCompPos(currId: string, addedId: string, cardId: string) {
|
|
let yOffset = 0;
|
|
let yOffset = 0;
|
|
- if (
|
|
|
|
- currId != this.store.currStreamCardId &&
|
|
|
|
- currId != "root"
|
|
|
|
- ) {
|
|
|
|
- const paths = this.helper.getCompTrees(currId)
|
|
|
|
|
|
+ if (currId != this.store.currStreamCardId && currId != "root") {
|
|
|
|
+ const paths = this.helper.getCompTrees(currId);
|
|
const bound = this.helper.getCardCompBound(paths[2].id);
|
|
const bound = this.helper.getCardCompBound(paths[2].id);
|
|
yOffset = bound.y + bound.h;
|
|
yOffset = bound.y + bound.h;
|
|
}
|
|
}
|
|
|
|
|
|
const currComp = this.helper.findComp(addedId) as DesignComp;
|
|
const currComp = this.helper.findComp(addedId) as DesignComp;
|
|
-
|
|
|
|
|
|
+
|
|
//添加组件到当前选中的组件下面
|
|
//添加组件到当前选中的组件下面
|
|
let xOffset = this.helper.designSizeToPx(
|
|
let xOffset = this.helper.designSizeToPx(
|
|
375 - (currComp.layout.size?.[0] || 750) / 2
|
|
375 - (currComp.layout.size?.[0] || 750) / 2
|
|
@@ -187,60 +181,58 @@ export const editActions = EditorModule.action({
|
|
this.controls.cropCtrl.close();
|
|
this.controls.cropCtrl.close();
|
|
},
|
|
},
|
|
|
|
|
|
-
|
|
|
|
// 通过拖拽添加组件到画布
|
|
// 通过拖拽添加组件到画布
|
|
- async dragCompToDesign(event: MouseEvent, compKey: string, data:any) {
|
|
|
|
-
|
|
|
|
|
|
+ async dragCompToDesign(event: MouseEvent, compKey: string, data: any) {
|
|
const currCardDom = this.store.currStreamCard.$el;
|
|
const currCardDom = this.store.currStreamCard.$el;
|
|
|
|
|
|
if (compKey == "CompCard") {
|
|
if (compKey == "CompCard") {
|
|
- const { result } = await this.https.getCompDetail(data.id, data.isSys);
|
|
|
|
- const comp = this.store.addUserCard(result);
|
|
|
|
|
|
+ const { result } = await this.https.getCompDetail(data.id, data.isSys);
|
|
|
|
+ const comp = this.store.addUserCard(result);
|
|
|
|
|
|
- const currCard = this.store.currStreamCard;
|
|
|
|
- const compId = comp.id;
|
|
|
|
- const childIds = [...(currCard.children.default || [])];
|
|
|
|
- childIds.push(compId);
|
|
|
|
- currCard.children.default = childIds;
|
|
|
|
-
|
|
|
|
- const addedComp = this.store.compMap[compId];
|
|
|
|
- addedComp.layout.position = "absolute";
|
|
|
|
- this.store.setCompPid(compId, currCard.id);
|
|
|
|
|
|
+ const currCard = this.store.currStreamCard;
|
|
|
|
+ const compId = comp.id;
|
|
|
|
+ const childIds = [...(currCard.children.default || [])];
|
|
|
|
+ childIds.push(compId);
|
|
|
|
+ currCard.children.default = childIds;
|
|
|
|
|
|
- this.actions.pickComp(compId);
|
|
|
|
|
|
+ const addedComp = this.store.compMap[compId];
|
|
|
|
+ addedComp.layout.position = "absolute";
|
|
|
|
+ this.store.setCompPid(compId, currCard.id);
|
|
|
|
|
|
|
|
+ this.actions.pickComp(compId);
|
|
} else {
|
|
} else {
|
|
- await this.actions.addCompToDesign(compKey as any);
|
|
|
|
|
|
+ await this.actions.addCompToDesign(compKey as any);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
- const cardPoints = this.helper.getPointOffsetWith(
|
|
|
|
- event,
|
|
|
|
- currCardDom
|
|
|
|
- );
|
|
|
|
|
|
+ const cardPoints = this.helper.getPointOffsetWith(event, currCardDom);
|
|
const { currComp } = this.store;
|
|
const { currComp } = this.store;
|
|
let selCtrl = this.controls.selectCtrl;
|
|
let selCtrl = this.controls.selectCtrl;
|
|
selCtrl.translate(
|
|
selCtrl.translate(
|
|
- this.helper.designSizeToPx(375 - (currComp.layout.size?.[0] || 750) / 2),
|
|
|
|
|
|
+ this.helper.designSizeToPx(
|
|
|
|
+ 375 - (currComp.layout.size?.[0] || 750) / 2
|
|
|
|
+ ),
|
|
cardPoints.y
|
|
cardPoints.y
|
|
);
|
|
);
|
|
-
|
|
|
|
|
|
+
|
|
this.helper.extendStreamCard(this.store.currStreamCardId);
|
|
this.helper.extendStreamCard(this.store.currStreamCardId);
|
|
-
|
|
|
|
|
|
+
|
|
if (compKey == "Text") {
|
|
if (compKey == "Text") {
|
|
this.actions.selectObjs([]);
|
|
this.actions.selectObjs([]);
|
|
this.actions.textFocus(currComp.id, true);
|
|
this.actions.textFocus(currComp.id, true);
|
|
}
|
|
}
|
|
this.controls.cropCtrl.close();
|
|
this.controls.cropCtrl.close();
|
|
-
|
|
|
|
}, 100);
|
|
}, 100);
|
|
},
|
|
},
|
|
|
|
|
|
async selectObjs(ids: string[], last = "") {
|
|
async selectObjs(ids: string[], last = "") {
|
|
this.store.selected = ids;
|
|
this.store.selected = ids;
|
|
this.store.selectId = ids.length > 1 ? Date.now() + "" : "";
|
|
this.store.selectId = ids.length > 1 ? Date.now() + "" : "";
|
|
- this.store.lastSelected = last ? last : ( ids.length > 0 ? ids[ids.length-1] : "")
|
|
|
|
|
|
+ this.store.lastSelected = last
|
|
|
|
+ ? last
|
|
|
|
+ : ids.length > 0
|
|
|
|
+ ? ids[ids.length - 1]
|
|
|
|
+ : "";
|
|
},
|
|
},
|
|
|
|
|
|
// 添加组件到画布
|
|
// 添加组件到画布
|
|
@@ -313,22 +305,21 @@ export const editActions = EditorModule.action({
|
|
|
|
|
|
ctrlc() {
|
|
ctrlc() {
|
|
// console.log("contrc ", this.store.selected);
|
|
// console.log("contrc ", this.store.selected);
|
|
- ctrlcselected = this.store.selected.slice(0);
|
|
|
|
|
|
+ ctrlcselected = this.store.selected.slice(0);
|
|
},
|
|
},
|
|
copyLastSelected() {
|
|
copyLastSelected() {
|
|
if (this.store.currCompId && this.store.currCompId != "root") {
|
|
if (this.store.currCompId && this.store.currCompId != "root") {
|
|
- ctrlcselected = [this.store.currCompId]
|
|
|
|
|
|
+ ctrlcselected = [this.store.currCompId];
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- setSameSize(isWidth:boolean) {
|
|
|
|
-
|
|
|
|
|
|
+ setSameSize(isWidth: boolean) {
|
|
const selectCtrl = this.controls.selectCtrl;
|
|
const selectCtrl = this.controls.selectCtrl;
|
|
const objc = selectCtrl.objContainer as ObjsContainer;
|
|
const objc = selectCtrl.objContainer as ObjsContainer;
|
|
- if (this.store.selected.length == 1 ) {
|
|
|
|
|
|
+ if (this.store.selected.length == 1) {
|
|
this.store.currComp.layout.size[0] = 750;
|
|
this.store.currComp.layout.size[0] = 750;
|
|
objc.updateSize();
|
|
objc.updateSize();
|
|
-
|
|
|
|
|
|
+
|
|
selectCtrl.upgateGizmoStyle();
|
|
selectCtrl.upgateGizmoStyle();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -336,25 +327,23 @@ export const editActions = EditorModule.action({
|
|
const anchorBox = this.helper.findComp(this.store.lastSelected);
|
|
const anchorBox = this.helper.findComp(this.store.lastSelected);
|
|
if (!anchorBox) return;
|
|
if (!anchorBox) return;
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- objc.parent.children.forEach((c)=>{
|
|
|
|
|
|
+ objc.parent.children.forEach((c) => {
|
|
const child = c as CompObject;
|
|
const child = c as CompObject;
|
|
const r = child.getBox();
|
|
const r = child.getBox();
|
|
- if (isWidth) child.comp.layout.size[0] = anchorBox.layout.size[0];
|
|
|
|
|
|
+ if (isWidth) child.comp.layout.size[0] = anchorBox.layout.size[0];
|
|
else child.comp.layout.size[1] = anchorBox.layout.size[1];
|
|
else child.comp.layout.size[1] = anchorBox.layout.size[1];
|
|
- })
|
|
|
|
|
|
+ });
|
|
|
|
|
|
objc.updateSize();
|
|
objc.updateSize();
|
|
-
|
|
|
|
|
|
+
|
|
selectCtrl.upgateGizmoStyle();
|
|
selectCtrl.upgateGizmoStyle();
|
|
},
|
|
},
|
|
|
|
|
|
toogleGroup() {
|
|
toogleGroup() {
|
|
- if (this.store.selected.length > 1) {
|
|
|
|
- this.actions.createGroupComps();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ if (this.store.selected.length > 1) {
|
|
|
|
+ this.actions.createGroupComps();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
if (this.store.selected.length == 1) {
|
|
if (this.store.selected.length == 1) {
|
|
const c = this.helper.findComp(this.store.selected[0]) as DesignComp;
|
|
const c = this.helper.findComp(this.store.selected[0]) as DesignComp;
|
|
if (c.compKey == "Group") {
|
|
if (c.compKey == "Group") {
|
|
@@ -366,49 +355,47 @@ export const editActions = EditorModule.action({
|
|
ctrlv() {
|
|
ctrlv() {
|
|
console.log("ctrlv ", this.store.selected);
|
|
console.log("ctrlv ", this.store.selected);
|
|
if (ctrlcselected.length < 1) return;
|
|
if (ctrlcselected.length < 1) return;
|
|
-
|
|
|
|
- const news :string[] = [];
|
|
|
|
-
|
|
|
|
- const deepCopy = (c:DesignComp) => {
|
|
|
|
- const childs = c.children.default || [];
|
|
|
|
- if (childs.length > 0 ) {
|
|
|
|
- childs.forEach((id, index)=>{
|
|
|
|
- const cp = this.helper.findComp(id) as DesignComp;
|
|
|
|
- const cp1 = cloneDeep(cp);
|
|
|
|
- cp1.id = nanoid();
|
|
|
|
- this.store.compMap[cp1.id] = cp1;
|
|
|
|
- this.store.setCompPid(cp1.id, c.id);
|
|
|
|
- childs[index] = cp1.id;
|
|
|
|
-
|
|
|
|
- deepCopy(cp);
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- ctrlcselected.forEach(c=>{
|
|
|
|
- const cp = this.helper.findComp(c) as DesignComp;
|
|
|
|
- const cp1 = cloneDeep(cp);
|
|
|
|
- cp1.id = nanoid();
|
|
|
|
- news.push(cp1.id);
|
|
|
|
-
|
|
|
|
- this.store.compMap[cp1.id] = cp1;
|
|
|
|
- this.store.setCompPid(cp1.id, this.store.currStreamCardId);
|
|
|
|
-
|
|
|
|
- deepCopy(cp);
|
|
|
|
- })
|
|
|
|
|
|
+
|
|
|
|
+ const news: string[] = [];
|
|
|
|
+
|
|
|
|
+ const deepCopy = (c: DesignComp) => {
|
|
|
|
+ const childs = c.children.default || [];
|
|
|
|
+ if (childs.length > 0) {
|
|
|
|
+ childs.forEach((id, index) => {
|
|
|
|
+ const cp = this.helper.findComp(id) as DesignComp;
|
|
|
|
+ const cp1 = cloneDeep(cp);
|
|
|
|
+ cp1.id = nanoid();
|
|
|
|
+ this.store.compMap[cp1.id] = cp1;
|
|
|
|
+ this.store.setCompPid(cp1.id, c.id);
|
|
|
|
+ childs[index] = cp1.id;
|
|
|
|
+
|
|
|
|
+ deepCopy(cp);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ ctrlcselected.forEach((c) => {
|
|
|
|
+ const cp = this.helper.findComp(c) as DesignComp;
|
|
|
|
+ const cp1 = cloneDeep(cp);
|
|
|
|
+ cp1.id = nanoid();
|
|
|
|
+ news.push(cp1.id);
|
|
|
|
+
|
|
|
|
+ this.store.compMap[cp1.id] = cp1;
|
|
|
|
+ this.store.setCompPid(cp1.id, this.store.currStreamCardId);
|
|
|
|
+
|
|
|
|
+ deepCopy(cp);
|
|
|
|
+ });
|
|
|
|
|
|
this.actions.addComps(news);
|
|
this.actions.addComps(news);
|
|
|
|
|
|
this.actions.selectObjs(news);
|
|
this.actions.selectObjs(news);
|
|
|
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
- this.controls.selectCtrl.translate(20, 20);
|
|
|
|
|
|
+ this.controls.selectCtrl.translate(20, 20);
|
|
}, 100);
|
|
}, 100);
|
|
-
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- addComps(ids:string[]) {
|
|
|
|
|
|
+ addComps(ids: string[]) {
|
|
const childs = this.store.currStreamCard.children.default?.slice(0) || [];
|
|
const childs = this.store.currStreamCard.children.default?.slice(0) || [];
|
|
childs.push(...ids);
|
|
childs.push(...ids);
|
|
this.store.currStreamCard.children.default = childs;
|
|
this.store.currStreamCard.children.default = childs;
|
|
@@ -426,7 +413,6 @@ export const editActions = EditorModule.action({
|
|
|
|
|
|
// 删除组件
|
|
// 删除组件
|
|
removeComp(compId: string) {
|
|
removeComp(compId: string) {
|
|
-
|
|
|
|
const paths = this.helper.getCompTrees(compId);
|
|
const paths = this.helper.getCompTrees(compId);
|
|
if (!paths[2]) {
|
|
if (!paths[2]) {
|
|
if (this.helper.isStreamCard(compId)) {
|
|
if (this.helper.isStreamCard(compId)) {
|
|
@@ -484,24 +470,25 @@ export const editActions = EditorModule.action({
|
|
// 保存容器为组件
|
|
// 保存容器为组件
|
|
async saveAsComp(comp: DesignComp) {
|
|
async saveAsComp(comp: DesignComp) {
|
|
try {
|
|
try {
|
|
-
|
|
|
|
const CompSave = this.components.CompSave as any;
|
|
const CompSave = this.components.CompSave as any;
|
|
let title = "";
|
|
let title = "";
|
|
let type = "comp";
|
|
let type = "comp";
|
|
|
|
|
|
try {
|
|
try {
|
|
- const ret:any = await queenApi.dialog(<CompSave />, {width:"300px", title: "保存到我的"});
|
|
|
|
|
|
+ const ret: any = await queenApi.dialog(<CompSave />, {
|
|
|
|
+ width: "300px",
|
|
|
|
+ title: "保存到我的",
|
|
|
|
+ });
|
|
if (!ret) {
|
|
if (!ret) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
title = ret.title;
|
|
title = ret.title;
|
|
type = ret.type;
|
|
type = ret.type;
|
|
-
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- console.log( title, type);
|
|
|
|
|
|
+ console.log(title, type);
|
|
|
|
|
|
// 组件封面
|
|
// 组件封面
|
|
const blob = await new ScreenshotCtrl().snap({
|
|
const blob = await new ScreenshotCtrl().snap({
|
|
@@ -515,7 +502,6 @@ export const editActions = EditorModule.action({
|
|
// )?.name,
|
|
// )?.name,
|
|
// });
|
|
// });
|
|
|
|
|
|
-
|
|
|
|
const data = {
|
|
const data = {
|
|
title,
|
|
title,
|
|
type,
|
|
type,
|
|
@@ -527,7 +513,9 @@ export const editActions = EditorModule.action({
|
|
data.compMap.root.id = "root";
|
|
data.compMap.root.id = "root";
|
|
|
|
|
|
//清除平移距离
|
|
//清除平移距离
|
|
- const mtx = Matrix.createFromMatrixStr(data.compMap.root.layout.transformMatrix as string);
|
|
|
|
|
|
+ const mtx = Matrix.createFromMatrixStr(
|
|
|
|
+ data.compMap.root.layout.transformMatrix as string
|
|
|
|
+ );
|
|
mtx.tx = 0;
|
|
mtx.tx = 0;
|
|
mtx.ty = 0;
|
|
mtx.ty = 0;
|
|
data.compMap.root.layout.transformMatrix = mtx.getMatrixStr();
|
|
data.compMap.root.layout.transformMatrix = mtx.getMatrixStr();
|
|
@@ -630,6 +618,16 @@ export const editActions = EditorModule.action({
|
|
setCompVisible(comp: DesignComp) {
|
|
setCompVisible(comp: DesignComp) {
|
|
comp.layout.visible = comp.layout.visible === false ? true : false;
|
|
comp.layout.visible = comp.layout.visible === false ? true : false;
|
|
},
|
|
},
|
|
|
|
+ // 组件重命名
|
|
|
|
+ async resetCompName(comp: DesignComp) {
|
|
|
|
+ console.log("comp.title: ", comp);
|
|
|
|
+ const res = await queenApi.showInput({
|
|
|
|
+ title: "重命名",
|
|
|
|
+ defaultValue: comp.title,
|
|
|
|
+ });
|
|
|
|
+ if (!res) return;
|
|
|
|
+ comp.title = res;
|
|
|
|
+ },
|
|
// 清除组件变换
|
|
// 清除组件变换
|
|
clearCompTransform(comp: DesignComp) {
|
|
clearCompTransform(comp: DesignComp) {
|
|
comp.layout.margin = "";
|
|
comp.layout.margin = "";
|
|
@@ -648,28 +646,26 @@ export const editActions = EditorModule.action({
|
|
},
|
|
},
|
|
//横向对齐
|
|
//横向对齐
|
|
setAlignX(flag: 0 | 1 | 2 | 3) {
|
|
setAlignX(flag: 0 | 1 | 2 | 3) {
|
|
- console.log("alignX")
|
|
|
|
|
|
+ console.log("alignX");
|
|
const selectCtrl = this.controls.selectCtrl;
|
|
const selectCtrl = this.controls.selectCtrl;
|
|
|
|
|
|
if (this.store.selected.length == 1) {
|
|
if (this.store.selected.length == 1) {
|
|
- const objc = selectCtrl.objContainer as ObjsContainer;
|
|
|
|
- const box = objc.getBound();
|
|
|
|
- switch(flag) {
|
|
|
|
- case 0:
|
|
|
|
- selectCtrl.translate(-box.left , 0);
|
|
|
|
- break;
|
|
|
|
- case 1:
|
|
|
|
- selectCtrl.translate(-(box.center.x - 187.5) , 0);
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- selectCtrl.translate(375 - box.right, 0);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- return;
|
|
|
|
|
|
+ const objc = selectCtrl.objContainer as ObjsContainer;
|
|
|
|
+ const box = objc.getBound();
|
|
|
|
+ switch (flag) {
|
|
|
|
+ case 0:
|
|
|
|
+ selectCtrl.translate(-box.left, 0);
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ selectCtrl.translate(-(box.center.x - 187.5), 0);
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ selectCtrl.translate(375 - box.right, 0);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
const anchorBox = this.helper.findComp(this.store.lastSelected);
|
|
const anchorBox = this.helper.findComp(this.store.lastSelected);
|
|
if (!anchorBox) return;
|
|
if (!anchorBox) return;
|
|
|
|
|
|
@@ -677,60 +673,65 @@ export const editActions = EditorModule.action({
|
|
const anchorRect = anchor.getBox();
|
|
const anchorRect = anchor.getBox();
|
|
|
|
|
|
const objc = selectCtrl.objContainer as ObjsContainer;
|
|
const objc = selectCtrl.objContainer as ObjsContainer;
|
|
- let min = 10000, max = -10000;
|
|
|
|
|
|
+ let min = 10000,
|
|
|
|
+ max = -10000;
|
|
let step = 0;
|
|
let step = 0;
|
|
- if (flag == 3) {//Y轴均匀排布
|
|
|
|
- objc.parent.children.forEach((c)=>{
|
|
|
|
|
|
+ if (flag == 3) {
|
|
|
|
+ //Y轴均匀排布
|
|
|
|
+ objc.parent.children.forEach((c) => {
|
|
const child = c as CompObject;
|
|
const child = c as CompObject;
|
|
const r = child.getBox();
|
|
const r = child.getBox();
|
|
const x = r.x + r.w / 2.0;
|
|
const x = r.x + r.w / 2.0;
|
|
- if (x <min) min = x;
|
|
|
|
- if (x >max ) max = x;
|
|
|
|
- })
|
|
|
|
|
|
+ if (x < min) min = x;
|
|
|
|
+ if (x > max) max = x;
|
|
|
|
+ });
|
|
const stepCount = objc.parent.children.length;
|
|
const stepCount = objc.parent.children.length;
|
|
|
|
|
|
step = (max - min) / (stepCount - 1);
|
|
step = (max - min) / (stepCount - 1);
|
|
|
|
|
|
- const stepIndexMap:any = {};
|
|
|
|
|
|
+ const stepIndexMap: any = {};
|
|
|
|
|
|
- objc.parent.children.forEach((c)=>{
|
|
|
|
|
|
+ objc.parent.children.forEach((c) => {
|
|
const child = c as CompObject;
|
|
const child = c as CompObject;
|
|
const r = child.getBox();
|
|
const r = child.getBox();
|
|
const x = r.x + r.w / 2.0;
|
|
const x = r.x + r.w / 2.0;
|
|
|
|
|
|
let minIndex = -1;
|
|
let minIndex = -1;
|
|
let minV = 10000;
|
|
let minV = 10000;
|
|
- for (let i=0; i<stepCount; i++) {
|
|
|
|
- const ty = i*step + min;
|
|
|
|
- if ( Math.abs(x - ty) < minV && !stepIndexMap[i]) {
|
|
|
|
- minV = Math.abs(x - ty);
|
|
|
|
- minIndex = i;
|
|
|
|
- }
|
|
|
|
|
|
+ for (let i = 0; i < stepCount; i++) {
|
|
|
|
+ const ty = i * step + min;
|
|
|
|
+ if (Math.abs(x - ty) < minV && !stepIndexMap[i]) {
|
|
|
|
+ minV = Math.abs(x - ty);
|
|
|
|
+ minIndex = i;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
stepIndexMap[minIndex] = true;
|
|
stepIndexMap[minIndex] = true;
|
|
- child.translate((minIndex*step + min) - x, 0);
|
|
|
|
- })
|
|
|
|
|
|
+ child.translate(minIndex * step + min - x, 0);
|
|
|
|
+ });
|
|
objc.updateSize();
|
|
objc.updateSize();
|
|
selectCtrl.upgateGizmoStyle();
|
|
selectCtrl.upgateGizmoStyle();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- objc.parent.children.forEach((c)=>{
|
|
|
|
- const child = c as CompObject;
|
|
|
|
- if (child.comp.id == this.store.lastSelected) return;
|
|
|
|
- const r = child.getBox();
|
|
|
|
- switch(flag) {
|
|
|
|
- case 0:
|
|
|
|
- child.translate(anchorRect.x -r.x, 0);
|
|
|
|
- break;
|
|
|
|
- case 1:
|
|
|
|
- child.translate(anchorRect.x + anchorRect.w / 2.0 - (r.x + r.w/2.0), 0);
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- child.translate(anchorRect.x + anchorRect.w - (r.x + r.w), 0);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ objc.parent.children.forEach((c) => {
|
|
|
|
+ const child = c as CompObject;
|
|
|
|
+ if (child.comp.id == this.store.lastSelected) return;
|
|
|
|
+ const r = child.getBox();
|
|
|
|
+ switch (flag) {
|
|
|
|
+ case 0:
|
|
|
|
+ child.translate(anchorRect.x - r.x, 0);
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ child.translate(
|
|
|
|
+ anchorRect.x + anchorRect.w / 2.0 - (r.x + r.w / 2.0),
|
|
|
|
+ 0
|
|
|
|
+ );
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ child.translate(anchorRect.x + anchorRect.w - (r.x + r.w), 0);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
objc.updateSize();
|
|
objc.updateSize();
|
|
selectCtrl.upgateGizmoStyle();
|
|
selectCtrl.upgateGizmoStyle();
|
|
},
|
|
},
|
|
@@ -738,24 +739,24 @@ export const editActions = EditorModule.action({
|
|
setAlignY(flag: 0 | 1 | 2 | 3) {
|
|
setAlignY(flag: 0 | 1 | 2 | 3) {
|
|
const selectCtrl = this.controls.selectCtrl;
|
|
const selectCtrl = this.controls.selectCtrl;
|
|
if (this.store.selected.length == 1) {
|
|
if (this.store.selected.length == 1) {
|
|
- const objc = selectCtrl.objContainer as ObjsContainer;
|
|
|
|
- const box = objc.getBound();
|
|
|
|
-
|
|
|
|
- const card = new CompObject(this.store.currStreamCard);
|
|
|
|
- const cardBox = card.getBox();
|
|
|
|
-
|
|
|
|
- switch(flag) {
|
|
|
|
- case 0:
|
|
|
|
- selectCtrl.translate(0, -box.top);
|
|
|
|
- break;
|
|
|
|
- case 1:
|
|
|
|
- selectCtrl.translate(0 , -(box.center.y - cardBox.h / 2.0));
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- selectCtrl.translate(0, cardBox.h - box.bottom);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- return;
|
|
|
|
|
|
+ const objc = selectCtrl.objContainer as ObjsContainer;
|
|
|
|
+ const box = objc.getBound();
|
|
|
|
+
|
|
|
|
+ const card = new CompObject(this.store.currStreamCard);
|
|
|
|
+ const cardBox = card.getBox();
|
|
|
|
+
|
|
|
|
+ switch (flag) {
|
|
|
|
+ case 0:
|
|
|
|
+ selectCtrl.translate(0, -box.top);
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ selectCtrl.translate(0, -(box.center.y - cardBox.h / 2.0));
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ selectCtrl.translate(0, cardBox.h - box.bottom);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
const anchorBox = this.helper.findComp(this.store.lastSelected);
|
|
const anchorBox = this.helper.findComp(this.store.lastSelected);
|
|
@@ -770,58 +771,62 @@ export const editActions = EditorModule.action({
|
|
let max = -10000;
|
|
let max = -10000;
|
|
let step = 0;
|
|
let step = 0;
|
|
|
|
|
|
- if (flag == 3) {//Y轴均匀排布
|
|
|
|
- objc.parent.children.forEach((c)=>{
|
|
|
|
|
|
+ if (flag == 3) {
|
|
|
|
+ //Y轴均匀排布
|
|
|
|
+ objc.parent.children.forEach((c) => {
|
|
const child = c as CompObject;
|
|
const child = c as CompObject;
|
|
const r = child.getBox();
|
|
const r = child.getBox();
|
|
const y = r.y + r.h / 2.0;
|
|
const y = r.y + r.h / 2.0;
|
|
- if (y <min) min = y;
|
|
|
|
- if (y >max ) max = y;
|
|
|
|
- })
|
|
|
|
|
|
+ if (y < min) min = y;
|
|
|
|
+ if (y > max) max = y;
|
|
|
|
+ });
|
|
const stepCount = objc.parent.children.length;
|
|
const stepCount = objc.parent.children.length;
|
|
|
|
|
|
step = (max - min) / (stepCount - 1);
|
|
step = (max - min) / (stepCount - 1);
|
|
|
|
|
|
- const stepIndexMap:any = {};
|
|
|
|
|
|
+ const stepIndexMap: any = {};
|
|
|
|
|
|
- objc.parent.children.forEach((c)=>{
|
|
|
|
|
|
+ objc.parent.children.forEach((c) => {
|
|
const child = c as CompObject;
|
|
const child = c as CompObject;
|
|
const r = child.getBox();
|
|
const r = child.getBox();
|
|
const y = r.y + r.h / 2.0;
|
|
const y = r.y + r.h / 2.0;
|
|
|
|
|
|
let minIndex = -1;
|
|
let minIndex = -1;
|
|
let minV = 10000;
|
|
let minV = 10000;
|
|
- for (let i=0; i<stepCount; i++) {
|
|
|
|
- const ty = i*step + min;
|
|
|
|
- if ( Math.abs(y - ty) < minV && !stepIndexMap[i]) {
|
|
|
|
- minV = Math.abs(y - ty);
|
|
|
|
- minIndex = i;
|
|
|
|
- }
|
|
|
|
|
|
+ for (let i = 0; i < stepCount; i++) {
|
|
|
|
+ const ty = i * step + min;
|
|
|
|
+ if (Math.abs(y - ty) < minV && !stepIndexMap[i]) {
|
|
|
|
+ minV = Math.abs(y - ty);
|
|
|
|
+ minIndex = i;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
stepIndexMap[minIndex] = true;
|
|
stepIndexMap[minIndex] = true;
|
|
- child.translate(0, (minIndex*step + min) - y);
|
|
|
|
- })
|
|
|
|
|
|
+ child.translate(0, minIndex * step + min - y);
|
|
|
|
+ });
|
|
objc.updateSize();
|
|
objc.updateSize();
|
|
selectCtrl.upgateGizmoStyle();
|
|
selectCtrl.upgateGizmoStyle();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- objc.parent.children.forEach((c)=>{
|
|
|
|
- const child = c as CompObject;
|
|
|
|
- if (child.comp.id == this.store.lastSelected) return;
|
|
|
|
- const r = child.getBox();
|
|
|
|
- switch(flag) {
|
|
|
|
- case 0:
|
|
|
|
- child.translate(0, anchorRect.y -r.y);
|
|
|
|
- break;
|
|
|
|
- case 1:
|
|
|
|
- child.translate(0, anchorRect.y + anchorRect.h / 2.0 - (r.y + r.h /2.0));
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- child.translate(0, anchorRect.y + anchorRect.h - (r.y + r.h));
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+
|
|
|
|
+ objc.parent.children.forEach((c) => {
|
|
|
|
+ const child = c as CompObject;
|
|
|
|
+ if (child.comp.id == this.store.lastSelected) return;
|
|
|
|
+ const r = child.getBox();
|
|
|
|
+ switch (flag) {
|
|
|
|
+ case 0:
|
|
|
|
+ child.translate(0, anchorRect.y - r.y);
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ child.translate(
|
|
|
|
+ 0,
|
|
|
|
+ anchorRect.y + anchorRect.h / 2.0 - (r.y + r.h / 2.0)
|
|
|
|
+ );
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ child.translate(0, anchorRect.y + anchorRect.h - (r.y + r.h));
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
objc.updateSize();
|
|
objc.updateSize();
|
|
selectCtrl.upgateGizmoStyle();
|
|
selectCtrl.upgateGizmoStyle();
|
|
},
|
|
},
|
|
@@ -859,15 +864,19 @@ export const editActions = EditorModule.action({
|
|
const childs = groupComp.children.default || [];
|
|
const childs = groupComp.children.default || [];
|
|
const objC = this.controls.selectCtrl.objContainer as ObjsContainer;
|
|
const objC = this.controls.selectCtrl.objContainer as ObjsContainer;
|
|
const parentMtrx = objC.parent.worldTransform.clone();
|
|
const parentMtrx = objC.parent.worldTransform.clone();
|
|
- childs.forEach(o=>{
|
|
|
|
|
|
+ childs.forEach((o) => {
|
|
const obj = this.helper.findComp(o) as DesignComp;
|
|
const obj = this.helper.findComp(o) as DesignComp;
|
|
- const mxt = Matrix.createFromMatrixStr(obj.layout.transformMatrix as string);
|
|
|
|
|
|
+ const mxt = Matrix.createFromMatrixStr(
|
|
|
|
+ obj.layout.transformMatrix as string
|
|
|
|
+ );
|
|
mxt.prepend(parentMtrx);
|
|
mxt.prepend(parentMtrx);
|
|
obj.layout.transformMatrix = mxt.getMatrixStr();
|
|
obj.layout.transformMatrix = mxt.getMatrixStr();
|
|
- })
|
|
|
|
- const paths = this.helper.getCompTrees(groupComp.id)
|
|
|
|
|
|
+ });
|
|
|
|
+ const paths = this.helper.getCompTrees(groupComp.id);
|
|
const card = paths[1];
|
|
const card = paths[1];
|
|
- const parentChilds = (card.children.default || []).filter(item=>item != groupComp.id);
|
|
|
|
|
|
+ const parentChilds = (card.children.default || []).filter(
|
|
|
|
+ (item) => item != groupComp.id
|
|
|
|
+ );
|
|
parentChilds.push(...childs);
|
|
parentChilds.push(...childs);
|
|
card.children.default = parentChilds;
|
|
card.children.default = parentChilds;
|
|
|
|
|
|
@@ -884,32 +893,35 @@ export const editActions = EditorModule.action({
|
|
//先删除现有的节点
|
|
//先删除现有的节点
|
|
const sels = this.store.selected.slice(0);
|
|
const sels = this.store.selected.slice(0);
|
|
const chils = this.store.currStreamCard.children.default || [];
|
|
const chils = this.store.currStreamCard.children.default || [];
|
|
- const newChilds :any = [];
|
|
|
|
- const groupChilds :any = [];
|
|
|
|
- chils.forEach(c=>{
|
|
|
|
|
|
+ const newChilds: any = [];
|
|
|
|
+ const groupChilds: any = [];
|
|
|
|
+ chils.forEach((c) => {
|
|
if (sels.indexOf(c) == -1) newChilds.push(c);
|
|
if (sels.indexOf(c) == -1) newChilds.push(c);
|
|
else {
|
|
else {
|
|
groupChilds.push(c);
|
|
groupChilds.push(c);
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ });
|
|
|
|
|
|
newChilds.push(id);
|
|
newChilds.push(id);
|
|
this.store.currStreamCard.children.default = newChilds;
|
|
this.store.currStreamCard.children.default = newChilds;
|
|
-
|
|
|
|
|
|
+
|
|
//更新节点的新位置
|
|
//更新节点的新位置
|
|
- Objc.parent.children.forEach(obj=>{
|
|
|
|
|
|
+ Objc.parent.children.forEach((obj) => {
|
|
const cobj = obj as CompObject;
|
|
const cobj = obj as CompObject;
|
|
const comp = cobj.comp;
|
|
const comp = cobj.comp;
|
|
comp.layout.transformMatrix = cobj.localTransform.getMatrixStr();
|
|
comp.layout.transformMatrix = cobj.localTransform.getMatrixStr();
|
|
- })
|
|
|
|
-
|
|
|
|
|
|
+ });
|
|
|
|
+
|
|
//再添加新的节点
|
|
//再添加新的节点
|
|
- comp.layout.size = [this.helper.pxToDesignSize(Objc.width), this.helper.pxToDesignSize(Objc.height)];
|
|
|
|
|
|
+ comp.layout.size = [
|
|
|
|
+ this.helper.pxToDesignSize(Objc.width),
|
|
|
|
+ this.helper.pxToDesignSize(Objc.height),
|
|
|
|
+ ];
|
|
comp.layout.transformMatrix = selectCtrl.transferStyle.matrix;
|
|
comp.layout.transformMatrix = selectCtrl.transferStyle.matrix;
|
|
-
|
|
|
|
|
|
+
|
|
comp.children.default = groupChilds;
|
|
comp.children.default = groupChilds;
|
|
|
|
|
|
- this.actions.selectObjs([])
|
|
|
|
|
|
+ this.actions.selectObjs([]);
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
this.actions.pickComp(comp.id);
|
|
this.actions.pickComp(comp.id);
|
|
}, 0);
|
|
}, 0);
|