mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 11:20:11 +00:00
feat: assets.components support reference field (#1355)
* feat: 资产包协议兼容低代码组件物料
This commit is contained in:
parent
de3443a9dc
commit
f9dcbaf618
@ -18,6 +18,7 @@ import { globalLocale } from './intl';
|
|||||||
import Preference from './utils/preference';
|
import Preference from './utils/preference';
|
||||||
import { obx } from './utils';
|
import { obx } from './utils';
|
||||||
import { AssetsJson, AssetLoader } from '@alilc/lowcode-utils';
|
import { AssetsJson, AssetLoader } from '@alilc/lowcode-utils';
|
||||||
|
import { assetsTransform } from './utils/assets-transform';
|
||||||
|
|
||||||
EventEmitter.defaultMaxListeners = 100;
|
EventEmitter.defaultMaxListeners = 100;
|
||||||
|
|
||||||
@ -124,7 +125,8 @@ export class Editor extends (EventEmitter as any) implements IEditor {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.context.set('assets', assets);
|
const innerAssets = assetsTransform(assets);
|
||||||
|
this.context.set('assets', innerAssets);
|
||||||
this.notifyGot('assets');
|
this.notifyGot('assets');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +147,7 @@ export class Editor extends (EventEmitter as any) implements IEditor {
|
|||||||
const x = this.context.get(keyOrType);
|
const x = this.context.get(keyOrType);
|
||||||
if (x !== undefined) {
|
if (x !== undefined) {
|
||||||
fn(x);
|
fn(x);
|
||||||
return () => {};
|
return () => { };
|
||||||
} else {
|
} else {
|
||||||
this.setWait(keyOrType, fn);
|
this.setWait(keyOrType, fn);
|
||||||
return () => {
|
return () => {
|
||||||
@ -169,7 +171,7 @@ export class Editor extends (EventEmitter as any) implements IEditor {
|
|||||||
const { hooks = [], lifeCycles } = this.config;
|
const { hooks = [], lifeCycles } = this.config;
|
||||||
|
|
||||||
this.emit('editor.beforeInit');
|
this.emit('editor.beforeInit');
|
||||||
const init = (lifeCycles && lifeCycles.init) || ((): void => {});
|
const init = (lifeCycles && lifeCycles.init) || ((): void => { });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await init(this);
|
await init(this);
|
||||||
@ -231,11 +233,11 @@ export class Editor extends (EventEmitter as any) implements IEditor {
|
|||||||
|
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
private waits = new Map<
|
private waits = new Map<
|
||||||
KeyType,
|
KeyType,
|
||||||
Array<{
|
Array<{
|
||||||
once?: boolean;
|
once?: boolean;
|
||||||
resolve: (data: any) => void;
|
resolve: (data: any) => void;
|
||||||
}>
|
}>
|
||||||
>();
|
>();
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
|
|
||||||
|
|||||||
26
packages/editor-core/src/utils/assets-transform.ts
Normal file
26
packages/editor-core/src/utils/assets-transform.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { AssetsJson, ComponentDescription } from '@alilc/lowcode-types';
|
||||||
|
|
||||||
|
|
||||||
|
export function assetsTransform(assets: AssetsJson) {
|
||||||
|
const { components, packages } = assets;
|
||||||
|
const packageMaps = (packages || []).reduce((acc, cur) => {
|
||||||
|
const key = (cur.id || cur.package) as string;
|
||||||
|
acc[key] = cur;
|
||||||
|
return acc;
|
||||||
|
}, {} as any);
|
||||||
|
components.forEach((componentDesc) => {
|
||||||
|
let { devMode, schema, reference } = componentDesc as ComponentDescription;
|
||||||
|
if ((devMode as string) === 'lowcode') {
|
||||||
|
devMode = 'lowCode';
|
||||||
|
} else if (devMode === 'proCode') {
|
||||||
|
devMode = 'proCode';
|
||||||
|
}
|
||||||
|
if (devMode) {
|
||||||
|
(componentDesc as ComponentDescription).devMode = devMode;
|
||||||
|
}
|
||||||
|
if (devMode === 'lowCode' && !schema && reference) {
|
||||||
|
(componentDesc as ComponentDescription).schema = packageMaps[reference.id as string].schema;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return assets;
|
||||||
|
}
|
||||||
@ -1,5 +1,7 @@
|
|||||||
import { Snippet, ComponentMetadata } from './metadata';
|
import { Snippet, ComponentMetadata } from './metadata';
|
||||||
import { I18nData } from './i18n';
|
import { I18nData } from './i18n';
|
||||||
|
import { Reference } from './npm';
|
||||||
|
import { EitherOr } from './utils';
|
||||||
|
|
||||||
export interface AssetItem {
|
export interface AssetItem {
|
||||||
type: AssetType;
|
type: AssetType;
|
||||||
@ -103,11 +105,15 @@ export interface ComponentSort {
|
|||||||
* 定义组件大包及 external 资源的信息
|
* 定义组件大包及 external 资源的信息
|
||||||
* 应该被编辑器默认加载
|
* 应该被编辑器默认加载
|
||||||
*/
|
*/
|
||||||
export interface Package {
|
export type Package = EitherOr<{
|
||||||
/**
|
/**
|
||||||
* 包名
|
* npm 包名
|
||||||
*/
|
*/
|
||||||
package: string;
|
package: string;
|
||||||
|
/**
|
||||||
|
* 包唯一标识
|
||||||
|
*/
|
||||||
|
id: string;
|
||||||
/**
|
/**
|
||||||
* 包版本号
|
* 包版本号
|
||||||
*/
|
*/
|
||||||
@ -142,7 +148,7 @@ export interface Package {
|
|||||||
* 组件描述导出名字,可以通过 window[exportName] 获取到组件描述的 Object 内容;
|
* 组件描述导出名字,可以通过 window[exportName] 获取到组件描述的 Object 内容;
|
||||||
*/
|
*/
|
||||||
exportName?: string;
|
exportName?: string;
|
||||||
}
|
}, 'package', 'id'>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 组件分类
|
* 组件分类
|
||||||
@ -208,6 +214,10 @@ export interface ComponentDescription extends ComponentMetadata {
|
|||||||
* @todo 待补充文档 @jinchan
|
* @todo 待补充文档 @jinchan
|
||||||
*/
|
*/
|
||||||
keywords: string[];
|
keywords: string[];
|
||||||
|
/**
|
||||||
|
* 替代 npm 字段的升级版本
|
||||||
|
*/
|
||||||
|
reference?: Reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
|
import { EitherOr } from './utils';
|
||||||
/**
|
/**
|
||||||
* npm 源引入完整描述对象
|
* npm 源引入完整描述对象
|
||||||
*/
|
*/
|
||||||
@ -33,6 +33,40 @@ export interface NpmInfo {
|
|||||||
main?: string;
|
main?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源引用信息,Npm 的升级版本,
|
||||||
|
*/
|
||||||
|
export type Reference = EitherOr<{
|
||||||
|
/**
|
||||||
|
* 引用资源的 id 标识
|
||||||
|
*/
|
||||||
|
id: string;
|
||||||
|
/**
|
||||||
|
* 引用资源的包名
|
||||||
|
*/
|
||||||
|
package: string;
|
||||||
|
/**
|
||||||
|
* 引用资源的导出对象中的属性值名称
|
||||||
|
*/
|
||||||
|
exportName: string;
|
||||||
|
/**
|
||||||
|
* 引用 exportName 上的子对象
|
||||||
|
*/
|
||||||
|
subName: string;
|
||||||
|
/**
|
||||||
|
* 引用的资源主入口
|
||||||
|
*/
|
||||||
|
main?: string;
|
||||||
|
/**
|
||||||
|
* 是否从引用资源的导出对象中获取属性值
|
||||||
|
*/
|
||||||
|
destructuring?: boolean;
|
||||||
|
/**
|
||||||
|
* 资源版本号
|
||||||
|
*/
|
||||||
|
version: string;
|
||||||
|
}, 'package', 'id'>;
|
||||||
|
|
||||||
export interface LowCodeComponentType {
|
export interface LowCodeComponentType {
|
||||||
/**
|
/**
|
||||||
* 研发模式
|
* 研发模式
|
||||||
|
|||||||
@ -15,3 +15,37 @@ export type ExternalUtils = {
|
|||||||
|
|
||||||
export type UtilItem = InternalUtils | ExternalUtils;
|
export type UtilItem = InternalUtils | ExternalUtils;
|
||||||
export type UtilsMap = UtilItem[];
|
export type UtilsMap = UtilItem[];
|
||||||
|
|
||||||
|
type FilterOptional<T> = Pick<
|
||||||
|
T,
|
||||||
|
Exclude<
|
||||||
|
{
|
||||||
|
[K in keyof T]: T extends Record<K, T[K]> ? K : never;
|
||||||
|
}[keyof T],
|
||||||
|
undefined
|
||||||
|
>
|
||||||
|
>;
|
||||||
|
|
||||||
|
type FilterNotOptional<T> = Pick<
|
||||||
|
T,
|
||||||
|
Exclude<
|
||||||
|
{
|
||||||
|
[K in keyof T]: T extends Record<K, T[K]> ? never : K;
|
||||||
|
}[keyof T],
|
||||||
|
undefined
|
||||||
|
>
|
||||||
|
>;
|
||||||
|
|
||||||
|
type PartialEither<T, K extends keyof any> = { [P in Exclude<keyof FilterOptional<T>, K>]-?: T[P] } &
|
||||||
|
{ [P in Exclude<keyof FilterNotOptional<T>, K>]?: T[P] } &
|
||||||
|
{ [P in Extract<keyof T, K>]?: undefined };
|
||||||
|
|
||||||
|
type Object = {
|
||||||
|
[name: string]: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EitherOr<O extends Object, L extends string, R extends string> =
|
||||||
|
(
|
||||||
|
PartialEither<Pick<O, L | R>, L> |
|
||||||
|
PartialEither<Pick<O, L | R>, R>
|
||||||
|
) & Omit<O, L | R>;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user