mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-19 14:04:28 +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 { Selection } from './selection';
|
||||||
import { History } from './history';
|
import { History } from './history';
|
||||||
import { TransformStage, ModalNodesManager } from './node';
|
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
|
export type GetDataType<T, NodeType> = T extends undefined
|
||||||
? NodeType extends {
|
? NodeType extends {
|
||||||
@ -366,6 +366,7 @@ export class DocumentModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export(stage: TransformStage = TransformStage.Serilize) {
|
export(stage: TransformStage = TransformStage.Serilize) {
|
||||||
|
stage = compatStage(stage);
|
||||||
// 置顶只作用于 Page 的第一级子节点,目前还用不到里层的置顶;如果后面有需要可以考虑将这段写到 node-children 中的 export
|
// 置顶只作用于 Page 的第一级子节点,目前还用不到里层的置顶;如果后面有需要可以考虑将这段写到 node-children 中的 export
|
||||||
const currentSchema = this.rootNode?.export(stage);
|
const currentSchema = this.rootNode?.export(stage);
|
||||||
if (Array.isArray(currentSchema?.children) && currentSchema?.children.length > 0) {
|
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 { Node, ParentalNode } from './node';
|
||||||
import { TransformStage } from './transform-stage';
|
import { TransformStage } from './transform-stage';
|
||||||
import { NodeData, isNodeSchema } from '@ali/lowcode-types';
|
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 { EventEmitter } from 'events';
|
||||||
import { foreachReverse } from '../../utils/tree';
|
import { foreachReverse } from '../../utils/tree';
|
||||||
import { NodeRemoveOptions } from '../../types';
|
import { NodeRemoveOptions } from '../../types';
|
||||||
@ -26,6 +26,7 @@ export class NodeChildren {
|
|||||||
* 导出 schema
|
* 导出 schema
|
||||||
*/
|
*/
|
||||||
export(stage: TransformStage = TransformStage.Save): NodeData[] {
|
export(stage: TransformStage = TransformStage.Save): NodeData[] {
|
||||||
|
stage = compatStage(stage);
|
||||||
return this.children.map(node => {
|
return this.children.map(node => {
|
||||||
const data = node.export(stage);
|
const data = node.export(stage);
|
||||||
if (node.isLeaf() && TransformStage.Save === stage) {
|
if (node.isLeaf() && TransformStage.Save === stage) {
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import {
|
|||||||
ComponentSchema,
|
ComponentSchema,
|
||||||
NodeStatus,
|
NodeStatus,
|
||||||
} from '@ali/lowcode-types';
|
} from '@ali/lowcode-types';
|
||||||
|
import { compatStage } from '@ali/lowcode-utils';
|
||||||
import { Props, getConvertedExtraKey } from './props/props';
|
import { Props, getConvertedExtraKey } from './props/props';
|
||||||
import { DocumentModel } from '../document-model';
|
import { DocumentModel } from '../document-model';
|
||||||
import { NodeChildren } from './node-children';
|
import { NodeChildren } from './node-children';
|
||||||
@ -635,6 +636,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
* 导出 schema
|
* 导出 schema
|
||||||
*/
|
*/
|
||||||
export(stage: TransformStage = TransformStage.Save, options: any = {}): Schema {
|
export(stage: TransformStage = TransformStage.Save, options: any = {}): Schema {
|
||||||
|
stage = compatStage(stage);
|
||||||
const baseSchema: any = {
|
const baseSchema: any = {
|
||||||
componentName: this.componentName,
|
componentName: this.componentName,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { untracked, computed, obx, engineConfig } from '@ali/lowcode-editor-core';
|
import { untracked, computed, obx, engineConfig } from '@ali/lowcode-editor-core';
|
||||||
import { CompositeValue, isJSExpression, isJSSlot, JSSlot, SlotSchema } from '@ali/lowcode-types';
|
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 { PropStash } from './prop-stash';
|
||||||
import { valueToSource } from './value-to-source';
|
import { valueToSource } from './value-to-source';
|
||||||
import { Props } from './props';
|
import { Props } from './props';
|
||||||
@ -98,6 +98,7 @@ export class Prop implements IPropParent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export(stage: TransformStage = TransformStage.Save): CompositeValue | UNSET {
|
export(stage: TransformStage = TransformStage.Save): CompositeValue | UNSET {
|
||||||
|
stage = compatStage(stage);
|
||||||
const type = this._type;
|
const type = this._type;
|
||||||
if (stage === TransformStage.Render && this.key === '___condition___') {
|
if (stage === TransformStage.Render && this.key === '___condition___') {
|
||||||
// 在设计器里,所有组件默认需要展示,除非开启了 enableCondition 配置
|
// 在设计器里,所有组件默认需要展示,除非开启了 enableCondition 配置
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { computed, obx } from '@ali/lowcode-editor-core';
|
import { computed, obx } from '@ali/lowcode-editor-core';
|
||||||
import { PropsMap, PropsList, CompositeValue } from '@ali/lowcode-types';
|
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 { PropStash } from './prop-stash';
|
||||||
import { Prop, IPropParent, UNSET } from './prop';
|
import { Prop, IPropParent, UNSET } from './prop';
|
||||||
import { Node } from '../node';
|
import { Node } from '../node';
|
||||||
@ -97,6 +97,7 @@ export class Props implements IPropParent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export(stage: TransformStage = TransformStage.Save): { props?: PropsMap | PropsList; extras?: object } {
|
export(stage: TransformStage = TransformStage.Save): { props?: PropsMap | PropsList; extras?: object } {
|
||||||
|
stage = compatStage(stage);
|
||||||
if (this.items.length < 1) {
|
if (this.items.length < 1) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ export {
|
|||||||
ILowCodePluginContext,
|
ILowCodePluginContext,
|
||||||
IDesignerCabin,
|
IDesignerCabin,
|
||||||
BuiltinSimulatorHost,
|
BuiltinSimulatorHost,
|
||||||
|
TransformStage,
|
||||||
} from '@ali/lowcode-designer';
|
} from '@ali/lowcode-designer';
|
||||||
|
|
||||||
// 这样做的目的是为了去除 Node / DocumentModel 等的值属性,仅保留类型属性
|
// 这样做的目的是为了去除 Node / DocumentModel 等的值属性,仅保留类型属性
|
||||||
|
|||||||
@ -112,7 +112,7 @@ export class DocumentInstance {
|
|||||||
constructor(readonly container: SimulatorRendererContainer, readonly document: DocumentModel) {
|
constructor(readonly container: SimulatorRendererContainer, readonly document: DocumentModel) {
|
||||||
this.dispose = host.autorun(() => {
|
this.dispose = host.autorun(() => {
|
||||||
// sync schema
|
// sync schema
|
||||||
this._schema = document.export(1);
|
this._schema = document.export(TransformStage.Render);
|
||||||
this.emitter.emit('rerender');
|
this.emitter.emit('rerender');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
export enum TransformStage {
|
export enum TransformStage {
|
||||||
Render = 1,
|
Render = 'render',
|
||||||
Serilize = 2,
|
Serilize = 'serilize',
|
||||||
Save = 3,
|
Save = 'save',
|
||||||
Clone = 4,
|
Clone = 'clone',
|
||||||
Init = 5,
|
Init = 'init',
|
||||||
Upgrade = 6,
|
Upgrade = 'upgrade',
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
import { isI18NObject } from './is-object';
|
import { isI18NObject } from './is-object';
|
||||||
import get from 'lodash.get';
|
import get from 'lodash.get';
|
||||||
import { ComponentMeta } from '@ali/lowcode-designer';
|
import { ComponentMeta } from '@ali/lowcode-designer';
|
||||||
|
import { TransformStage } from '@ali/lowcode-types';
|
||||||
interface Variable {
|
interface Variable {
|
||||||
type: 'variable';
|
type: 'variable';
|
||||||
variable: string;
|
variable: string;
|
||||||
@ -71,3 +72,24 @@ export function arrShallowEquals(arr1: any[], arr2: any[]): boolean {
|
|||||||
export function executePendingFn(fn: () => void, timeout: number = 2000) {
|
export function executePendingFn(fn: () => void, timeout: number = 2000) {
|
||||||
return setTimeout(fn, timeout);
|
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