mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-02-28 12:50:38 +00:00
refactor: 重构判断是否是 simulator 环境的逻辑
fix: 支持 NodeChildren#find 函数
This commit is contained in:
parent
66c21c07be
commit
795a4e6a69
@ -87,7 +87,7 @@ const defaultRaxSimulatorUrl = (() => {
|
|||||||
|
|
||||||
const defaultEnvironment = [
|
const defaultEnvironment = [
|
||||||
// https://g.alicdn.com/mylib/??react/16.11.0/umd/react.production.min.js,react-dom/16.8.6/umd/react-dom.production.min.js,prop-types/15.7.2/prop-types.min.js
|
// https://g.alicdn.com/mylib/??react/16.11.0/umd/react.production.min.js,react-dom/16.8.6/umd/react-dom.production.min.js,prop-types/15.7.2/prop-types.min.js
|
||||||
assetItem(AssetType.JSText, 'window.React=parent.React;window.ReactDOM=parent.ReactDOM;', undefined, 'react'),
|
assetItem(AssetType.JSText, 'window.React=parent.React;window.ReactDOM=parent.ReactDOM;window.__is_simulator_env__=true;', undefined, 'react'),
|
||||||
assetItem(
|
assetItem(
|
||||||
AssetType.JSText,
|
AssetType.JSText,
|
||||||
'window.PropTypes=parent.PropTypes;React.PropTypes=parent.PropTypes; window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__;',
|
'window.PropTypes=parent.PropTypes;React.PropTypes=parent.PropTypes; window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__;',
|
||||||
@ -877,7 +877,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
|||||||
if (nodes && (!operationalNodes || operationalNodes.length === 0)) {
|
if (nodes && (!operationalNodes || operationalNodes.length === 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sensing = true;
|
this.sensing = true;
|
||||||
this.scroller.scrolling(e);
|
this.scroller.scrolling(e);
|
||||||
const dropContainer = this.getDropContainer(e);
|
const dropContainer = this.getDropContainer(e);
|
||||||
|
|||||||
@ -13,6 +13,7 @@ export class NodeChildren {
|
|||||||
this.children = (Array.isArray(data) ? data : [data]).map(child => {
|
this.children = (Array.isArray(data) ? data : [data]).map(child => {
|
||||||
return this.owner.document.createNode(child);
|
return this.owner.document.createNode(child);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interalInitParent() {
|
interalInitParent() {
|
||||||
@ -63,7 +64,7 @@ export class NodeChildren {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* @param nodes
|
* @param nodes
|
||||||
*/
|
*/
|
||||||
concat(nodes: Node[]) {
|
concat(nodes: Node[]) {
|
||||||
return this.children.concat(nodes);
|
return this.children.concat(nodes);
|
||||||
@ -235,7 +236,6 @@ export class NodeChildren {
|
|||||||
return fn(child, index);
|
return fn(child, index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
every(fn: (item: Node, index: number) => any): boolean {
|
every(fn: (item: Node, index: number) => any): boolean {
|
||||||
return this.children.every((child, index) => fn(child, index));
|
return this.children.every((child, index) => fn(child, index));
|
||||||
}
|
}
|
||||||
@ -248,6 +248,10 @@ export class NodeChildren {
|
|||||||
return this.children.filter(fn);
|
return this.children.filter(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
find(fn: (item: Node, index: number) => Node) {
|
||||||
|
return this.children.find(fn);
|
||||||
|
}
|
||||||
|
|
||||||
mergeChildren(remover: () => any, adder: (children: Node[]) => NodeData[] | null, sorter: () => any) {
|
mergeChildren(remover: () => any, adder: (children: Node[]) => NodeData[] | null, sorter: () => any) {
|
||||||
let changed = false;
|
let changed = false;
|
||||||
if (remover) {
|
if (remover) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { ComponentType, ReactElement, Component, FunctionComponent } from 'react';
|
import { ComponentType, ReactElement, Component, FunctionComponent } from 'react';
|
||||||
import { ComponentMetadata, FieldConfig, InitialItem, FilterItem, AutorunItem, isI18nData } from '@ali/lowcode-types';
|
import { ComponentMetadata, FieldConfig, InitialItem, FilterItem, AutorunItem } from '@ali/lowcode-types';
|
||||||
import {
|
import {
|
||||||
ComponentMeta,
|
ComponentMeta,
|
||||||
addBuiltinComponentAction,
|
addBuiltinComponentAction,
|
||||||
@ -7,6 +7,8 @@ import {
|
|||||||
registerMetadataTransducer,
|
registerMetadataTransducer,
|
||||||
TransformStage,
|
TransformStage,
|
||||||
} from '@ali/lowcode-designer';
|
} from '@ali/lowcode-designer';
|
||||||
|
import { intl } from '@ali/lowcode-editor-core';
|
||||||
|
import { isInSimulator } from '@ali/lowcode-utils';
|
||||||
import {
|
import {
|
||||||
OldPropConfig,
|
OldPropConfig,
|
||||||
OldPrototypeConfig,
|
OldPrototypeConfig,
|
||||||
@ -15,7 +17,7 @@ import {
|
|||||||
upgradePropConfig,
|
upgradePropConfig,
|
||||||
upgradeConfigure,
|
upgradeConfigure,
|
||||||
} from './upgrade-metadata';
|
} from './upgrade-metadata';
|
||||||
import { intl } from '@ali/lowcode-editor-core';
|
|
||||||
import { designer } from '../editor';
|
import { designer } from '../editor';
|
||||||
|
|
||||||
const GlobalPropsConfigure: Array<{
|
const GlobalPropsConfigure: Array<{
|
||||||
@ -213,6 +215,10 @@ class Prototype {
|
|||||||
static removeGlobalPropsConfigure = removeGlobalPropsConfigure;
|
static removeGlobalPropsConfigure = removeGlobalPropsConfigure;
|
||||||
static overridePropsConfigure = overridePropsConfigure;
|
static overridePropsConfigure = overridePropsConfigure;
|
||||||
static create(config: OldPrototypeConfig | ComponentMetadata | ComponentMeta, extraConfigs: any = null, lookup: boolean = false) {
|
static create(config: OldPrototypeConfig | ComponentMetadata | ComponentMeta, extraConfigs: any = null, lookup: boolean = false) {
|
||||||
|
// 目前 vc-xxx 会在设计器和渲染 simulator iframe 中执行两遍,在 simulator 中不需要重新创建,直接复用外层的
|
||||||
|
if (isInSimulator()) {
|
||||||
|
lookup = true;
|
||||||
|
}
|
||||||
return new Prototype(config, extraConfigs, lookup);
|
return new Prototype(config, extraConfigs, lookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -107,7 +107,7 @@ designer.addPropsReducer((props, node) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 全局的关闭 uniqueIdChecker 信号,在 ve-utils 中实现
|
// 全局的关闭 uniqueIdChecker 信号,在 ve-utils 中实现
|
||||||
if (fieldIds.indexOf(props.fieldId) >= 0 && !window.__disable_unique_id_checker__) {
|
if (fieldIds.indexOf(props.fieldId) >= 0 && !(window as any).__disable_unique_id_checker__) {
|
||||||
newProps.fieldId = undefined;
|
newProps.fieldId = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
packages/utils/src/env.ts
Normal file
3
packages/utils/src/env.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export function isInSimulator() {
|
||||||
|
return Boolean((window as any).__is_simulator_env__);
|
||||||
|
}
|
||||||
@ -18,3 +18,4 @@ export * from './set-prototype-of';
|
|||||||
export * from './shallow-equal';
|
export * from './shallow-equal';
|
||||||
export * from './svg-icon';
|
export * from './svg-icon';
|
||||||
export * from './unique-id';
|
export * from './unique-id';
|
||||||
|
export * from './env';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user