forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhistory.ts
More file actions
81 lines (70 loc) · 1.7 KB
/
history.ts
File metadata and controls
81 lines (70 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import type {
IDocumentModel as InnerDocumentModel,
IHistory as InnerHistory,
} from '@felce/lowcode-designer';
import { historySymbol, documentSymbol } from '../symbols';
import { IPublicModelHistory, IPublicTypeDisposable } from '@felce/lowcode-types';
export class History implements IPublicModelHistory {
private readonly [documentSymbol]: InnerDocumentModel;
private get [historySymbol](): InnerHistory {
return this[documentSymbol].getHistory();
}
constructor(document: InnerDocumentModel) {
this[documentSymbol] = document;
}
/**
* 历史记录跳转到指定位置
* @param cursor
*/
go(cursor: number): void {
this[historySymbol].go(cursor);
}
/**
* 历史记录后退
*/
back(): void {
this[historySymbol].back();
}
/**
* 历史记录前进
*/
forward(): void {
this[historySymbol].forward();
}
/**
* 保存当前状态
*/
savePoint(): void {
this[historySymbol].savePoint();
}
/**
* 当前是否是「保存点」,即是否有状态变更但未保存
* @returns
*/
isSavePoint(): boolean {
return this[historySymbol].isSavePoint();
}
/**
* 获取 state,判断当前是否为「可回退」、「可前进」的状态
* @returns
*/
getState(): number {
return this[historySymbol].getState();
}
/**
* 监听 state 变更事件
* @param func
* @returns
*/
onChangeState(func: () => any): IPublicTypeDisposable {
return this[historySymbol].onChangeState(func);
}
/**
* 监听历史记录游标位置变更事件
* @param func
* @returns
*/
onChangeCursor(func: () => any): IPublicTypeDisposable {
return this[historySymbol].onChangeCursor(func);
}
}