@ccpc/core 0.1.0
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/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/document/document.d.ts +21 -0
- package/dist/document/document.d.ts.map +1 -0
- package/dist/document/document.js +53 -0
- package/dist/document/element_mgr.d.ts +11 -0
- package/dist/document/element_mgr.d.ts.map +1 -0
- package/dist/document/element_mgr.js +27 -0
- package/dist/document/i_document.d.ts +19 -0
- package/dist/document/i_document.d.ts.map +1 -0
- package/dist/document/i_document.js +1 -0
- package/dist/document/id_pool.d.ts +20 -0
- package/dist/document/id_pool.d.ts.map +1 -0
- package/dist/document/id_pool.js +67 -0
- package/dist/element/c_element.d.ts +6 -0
- package/dist/element/c_element.d.ts.map +1 -0
- package/dist/element/c_element.js +6 -0
- package/dist/element/element.d.ts +42 -0
- package/dist/element/element.d.ts.map +1 -0
- package/dist/element/element.js +72 -0
- package/dist/element/element_decorator.d.ts +3 -0
- package/dist/element/element_decorator.d.ts.map +1 -0
- package/dist/element/element_decorator.js +40 -0
- package/dist/element/element_id.d.ts +14 -0
- package/dist/element/element_id.d.ts.map +1 -0
- package/dist/element/element_id.js +30 -0
- package/dist/element/i_element.d.ts +30 -0
- package/dist/element/i_element.d.ts.map +1 -0
- package/dist/element/i_element.js +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/request/i_request.d.ts +8 -0
- package/dist/request/i_request.d.ts.map +1 -0
- package/dist/request/i_request.js +1 -0
- package/dist/request/request.d.ts +12 -0
- package/dist/request/request.d.ts.map +1 -0
- package/dist/request/request.js +11 -0
- package/dist/request/request_decorator.d.ts +8 -0
- package/dist/request/request_decorator.d.ts.map +1 -0
- package/dist/request/request_decorator.js +10 -0
- package/dist/request/request_mgr.d.ts +42 -0
- package/dist/request/request_mgr.d.ts.map +1 -0
- package/dist/request/request_mgr.js +77 -0
- package/dist/toolkit/class_manager.d.ts +30 -0
- package/dist/toolkit/class_manager.d.ts.map +1 -0
- package/dist/toolkit/class_manager.js +54 -0
- package/dist/toolkit/debug_util.d.ts +5 -0
- package/dist/toolkit/debug_util.d.ts.map +1 -0
- package/dist/toolkit/debug_util.js +15 -0
- package/dist/transaction/i_transaction.d.ts +21 -0
- package/dist/transaction/i_transaction.d.ts.map +1 -0
- package/dist/transaction/i_transaction.js +1 -0
- package/dist/transaction/i_transaction_base.d.ts +44 -0
- package/dist/transaction/i_transaction_base.d.ts.map +1 -0
- package/dist/transaction/i_transaction_base.js +11 -0
- package/dist/transaction/i_transaction_group.d.ts +41 -0
- package/dist/transaction/i_transaction_group.d.ts.map +1 -0
- package/dist/transaction/i_transaction_group.js +1 -0
- package/dist/transaction/transaction.d.ts +18 -0
- package/dist/transaction/transaction.d.ts.map +1 -0
- package/dist/transaction/transaction.js +41 -0
- package/dist/transaction/transaction_base.d.ts +17 -0
- package/dist/transaction/transaction_base.d.ts.map +1 -0
- package/dist/transaction/transaction_base.js +32 -0
- package/dist/transaction/transaction_group.d.ts +51 -0
- package/dist/transaction/transaction_group.d.ts.map +1 -0
- package/dist/transaction/transaction_group.js +242 -0
- package/dist/transaction/transaction_mgr.d.ts +54 -0
- package/dist/transaction/transaction_mgr.d.ts.map +1 -0
- package/dist/transaction/transaction_mgr.js +84 -0
- package/dist/transaction/undo_redo_entity.d.ts +71 -0
- package/dist/transaction/undo_redo_entity.d.ts.map +1 -0
- package/dist/transaction/undo_redo_entity.js +261 -0
- package/dist/types/dump_type.d.ts +4 -0
- package/dist/types/dump_type.d.ts.map +1 -0
- package/dist/types/dump_type.js +1 -0
- package/dist/types/type_guard.d.ts +5 -0
- package/dist/types/type_guard.d.ts.map +1 -0
- package/dist/types/type_guard.js +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1,242 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { IDocument } from '../document/i_document';
|
|
2
|
+
import { ITransaction } from './i_transaction';
|
|
3
|
+
import { ITransactionGroup } from './i_transaction_group';
|
|
4
|
+
import { UndoRedoEntity } from './undo_redo_entity';
|
|
5
|
+
/**
|
|
6
|
+
* 事务管理器
|
|
7
|
+
*/
|
|
8
|
+
export declare class TransactionMgr {
|
|
9
|
+
/**事务树的根节点*/
|
|
10
|
+
private _rootNode;
|
|
11
|
+
init(doc: IDocument): void;
|
|
12
|
+
/**
|
|
13
|
+
* 清空事务树
|
|
14
|
+
*/
|
|
15
|
+
clear(): void;
|
|
16
|
+
/**
|
|
17
|
+
* 设置最大回撤步数
|
|
18
|
+
*/
|
|
19
|
+
setMaxUndoStackSize(size: number): void;
|
|
20
|
+
/**
|
|
21
|
+
* 获取当前正在进行的事务
|
|
22
|
+
*/
|
|
23
|
+
getCurrentTransaction(): ITransaction | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* 获取当前事务组
|
|
26
|
+
*/
|
|
27
|
+
getCurrentTransactionGroup(): ITransactionGroup | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* 获取最后的叶子节点事务组
|
|
30
|
+
*/
|
|
31
|
+
getLastLeafTranGroup(undoList: boolean): ITransactionGroup | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* 获取当前正在进行的事务的undoRedoEntity
|
|
34
|
+
*/
|
|
35
|
+
getCurrentUndoRedoEntity(): UndoRedoEntity;
|
|
36
|
+
/**
|
|
37
|
+
* 撤销
|
|
38
|
+
*/
|
|
39
|
+
undo(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 回退
|
|
42
|
+
*/
|
|
43
|
+
redo(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 是否可撤销
|
|
46
|
+
*/
|
|
47
|
+
canUndo(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* 是否可回退
|
|
50
|
+
*/
|
|
51
|
+
canRedo(): boolean;
|
|
52
|
+
idPoolGC(): Set<number>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=transaction_mgr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { IDocument } from '../document/i_document';
|
|
2
|
+
import { IElement } from '../element/i_element';
|
|
3
|
+
/**
|
|
4
|
+
* 记录一次undo/redo的Element变化
|
|
5
|
+
*/
|
|
6
|
+
export declare class UndoRedoEntity {
|
|
7
|
+
private _doc;
|
|
8
|
+
/**增加的元素*/
|
|
9
|
+
private readonly _added;
|
|
10
|
+
/**删除的元素*/
|
|
11
|
+
private readonly _deleted;
|
|
12
|
+
/**修改的元素*/
|
|
13
|
+
private readonly _modified;
|
|
14
|
+
/**修改的元素-属性集合映射*/
|
|
15
|
+
private readonly _modifiedProperties;
|
|
16
|
+
constructor(doc: IDocument);
|
|
17
|
+
/**监听元素增加*/
|
|
18
|
+
onElementsAdded(eles: IElement[]): void;
|
|
19
|
+
/**监听元素更新*/
|
|
20
|
+
onElementsUpdated(eles: IElement[]): void;
|
|
21
|
+
/**监听元素删除*/
|
|
22
|
+
onElementsDeleted(eles: IElement[]): void;
|
|
23
|
+
clear(): void;
|
|
24
|
+
/**
|
|
25
|
+
* 真正去改变db
|
|
26
|
+
*/
|
|
27
|
+
commit(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* 数据回滚
|
|
30
|
+
*/
|
|
31
|
+
rollBack(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* undo变redo,redo变undo
|
|
34
|
+
*/
|
|
35
|
+
reverseAndExecute(): void;
|
|
36
|
+
/**
|
|
37
|
+
* 合并其它提交
|
|
38
|
+
*/
|
|
39
|
+
merge(other: UndoRedoEntity): void;
|
|
40
|
+
/**
|
|
41
|
+
* 将操作reverse
|
|
42
|
+
*/
|
|
43
|
+
private _reverse;
|
|
44
|
+
/**
|
|
45
|
+
* 正向执行
|
|
46
|
+
*/
|
|
47
|
+
_execute(): void;
|
|
48
|
+
/**
|
|
49
|
+
* 压缩事务
|
|
50
|
+
* 主要处理例如,新增一个Element,然后更改这个Element的属性,事务管理器会记录每一个操作,这时只需要记录增加的操作即可
|
|
51
|
+
*/
|
|
52
|
+
private _compress;
|
|
53
|
+
/**是否为空*/
|
|
54
|
+
_isEmpty(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* 从容器中增删对象
|
|
57
|
+
* @param del 是否删除
|
|
58
|
+
* @param eles 对象数组
|
|
59
|
+
*/
|
|
60
|
+
private _handleElementsFromDB;
|
|
61
|
+
/**
|
|
62
|
+
* 收集使用过的id
|
|
63
|
+
*/
|
|
64
|
+
collectUsedIds(set: Set<number>): void;
|
|
65
|
+
/**
|
|
66
|
+
* 获取所有修改的ElementId集合
|
|
67
|
+
*/
|
|
68
|
+
getModifiedElementIds(): Set<number>;
|
|
69
|
+
private _updateViewCache;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=undo_redo_entity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|