mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-12 17:08:14 +00:00
refactor: 修改 TransformStage 为字符串实现
This commit is contained in:
parent
87a1c74420
commit
a10e1e4d2a
@ -9,7 +9,7 @@ import { Node, insertChildren, insertChild, isNode, RootNode, ParentalNode } fro
|
||||
import { Selection } from './selection';
|
||||
import { History } from './history';
|
||||
import { TransformStage, ModalNodesManager } from './node';
|
||||
import { uniqueId, isPlainObject } from '@ali/lowcode-utils';
|
||||
import { uniqueId, isPlainObject, compatStage } from '@ali/lowcode-utils';
|
||||
|
||||
export type GetDataType<T, NodeType> = T extends undefined
|
||||
? NodeType extends {
|
||||
@ -366,6 +366,7 @@ export class DocumentModel {
|
||||
}
|
||||
|
||||
export(stage: TransformStage = TransformStage.Serilize) {
|
||||
stage = compatStage(stage);
|
||||
// 置顶只作用于 Page 的第一级子节点,目前还用不到里层的置顶;如果后面有需要可以考虑将这段写到 node-children 中的 export
|
||||
const currentSchema = this.rootNode?.export(stage);
|
||||
if (Array.isArray(currentSchema?.children) && currentSchema?.children.length > 0) {
|
||||
|
||||
@ -2,7 +2,7 @@ import { obx, computed, globalContext } from '@ali/lowcode-editor-core';
|
||||
import { Node, ParentalNode } from './node';
|
||||
import { TransformStage } from './transform-stage';
|
||||
import { NodeData, isNodeSchema } from '@ali/lowcode-types';
|
||||
import { shallowEqual } from '@ali/lowcode-utils';
|
||||
import { shallowEqual, compatStage } from '@ali/lowcode-utils';
|
||||
import { EventEmitter } from 'events';
|
||||
import { foreachReverse } from '../../utils/tree';
|
||||
import { NodeRemoveOptions } from '../../types';
|
||||
@ -26,6 +26,7 @@ export class NodeChildren {
|
||||
* 导出 schema
|
||||
*/
|
||||
export(stage: TransformStage = TransformStage.Save): NodeData[] {
|
||||
stage = compatStage(stage);
|
||||
return this.children.map(node => {
|
||||
const data = node.export(stage);
|
||||
if (node.isLeaf() && TransformStage.Save === stage) {
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
ComponentSchema,
|
||||
NodeStatus,
|
||||
} from '@ali/lowcode-types';
|
||||
import { compatStage } from '@ali/lowcode-utils';
|
||||
import { Props, getConvertedExtraKey } from './props/props';
|
||||
import { DocumentModel } from '../document-model';
|
||||
import { NodeChildren } from './node-children';
|
||||
@ -635,6 +636,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
* 导出 schema
|
||||
*/
|
||||
export(stage: TransformStage = TransformStage.Save, options: any = {}): Schema {
|
||||
stage = compatStage(stage);
|
||||
const baseSchema: any = {
|
||||
componentName: this.componentName,
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { untracked, computed, obx, engineConfig } from '@ali/lowcode-editor-core';
|
||||
import { CompositeValue, isJSExpression, isJSSlot, JSSlot, SlotSchema } from '@ali/lowcode-types';
|
||||
import { uniqueId, isPlainObject, hasOwnProperty } from '@ali/lowcode-utils';
|
||||
import { uniqueId, isPlainObject, hasOwnProperty, compatStage } from '@ali/lowcode-utils';
|
||||
import { PropStash } from './prop-stash';
|
||||
import { valueToSource } from './value-to-source';
|
||||
import { Props } from './props';
|
||||
@ -98,6 +98,7 @@ export class Prop implements IPropParent {
|
||||
}
|
||||
|
||||
export(stage: TransformStage = TransformStage.Save): CompositeValue | UNSET {
|
||||
stage = compatStage(stage);
|
||||
const type = this._type;
|
||||
if (stage === TransformStage.Render && this.key === '___condition___') {
|
||||
// 在设计器里,所有组件默认需要展示,除非开启了 enableCondition 配置
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { computed, obx } from '@ali/lowcode-editor-core';
|
||||
import { PropsMap, PropsList, CompositeValue } from '@ali/lowcode-types';
|
||||
import { uniqueId } from '@ali/lowcode-utils';
|
||||
import { uniqueId, compatStage } from '@ali/lowcode-utils';
|
||||
import { PropStash } from './prop-stash';
|
||||
import { Prop, IPropParent, UNSET } from './prop';
|
||||
import { Node } from '../node';
|
||||
@ -97,6 +97,7 @@ export class Props implements IPropParent {
|
||||
}
|
||||
|
||||
export(stage: TransformStage = TransformStage.Save): { props?: PropsMap | PropsList; extras?: object } {
|
||||
stage = compatStage(stage);
|
||||
if (this.items.length < 1) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ export {
|
||||
ILowCodePluginContext,
|
||||
IDesignerCabin,
|
||||
BuiltinSimulatorHost,
|
||||
TransformStage,
|
||||
} from '@ali/lowcode-designer';
|
||||
|
||||
// 这样做的目的是为了去除 Node / DocumentModel 等的值属性,仅保留类型属性
|
||||
|
||||
@ -112,7 +112,7 @@ export class DocumentInstance {
|
||||
constructor(readonly container: SimulatorRendererContainer, readonly document: DocumentModel) {
|
||||
this.dispose = host.autorun(() => {
|
||||
// sync schema
|
||||
this._schema = document.export(1);
|
||||
this._schema = document.export(TransformStage.Render);
|
||||
this.emitter.emit('rerender');
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
export enum TransformStage {
|
||||
Render = 1,
|
||||
Serilize = 2,
|
||||
Save = 3,
|
||||
Clone = 4,
|
||||
Init = 5,
|
||||
Upgrade = 6,
|
||||
Render = 'render',
|
||||
Serilize = 'serilize',
|
||||
Save = 'save',
|
||||
Clone = 'clone',
|
||||
Init = 'init',
|
||||
Upgrade = 'upgrade',
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
import { isI18NObject } from './is-object';
|
||||
import get from 'lodash.get';
|
||||
import { ComponentMeta } from '@ali/lowcode-designer';
|
||||
import { TransformStage } from '@ali/lowcode-types';
|
||||
interface Variable {
|
||||
type: 'variable';
|
||||
variable: string;
|
||||
@ -70,4 +71,25 @@ export function arrShallowEquals(arr1: any[], arr2: any[]): boolean {
|
||||
|
||||
export function executePendingFn(fn: () => void, timeout: number = 2000) {
|
||||
return setTimeout(fn, timeout);
|
||||
}
|
||||
|
||||
const stageList = [
|
||||
'render',
|
||||
'serilize',
|
||||
'save',
|
||||
'clone',
|
||||
'init',
|
||||
'upgrade',
|
||||
];
|
||||
/**
|
||||
* 兼容原来的数字版本的枚举对象
|
||||
* @param stage
|
||||
* @returns
|
||||
*/
|
||||
export function compatStage(stage: TransformStage | number): TransformStage {
|
||||
if (typeof stage === 'number') {
|
||||
console.warn('stage 直接指定为数字的使用方式已经过时,将在下一版本移除,请直接使用 TransformStage.Render|Serilize|Save|Clone|Init|Upgrade');
|
||||
return stageList[stage - 1] as TransformStage;
|
||||
}
|
||||
return stage as TransformStage;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user