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