mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
feat: update idraw undo/redo return
This commit is contained in:
parent
b70eebcdc0
commit
b67077d6cb
2 changed files with 29 additions and 9 deletions
|
|
@ -172,13 +172,15 @@ class Core {
|
|||
if (this[_hasInitedData] === true) {
|
||||
return;
|
||||
}
|
||||
this.setData(data);
|
||||
this[_emitChangeData]();
|
||||
this.setData(data, { triggerChangeEvent: true });
|
||||
this[_hasInitedData] = true;
|
||||
}
|
||||
|
||||
setData(data: any | TypeData): void {
|
||||
setData(data: any | TypeData, opts?: { triggerChangeEvent: boolean }): void {
|
||||
this[_data] = this[_element].initData(deepClone(parseData(data)));
|
||||
if (opts && opts.triggerChangeEvent === true) {
|
||||
this[_emitChangeData]();
|
||||
}
|
||||
this.draw();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,9 +43,15 @@ class IDraw extends Core {
|
|||
this[_initEvent]();
|
||||
}
|
||||
|
||||
undo() {
|
||||
undo(): {
|
||||
doRecordCount: number,
|
||||
data: TypeData | null,
|
||||
} {
|
||||
if (!(this[_doRecords].length > 1)) {
|
||||
return this[_doRecords].length;
|
||||
return {
|
||||
doRecordCount: this[_doRecords].length,
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
const popRecord = this[_doRecords].pop();
|
||||
if (popRecord) {
|
||||
|
|
@ -56,19 +62,31 @@ class IDraw extends Core {
|
|||
this.setData(record.data);
|
||||
this.draw();
|
||||
}
|
||||
return this[_doRecords].length;
|
||||
return {
|
||||
doRecordCount: this[_doRecords].length,
|
||||
data: record?.data || null,
|
||||
};
|
||||
}
|
||||
|
||||
redo() {
|
||||
redo(): {
|
||||
undoRecordCount: number,
|
||||
data: TypeData | null,
|
||||
} {
|
||||
if (!(this[_unDoRecords].length > 0)) {
|
||||
return this[_unDoRecords].length;
|
||||
return {
|
||||
undoRecordCount: this[_unDoRecords].length,
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
const record = this[_unDoRecords].pop();
|
||||
if (record?.data) {
|
||||
this.setData(record.data);
|
||||
this.draw();
|
||||
}
|
||||
return this[_unDoRecords].length;
|
||||
return {
|
||||
undoRecordCount: this[_unDoRecords].length,
|
||||
data: record?.data || null,
|
||||
};
|
||||
}
|
||||
|
||||
private [_initEvent]() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue