Skip to content

Commit

Permalink
feat: add renderer-core codes
Browse files Browse the repository at this point in the history
  • Loading branch information
1ncounter committed Mar 19, 2024
1 parent 3ba0926 commit fb5de64
Show file tree
Hide file tree
Showing 66 changed files with 2,002 additions and 919 deletions.
772 changes: 378 additions & 394 deletions docs/docs/specs/lowcode-spec.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"lerna": "^4.0.0",
"typescript": "^5.4.2",
"yarn": "^1.22.17",
"prettier": "^3.2.5",
"rimraf": "^3.0.2",
"rollup": "^4.13.0",
"vite": "^5.1.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alilc/lowcode-types",
"version": "1.3.2",
"version": "1.3.3",
"description": "Types for Ali lowCode engine",
"files": [
"es",
Expand Down
16 changes: 11 additions & 5 deletions packages/types/src/shell/type/context-menu.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { IPublicEnumContextMenuType } from '../enum';
import { IPublicModelNode } from '../model';
import { IPublicTypeI18nData } from './i8n-data';
import { IPublicTypeI18nData } from './i18n-data';
import { IPublicTypeHelpTipConfig } from './widget-base-config';

export interface IPublicTypeContextMenuItem extends Omit<IPublicTypeContextMenuAction, 'condition' | 'disabled' | 'items'> {
export interface IPublicTypeContextMenuItem
extends Omit<
IPublicTypeContextMenuAction,
'condition' | 'disabled' | 'items'
> {
disabled?: boolean;

items?: Omit<IPublicTypeContextMenuItem, 'items'>[];
}

export interface IPublicTypeContextMenuAction {

/**
* 动作的唯一标识符
* Unique identifier for the action
Expand Down Expand Up @@ -41,7 +44,11 @@ export interface IPublicTypeContextMenuAction {
* 子菜单项或生成子节点的函数,可选,仅支持两级
* Sub-menu items or function to generate child node, optional
*/
items?: Omit<IPublicTypeContextMenuAction, 'items'>[] | ((nodes?: IPublicModelNode[]) => Omit<IPublicTypeContextMenuAction, 'items'>[]);
items?:
| Omit<IPublicTypeContextMenuAction, 'items'>[]
| ((
nodes?: IPublicModelNode[],
) => Omit<IPublicTypeContextMenuAction, 'items'>[]);

/**
* 显示条件函数
Expand All @@ -60,4 +67,3 @@ export interface IPublicTypeContextMenuAction {
*/
help?: IPublicTypeHelpTipConfig;
}

File renamed without changes.
4 changes: 2 additions & 2 deletions packages/types/src/shell/type/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export * from './widget-base-config';
export * from './node-data';
export * from './icon-type';
export * from './transformed-component-metadata';
export * from './i8n-data';
export * from './i18n-data';
export * from './npm-info';
export * from './drag-node-data-object';
export * from './drag-node-object';
Expand Down Expand Up @@ -93,4 +93,4 @@ export * from './scrollable';
export * from './simulator-renderer';
export * from './config-transducer';
export * from './context-menu';
export * from './command';
export * from './command';
4 changes: 3 additions & 1 deletion packages/types/src/shell/type/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ export interface IPublicTypeLowCodeComponent {
}

export type IPublicTypeProCodeComponent = IPublicTypeNpmInfo;
export type IPublicTypeComponentMap = IPublicTypeProCodeComponent | IPublicTypeLowCodeComponent;
export type IPublicTypeComponentMap =
| IPublicTypeProCodeComponent
| IPublicTypeLowCodeComponent;
export type IPublicTypeComponentsMap = IPublicTypeComponentMap[];
7 changes: 7 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
input: 'src/main.js',
output: {
file: 'bundle.js',
format: 'cjs'
}
};
11 changes: 0 additions & 11 deletions runtime/react-renderer/package.json

This file was deleted.

65 changes: 0 additions & 65 deletions runtime/react-renderer/src/api/create-app.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions runtime/react-renderer/tsconfig.json

This file was deleted.

Empty file.
6 changes: 6 additions & 0 deletions runtime/renderer-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"type": "module",
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
"homepage": "https://github.com/alibaba/lowcode-engine/#readme",
"license": "MIT",
"scripts": {
"build": "",
"test": "vitest --run",
"test:watch": "vitest"
},
"dependencies": {
"@alilc/lowcode-types": "1.3.2",
"lodash-es": "^4.17.21"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import {
type ProjectSchema,
type Package,
type AnyObject,
} from '@alilc/runtime-shared';
import { type PackageManager, createPackageManager } from '../core/package';
import { createPluginManager, type Plugin } from '../core/plugin';
import { createScope, type CodeScope } from '../core/codeRuntime';
import {
appBoosts,
type AppBoosts,
type AppBoostsManager,
} from '../core/boosts';
import { type AppSchema, createAppSchema } from '../core/schema';
import type { Project, Package, PlainObject } from '../types';
import { type PackageManager, createPackageManager } from '../package';
import { createPluginManager, type Plugin } from '../plugin';
import { createScope, type CodeScope } from '../code-runtime';
import { appBoosts, type AppBoosts, type AppBoostsManager } from '../boosts';
import { type AppSchema, createAppSchema } from '../schema';

export interface AppOptionsBase {
schema: ProjectSchema;
schema: Project;
packages?: Package[];
plugins?: Plugin[];
appScopeValue?: AnyObject;
appScopeValue?: PlainObject;
}

export interface RenderBase {
export interface AppBase {
mount: (el: HTMLElement) => void | Promise<void>;
unmount: () => void | Promise<void>;
}
Expand All @@ -36,13 +28,13 @@ export interface AppContext {
boosts: AppBoostsManager;
}

type AppCreator<O, T> = (
type AppCreator<O, T extends AppBase> = (
appContext: Omit<AppContext, 'renderer'>,
appOptions: O
) => Promise<{ renderBase: T; renderer?: any }>;
appOptions: O,
) => Promise<{ appBase: T; renderer?: any }>;

export type App<T extends RenderBase = RenderBase> = {
schema: ProjectSchema;
export type App<T extends AppBase = AppBase> = {
schema: Project;
config: Map<string, any>;
readonly boosts: AppBoosts;

Expand All @@ -55,11 +47,14 @@ export type App<T extends RenderBase = RenderBase> = {
* @param options
* @returns
*/
export function createAppFunction<
O extends AppOptionsBase,
T extends RenderBase = RenderBase
>(appCreator: AppCreator<O, T>): (options: O) => Promise<App<T>> {
return async options => {
export function createAppFunction<O extends AppOptionsBase, T extends AppBase = AppBase>(
appCreator: AppCreator<O, T>,
): (options: O) => Promise<App<T>> {
if (typeof appCreator !== 'function') {
throw Error('The first parameter must be a function.');
}

return async (options) => {
const { schema, appScopeValue = {} } = options;
const appSchema = createAppSchema(schema);
const appConfig = new Map<string, any>();
Expand All @@ -77,14 +72,19 @@ export function createAppFunction<
boosts: appBoosts,
};

const { renderBase, renderer } = await appCreator(appContext, options);
const { appBase, renderer } = await appCreator(appContext, options);

if (!('mount' in appBase) || !('unmount' in appBase)) {
throw Error('appBase 必须返回 mount 和 unmount 方法');
}

const pluginManager = createPluginManager({
...appContext,
renderer,
});

if (options.plugins?.length) {
await Promise.all(options.plugins.map(p => pluginManager.add(p)));
await Promise.all(options.plugins.map((p) => pluginManager.add(p)));
}

if (options.packages?.length) {
Expand All @@ -100,7 +100,7 @@ export function createAppFunction<
return appBoosts.value;
},
},
renderBase
appBase,
);
};
}
Loading

0 comments on commit fb5de64

Please sign in to comment.