|
@@ -3,6 +3,7 @@ import { Exception, queenApi } from "queenjs";
|
|
|
import { EditorModule } from "..";
|
|
|
import { DesignComp } from "../../objects/DesignTemp/DesignComp";
|
|
|
import { ICompKeys, Layout } from "../../typings";
|
|
|
+import { Matrix } from "../../objects/DesignTemp/creates/Matrix";
|
|
|
|
|
|
export const editActions = EditorModule.action({
|
|
|
|
|
@@ -13,7 +14,7 @@ export const editActions = EditorModule.action({
|
|
|
}
|
|
|
|
|
|
if (compKey == "Container") {
|
|
|
- index = this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1
|
|
|
+ index = this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1;
|
|
|
const compId = await this.store.insertDesignContent(compKey, index);
|
|
|
this.actions.pickComp(compId);
|
|
|
return;
|
|
@@ -38,8 +39,25 @@ export const editActions = EditorModule.action({
|
|
|
},
|
|
|
|
|
|
pickComp(compId: string) {
|
|
|
- if (this.store.groupModeStatus) {
|
|
|
- this.store.groupIds.push(compId);
|
|
|
+ const { store, helper } = this;
|
|
|
+
|
|
|
+ if (store.currCompId && store.groupModeStatus) {
|
|
|
+ const enableGroupIds = helper
|
|
|
+ .findParentComp(compId)
|
|
|
+ ?.getChildIds() as string[];
|
|
|
+ const comps = helper.getCompTrees(compId);
|
|
|
+ while (comps.length) {
|
|
|
+ const comp = comps.pop() as DesignComp;
|
|
|
+ const index = store.groupIds.indexOf(comp.id);
|
|
|
+ if (index >= 0) {
|
|
|
+ const groupIds = [...store.groupIds];
|
|
|
+ groupIds.splice(index, 1);
|
|
|
+ store.setGroupIds(groupIds);
|
|
|
+ } else if (enableGroupIds.includes(comp.id)) {
|
|
|
+ store.groupIds.push(comp.id);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -47,6 +65,9 @@ export const editActions = EditorModule.action({
|
|
|
|
|
|
|
|
|
|
|
|
+ if (this.store.currCompId == compId) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.store.currCompId = "";
|
|
|
this.store.currStreamCardId = "";
|
|
|
this.store.setCurrComp(compId);
|
|
@@ -70,20 +91,19 @@ export const editActions = EditorModule.action({
|
|
|
},
|
|
|
|
|
|
async removeStreamCard(compId: string) {
|
|
|
-
|
|
|
- await queenApi.showConfirm({title:"删除", content:"确认删除当前内容?"})
|
|
|
+ await queenApi.showConfirm({ title: "删除", content: "确认删除当前内容?" });
|
|
|
|
|
|
if (this.store.streamCardIds.length < 2) {
|
|
|
return;
|
|
|
}
|
|
|
let nextCard = this.store.currStreamCardId;
|
|
|
if (compId == this.store.currStreamCardId) {
|
|
|
- const i = this.store.streamCardIds.indexOf(compId)
|
|
|
- nextCard = this.store.streamCardIds[i+1]
|
|
|
- if (!nextCard) {
|
|
|
- nextCard = this.store.streamCardIds[i-1]
|
|
|
- }
|
|
|
- }
|
|
|
+ const i = this.store.streamCardIds.indexOf(compId);
|
|
|
+ nextCard = this.store.streamCardIds[i + 1];
|
|
|
+ if (!nextCard) {
|
|
|
+ nextCard = this.store.streamCardIds[i - 1];
|
|
|
+ }
|
|
|
+ }
|
|
|
this.store.deleteComp(compId);
|
|
|
this.store.setCurrComp(nextCard);
|
|
|
},
|
|
@@ -162,7 +182,7 @@ export const editActions = EditorModule.action({
|
|
|
ratio: this.store.isEditComp ? 0 : 1,
|
|
|
});
|
|
|
const thumbnail = URL.createObjectURL(blob);
|
|
|
- this.store.updateDesignThumbnail(thumbnail);
|
|
|
+ this.store.setDesignThumbnail(thumbnail);
|
|
|
|
|
|
if (autoSave) {
|
|
|
await this.controls.uploader.uploadBlobs(this.store.designData);
|
|
@@ -227,4 +247,118 @@ export const editActions = EditorModule.action({
|
|
|
comp.layout.transform.x = 0;
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
+
|
|
|
+ enableGroupMode() {
|
|
|
+ this.store.setGroupIds(
|
|
|
+ this.store.currCompId ? [this.store.currCompId] : []
|
|
|
+ );
|
|
|
+ this.store.setGroupMode(true);
|
|
|
+ },
|
|
|
+
|
|
|
+ async disableGroupMode() {
|
|
|
+ const groupId = await this.actions.combineGroupComps();
|
|
|
+ if (groupId) {
|
|
|
+ this.store.setCurrComp(groupId);
|
|
|
+ }
|
|
|
+ this.store.setGroupIds([]);
|
|
|
+ this.store.setGroupMode(false);
|
|
|
+ },
|
|
|
+
|
|
|
+ async combineGroupComps() {
|
|
|
+ const { helper, store } = this;
|
|
|
+ const { groupIds } = store;
|
|
|
+ if (groupIds.length < 2) return;
|
|
|
+ const compsRect: Record<
|
|
|
+ string,
|
|
|
+ { t: number; l: number; r: number; b: number }
|
|
|
+ > = {};
|
|
|
+ const parentComp = helper.findParentComp(groupIds[0]) as DesignComp;
|
|
|
+ const parentRect = parentComp.$el.getBoundingClientRect();
|
|
|
+ groupIds.forEach((id) => {
|
|
|
+ const comp = helper.findComp(id) as DesignComp;
|
|
|
+ const itemRect = comp.$el.getBoundingClientRect();
|
|
|
+ compsRect[id] = {
|
|
|
+ t: itemRect.top - parentRect.top,
|
|
|
+ l: itemRect.left - parentRect.left,
|
|
|
+ r: itemRect.right - parentRect.left,
|
|
|
+ b: itemRect.bottom - parentRect.top,
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ const confVals = Object.values(compsRect);
|
|
|
+ const groupConf = {
|
|
|
+ t: Math.min(...confVals.map((d) => d.t)),
|
|
|
+ l: Math.min(...confVals.map((d) => d.l)),
|
|
|
+ r: Math.max(...confVals.map((d) => d.r)),
|
|
|
+ b: Math.max(...confVals.map((d) => d.b)),
|
|
|
+ };
|
|
|
+
|
|
|
+ const groupId = await this.store.insertCompContainer("Group", parentComp);
|
|
|
+
|
|
|
+ const groupComp = helper.findComp(groupId) as DesignComp;
|
|
|
+
|
|
|
+ groupComp.layout = {
|
|
|
+ size: [
|
|
|
+ helper.pxToDesignSize(groupConf.r - groupConf.l),
|
|
|
+ helper.pxToDesignSize(groupConf.b - groupConf.t),
|
|
|
+ ],
|
|
|
+ position: "absolute",
|
|
|
+ transform: {
|
|
|
+ x: helper.pxToDesignSize(groupConf.l),
|
|
|
+ y: helper.pxToDesignSize(groupConf.t),
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ groupIds.forEach((id) => {
|
|
|
+ const comp = helper.findComp(id) as DesignComp;
|
|
|
+ comp.layout.transform || (comp.layout.transform = {});
|
|
|
+ comp.layout.transform.x =
|
|
|
+ (comp.layout.transform.x || 0) - (groupComp.layout.transform?.x || 0);
|
|
|
+
|
|
|
+ comp.layout.transform.y =
|
|
|
+ (comp.layout.transform.y || 0) - (groupComp.layout.transform?.y || 0);
|
|
|
+ });
|
|
|
+
|
|
|
+ groupComp.children.default = parentComp.children.default?.filter((d) =>
|
|
|
+ groupIds.includes(d)
|
|
|
+ );
|
|
|
+ parentComp.children.default = parentComp.children.default?.filter(
|
|
|
+ (d) => !groupIds.includes(d)
|
|
|
+ );
|
|
|
+
|
|
|
+ return groupId;
|
|
|
+ },
|
|
|
+
|
|
|
+ cancelGroupComps(groupComp: DesignComp) {
|
|
|
+ const { helper } = this;
|
|
|
+ const groupIds = groupComp.children.default as string[];
|
|
|
+
|
|
|
+ const parentComp = helper.findParentComp(groupComp.id) as DesignComp;
|
|
|
+
|
|
|
+ const parentMatrix = new Matrix();
|
|
|
+
|
|
|
+ groupIds.forEach((id) => {
|
|
|
+ const comp = helper.findComp(id) as DesignComp;
|
|
|
+
|
|
|
+ parentMatrix.setFormDiv(parentComp.$el);
|
|
|
+
|
|
|
+ const compMatrix = new Matrix();
|
|
|
+ compMatrix.setFormDiv(comp.$el);
|
|
|
+ compMatrix.multipy(parentMatrix);
|
|
|
+
|
|
|
+ comp.layout.transform || (comp.layout.transform = {});
|
|
|
+ comp.layout.transform.x = helper.pxToDesignSize(compMatrix.getX());
|
|
|
+ comp.layout.transform.y = helper.pxToDesignSize(compMatrix.getY());
|
|
|
+ comp.layout.transform.s = compMatrix.getScale();
|
|
|
+ comp.layout.transform.r = compMatrix.getRotate();
|
|
|
+ });
|
|
|
+
|
|
|
+ const childIds = [...(parentComp.children.default as string[])];
|
|
|
+
|
|
|
+ const groupIndex = childIds.findIndex((id) => groupComp.id === id);
|
|
|
+ childIds.splice(groupIndex, 1, ...groupIds);
|
|
|
+
|
|
|
+ parentComp.children.default = childIds;
|
|
|
+ },
|
|
|
});
|