mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-05 17:57:13 +00:00
fix: 增加 onChangeDocument 的补偿机制
This commit is contained in:
parent
eca95b288f
commit
7d7615cdce
@ -1,6 +1,7 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { autorun, reaction, mobx, untracked, globalContext, Editor } from '@ali/lowcode-editor-core';
|
||||
import { NodeSchema } from '@ali/lowcode-types';
|
||||
import { History as ShellHistory } from '@ali/lowcode-shell';
|
||||
|
||||
// TODO: cache to localStorage
|
||||
|
||||
@ -100,7 +101,7 @@ export class History {
|
||||
this.redoer(currentSerialization.unserialize(hotData));
|
||||
this.emitter.emit('cursor', hotData);
|
||||
} catch (e) {
|
||||
//
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
this.wakeup();
|
||||
@ -194,6 +195,10 @@ export class History {
|
||||
isModified() {
|
||||
return this.isSavePoint();
|
||||
}
|
||||
|
||||
internalToShellHistory() {
|
||||
return new ShellHistory(this);
|
||||
}
|
||||
}
|
||||
|
||||
class Session {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
export {
|
||||
Title,
|
||||
Tip,
|
||||
shallowIntl,
|
||||
createIntl,
|
||||
createSetterContent,
|
||||
|
||||
@ -42,7 +42,7 @@ export default class DocumentModel {
|
||||
this[editorSymbol] = document.designer.editor as Editor;
|
||||
this.selection = new Selection(document);
|
||||
this.detecting = new Detecting(document);
|
||||
this.history = new History(document);
|
||||
this.history = new History(document.getHistory());
|
||||
this.canvas = new Canvas(document.designer);
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,10 @@ export default class Event {
|
||||
}
|
||||
|
||||
on(event: string, listener: (...args: unknown[]) => void) {
|
||||
if (event.startsWith('designer')) {
|
||||
logger.warn('designer events are disabled');
|
||||
return;
|
||||
}
|
||||
this[editorSymbol].on(event, listener);
|
||||
}
|
||||
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
import { History as InnerHistory, DocumentModel as InnerDocumentModel } from '@ali/lowcode-designer';
|
||||
import { documentSymbol, historySymbol } from './symbols';
|
||||
import { historySymbol } from './symbols';
|
||||
|
||||
export default class History {
|
||||
private readonly [documentSymbol]: InnerDocumentModel;
|
||||
private readonly [historySymbol]: InnerHistory;
|
||||
|
||||
constructor(document: InnerDocumentModel) {
|
||||
this[documentSymbol] = document;
|
||||
this[historySymbol] = this[documentSymbol].getHistory();
|
||||
constructor(history: InnerHistory) {
|
||||
this[historySymbol] = history;
|
||||
}
|
||||
|
||||
go(cursor: number) {
|
||||
|
||||
@ -117,7 +117,10 @@ export default class Project {
|
||||
* 当前 project 内的 document 变更事件
|
||||
*/
|
||||
onChangeDocument(fn: (doc: DocumentModel) => void) {
|
||||
// TODO: 思考一下是否要实现补偿触发能力
|
||||
if (this[projectSymbol].currentDocument) {
|
||||
fn(DocumentModel.create(this[projectSymbol].currentDocument)!);
|
||||
return () => {};
|
||||
}
|
||||
return this[projectSymbol].onCurrentDocumentChange((originalDoc) => {
|
||||
fn(DocumentModel.create(originalDoc)!);
|
||||
});
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
module.exports = {
|
||||
eslintType: 'typescript/react',
|
||||
enableStylelint: false,
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user