Merge branch 'develop' into release/1.1.11-beta

This commit is contained in:
JackLian 2023-10-18 09:55:20 +08:00
commit 84cb455fe9
5 changed files with 33 additions and 6 deletions

View File

@ -56,12 +56,13 @@ export function createSimulator(
}
const id = asset.id ? ` data-id="${asset.id}"` : '';
const lv = asset.level || level || AssetLevel.Environment;
const scriptType = asset.scriptType ? ` type="${asset.scriptType}"` : '';
if (asset.type === AssetType.JSUrl) {
scripts[lv].push(
`<script src="${asset.content}"${id}></script>`,
`<script src="${asset.content}"${id}${scriptType}></script>`,
);
} else if (asset.type === AssetType.JSText) {
scripts[lv].push(`<script${id}>${asset.content}</script>`);
scripts[lv].push(`<script${id}${scriptType}>${asset.content}</script>`);
} else if (asset.type === AssetType.CSSUrl) {
styles[lv].push(
`<link rel="stylesheet" href="${asset.content}"${id} />`,

View File

@ -10,6 +10,14 @@ import {
} from './icons';
import { componentDefaults, legacyIssues } from './transducers';
function deduplicateRef(node: IPublicModelNode | null | undefined) {
const currentRef = node?.getPropValue('ref');
if (currentRef) {
node?.setPropValue('ref', `${node.componentName.toLowerCase()}-${Math.random().toString(36).slice(2, 9)}`);
}
node?.children?.forEach(deduplicateRef);
}
export class ComponentActions {
private metadataTransducers: IPublicTypeMetadataTransducer[] = [];
@ -53,6 +61,7 @@ export class ComponentActions {
const { document: doc, parent, index } = node;
if (parent) {
const newNode = doc?.insertNode(parent, node, (index ?? 0) + 1, true);
deduplicateRef(newNode);
newNode?.select();
const { isRGL, rglNode } = node?.getRGL();
if (isRGL) {

View File

@ -2,7 +2,12 @@ import { cloneEnumerableProperty } from '@alilc/lowcode-utils';
import adapter from '../adapter';
import { IBaseRendererInstance, IRendererProps } from '../types';
function patchDidCatch(Comp: any, { baseRenderer }: { baseRenderer: IBaseRendererInstance }) {
interface Options {
baseRenderer: IBaseRendererInstance;
schema: any;
}
function patchDidCatch(Comp: any, { baseRenderer }: Options) {
if (Comp.patchedCatch) {
return;
}
@ -44,7 +49,9 @@ function patchDidCatch(Comp: any, { baseRenderer }: { baseRenderer: IBaseRendere
}
}
export function compWrapper(Comp: any, options: { baseRenderer: IBaseRendererInstance }) {
const cache = new Map();
export function compWrapper(Comp: any, options: Options) {
const { createElement, Component, forwardRef } = adapter.getRuntime();
if (
Comp?.prototype?.isReactComponent || // react
@ -54,6 +61,11 @@ export function compWrapper(Comp: any, options: { baseRenderer: IBaseRendererIns
patchDidCatch(Comp, options);
return Comp;
}
if (cache.has(options.schema.id)) {
return cache.get(options.schema.id);
}
class Wrapper extends Component {
render() {
return createElement(Comp, { ...this.props, ref: this.props.forwardRef });
@ -63,10 +75,14 @@ export function compWrapper(Comp: any, options: { baseRenderer: IBaseRendererIns
patchDidCatch(Wrapper, options);
return cloneEnumerableProperty(
const WrapperComponent = cloneEnumerableProperty(
forwardRef((props: any, ref: any) => {
return createElement(Wrapper, { ...props, forwardRef: ref });
}),
Comp,
);
cache.set(options.schema.id, WrapperComponent);
return WrapperComponent;
}

View File

@ -615,7 +615,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
});
});
Comp = compWrapper(Comp, { baseRenderer: this });
Comp = compWrapper(Comp, { baseRenderer: this, schema });
components[schema.componentName] = Comp;
otherProps.ref = (ref: any) => {

View File

@ -38,6 +38,7 @@ export interface AssetItem {
device?: string;
level?: AssetLevel;
id?: string;
scriptType?: string;
}
export type AssetList = Array<Asset | undefined | null>;