Merge branch feat/autoRepaintNode into release/1.0.16-beta

This commit is contained in:
liujuping 2022-11-02 19:47:03 +08:00
commit fe5b848044
10 changed files with 93 additions and 5 deletions

View File

@ -36,6 +36,7 @@ import {
hasOwnProperty, hasOwnProperty,
UtilsMetadata, UtilsMetadata,
getClosestNode, getClosestNode,
transactionManage,
} from '@alilc/lowcode-utils'; } from '@alilc/lowcode-utils';
import { import {
DragObjectType, DragObjectType,
@ -59,9 +60,8 @@ import { getClosestClickableNode } from './utils/clickable';
import { import {
ComponentMetadata, ComponentMetadata,
ComponentSchema, ComponentSchema,
TransformStage,
ActivityData,
Package, Package,
TransitionType,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { BuiltinSimulatorRenderer } from './renderer'; import { BuiltinSimulatorRenderer } from './renderer';
import clipboard from '../designer/clipboard'; import clipboard from '../designer/clipboard';
@ -181,6 +181,14 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
*/ */
autoRender = true; autoRender = true;
stopAutoRepaintNode() {
this.renderer?.stopAutoRepaintNode();
}
enableAutoRepaintNode() {
this.renderer?.enableAutoRepaintNode();
}
constructor(project: Project) { constructor(project: Project) {
makeObservable(this); makeObservable(this);
this.project = project; this.project = project;
@ -194,6 +202,11 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
i18n: this.project.i18n, i18n: this.project.i18n,
}; };
}); });
transactionManage.onStartTransaction(this.stopAutoRepaintNode, TransitionType.repaint);
transactionManage.onEndTransaction(() => {
this.rerender();
this.enableAutoRepaintNode();
}, TransitionType.repaint);
} }
get currentDocument() { get currentDocument() {

View File

@ -13,6 +13,8 @@ export interface BuiltinSimulatorRenderer {
setCopyState(state: boolean): void; setCopyState(state: boolean): void;
loadAsyncLibrary(asyncMap: { [index: string]: any }): void; loadAsyncLibrary(asyncMap: { [index: string]: any }): void;
clearState(): void; clearState(): void;
stopAutoRepaintNode(): void;
enableAutoRepaintNode(): void;
run(): void; run(): void;
} }

View File

@ -1,6 +1,6 @@
import { isFormEvent, compatibleLegaoSchema, getNodeSchemaById } from '@alilc/lowcode-utils'; import { isFormEvent, compatibleLegaoSchema, getNodeSchemaById, transactionManage } from '@alilc/lowcode-utils';
import { isNodeSchema } from '@alilc/lowcode-types'; import { isNodeSchema } from '@alilc/lowcode-types';
import { getConvertedExtraKey, getOriginalExtraKey, isNode, isSettingField } from '@alilc/lowcode-designer'; import { getConvertedExtraKey, getOriginalExtraKey } from '@alilc/lowcode-designer';
const utils = { const utils = {
isNodeSchema, isNodeSchema,
@ -9,6 +9,7 @@ const utils = {
getNodeSchemaById, getNodeSchemaById,
getConvertedExtraKey, getConvertedExtraKey,
getOriginalExtraKey, getOriginalExtraKey,
startTransaction: transactionManage.startTransaction,
}; };
export default utils; export default utils;

View File

@ -349,6 +349,11 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
* *
*/ */
autoRender = true; autoRender = true;
/**
*
*/
autoRepaintNode = true;
/** /**
* *
*/ */
@ -491,6 +496,14 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
this._appContext = { ...this._appContext }; this._appContext = { ...this._appContext };
} }
stopAutoRepaintNode() {
this.autoRepaintNode = false;
}
enableAutoRepaintNode() {
this.autoRepaintNode = true;
}
dispose() { dispose() {
this.disposeFunctions.forEach(fn => fn()); this.disposeFunctions.forEach(fn => fn());
this.documentInstances.forEach(docInst => docInst.dispose()); this.documentInstances.forEach(docInst => docInst.dispose());

View File

@ -102,14 +102,23 @@ function initRerenderEvent({
leaf, leaf,
dispose: [ dispose: [
leaf?.onPropChange?.(() => { leaf?.onPropChange?.(() => {
if (!container.autoRepaintNode) {
return;
}
__debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onPropsChange make rerender`); __debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onPropsChange make rerender`);
container.rerender(); container.rerender();
}), }),
leaf?.onChildrenChange?.(() => { leaf?.onChildrenChange?.(() => {
if (!container.autoRepaintNode) {
return;
}
__debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onChildrenChange make rerender`); __debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onChildrenChange make rerender`);
container.rerender(); container.rerender();
}) as Function, }) as Function,
leaf?.onVisibleChange?.(() => { leaf?.onVisibleChange?.(() => {
if (!container.autoRepaintNode) {
return;
}
__debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onVisibleChange make rerender`); __debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onVisibleChange make rerender`);
container.rerender(); container.rerender();
}), }),
@ -279,6 +288,10 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
singleRender?: boolean; singleRender?: boolean;
}; };
get autoRepaintNode() {
return container.autoRepaintNode;
}
judgeMiniUnitRender() { judgeMiniUnitRender() {
if (!this.renderUnitInfo) { if (!this.renderUnitInfo) {
this.getRenderUnitInfo(); this.getRenderUnitInfo();
@ -387,6 +400,9 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
/** 监听参数变化 */ /** 监听参数变化 */
initOnPropsChangeEvent(leaf = this.leaf): void { initOnPropsChangeEvent(leaf = this.leaf): void {
const dispose = leaf?.onPropChange?.(debounce((propChangeInfo: PropChangeOptions) => { const dispose = leaf?.onPropChange?.(debounce((propChangeInfo: PropChangeOptions) => {
if (!this.autoRepaintNode) {
return;
}
const { const {
key, key,
newValue = null, newValue = null,
@ -443,6 +459,9 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
*/ */
initOnVisibleChangeEvent(leaf = this.leaf) { initOnVisibleChangeEvent(leaf = this.leaf) {
const dispose = leaf?.onVisibleChange?.((flag: boolean) => { const dispose = leaf?.onVisibleChange?.((flag: boolean) => {
if (!this.autoRepaintNode) {
return;
}
if (this.state.visible === flag) { if (this.state.visible === flag) {
return; return;
} }
@ -463,6 +482,9 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
*/ */
initOnChildrenChangeEvent(leaf = this.leaf) { initOnChildrenChangeEvent(leaf = this.leaf) {
const dispose = leaf?.onChildrenChange?.((param): void => { const dispose = leaf?.onChildrenChange?.((param): void => {
if (!this.autoRepaintNode) {
return;
}
const { const {
type, type,
node, node,

View File

@ -35,7 +35,8 @@ const baseRenderer: any = {
__container: { __container: {
rerender: () => { rerender: () => {
rerenderCount = 1 + rerenderCount; rerenderCount = 1 + rerenderCount;
} },
autoRepaintNode: true,
}, },
documentId: '01' documentId: '01'
}, },

View File

@ -21,3 +21,4 @@ export * from './code-result';
export * from './assets'; export * from './assets';
export * as GlobalEvent from './event'; export * as GlobalEvent from './event';
export * from './disposable'; export * from './disposable';
export * from './start-transaction';

View File

@ -0,0 +1,4 @@
export enum TransitionType {
/** 节点更新后重绘处理 */
repaint
}

View File

@ -26,3 +26,4 @@ export * from './node-helper';
export * from './clone-enumerable-property'; export * from './clone-enumerable-property';
export * from './logger'; export * from './logger';
export * as css from './css-helper'; export * as css from './css-helper';
export { transactionManage } from './start-transaction';

View File

@ -0,0 +1,30 @@
import { TransitionType } from '@alilc/lowcode-types';
import EventEmitter from 'events';
class TransactionManage {
emitter = new EventEmitter();
startTransaction(fn: () => void, type: TransitionType = TransitionType.repaint): void {
this.emitter.emit(`[${type}]startTransaction`);
fn();
this.emitter.emit(`[${type}]endTransaction`);
}
onStartTransaction(fn: () => void, type: TransitionType = TransitionType.repaint): () => void {
this.emitter.on(`[${type}]startTransaction`, fn);
return () => {
this.emitter.off(`[${type}]startTransaction`, fn);
};
}
onEndTransaction(fn: () => void, type: TransitionType = TransitionType.repaint): () => void {
this.emitter.on(`[${type}]endTransaction`, fn);
return () => {
this.emitter.off(`[${type}]endTransaction`, fn);
};
}
}
export const transactionManage = new TransactionManage();
export default transactionManage;