@ccpc/core 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2080 -0
- package/package.json +4 -23
- package/types/display/dirty_prop.d.ts +3 -0
- package/types/display/state_object.d.ts +30 -0
- package/types/document/doc_saver.d.ts +13 -0
- package/types/document/document.d.ts +37 -0
- package/types/document/element_mgr.d.ts +28 -0
- package/types/document/i_document.d.ts +60 -0
- package/{dist → types}/document/id_pool.d.ts +3 -1
- package/types/element/db.d.ts +49 -0
- package/types/element/element.d.ts +55 -0
- package/{dist → types}/element/element_decorator.d.ts +0 -1
- package/{dist → types}/element/element_id.d.ts +1 -2
- package/types/element/i_element.d.ts +64 -0
- package/types/element/tmp_element/tmp_element.d.ts +6 -0
- package/types/element/tmp_element/tmp_element_painter.d.ts +27 -0
- package/types/grep/display/display_object.d.ts +37 -0
- package/types/grep/display/display_object_mgr.d.ts +23 -0
- package/types/grep/display/grep_display.d.ts +16 -0
- package/types/grep/gcurve2d.d.ts +15 -0
- package/types/grep/ggroup.d.ts +29 -0
- package/types/grep/gnode.d.ts +110 -0
- package/types/grep/gnode2d.d.ts +9 -0
- package/types/grep/gnode_type.d.ts +10 -0
- package/types/grep/gpoint2d.d.ts +14 -0
- package/types/grep/gpolycurve.d.ts +13 -0
- package/types/grep/gpolygon.d.ts +14 -0
- package/types/grep/grep.d.ts +15 -0
- package/types/grep/gtext2d.d.ts +14 -0
- package/types/grep/i_style.d.ts +42 -0
- package/types/grep/style_utils.d.ts +22 -0
- package/types/index.d.ts +41 -0
- package/types/model_view/i_high_light.d.ts +6 -0
- package/types/model_view/i_selection.d.ts +6 -0
- package/types/model_view/model_changed_cache.d.ts +35 -0
- package/types/model_view/model_view.d.ts +45 -0
- package/types/render/i_render.d.ts +24 -0
- package/types/render/null_render.d.ts +10 -0
- package/types/render/render_node.d.ts +68 -0
- package/types/render/render_node_util.d.ts +4 -0
- package/types/request/buildin_request/redo_request.d.ts +5 -0
- package/types/request/buildin_request/undo_request.d.ts +5 -0
- package/{dist → types}/request/i_request.d.ts +0 -1
- package/{dist → types}/request/request.d.ts +0 -1
- package/{dist → types}/request/request_decorator.d.ts +0 -1
- package/{dist → types}/request/request_mgr.d.ts +0 -1
- package/{dist → types}/toolkit/class_manager.d.ts +0 -1
- package/types/toolkit/cmath_util.d.ts +4 -0
- package/{dist → types}/toolkit/debug_util.d.ts +0 -1
- package/{dist → types}/transaction/i_transaction.d.ts +0 -1
- package/{dist → types}/transaction/i_transaction_base.d.ts +0 -1
- package/{dist → types}/transaction/i_transaction_group.d.ts +0 -1
- package/{dist → types}/transaction/transaction.d.ts +0 -1
- package/{dist → types}/transaction/transaction_base.d.ts +0 -1
- package/{dist → types}/transaction/transaction_group.d.ts +0 -1
- package/{dist → types}/transaction/transaction_mgr.d.ts +0 -1
- package/{dist → types}/transaction/undo_redo_entity.d.ts +0 -1
- package/types/types/type_define.d.ts +31 -0
- package/{dist → types}/types/type_guard.d.ts +1 -1
- package/README.md +0 -11
- package/dist/document/document.d.ts +0 -21
- package/dist/document/document.d.ts.map +0 -1
- package/dist/document/document.js +0 -53
- package/dist/document/element_mgr.d.ts +0 -11
- package/dist/document/element_mgr.d.ts.map +0 -1
- package/dist/document/element_mgr.js +0 -27
- package/dist/document/i_document.d.ts +0 -19
- package/dist/document/i_document.d.ts.map +0 -1
- package/dist/document/i_document.js +0 -1
- package/dist/document/id_pool.d.ts.map +0 -1
- package/dist/document/id_pool.js +0 -67
- package/dist/element/c_element.d.ts +0 -6
- package/dist/element/c_element.d.ts.map +0 -1
- package/dist/element/c_element.js +0 -6
- package/dist/element/element.d.ts +0 -42
- package/dist/element/element.d.ts.map +0 -1
- package/dist/element/element.js +0 -72
- package/dist/element/element_decorator.d.ts.map +0 -1
- package/dist/element/element_decorator.js +0 -40
- package/dist/element/element_id.d.ts.map +0 -1
- package/dist/element/element_id.js +0 -30
- package/dist/element/i_element.d.ts +0 -30
- package/dist/element/i_element.d.ts.map +0 -1
- package/dist/element/i_element.js +0 -1
- package/dist/index.d.ts +0 -12
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -8
- package/dist/request/i_request.d.ts.map +0 -1
- package/dist/request/i_request.js +0 -1
- package/dist/request/request.d.ts.map +0 -1
- package/dist/request/request.js +0 -11
- package/dist/request/request_decorator.d.ts.map +0 -1
- package/dist/request/request_decorator.js +0 -10
- package/dist/request/request_mgr.d.ts.map +0 -1
- package/dist/request/request_mgr.js +0 -77
- package/dist/toolkit/class_manager.d.ts.map +0 -1
- package/dist/toolkit/class_manager.js +0 -54
- package/dist/toolkit/debug_util.d.ts.map +0 -1
- package/dist/toolkit/debug_util.js +0 -15
- package/dist/transaction/i_transaction.d.ts.map +0 -1
- package/dist/transaction/i_transaction.js +0 -1
- package/dist/transaction/i_transaction_base.d.ts.map +0 -1
- package/dist/transaction/i_transaction_base.js +0 -11
- package/dist/transaction/i_transaction_group.d.ts.map +0 -1
- package/dist/transaction/i_transaction_group.js +0 -1
- package/dist/transaction/transaction.d.ts.map +0 -1
- package/dist/transaction/transaction.js +0 -41
- package/dist/transaction/transaction_base.d.ts.map +0 -1
- package/dist/transaction/transaction_base.js +0 -32
- package/dist/transaction/transaction_group.d.ts.map +0 -1
- package/dist/transaction/transaction_group.js +0 -242
- package/dist/transaction/transaction_mgr.d.ts.map +0 -1
- package/dist/transaction/transaction_mgr.js +0 -84
- package/dist/transaction/undo_redo_entity.d.ts.map +0 -1
- package/dist/transaction/undo_redo_entity.js +0 -261
- package/dist/types/dump_type.d.ts +0 -4
- package/dist/types/dump_type.d.ts.map +0 -1
- package/dist/types/dump_type.js +0 -1
- package/dist/types/type_guard.d.ts.map +0 -1
- package/dist/types/type_guard.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"i_transaction_group.d.ts","sourceRoot":"","sources":["../../src/transaction/i_transaction_group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEvD,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACvD,WAAW;IACX,MAAM,EAAE,OAAO,CAAA;IAEf,QAAQ,EAAE,gBAAgB,EAAE,CAAA;IAE5B,QAAQ,EAAE,gBAAgB,EAAE,CAAA;IAE5B,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAE1B,qBAAqB;IACrB,gBAAgB,CAAC,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAA;IAE3C;;;OAGG;IACH,UAAU,IAAI,YAAY,GAAG,SAAS,CAAA;IAEtC,OAAO,IAAI,OAAO,CAAA;IAElB,OAAO,IAAI,OAAO,CAAA;IAElB,IAAI,IAAI,OAAO,CAAA;IAEf,IAAI,IAAI,OAAO,CAAA;IAEf,aAAa,IAAI,IAAI,CAAA;IAErB,qBAAqB;IACrB,cAAc,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAA;IAE5C,WAAW;IACX,qBAAqB,IAAI,YAAY,GAAG,SAAS,CAAA;IAEjD,wBAAwB;IACxB,0BAA0B,IAAI,iBAAiB,GAAG,SAAS,CAAA;IAE3D,iBAAiB;IACjB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,GAAG,iBAAiB,GAAG,SAAS,CAAA;IAEvE,4BAA4B;IAC5B,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAEvC,mBAAmB;IACnB,mBAAmB,IAAI,MAAM,CAAA;IAE7B;;;;OAIG;IACH,sBAAsB,CAAC,IAAI,EAAE,gBAAgB,EAAE,CAAC,EAAE,YAAY,GAAG,OAAO,CAAA;IAExE,eAAe,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAAA;CAC7C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/transaction/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,qBAAa,WAAY,SAAQ,eAAgB,YAAW,YAAY;IACpE,SAAgB,cAAc,EAAE,cAAc,CAAC;IAExC,OAAO,EAAE,OAAO,CAAQ;IAExB,MAAM,EAAG,iBAAiB,CAAC;gBAEtB,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM;IAMjC,KAAK,IAAI,OAAO;IAOhB,MAAM,IAAI,OAAO;IAQjB,QAAQ,IAAI,OAAO;IAQnB,iBAAiB,IAAI,IAAI;IAIzB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAKlC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI;CAGhD"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { EN_TransactionStatus } from './i_transaction_base';
|
|
2
|
-
import { TransactionBase } from './transaction_base';
|
|
3
|
-
import { UndoRedoEntity } from './undo_redo_entity';
|
|
4
|
-
export class Transaction extends TransactionBase {
|
|
5
|
-
constructor(doc, name) {
|
|
6
|
-
super(doc, name);
|
|
7
|
-
this.canUndo = true;
|
|
8
|
-
this.start();
|
|
9
|
-
this.undoRedoEntity = new UndoRedoEntity(doc);
|
|
10
|
-
}
|
|
11
|
-
start() {
|
|
12
|
-
super.start();
|
|
13
|
-
this.doc.transactionMgr.getLastLeafTranGroup(true)?.clearRedoList();
|
|
14
|
-
this.parent = this.getStartParent();
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
commit() {
|
|
18
|
-
// TODO 发送事件
|
|
19
|
-
const ok = this.undoRedoEntity.commit();
|
|
20
|
-
if (!ok)
|
|
21
|
-
this.parent.popTransaction(this);
|
|
22
|
-
this._status = EN_TransactionStatus.COMMITTED;
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
rollBack() {
|
|
26
|
-
this.undoRedoEntity.rollBack();
|
|
27
|
-
this.parent.popTransaction(this);
|
|
28
|
-
super.rollBack();
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
reverseAndExecute() {
|
|
32
|
-
this.undoRedoEntity.reverseAndExecute();
|
|
33
|
-
}
|
|
34
|
-
merge(another) {
|
|
35
|
-
this.undoRedoEntity.merge(another.undoRedoEntity);
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
collectUsedIds(set) {
|
|
39
|
-
this.undoRedoEntity.collectUsedIds(set);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction_base.d.ts","sourceRoot":"","sources":["../../src/transaction/transaction_base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE9E,8BAAsB,eAAgB,YAAW,gBAAgB;IACtD,IAAI,EAAE,MAAM,CAAC;IAEb,GAAG,EAAE,SAAS,CAAC;IAEtB,SAAS,CAAC,OAAO,uBAAoC;gBAEzC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM;aAKxB,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI;IAC/C,KAAK,IAAI,OAAO;IAKhB,cAAc;IAOd,SAAS,IAAI,oBAAoB;IAIjC,SAAS,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;IAI7C,QAAQ,IAAI,OAAO;IAKnB,iBAAiB,CAAC,CAAC,SAAS,gBAAgB,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC;CAGjH"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { DebugUtil } from '../toolkit/debug_util';
|
|
2
|
-
import { EN_TransactionStatus } from './i_transaction_base';
|
|
3
|
-
export class TransactionBase {
|
|
4
|
-
constructor(doc, name) {
|
|
5
|
-
this._status = EN_TransactionStatus.NOT_STARTED;
|
|
6
|
-
this.name = name;
|
|
7
|
-
this.doc = doc;
|
|
8
|
-
}
|
|
9
|
-
start() {
|
|
10
|
-
this._status = EN_TransactionStatus.STARTED;
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
getStartParent() {
|
|
14
|
-
const parent = this.doc.transactionMgr.getCurrentTransactionGroup();
|
|
15
|
-
DebugUtil.assert(parent, '没有找到TransactionGroup', 'wg', '2026-03-05');
|
|
16
|
-
parent.startTransaction(this);
|
|
17
|
-
return parent;
|
|
18
|
-
}
|
|
19
|
-
getStatus() {
|
|
20
|
-
return this._status;
|
|
21
|
-
}
|
|
22
|
-
setStatus(status) {
|
|
23
|
-
this._status = status;
|
|
24
|
-
}
|
|
25
|
-
rollBack() {
|
|
26
|
-
this._status = EN_TransactionStatus.ROLLED_BACK;
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
isTransactionLike(ctor) {
|
|
30
|
-
return this instanceof ctor;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction_group.d.ts","sourceRoot":"","sources":["../../src/transaction/transaction_group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAwB,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,qBAAa,gBAAiB,SAAQ,eAAgB,YAAW,iBAAiB;IAS7B,MAAM;IARhD,QAAQ,EAAE,gBAAgB,EAAE,CAAM;IAElC,QAAQ,EAAE,gBAAgB,EAAE,CAAM;IAEzC,OAAO,CAAC,iBAAiB,CAAc;IAEhC,MAAM,CAAC,EAAE,iBAAiB,CAAC;gBAEtB,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAS,MAAM,UAAQ;IAMxD,KAAK;IASL,gBAAgB,CAAC,CAAC,EAAE,gBAAgB;IAgC3C;;OAEG;IACH,OAAO,CAAC,cAAc;IAKtB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA0BvB,UAAU,IAAI,YAAY,GAAG,SAAS;IAa7C;;OAEG;IACI,QAAQ,IAAI,OAAO;IAYnB,eAAe,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO;IAM1C,sBAAsB,CAAC,IAAI,EAAE,gBAAgB,EAAE,CAAC,EAAE,YAAY;IAW9D,OAAO,IAAI,OAAO;IAelB,OAAO,IAAI,OAAO;IAczB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIlB,IAAI,IAAI,OAAO;IAkBf,IAAI,IAAI,OAAO;IAiBf,aAAa,IAAI,IAAI;IAIrB,cAAc,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO;IAK5C,qBAAqB,IAAI,YAAY,GAAG,SAAS;IAOjD,0BAA0B,IAAI,iBAAiB,GAAG,SAAS;IAa3D,qBAAqB,CAAC,QAAQ,EAAE,OAAO,GAAG,iBAAiB,GAAG,SAAS;IAiBvE,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIvC,mBAAmB,IAAI,MAAM;IAI7B,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI;CAGhD"}
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { DebugUtil } from '../toolkit/debug_util';
|
|
2
|
-
import { EN_TransactionStatus } from './i_transaction_base';
|
|
3
|
-
import { Transaction } from './transaction';
|
|
4
|
-
import { TransactionBase } from './transaction_base';
|
|
5
|
-
export class TransactionGroup extends TransactionBase {
|
|
6
|
-
constructor(doc, name, isRoot = false) {
|
|
7
|
-
super(doc, name);
|
|
8
|
-
this.isRoot = isRoot;
|
|
9
|
-
this.undoList = [];
|
|
10
|
-
this.redoList = [];
|
|
11
|
-
this._maxUndoStackSize = 30;
|
|
12
|
-
this.isRoot = isRoot;
|
|
13
|
-
this.start();
|
|
14
|
-
}
|
|
15
|
-
start() {
|
|
16
|
-
// TODO 发送事件
|
|
17
|
-
super.start();
|
|
18
|
-
if (this.isRoot)
|
|
19
|
-
return true;
|
|
20
|
-
this.doc.transactionMgr.getLastLeafTranGroup(true)?.clearRedoList();
|
|
21
|
-
this.parent = this.getStartParent();
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
startTransaction(t) {
|
|
25
|
-
DebugUtil.assert(this.getStatus() === EN_TransactionStatus.STARTED, '事务组已完成,不能再启动事务', 'wg', '2026-03-05');
|
|
26
|
-
const oldName = this.getCurrentTransaction()?.name;
|
|
27
|
-
const newName = t.name;
|
|
28
|
-
DebugUtil.assert(this.getStatus() === EN_TransactionStatus.STARTED && !this.getCurrentTransaction(), `事务不能嵌套, 新事务${newName}, 未完成的事务${oldName}`, 'wg', '2025-03-05');
|
|
29
|
-
this.undoList.push(t);
|
|
30
|
-
this.redoList.splice(0);
|
|
31
|
-
const max = Math.max(this.getMaxUndoStackSize(), 4);
|
|
32
|
-
if (this.undoList.length <= max) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const head = this.undoList.shift();
|
|
36
|
-
// edit mode will compress all transactions to one single node,so we should merge first node to second
|
|
37
|
-
if (head && this.parent) {
|
|
38
|
-
const first = this._toTransaction(head);
|
|
39
|
-
const second = this._toTransaction(this.undoList[0]);
|
|
40
|
-
this.undoList[0] = first.merge(second);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 事务或事务组转成事务
|
|
45
|
-
*/
|
|
46
|
-
_toTransaction(t) {
|
|
47
|
-
if (t.isTransactionLike(TransactionGroup))
|
|
48
|
-
return t._compressToTransaction();
|
|
49
|
-
else
|
|
50
|
-
return t;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* 事务组压缩成事务
|
|
54
|
-
*/
|
|
55
|
-
_compressToTransaction() {
|
|
56
|
-
//空的事务组 压缩成一个空事务
|
|
57
|
-
if (!this.undoList.length) {
|
|
58
|
-
const empty = new Transaction(this.doc, 'empty');
|
|
59
|
-
empty.setStatus(EN_TransactionStatus.COMMITTED);
|
|
60
|
-
return empty;
|
|
61
|
-
}
|
|
62
|
-
const newName = this.undoList[0].name + '->' + this.undoList[this.undoList.length - 1].name;
|
|
63
|
-
while (this.undoList.length > 1) {
|
|
64
|
-
const popped = this.undoList.pop();
|
|
65
|
-
DebugUtil.assert(popped, 'undoList不应该为空', 'wg', '2026-03-05');
|
|
66
|
-
const next = this._toTransaction(popped);
|
|
67
|
-
const pre = this._toTransaction(this.undoList[this.undoList.length - 1]);
|
|
68
|
-
this.undoList[this.undoList.length - 1] = pre;
|
|
69
|
-
pre.merge(next);
|
|
70
|
-
}
|
|
71
|
-
const result = this.undoList[0];
|
|
72
|
-
result.name = newName;
|
|
73
|
-
result.canUndo = true;
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
assimilate() {
|
|
77
|
-
this._status = EN_TransactionStatus.COMMITTED;
|
|
78
|
-
if (!this.undoList.length) {
|
|
79
|
-
this.parent?.undoList.pop();
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
const transaction = this._compressToTransaction();
|
|
83
|
-
this.parent?.replaceTailTransaction(this, transaction);
|
|
84
|
-
// TODO 刷新视图, 发送事件
|
|
85
|
-
// this.doc.updateView();
|
|
86
|
-
return transaction;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* 压缩成一个事务,然后undo
|
|
90
|
-
*/
|
|
91
|
-
rollBack() {
|
|
92
|
-
super.rollBack();
|
|
93
|
-
if (!this.undoList.length) {
|
|
94
|
-
this.parent?.undoList.pop();
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
const transaction = this._compressToTransaction();
|
|
98
|
-
this.parent?.replaceTailTransaction(this, transaction);
|
|
99
|
-
this.parent?.undoWithoutRedo(transaction);
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
undoWithoutRedo(ut) {
|
|
103
|
-
ut.reverseAndExecute();
|
|
104
|
-
this.undoList.pop();
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
replaceTailTransaction(tail, t) {
|
|
108
|
-
DebugUtil.assert(this.undoList[this.undoList.length - 1] === tail, '只能替换栈顶事务', 'wg', '2026-03-05');
|
|
109
|
-
this.undoList[this.undoList.length - 1] = t;
|
|
110
|
-
t.parent = this;
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
canUndo() {
|
|
114
|
-
const ut = this.undoList[this.undoList.length - 1];
|
|
115
|
-
if (!ut)
|
|
116
|
-
return false;
|
|
117
|
-
if (ut.isTransactionLike(TransactionGroup)) {
|
|
118
|
-
if (ut._undoListNotEmpty()) {
|
|
119
|
-
return ut.canUndo();
|
|
120
|
-
}
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
else if (ut.isTransactionLike(Transaction)) {
|
|
124
|
-
return !!ut.canUndo;
|
|
125
|
-
}
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
canRedo() {
|
|
129
|
-
const ut = this.redoList[this.redoList.length - 1];
|
|
130
|
-
if (!ut)
|
|
131
|
-
return false;
|
|
132
|
-
if (ut.isTransactionLike(TransactionGroup)) {
|
|
133
|
-
if (ut._redoListNotEmpty()) {
|
|
134
|
-
return ut.canRedo();
|
|
135
|
-
}
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* undo数组是否为空
|
|
142
|
-
*/
|
|
143
|
-
_undoListNotEmpty() {
|
|
144
|
-
return !!this.undoList.length;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* redo是否为空
|
|
148
|
-
*/
|
|
149
|
-
_redoListNotEmpty() {
|
|
150
|
-
return !!this.redoList.length;
|
|
151
|
-
}
|
|
152
|
-
undo() {
|
|
153
|
-
const ut = this.undoList[this.undoList.length - 1];
|
|
154
|
-
if (!ut)
|
|
155
|
-
return false;
|
|
156
|
-
if (ut.isTransactionLike(TransactionGroup)) {
|
|
157
|
-
if (ut._undoListNotEmpty()) {
|
|
158
|
-
return ut.undo();
|
|
159
|
-
}
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
else if (ut.isTransactionLike(Transaction)) {
|
|
163
|
-
if (!ut.canUndo)
|
|
164
|
-
return false;
|
|
165
|
-
ut.reverseAndExecute();
|
|
166
|
-
this.undoList.pop();
|
|
167
|
-
this.redoList.push(ut);
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
redo() {
|
|
173
|
-
const ut = this.redoList[this.redoList.length - 1];
|
|
174
|
-
if (!ut)
|
|
175
|
-
return false;
|
|
176
|
-
if (ut.isTransactionLike(TransactionGroup)) {
|
|
177
|
-
if (ut._redoListNotEmpty()) {
|
|
178
|
-
return ut.redo();
|
|
179
|
-
}
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
else if (ut.isTransactionLike(Transaction)) {
|
|
183
|
-
ut.reverseAndExecute();
|
|
184
|
-
this.redoList.pop();
|
|
185
|
-
this.undoList.push(ut);
|
|
186
|
-
return true;
|
|
187
|
-
}
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
clearRedoList() {
|
|
191
|
-
this.redoList.splice(0);
|
|
192
|
-
}
|
|
193
|
-
popTransaction(t) {
|
|
194
|
-
DebugUtil.assert(this.undoList.pop() === t, '只能pop栈顶事务', 'wg', '2026-03-05');
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
getCurrentTransaction() {
|
|
198
|
-
const t = this.undoList[this.undoList.length - 1];
|
|
199
|
-
if (t && t.isTransactionLike(Transaction) && t.getStatus() === EN_TransactionStatus.STARTED)
|
|
200
|
-
return t;
|
|
201
|
-
return undefined;
|
|
202
|
-
}
|
|
203
|
-
getCurrentTransactionGroup() {
|
|
204
|
-
const t = this.undoList.slice(0)
|
|
205
|
-
.reverse()
|
|
206
|
-
.find((i) => i.isTransactionLike(TransactionGroup) && i.getStatus() === EN_TransactionStatus.STARTED);
|
|
207
|
-
if (t && t.isTransactionLike(TransactionGroup)) {
|
|
208
|
-
return t.getCurrentTransactionGroup();
|
|
209
|
-
}
|
|
210
|
-
if (this.getStatus() === EN_TransactionStatus.STARTED) {
|
|
211
|
-
return this;
|
|
212
|
-
}
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
getLastLeafTransGroup(undoList) {
|
|
216
|
-
let t;
|
|
217
|
-
if (this.undoList[this.undoList.length - 1]) {
|
|
218
|
-
t = this.undoList[this.undoList.length - 1];
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
const list = undoList ? this.undoList : this.redoList;
|
|
222
|
-
t = list[list.length - 1];
|
|
223
|
-
}
|
|
224
|
-
if (!t)
|
|
225
|
-
return this;
|
|
226
|
-
if (t.isTransactionLike(Transaction)) {
|
|
227
|
-
return t.parent;
|
|
228
|
-
}
|
|
229
|
-
if (t.isTransactionLike(TransactionGroup)) {
|
|
230
|
-
return t.getLastLeafTransGroup(undoList);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
setMaxUndoStackSize(size) {
|
|
234
|
-
this._maxUndoStackSize = size;
|
|
235
|
-
}
|
|
236
|
-
getMaxUndoStackSize() {
|
|
237
|
-
return this._maxUndoStackSize || this.parent?.getMaxUndoStackSize() || 30;
|
|
238
|
-
}
|
|
239
|
-
collectUsedIds(set) {
|
|
240
|
-
this.undoList.concat(this.redoList).forEach(t => t.collectUsedIds(set));
|
|
241
|
-
}
|
|
242
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction_mgr.d.ts","sourceRoot":"","sources":["../../src/transaction/transaction_mgr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,qBAAa,cAAc;IACvB,YAAY;IACZ,OAAO,CAAC,SAAS,CAAqB;IAE/B,IAAI,CAAC,GAAG,EAAE,SAAS;IAK1B;;OAEG;IACI,KAAK;IAKZ;;OAEG;IACI,mBAAmB,CAAC,IAAI,EAAE,MAAM;IAIvC;;OAEG;IACI,qBAAqB,IAAI,YAAY,GAAG,SAAS;IAMxD;;OAEG;IACI,0BAA0B,IAAI,iBAAiB,GAAG,SAAS;IAIlE;;OAEG;IACI,oBAAoB,CAAC,QAAQ,EAAE,OAAO,GAAG,iBAAiB,GAAG,SAAS;IAI7E;;OAEG;IACI,wBAAwB,IAAI,cAAc;IAMjD;;OAEG;IACI,IAAI;IAKX;;OAEG;IACI,IAAI;IAKX;;OAEG;IACI,OAAO;IAId;;OAEG;IACI,OAAO;IAIP,QAAQ,IAAI,GAAG,CAAC,MAAM,CAAC;CAKjC"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { DebugUtil } from '../toolkit/debug_util';
|
|
2
|
-
import { TransactionGroup } from './transaction_group';
|
|
3
|
-
/**
|
|
4
|
-
* 事务管理器
|
|
5
|
-
*/
|
|
6
|
-
export class TransactionMgr {
|
|
7
|
-
init(doc) {
|
|
8
|
-
this._rootNode = new TransactionGroup(doc, 'root', true);
|
|
9
|
-
this.setMaxUndoStackSize(50);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* 清空事务树
|
|
13
|
-
*/
|
|
14
|
-
clear() {
|
|
15
|
-
this._rootNode.undoList.splice(0);
|
|
16
|
-
this._rootNode.clearRedoList();
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 设置最大回撤步数
|
|
20
|
-
*/
|
|
21
|
-
setMaxUndoStackSize(size) {
|
|
22
|
-
this._rootNode.setMaxUndoStackSize(size);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* 获取当前正在进行的事务
|
|
26
|
-
*/
|
|
27
|
-
getCurrentTransaction() {
|
|
28
|
-
const group = this._rootNode.getCurrentTransactionGroup();
|
|
29
|
-
if (!group)
|
|
30
|
-
return undefined;
|
|
31
|
-
return group.getCurrentTransaction();
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 获取当前事务组
|
|
35
|
-
*/
|
|
36
|
-
getCurrentTransactionGroup() {
|
|
37
|
-
return this._rootNode.getCurrentTransactionGroup();
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 获取最后的叶子节点事务组
|
|
41
|
-
*/
|
|
42
|
-
getLastLeafTranGroup(undoList) {
|
|
43
|
-
return this._rootNode.getLastLeafTransGroup(undoList);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* 获取当前正在进行的事务的undoRedoEntity
|
|
47
|
-
*/
|
|
48
|
-
getCurrentUndoRedoEntity() {
|
|
49
|
-
const transaction = this.getCurrentTransaction();
|
|
50
|
-
DebugUtil.assert(transaction, '没有事务', 'wg', '2025-11-18');
|
|
51
|
-
return transaction.undoRedoEntity;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* 撤销
|
|
55
|
-
*/
|
|
56
|
-
undo() {
|
|
57
|
-
const result = !!this.getLastLeafTranGroup(true)?.undo();
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* 回退
|
|
62
|
-
*/
|
|
63
|
-
redo() {
|
|
64
|
-
const result = !!this.getLastLeafTranGroup(false)?.redo();
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 是否可撤销
|
|
69
|
-
*/
|
|
70
|
-
canUndo() {
|
|
71
|
-
return !!this.getLastLeafTranGroup(true)?.canUndo();
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* 是否可回退
|
|
75
|
-
*/
|
|
76
|
-
canRedo() {
|
|
77
|
-
return !!this.getLastLeafTranGroup(false)?.canRedo();
|
|
78
|
-
}
|
|
79
|
-
idPoolGC() {
|
|
80
|
-
const set = new Set();
|
|
81
|
-
this._rootNode.collectUsedIds(set);
|
|
82
|
-
return set;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"undo_redo_entity.d.ts","sourceRoot":"","sources":["../../src/transaction/undo_redo_entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAkB,MAAM,sBAAsB,CAAC;AAGhE;;GAEG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,IAAI,CAAY;IAExB,UAAU;IACV,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAE9C,UAAU;IACV,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;IAEhD,UAAU;IACV,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuB;IAEjD,iBAAiB;IACjB,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA4C;gBAEpE,GAAG,EAAE,SAAS;IAI1B,WAAW;IACJ,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE;IAIvC,WAAW;IACJ,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE;IAIzC,WAAW;IACJ,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE;IAIlC,KAAK;IAOZ;;OAEG;IACI,MAAM;IAsBb;;OAEG;IACI,QAAQ;IAaf;;OAEG;IACI,iBAAiB;IAKxB;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,cAAc;IAsElC;;OAEG;IACH,OAAO,CAAC,QAAQ;IAmBhB;;OAEG;IACI,QAAQ;IAiBf;;;OAGG;IACH,OAAO,CAAC,SAAS;IA0BjB,SAAS;IACF,QAAQ;IAIf;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IAQ7B;;OAEG;IACI,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;IAKtC;;OAEG;IACI,qBAAqB;IAQ5B,OAAO,CAAC,gBAAgB;CAiB3B"}
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { DebugUtil } from '../toolkit/debug_util';
|
|
2
|
-
/**
|
|
3
|
-
* 记录一次undo/redo的Element变化
|
|
4
|
-
*/
|
|
5
|
-
export class UndoRedoEntity {
|
|
6
|
-
constructor(doc) {
|
|
7
|
-
/**增加的元素*/
|
|
8
|
-
this._added = new Set();
|
|
9
|
-
/**删除的元素*/
|
|
10
|
-
this._deleted = new Set();
|
|
11
|
-
/**修改的元素*/
|
|
12
|
-
this._modified = new Set();
|
|
13
|
-
/**修改的元素-属性集合映射*/
|
|
14
|
-
this._modifiedProperties = new Map();
|
|
15
|
-
this._doc = doc;
|
|
16
|
-
}
|
|
17
|
-
/**监听元素增加*/
|
|
18
|
-
onElementsAdded(eles) {
|
|
19
|
-
eles.forEach(ele => this._added.add(ele));
|
|
20
|
-
}
|
|
21
|
-
/**监听元素更新*/
|
|
22
|
-
onElementsUpdated(eles) {
|
|
23
|
-
eles.forEach(ele => this._modified.add(ele));
|
|
24
|
-
}
|
|
25
|
-
/**监听元素删除*/
|
|
26
|
-
onElementsDeleted(eles) {
|
|
27
|
-
eles.forEach(ele => this._deleted.add(ele));
|
|
28
|
-
}
|
|
29
|
-
clear() {
|
|
30
|
-
this._added.clear();
|
|
31
|
-
this._modified.clear();
|
|
32
|
-
this._modifiedProperties.clear();
|
|
33
|
-
this._deleted.clear();
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* 真正去改变db
|
|
37
|
-
*/
|
|
38
|
-
commit() {
|
|
39
|
-
// 1.压缩事务
|
|
40
|
-
this._compress();
|
|
41
|
-
if (this._isEmpty())
|
|
42
|
-
return false;
|
|
43
|
-
// 2.记录属性的修改
|
|
44
|
-
this._modifiedProperties.clear();
|
|
45
|
-
this._modified.forEach(ele => {
|
|
46
|
-
const modify = ele.getModified();
|
|
47
|
-
if (!ele.isTemporary() && modify.length) {
|
|
48
|
-
this._modifiedProperties.set(ele.id.asInt(), modify);
|
|
49
|
-
}
|
|
50
|
-
ele.commit();
|
|
51
|
-
});
|
|
52
|
-
this._added.forEach(ele => ele.commit());
|
|
53
|
-
// TODO 事件分发和 关联更新 更新视图等 暂时注释
|
|
54
|
-
// this._updateViewCache();
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* 数据回滚
|
|
59
|
-
*/
|
|
60
|
-
rollBack() {
|
|
61
|
-
// 增加和删除的回滚
|
|
62
|
-
this._handleElementsFromDB(true, ...this._added);
|
|
63
|
-
this._handleElementsFromDB(false, ...this._deleted);
|
|
64
|
-
// 修改的回滚
|
|
65
|
-
this._modified.forEach(ele => {
|
|
66
|
-
ele.rollBack();
|
|
67
|
-
});
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* undo变redo,redo变undo
|
|
72
|
-
*/
|
|
73
|
-
reverseAndExecute() {
|
|
74
|
-
this._reverse();
|
|
75
|
-
this._execute();
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* 合并其它提交
|
|
79
|
-
*/
|
|
80
|
-
merge(other) {
|
|
81
|
-
const otherAdded = new Set([...other._added]);
|
|
82
|
-
const otherDeleted = new Set([...other._deleted]);
|
|
83
|
-
const otherModifiedProps = new Map();
|
|
84
|
-
other._modifiedProperties.forEach((v, k) => otherModifiedProps.set(k, v));
|
|
85
|
-
// 新增
|
|
86
|
-
for (const ele of [...this._added]) {
|
|
87
|
-
DebugUtil.assert(!otherAdded.has(ele), '不可能发生', 'wg', '2026-03-05');
|
|
88
|
-
if (otherDeleted.has(ele)) {
|
|
89
|
-
// add + delete = null
|
|
90
|
-
this._added.delete(ele);
|
|
91
|
-
otherDeleted.delete(ele);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
// add + modify = add
|
|
95
|
-
otherModifiedProps.delete(ele.id.asInt());
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// 删除
|
|
99
|
-
for (const ele of [...this._deleted]) {
|
|
100
|
-
DebugUtil.assert(!otherAdded.has(ele) &&
|
|
101
|
-
!otherDeleted.has(ele) &&
|
|
102
|
-
!otherModifiedProps.has(ele.id.asInt()), '不可能发生', 'wg', '2026-03-05');
|
|
103
|
-
}
|
|
104
|
-
// 修改
|
|
105
|
-
for (const [thisId, thisPvs] of this._modifiedProperties) {
|
|
106
|
-
if ([...otherAdded].find(_ => _.id.asInt() === thisId)) {
|
|
107
|
-
DebugUtil.assert(false, '不可能发生', 'wg', '2026-03-05');
|
|
108
|
-
}
|
|
109
|
-
else if (otherModifiedProps.has(thisId)) {
|
|
110
|
-
const otherPvs = otherModifiedProps.get(thisId);
|
|
111
|
-
otherPvs?.forEach(otherPv => {
|
|
112
|
-
const thisPv = thisPvs.find(_ => _.propertyName === otherPv.propertyName);
|
|
113
|
-
if (thisPv) {
|
|
114
|
-
thisPv.newValue = otherPv.newValue;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
thisPvs.push(otherPv);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
// 合并完需要删除
|
|
121
|
-
otherModifiedProps.delete(thisId);
|
|
122
|
-
}
|
|
123
|
-
else if ([...otherDeleted].find(_ => _.id.asInt() === thisId)) {
|
|
124
|
-
// modify + delete = delete
|
|
125
|
-
this._modifiedProperties.delete(thisId);
|
|
126
|
-
// 需要把更新回滚
|
|
127
|
-
const otherDelElement = [...otherDeleted].find(_ => _.id.asInt() === thisId);
|
|
128
|
-
thisPvs.forEach(({ propertyName, oldValue }) => {
|
|
129
|
-
const tKey = propertyName;
|
|
130
|
-
const tVal = oldValue;
|
|
131
|
-
if (otherDelElement) {
|
|
132
|
-
otherDelElement.db[tKey] = tVal;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
otherAdded.forEach(ele => this._added.add(ele));
|
|
138
|
-
otherDeleted.forEach(ele => this._deleted.add(ele));
|
|
139
|
-
otherModifiedProps.forEach((v, k) => {
|
|
140
|
-
this._modifiedProperties.set(k, v);
|
|
141
|
-
});
|
|
142
|
-
this._modified.clear();
|
|
143
|
-
this._modifiedProperties.forEach((_v, k) => {
|
|
144
|
-
const ele = this._doc.getElementByIdEnsure(k);
|
|
145
|
-
this._modified.add(ele);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* 将操作reverse
|
|
150
|
-
*/
|
|
151
|
-
_reverse() {
|
|
152
|
-
// 新增变删除
|
|
153
|
-
const oldAdded = [...this._added];
|
|
154
|
-
const oldDeleted = [...this._deleted];
|
|
155
|
-
this._added.clear();
|
|
156
|
-
this._deleted.clear();
|
|
157
|
-
oldAdded.forEach(ele => this._deleted.add(ele));
|
|
158
|
-
oldDeleted.forEach(ele => this._added.add(ele));
|
|
159
|
-
// 修改
|
|
160
|
-
for (const [, values] of this._modifiedProperties) {
|
|
161
|
-
for (const v of values) {
|
|
162
|
-
[v.oldValue, v.newValue] = [v.newValue, v.oldValue];
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* 正向执行
|
|
168
|
-
*/
|
|
169
|
-
_execute() {
|
|
170
|
-
this._handleElementsFromDB(false, ...this._added);
|
|
171
|
-
// 修改
|
|
172
|
-
for (const [id, values] of this._modifiedProperties) {
|
|
173
|
-
const element = this._doc.getElementByIdEnsure(id);
|
|
174
|
-
for (const v of values) {
|
|
175
|
-
const tKey = v.propertyName;
|
|
176
|
-
const tVal = v.newValue;
|
|
177
|
-
element.db[tKey] = tVal;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
this._handleElementsFromDB(true, ...this._deleted);
|
|
181
|
-
this._updateViewCache();
|
|
182
|
-
// TODO 事件分发
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* 压缩事务
|
|
186
|
-
* 主要处理例如,新增一个Element,然后更改这个Element的属性,事务管理器会记录每一个操作,这时只需要记录增加的操作即可
|
|
187
|
-
*/
|
|
188
|
-
_compress() {
|
|
189
|
-
// add + modified = add
|
|
190
|
-
for (const ele of this._added) {
|
|
191
|
-
if (this._modified.has(ele)) {
|
|
192
|
-
ele.commit();
|
|
193
|
-
this._modified.delete(ele);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
// modified + delete = (rollback modified) + delete
|
|
197
|
-
for (const ele of this._deleted) {
|
|
198
|
-
if (this._modified.has(ele)) {
|
|
199
|
-
ele.rollBack();
|
|
200
|
-
this._modified.delete(ele);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
// add + delete = null
|
|
204
|
-
for (const ele of this._deleted) {
|
|
205
|
-
if (this._added.has(ele)) {
|
|
206
|
-
this._deleted.delete(ele);
|
|
207
|
-
this._added.delete(ele);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
/**是否为空*/
|
|
212
|
-
_isEmpty() {
|
|
213
|
-
return !this._added.size && !this._deleted.size && !this._modified.size;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* 从容器中增删对象
|
|
217
|
-
* @param del 是否删除
|
|
218
|
-
* @param eles 对象数组
|
|
219
|
-
*/
|
|
220
|
-
_handleElementsFromDB(del, ...eles) {
|
|
221
|
-
const eleMgr = this._doc.elementMgr;
|
|
222
|
-
eles.forEach(ele => {
|
|
223
|
-
if (del)
|
|
224
|
-
eleMgr.delete(ele.id.asInt());
|
|
225
|
-
else
|
|
226
|
-
eleMgr.add(ele);
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* 收集使用过的id
|
|
231
|
-
*/
|
|
232
|
-
collectUsedIds(set) {
|
|
233
|
-
[...this._added, ...this._deleted].forEach(e => set.add(e.id.asInt()));
|
|
234
|
-
[...this._modifiedProperties.keys()].forEach(id => set.add(id));
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* 获取所有修改的ElementId集合
|
|
238
|
-
*/
|
|
239
|
-
getModifiedElementIds() {
|
|
240
|
-
const result = new Set();
|
|
241
|
-
this._added.forEach(ele => result.add(ele.id.asInt()));
|
|
242
|
-
this._modified.forEach(ele => result.add(ele.id.asInt()));
|
|
243
|
-
return result;
|
|
244
|
-
}
|
|
245
|
-
// TODO 暂时注释
|
|
246
|
-
_updateViewCache() {
|
|
247
|
-
// const changedElements: Set<Element> = new Set();
|
|
248
|
-
// for (const [id, values] of this._modifiedProperties) {
|
|
249
|
-
// const element = this._doc.getElementByIdEnsure(id);
|
|
250
|
-
// if (values.find(({ propertyName }) => {
|
|
251
|
-
// return element?.propNameChangeShouldCacheToView(propertyName);
|
|
252
|
-
// })) {
|
|
253
|
-
// changedElements.add(element);
|
|
254
|
-
// }
|
|
255
|
-
// }
|
|
256
|
-
// // 刷新视图
|
|
257
|
-
// this._doc.cacheElementChanged(EN_ModelViewChanged.ELEMENT_CREATE, [...this._added]);
|
|
258
|
-
// this._doc.cacheElementChanged(EN_ModelViewChanged.ELEMENT_UPDATE, [...changedElements]);
|
|
259
|
-
// this._doc.cacheElementChanged(EN_ModelViewChanged.ELEMENT_DELETE, [...this._deleted]);
|
|
260
|
-
}
|
|
261
|
-
}
|