diff --git a/packages/designer/src/builtin-simulator/host.ts b/packages/designer/src/builtin-simulator/host.ts index 99a715305..d12427074 100644 --- a/packages/designer/src/builtin-simulator/host.ts +++ b/packages/designer/src/builtin-simulator/host.ts @@ -203,12 +203,9 @@ export class BuiltinSimulatorHost implements ISimulatorHost { - this.project.currentDocument?.history?.sleep(); this.stopAutoRepaintNode(); }, TransitionType.REPAINT); transactionManager.onEndTransaction(() => { - this.project.currentDocument?.history?.wakeup(); - this.project.currentDocument?.history?.savePoint(); this.rerender(); this.enableAutoRepaintNode(); }, TransitionType.REPAINT); diff --git a/packages/designer/src/document/history.ts b/packages/designer/src/document/history.ts index 113a677c7..3f9cb9ba4 100644 --- a/packages/designer/src/document/history.ts +++ b/packages/designer/src/document/history.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import { autorun, reaction, mobx, untracked, globalContext, Editor } from '@alilc/lowcode-editor-core'; +import { reaction, untracked, globalContext, Editor } from '@alilc/lowcode-editor-core'; import { NodeSchema } from '@alilc/lowcode-types'; import { History as ShellHistory } from '@alilc/lowcode-shell'; @@ -40,24 +40,22 @@ export class History { if (this.asleep) return null; return dataFn(); }, (data: T) => { - if (this.asleep) return; untracked(() => { const log = this.currentSerialization.serialize(data); - if (this.session.isActive()) { - this.session.log(log); - } else { - this.session.end(); - const lastState = this.getState(); - const cursor = this.session.cursor + 1; - const session = new Session(cursor, log, this.timeGap); - this.session = session; - this.records.splice(cursor, this.records.length - cursor, session); - const currentState = this.getState(); - if (currentState !== lastState) { - this.emitter.emit('statechange', currentState); - } + if (this.session.isActive()) { + this.session.log(log); + } else { + this.session.end(); + const lastState = this.getState(); + const cursor = this.session.cursor + 1; + const session = new Session(cursor, log, this.timeGap); + this.session = session; + this.records.splice(cursor, this.records.length - cursor, session); + const currentState = this.getState(); + if (currentState !== lastState) { + this.emitter.emit('statechange', currentState); } - // } + } }); }, { fireImmediately: true }); } diff --git a/packages/renderer-core/src/hoc/leaf.tsx b/packages/renderer-core/src/hoc/leaf.tsx index e8bf01154..0dfb2d9a0 100644 --- a/packages/renderer-core/src/hoc/leaf.tsx +++ b/packages/renderer-core/src/hoc/leaf.tsx @@ -229,11 +229,11 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { this.recordTime(); } - get defaultState() { + getDefaultState(nextProps: any) { const { hidden = false, condition = true, - } = this.leaf?.export?.(TransformStage.Render) || {}; + } = nextProps.__inner__ || {}; return { nodeChildren: null, childrenInState: false, @@ -257,7 +257,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { let cacheState = cache.state.get(componentCacheId); if (!cacheState || cacheState.__tag !== props.__tag) { - cacheState = this.defaultState; + cacheState = this.getDefaultState(props); } this.state = cacheState; @@ -393,7 +393,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { const { visible, ...resetState - } = this.defaultState; + } = this.getDefaultState(nextProps); this.setState(resetState); } @@ -562,6 +562,8 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { ref: forwardedRef, }; + delete compProps.__inner__; + return engine.createElement(Comp, compProps, this.hasChildren ? this.children : null); } } diff --git a/packages/renderer-core/src/renderer/base.tsx b/packages/renderer-core/src/renderer/base.tsx index 2d58cac76..d64ff4196 100644 --- a/packages/renderer-core/src/renderer/base.tsx +++ b/packages/renderer-core/src/renderer/base.tsx @@ -670,7 +670,14 @@ export default function baseRendererFactory(): IBaseRenderComponent { } } } - return renderComp({ ...props, ...otherProps }); + return renderComp({ + ...props, + ...otherProps, + __inner__: { + hidden: schema.hidden, + condition, + }, + }); } catch (e) { return engine.createElement(engine.getFaultComponent(), { error: e, diff --git a/packages/utils/src/start-transaction.ts b/packages/utils/src/start-transaction.ts index 330012528..8c7c0db3e 100644 --- a/packages/utils/src/start-transaction.ts +++ b/packages/utils/src/start-transaction.ts @@ -1,4 +1,5 @@ import { TransitionType } from '@alilc/lowcode-types'; +import { transaction } from 'mobx'; import EventEmitter from 'events'; class TransactionManager { @@ -6,7 +7,7 @@ class TransactionManager { startTransaction = (fn: () => void, type: TransitionType = TransitionType.REPAINT): void => { this.emitter.emit(`[${type}]startTransaction`); - fn(); + transaction(fn); this.emitter.emit(`[${type}]endTransaction`); };