mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-18 21:38:14 +00:00
Merge branch 'release/1.0.0' of gitlab.alibaba-inc.com:ali-lowcode/ali-lowcode-engine into release/1.0.0
This commit is contained in:
commit
4083945c5d
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -67,7 +67,7 @@
|
|||||||
|
|
||||||
.event-menu {
|
.event-menu {
|
||||||
max-height: 300px;
|
max-height: 300px;
|
||||||
width: 230px;
|
width: 256px;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 67px;
|
top: 67px;
|
||||||
|
|||||||
@ -29,30 +29,31 @@ export default class EventsSetter extends Component<{
|
|||||||
selectType: null,
|
selectType: null,
|
||||||
nativeEventList: [],
|
nativeEventList: [],
|
||||||
lifeCycleEventList: [],
|
lifeCycleEventList: [],
|
||||||
eventDataList: this.props.value || [],
|
eventDataList: (this.props?.value?.eventDataList ? this.props.value.eventDataList : this.props?.value) || [],
|
||||||
relatedEventName: '',
|
relatedEventName: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
// constructor (){
|
// constructor (){
|
||||||
// super();
|
// super();
|
||||||
// debugger;
|
// debugger;
|
||||||
// if (!this.props || !this.props.value){
|
// // if (!this.props || !this.props.value){
|
||||||
// this.setState({
|
// // this.setState({
|
||||||
// eventDataList:[]
|
// // eventDataList:[]
|
||||||
// })
|
// // })
|
||||||
// }
|
// // }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
static getDerivedStateFromProps(nextProps, prevState) {
|
// static getDerivedStateFromProps(nextProps, prevState) {
|
||||||
// const { value } = nextProps;
|
|
||||||
// debugger;
|
// debugger;
|
||||||
// if (value !== prevState.eventDataList) {
|
// // const { value } = nextProps;
|
||||||
// return {
|
// // debugger;
|
||||||
// value,
|
// // if (value !== prevState.eventDataList) {
|
||||||
// };
|
// // return {
|
||||||
|
// // value,
|
||||||
|
// // };
|
||||||
|
// // }
|
||||||
|
// return null;
|
||||||
// }
|
// }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bindEventName:String;
|
private bindEventName:String;
|
||||||
|
|
||||||
@ -310,7 +311,7 @@ export default class EventsSetter extends Component<{
|
|||||||
};
|
};
|
||||||
|
|
||||||
deleteEvent = (eventName: String) => {
|
deleteEvent = (eventName: String) => {
|
||||||
const { eventDataList } = this.state;
|
const { eventDataList,eventList} = this.state;
|
||||||
eventDataList.map((item, index) => {
|
eventDataList.map((item, index) => {
|
||||||
if (item.name === eventName) {
|
if (item.name === eventName) {
|
||||||
eventDataList.splice(index, 1);
|
eventDataList.splice(index, 1);
|
||||||
@ -320,7 +321,7 @@ export default class EventsSetter extends Component<{
|
|||||||
this.setState({
|
this.setState({
|
||||||
eventDataList,
|
eventDataList,
|
||||||
});
|
});
|
||||||
|
this.props.onChange({eventDataList,eventList});
|
||||||
this.updateEventListStatus(eventName, true);
|
this.updateEventListStatus(eventName, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -332,7 +333,7 @@ export default class EventsSetter extends Component<{
|
|||||||
|
|
||||||
|
|
||||||
bindEvent = (relatedEventName: String) => {
|
bindEvent = (relatedEventName: String) => {
|
||||||
const {eventDataList} = this.state;
|
const {eventDataList,eventList} = this.state;
|
||||||
eventDataList.map(item => {
|
eventDataList.map(item => {
|
||||||
if (item.name === this.bindEventName) {
|
if (item.name === this.bindEventName) {
|
||||||
item.relatedEventName = relatedEventName;
|
item.relatedEventName = relatedEventName;
|
||||||
@ -344,7 +345,7 @@ export default class EventsSetter extends Component<{
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
this.props.onChange(eventDataList);
|
this.props.onChange({eventDataList,eventList});
|
||||||
|
|
||||||
//this.closeDialog();
|
//this.closeDialog();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -206,7 +206,12 @@ export default function(metadata: TransformedComponentMetadata): TransformedComp
|
|||||||
return val;
|
return val;
|
||||||
},
|
},
|
||||||
|
|
||||||
setValue(field: SettingTarget, eventDataList: any[]) {
|
setValue(field: SettingTarget, eventData) {
|
||||||
|
const {eventDataList,eventList} = eventData;
|
||||||
|
eventList.map((item)=>{
|
||||||
|
field.parent.clearPropValue(item.name);
|
||||||
|
return item;
|
||||||
|
})
|
||||||
eventDataList.map((item) => {
|
eventDataList.map((item) => {
|
||||||
field.parent.setPropValue(item.name, {
|
field.parent.setPropValue(item.name, {
|
||||||
type: 'JSFunction',
|
type: 'JSFunction',
|
||||||
|
|||||||
@ -188,7 +188,7 @@ function propTypeToSetter(propType: PropType): SetterType {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const EVENT_RE = /^on[A-Z][\w]*$/;
|
const EVENT_RE = /^on|after[A-Z][\w]*$/;
|
||||||
|
|
||||||
export default function(metadata: TransformedComponentMetadata): TransformedComponentMetadata {
|
export default function(metadata: TransformedComponentMetadata): TransformedComponentMetadata {
|
||||||
const { configure = {} } = metadata;
|
const { configure = {} } = metadata;
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import React, { useState, ComponentType } from 'react';
|
|||||||
import { Button, Dialog } from '@alifd/next';
|
import { Button, Dialog } from '@alifd/next';
|
||||||
import { PluginProps, NpmInfo } from '@ali/lowcode-types';
|
import { PluginProps, NpmInfo } from '@ali/lowcode-types';
|
||||||
import { Designer } from '@ali/lowcode-designer';
|
import { Designer } from '@ali/lowcode-designer';
|
||||||
import { buildComponents } from '@ali/lowcode-utils';
|
import { buildComponents, assetBundle, AssetList, AssetLevel, AssetLoader } from '@ali/lowcode-utils';
|
||||||
import ReactRenderer from '@ali/lowcode-react-renderer';
|
import ReactRenderer from '@ali/lowcode-react-renderer';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
|
|
||||||
@ -16,15 +16,34 @@ const SamplePreview = ({ editor }: PluginProps) => {
|
|||||||
const designer = editor.get(Designer);
|
const designer = editor.get(Designer);
|
||||||
if (designer) {
|
if (designer) {
|
||||||
const assets = await editor.get('assets');
|
const assets = await editor.get('assets');
|
||||||
|
const { packages } = assets;
|
||||||
|
const { componentsMap, schema } = designer;
|
||||||
|
|
||||||
console.info('save schema:', designer, assets);
|
console.info('save schema:', designer, assets);
|
||||||
|
|
||||||
const libraryMap = {};
|
const libraryMap = {};
|
||||||
assets.packages.forEach(({ package, library }) => {
|
const libraryAsset: AssetList = [];
|
||||||
|
packages.forEach(({ package, library, urls }) => {
|
||||||
libraryMap[package] = library;
|
libraryMap[package] = library;
|
||||||
|
if (urls) {
|
||||||
|
libraryAsset.push(urls);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const vendors = [
|
||||||
|
assetBundle(libraryAsset, AssetLevel.Library),
|
||||||
|
];
|
||||||
|
console.log('libraryMap&vendors', libraryMap, vendors);
|
||||||
|
|
||||||
|
// TODO asset may cause pollution
|
||||||
|
const assetLoader = new AssetLoader();
|
||||||
|
await assetLoader.load(libraryAsset);
|
||||||
|
const components = buildComponents(libraryMap, componentsMap);
|
||||||
|
console.log('components', components);
|
||||||
|
|
||||||
setData({
|
setData({
|
||||||
schema: designer.schema.componentsTree[0],
|
schema: schema.componentsTree[0],
|
||||||
components: buildComponents(libraryMap, designer.componentsMap),
|
components,
|
||||||
});
|
});
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -275,9 +275,9 @@ export default class SourceEditor extends Component<{
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div className="full-screen-container" onClick={this.fullScreen}>
|
{/* <div className="full-screen-container" onClick={this.fullScreen}>
|
||||||
<img src="https://gw.alicdn.com/tfs/TB1d7XqE1T2gK0jSZFvXXXnFXXa-200-200.png"></img>
|
<img src="https://gw.alicdn.com/tfs/TB1d7XqE1T2gK0jSZFvXXXnFXXa-200-200.png"></img>
|
||||||
</div>
|
</div> */}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,15 +5,16 @@ import SimulatorRendererView from './renderer-view';
|
|||||||
import { computed, obx } from '@recore/obx';
|
import { computed, obx } from '@recore/obx';
|
||||||
import { Asset } from '@ali/lowcode-utils';
|
import { Asset } from '@ali/lowcode-utils';
|
||||||
import { getClientRects } from './utils/get-client-rects';
|
import { getClientRects } from './utils/get-client-rects';
|
||||||
import loader from './utils/loader';
|
|
||||||
import { reactFindDOMNodes, FIBER_KEY } from './utils/react-find-dom-nodes';
|
import { reactFindDOMNodes, FIBER_KEY } from './utils/react-find-dom-nodes';
|
||||||
import { isElement, cursor, setNativeSelection, buildComponents, getSubComponent } from '@ali/lowcode-utils';
|
import { isElement, cursor, setNativeSelection, buildComponents, getSubComponent, AssetLoader } from '@ali/lowcode-utils';
|
||||||
import { RootSchema, ComponentSchema, TransformStage } from '@ali/lowcode-types';
|
import { RootSchema, ComponentSchema, TransformStage } from '@ali/lowcode-types';
|
||||||
// just use types
|
// just use types
|
||||||
import { BuiltinSimulatorRenderer, NodeInstance, Component } from '@ali/lowcode-designer';
|
import { BuiltinSimulatorRenderer, NodeInstance, Component } from '@ali/lowcode-designer';
|
||||||
import Slot from './builtin-components/slot';
|
import Slot from './builtin-components/slot';
|
||||||
import Leaf from './builtin-components/leaf';
|
import Leaf from './builtin-components/leaf';
|
||||||
|
|
||||||
|
const loader = new AssetLoader();
|
||||||
|
|
||||||
export class SimulatorRenderer implements BuiltinSimulatorRenderer {
|
export class SimulatorRenderer implements BuiltinSimulatorRenderer {
|
||||||
readonly isSimulatorRenderer = true;
|
readonly isSimulatorRenderer = true;
|
||||||
private dispose?: () => void;
|
private dispose?: () => void;
|
||||||
|
|||||||
@ -1,113 +0,0 @@
|
|||||||
import { load, evaluate } from './script';
|
|
||||||
import StylePoint from './style';
|
|
||||||
import {
|
|
||||||
Asset,
|
|
||||||
AssetLevel,
|
|
||||||
AssetLevels,
|
|
||||||
AssetType,
|
|
||||||
AssetList,
|
|
||||||
isAssetBundle,
|
|
||||||
isAssetItem,
|
|
||||||
assetItem,
|
|
||||||
AssetItem,
|
|
||||||
isCSSUrl,
|
|
||||||
} from '@ali/lowcode-utils';
|
|
||||||
|
|
||||||
function parseAssetList(scripts: any, styles: any, assets: AssetList, level?: AssetLevel) {
|
|
||||||
for (const asset of assets) {
|
|
||||||
parseAsset(scripts, styles, asset, level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseAsset(scripts: any, styles: any, asset: Asset | undefined | null, level?: AssetLevel) {
|
|
||||||
if (!asset) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Array.isArray(asset)) {
|
|
||||||
return parseAssetList(scripts, styles, asset, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isAssetBundle(asset)) {
|
|
||||||
if (asset.assets) {
|
|
||||||
if (Array.isArray(asset.assets)) {
|
|
||||||
parseAssetList(scripts, styles, asset.assets, asset.level || level);
|
|
||||||
} else {
|
|
||||||
parseAsset(scripts, styles, asset.assets, asset.level || level);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isAssetItem(asset)) {
|
|
||||||
asset = assetItem(isCSSUrl(asset) ? AssetType.CSSUrl : AssetType.JSUrl, asset, level)!;
|
|
||||||
}
|
|
||||||
|
|
||||||
let lv = asset.level || level;
|
|
||||||
|
|
||||||
if (!lv || AssetLevel[lv] == null) {
|
|
||||||
lv = AssetLevel.App;
|
|
||||||
}
|
|
||||||
|
|
||||||
asset.level = lv;
|
|
||||||
if (asset.type === AssetType.CSSUrl || asset.type == AssetType.CSSText) {
|
|
||||||
styles[lv].push(asset);
|
|
||||||
} else {
|
|
||||||
scripts[lv].push(asset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AssetLoader {
|
|
||||||
async load(asset: Asset) {
|
|
||||||
const styles: any = {};
|
|
||||||
const scripts: any = {};
|
|
||||||
AssetLevels.forEach(lv => {
|
|
||||||
styles[lv] = [];
|
|
||||||
scripts[lv] = [];
|
|
||||||
});
|
|
||||||
parseAsset(scripts, styles, asset);
|
|
||||||
const styleQueue: AssetItem[] = styles[AssetLevel.Environment].concat(
|
|
||||||
styles[AssetLevel.Library],
|
|
||||||
styles[AssetLevel.Theme],
|
|
||||||
styles[AssetLevel.Runtime],
|
|
||||||
styles[AssetLevel.App],
|
|
||||||
);
|
|
||||||
const scriptQueue: AssetItem[] = scripts[AssetLevel.Environment].concat(
|
|
||||||
scripts[AssetLevel.Library],
|
|
||||||
scripts[AssetLevel.Theme],
|
|
||||||
scripts[AssetLevel.Runtime],
|
|
||||||
scripts[AssetLevel.App],
|
|
||||||
);
|
|
||||||
await Promise.all(
|
|
||||||
styleQueue.map(({ content, level, type, id }) => this.loadStyle(content, level!, type === AssetType.CSSUrl, id)),
|
|
||||||
);
|
|
||||||
await Promise.all(scriptQueue.map(({ content, type }) => this.loadScript(content, type === AssetType.JSUrl)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private stylePoints = new Map<string, StylePoint>();
|
|
||||||
private loadStyle(content: string | undefined | null, level: AssetLevel, isUrl?: boolean, id?: string) {
|
|
||||||
if (!content) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let point: StylePoint | undefined;
|
|
||||||
if (id) {
|
|
||||||
point = this.stylePoints.get(id);
|
|
||||||
if (!point) {
|
|
||||||
point = new StylePoint(level, id);
|
|
||||||
this.stylePoints.set(id, point);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
point = new StylePoint(level);
|
|
||||||
}
|
|
||||||
return isUrl ? point.applyUrl(content) : point.applyText(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
private loadScript(content: string | undefined | null, isUrl?: boolean) {
|
|
||||||
if (!content) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return isUrl ? load(content) : evaluate(content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default new AssetLoader();
|
|
||||||
@ -1,73 +0,0 @@
|
|||||||
import { createDefer } from './create-defer';
|
|
||||||
|
|
||||||
export default class StylePoint {
|
|
||||||
private lastContent: string | undefined;
|
|
||||||
private lastUrl: string | undefined;
|
|
||||||
private placeholder: Element | Text;
|
|
||||||
|
|
||||||
constructor(readonly level: number, readonly id?: string) {
|
|
||||||
let placeholder: any;
|
|
||||||
if (id) {
|
|
||||||
placeholder = document.head.querySelector(`style[data-id="${id}"]`);
|
|
||||||
}
|
|
||||||
if (!placeholder) {
|
|
||||||
placeholder = document.createTextNode('');
|
|
||||||
const meta = document.head.querySelector(`meta[level="${level}"]`);
|
|
||||||
if (meta) {
|
|
||||||
document.head.insertBefore(placeholder, meta);
|
|
||||||
} else {
|
|
||||||
document.head.appendChild(placeholder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.placeholder = placeholder;
|
|
||||||
}
|
|
||||||
|
|
||||||
applyText(content: string) {
|
|
||||||
if (this.lastContent === content) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.lastContent = content;
|
|
||||||
this.lastUrl = undefined;
|
|
||||||
const element = document.createElement('style');
|
|
||||||
element.setAttribute('type', 'text/css');
|
|
||||||
if (this.id) {
|
|
||||||
element.setAttribute('data-id', this.id);
|
|
||||||
}
|
|
||||||
element.appendChild(document.createTextNode(content));
|
|
||||||
document.head.insertBefore(element, this.placeholder.parentNode === document.head ? this.placeholder.nextSibling : null);
|
|
||||||
document.head.removeChild(this.placeholder);
|
|
||||||
this.placeholder = element;
|
|
||||||
}
|
|
||||||
|
|
||||||
applyUrl(url: string) {
|
|
||||||
if (this.lastUrl === url) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.lastContent = undefined;
|
|
||||||
this.lastUrl = url;
|
|
||||||
const element = document.createElement('link');
|
|
||||||
element.onload = onload;
|
|
||||||
element.onerror = onload;
|
|
||||||
|
|
||||||
const i = createDefer();
|
|
||||||
function onload(e: any) {
|
|
||||||
element.onload = null;
|
|
||||||
element.onerror = null;
|
|
||||||
if (e.type === 'load') {
|
|
||||||
i.resolve();
|
|
||||||
} else {
|
|
||||||
i.reject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
element.href = url;
|
|
||||||
element.rel = 'stylesheet';
|
|
||||||
if (this.id) {
|
|
||||||
element.setAttribute('data-id', this.id);
|
|
||||||
}
|
|
||||||
document.head.insertBefore(element, this.placeholder.parentNode === document.head ? this.placeholder.nextSibling : null);
|
|
||||||
document.head.removeChild(this.placeholder);
|
|
||||||
this.placeholder = element;
|
|
||||||
return i.promise();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,3 +1,7 @@
|
|||||||
|
import { isCSSUrl } from './is-css-url';
|
||||||
|
import { createDefer } from './create-defer';
|
||||||
|
import { load, evaluate } from './script';
|
||||||
|
|
||||||
export interface AssetItem {
|
export interface AssetItem {
|
||||||
type: AssetType;
|
type: AssetType;
|
||||||
content?: string | null;
|
content?: string | null;
|
||||||
@ -88,3 +92,172 @@ export function assetItem(type: AssetType, content?: string | null, level?: Asse
|
|||||||
id,
|
id,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class StylePoint {
|
||||||
|
private lastContent: string | undefined;
|
||||||
|
private lastUrl: string | undefined;
|
||||||
|
private placeholder: Element | Text;
|
||||||
|
|
||||||
|
constructor(readonly level: number, readonly id?: string) {
|
||||||
|
let placeholder: any;
|
||||||
|
if (id) {
|
||||||
|
placeholder = document.head.querySelector(`style[data-id="${id}"]`);
|
||||||
|
}
|
||||||
|
if (!placeholder) {
|
||||||
|
placeholder = document.createTextNode('');
|
||||||
|
const meta = document.head.querySelector(`meta[level="${level}"]`);
|
||||||
|
if (meta) {
|
||||||
|
document.head.insertBefore(placeholder, meta);
|
||||||
|
} else {
|
||||||
|
document.head.appendChild(placeholder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.placeholder = placeholder;
|
||||||
|
}
|
||||||
|
|
||||||
|
applyText(content: string) {
|
||||||
|
if (this.lastContent === content) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.lastContent = content;
|
||||||
|
this.lastUrl = undefined;
|
||||||
|
const element = document.createElement('style');
|
||||||
|
element.setAttribute('type', 'text/css');
|
||||||
|
if (this.id) {
|
||||||
|
element.setAttribute('data-id', this.id);
|
||||||
|
}
|
||||||
|
element.appendChild(document.createTextNode(content));
|
||||||
|
document.head.insertBefore(element, this.placeholder.parentNode === document.head ? this.placeholder.nextSibling : null);
|
||||||
|
document.head.removeChild(this.placeholder);
|
||||||
|
this.placeholder = element;
|
||||||
|
}
|
||||||
|
|
||||||
|
applyUrl(url: string) {
|
||||||
|
if (this.lastUrl === url) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.lastContent = undefined;
|
||||||
|
this.lastUrl = url;
|
||||||
|
const element = document.createElement('link');
|
||||||
|
element.onload = onload;
|
||||||
|
element.onerror = onload;
|
||||||
|
|
||||||
|
const i = createDefer();
|
||||||
|
function onload(e: any) {
|
||||||
|
element.onload = null;
|
||||||
|
element.onerror = null;
|
||||||
|
if (e.type === 'load') {
|
||||||
|
i.resolve();
|
||||||
|
} else {
|
||||||
|
i.reject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
element.href = url;
|
||||||
|
element.rel = 'stylesheet';
|
||||||
|
if (this.id) {
|
||||||
|
element.setAttribute('data-id', this.id);
|
||||||
|
}
|
||||||
|
document.head.insertBefore(element, this.placeholder.parentNode === document.head ? this.placeholder.nextSibling : null);
|
||||||
|
document.head.removeChild(this.placeholder);
|
||||||
|
this.placeholder = element;
|
||||||
|
return i.promise();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseAssetList(scripts: any, styles: any, assets: AssetList, level?: AssetLevel) {
|
||||||
|
for (const asset of assets) {
|
||||||
|
parseAsset(scripts, styles, asset, level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseAsset(scripts: any, styles: any, asset: Asset | undefined | null, level?: AssetLevel) {
|
||||||
|
if (!asset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Array.isArray(asset)) {
|
||||||
|
return parseAssetList(scripts, styles, asset, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAssetBundle(asset)) {
|
||||||
|
if (asset.assets) {
|
||||||
|
if (Array.isArray(asset.assets)) {
|
||||||
|
parseAssetList(scripts, styles, asset.assets, asset.level || level);
|
||||||
|
} else {
|
||||||
|
parseAsset(scripts, styles, asset.assets, asset.level || level);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAssetItem(asset)) {
|
||||||
|
asset = assetItem(isCSSUrl(asset) ? AssetType.CSSUrl : AssetType.JSUrl, asset, level)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
let lv = asset.level || level;
|
||||||
|
|
||||||
|
if (!lv || AssetLevel[lv] == null) {
|
||||||
|
lv = AssetLevel.App;
|
||||||
|
}
|
||||||
|
|
||||||
|
asset.level = lv;
|
||||||
|
if (asset.type === AssetType.CSSUrl || asset.type == AssetType.CSSText) {
|
||||||
|
styles[lv].push(asset);
|
||||||
|
} else {
|
||||||
|
scripts[lv].push(asset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AssetLoader {
|
||||||
|
async load(asset: Asset) {
|
||||||
|
const styles: any = {};
|
||||||
|
const scripts: any = {};
|
||||||
|
AssetLevels.forEach(lv => {
|
||||||
|
styles[lv] = [];
|
||||||
|
scripts[lv] = [];
|
||||||
|
});
|
||||||
|
parseAsset(scripts, styles, asset);
|
||||||
|
const styleQueue: AssetItem[] = styles[AssetLevel.Environment].concat(
|
||||||
|
styles[AssetLevel.Library],
|
||||||
|
styles[AssetLevel.Theme],
|
||||||
|
styles[AssetLevel.Runtime],
|
||||||
|
styles[AssetLevel.App],
|
||||||
|
);
|
||||||
|
const scriptQueue: AssetItem[] = scripts[AssetLevel.Environment].concat(
|
||||||
|
scripts[AssetLevel.Library],
|
||||||
|
scripts[AssetLevel.Theme],
|
||||||
|
scripts[AssetLevel.Runtime],
|
||||||
|
scripts[AssetLevel.App],
|
||||||
|
);
|
||||||
|
await Promise.all(
|
||||||
|
styleQueue.map(({ content, level, type, id }) => this.loadStyle(content, level!, type === AssetType.CSSUrl, id)),
|
||||||
|
);
|
||||||
|
await Promise.all(scriptQueue.map(({ content, type }) => this.loadScript(content, type === AssetType.JSUrl)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private stylePoints = new Map<string, StylePoint>();
|
||||||
|
private loadStyle(content: string | undefined | null, level: AssetLevel, isUrl?: boolean, id?: string) {
|
||||||
|
if (!content) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let point: StylePoint | undefined;
|
||||||
|
if (id) {
|
||||||
|
point = this.stylePoints.get(id);
|
||||||
|
if (!point) {
|
||||||
|
point = new StylePoint(level, id);
|
||||||
|
this.stylePoints.set(id, point);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
point = new StylePoint(level);
|
||||||
|
}
|
||||||
|
return isUrl ? point.applyUrl(content) : point.applyText(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
private loadScript(content: string | undefined | null, isUrl?: boolean) {
|
||||||
|
if (!content) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return isUrl ? load(content) : evaluate(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { ComponentType } from 'react';
|
import { ComponentType, forwardRef, createElement } from 'react';
|
||||||
import { NpmInfo} from '@ali/lowcode-types';
|
import { NpmInfo } from '@ali/lowcode-types';
|
||||||
import { isReactComponent } from './is-react';
|
import { isReactComponent } from './is-react';
|
||||||
import { isESModule } from './is-es-module';
|
import { isESModule } from './is-es-module';
|
||||||
|
|
||||||
@ -12,7 +12,15 @@ function accessLibrary(library: string | object) {
|
|||||||
return library;
|
return library;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (window as any)[library] || library;
|
return (window as any)[library] || generateHtmlComp(library);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function generateHtmlComp(library: string) {
|
||||||
|
if (['a', 'img', 'div', 'span', 'svg'].includes(library)) {
|
||||||
|
return forwardRef((props, ref) => {
|
||||||
|
return createElement(library, { ref, ...props }, props.children);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSubComponent(library: any, paths: string[]) {
|
export function getSubComponent(library: any, paths: string[]) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user