editWithManualHistory.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { set } from "lodash";
  2. import { EditorModule } from "..";
  3. import { DesignComp } from "../../objects/DesignTemp/DesignComp";
  4. import { CompObject } from "../../controllers/SelectCtrl/compObj";
  5. export const manualActions = EditorModule.action({
  6. pickComp(compId: string) {
  7. const selectCardChild = (id:string)=>{
  8. const paths = this.helper.getCompTrees(id)
  9. const cardChilds = paths[2];
  10. if (cardChilds) {
  11. this.controls.selectCtrl.selecteObjs([new CompObject(cardChilds)]);
  12. } else {
  13. this.controls.selectCtrl.selecteObjs([])
  14. }
  15. }
  16. if (this.store.currCompId == compId) {
  17. if (this.controls.selectCtrl.selected.length < 1 ) {
  18. selectCardChild(compId);
  19. }else {
  20. this.controls.selectCtrl.upgateGizmoStyle();
  21. }
  22. return;
  23. }
  24. //const { historyCtrl } = this.controls;
  25. const history = this.controls.historyCtrl.history;
  26. let preCompId = this.store.currCompId;
  27. let lasCompId = compId;
  28. history.record({undo:()=>{
  29. this.store.setCurrComp(preCompId);
  30. selectCardChild(preCompId);
  31. }, redo:()=>{
  32. this.store.setCurrComp(lasCompId);
  33. selectCardChild(lasCompId);
  34. }} as any)
  35. history.submit();
  36. this.store.setCurrComp(compId);
  37. selectCardChild(compId);
  38. },
  39. updateCompData(comp: DesignComp, path: string, value: any) {
  40. const { historyCtrl } = this.controls;
  41. historyCtrl.historyActionDoing = true;
  42. historyCtrl.historyCombine = true;
  43. set(comp, path, value);
  44. historyCtrl.historyCombine = false;
  45. historyCtrl.historyActionDoing = false;
  46. },
  47. submitUpdate() {
  48. this.controls.historyCtrl.history.submit();
  49. },
  50. });