Browse Source

·完善undo框架,支持图元对象移动。

sybotan 4 năm trước cách đây
mục cha
commit
352e735a2f

+ 1 - 1
saga-web-base/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/base",
-    "version": "2.1.12",
+    "version": "2.1.14",
     "description": "上格云Web基础库。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 9 - 7
saga-web-base/src/SObjectObserver.ts

@@ -24,19 +24,21 @@ export class SObjectObserver {
      */
     // eslint-disable-next-line @typescript-eslint/no-explicit-any
     notify(...args: any[]): void {
-        if (args.length == 2) {
+        if (args.length === 1) {
+            this.callback.call(this.receiver, args[0]);
+        } else if (args.length === 2) {
             this.callback.call(this.receiver, args[0], args[1]);
-        } else if (args.length == 3) {
+        } else if (args.length === 3) {
             this.callback.call(this.receiver, args[0], args[1], args[2]);
-        } else if (args.length == 4) {
+        } else if (args.length === 4) {
             this.callback.call(this.receiver, args[0], args[1], args[2], args[3]);
-        } else if (args.length == 5) {
+        } else if (args.length === 5) {
             this.callback.call(this.receiver, args[0], args[1], args[2], args[3], args[4]);
-        } else if (args.length == 6) {
+        } else if (args.length === 6) {
             this.callback.call(this.receiver, args[0], args[1], args[2], args[3], args[4], args[5]);
-        } else if (args.length == 7) {
+        } else if (args.length === 7) {
             this.callback.call(this.receiver, args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
-        } else if (args.length == 8) {
+        } else if (args.length === 8) {
             this.callback.call(this.receiver, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
         } else {
             this.callback.call(this.receiver, ...args);

+ 4 - 0
saga-web-base/src/undo/SUndoStack.ts

@@ -98,6 +98,10 @@ export class SUndoStack extends SObject {
      * @param   cmd     被添加的命令
      */
     push(cmd: SUndoCommand): void {
+        if (this._index >= 0 && cmd.mergeWith(this.cmdStack[this._index])) {
+            return;
+        }
+
         this.cmdStack.length = this._index + 1;
         this.cmdStack.push(cmd);
         this._index = this.cmdStack.length - 1;

+ 1 - 1
saga-web-graphy/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/graphy",
-    "version": "2.1.53",
+    "version": "2.1.58",
     "description": "上格云二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 2 - 2
saga-web-graphy/src/SGraphyItem.ts

@@ -78,7 +78,6 @@ export class SGraphyItem extends SObject {
         let old = this.pos.x;
         this.pos.x = v;
         this.update();
-        this.$emit("onMove", new SPoint(old, this.pos.y), this.pos);
     } // Set x
     /** Y轴坐标 */
     get y(): number {
@@ -91,7 +90,6 @@ export class SGraphyItem extends SObject {
         let old = this.pos.y;
         this.pos.y = v;
         this.update();
-        this.$emit("onMove", new SPoint(this.pos.x, old), this.pos);
     } // Set y
     /** 缩放比例 */
     scale: number = 1;
@@ -405,10 +403,12 @@ export class SGraphyItem extends SObject {
             this.moveable &&
             this._isMoving
         ) {
+            let old = new SPoint(this.pos.x, this.pos.y);
             this.moveTo(
                 this.pos.x + event.x - this._mouseDownPos.x,
                 this.pos.y + event.y - this._mouseDownPos.y
             );
+            this.$emit("onMove", old, this.pos);
         }
 
         // 处理hover