mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-11 18:42:56 +00:00
refactor(editor-core): refactor codes
This commit is contained in:
parent
35db123cbf
commit
1f1da44199
@ -223,7 +223,7 @@ delete(pluginName: string): void;
|
||||
*/
|
||||
getPluginPreference(
|
||||
pluginName: string,
|
||||
): Record<string, IPublicTypePreferenceValueType> | null | undefined;
|
||||
): Record<string, IPublicTypePluginPreferenceValueType> | null | undefined;
|
||||
```
|
||||
|
||||
## 相关类型定义
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@alilc/lowcode-editor-core": "workspace:*",
|
||||
"@alilc/lowcode-shared": "workspace:*",
|
||||
"@alilc/lowcode-types": "workspace:*",
|
||||
"@alilc/lowcode-utils": "workspace:*",
|
||||
"@alifd/next": "^1.27.8",
|
||||
@ -55,6 +56,7 @@
|
||||
"peerDependencies": {
|
||||
"@alifd/next": "^1.27.8",
|
||||
"@alilc/lowcode-editor-core": "workspace:*",
|
||||
"@alilc/lowcode-shared": "workspace:*",
|
||||
"@alilc/lowcode-types": "workspace:*",
|
||||
"@alilc/lowcode-utils": "workspace:*",
|
||||
"react": "^18.2.0",
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
import * as React from 'react';
|
||||
import { Component, Fragment, ReactElement, PureComponent } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { computed, observer, Title, globalLocale } from '@alilc/lowcode-editor-core';
|
||||
import { computed, observer, globalLocale } from '@alilc/lowcode-editor-core';
|
||||
import { IPublicTypeI18nData, IPublicTypeTitleContent } from '@alilc/lowcode-types';
|
||||
import { isI18nData } from '@alilc/lowcode-utils';
|
||||
import { DropLocation } from '../../designer';
|
||||
import { BuiltinSimulatorHost } from '../../builtin-simulator/host';
|
||||
import { INode } from '../../document/node';
|
||||
import { Title } from '../../widgets';
|
||||
|
||||
export class BorderContainerInstance extends PureComponent<{
|
||||
title: IPublicTypeTitleContent;
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { Component, Fragment, PureComponent } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { computed, observer, Title } from '@alilc/lowcode-editor-core';
|
||||
import { computed, observer } from '@alilc/lowcode-editor-core';
|
||||
import { IPublicTypeTitleContent } from '@alilc/lowcode-types';
|
||||
import { getClosestNode } from '@alilc/lowcode-utils';
|
||||
import { intl } from '../../locale';
|
||||
import { BuiltinSimulatorHost } from '../host';
|
||||
import { Title } from '../../widgets';
|
||||
|
||||
export class BorderDetectingInstance extends PureComponent<{
|
||||
title: IPublicTypeTitleContent;
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import { Overlay } from '@alifd/next';
|
||||
import React, { MouseEvent } from 'react';
|
||||
import { Title, observer } from '@alilc/lowcode-editor-core';
|
||||
import { observer } from '@alilc/lowcode-editor-core';
|
||||
import { canClickNode } from '@alilc/lowcode-utils';
|
||||
import { INode } from '../../document';
|
||||
import { Title } from '../../widgets';
|
||||
|
||||
import './index.less';
|
||||
|
||||
const { Popup } = Overlay;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { observable, computed, makeObservable, action } from '@alilc/lowcode-editor-core';
|
||||
import { Point, ScrollTarget } from '../designer';
|
||||
import { AutoFit, IViewport } from '../simulator';
|
||||
import { AutoFit, AUTO_FIT, IViewport } from '../simulator';
|
||||
|
||||
export default class Viewport implements IViewport {
|
||||
@observable.ref private rect?: DOMRect;
|
||||
@ -92,9 +92,9 @@ export default class Viewport implements IViewport {
|
||||
this._contentHeight = this.height / this.scale;
|
||||
}
|
||||
|
||||
@observable.ref private _contentWidth: number | AutoFit = AutoFit;
|
||||
@observable.ref private _contentWidth: number | AutoFit = AUTO_FIT;
|
||||
|
||||
@observable.ref private _contentHeight: number | AutoFit = AutoFit;
|
||||
@observable.ref private _contentHeight: number | AutoFit = AUTO_FIT;
|
||||
|
||||
@computed get contentHeight(): number | AutoFit {
|
||||
return this._contentHeight;
|
||||
|
||||
@ -150,7 +150,9 @@ export class ComponentActions {
|
||||
) {
|
||||
transducer.level = level;
|
||||
transducer.id = id;
|
||||
const i = this.metadataTransducers.findIndex((item) => item.level != null && item.level > level);
|
||||
const i = this.metadataTransducers.findIndex(
|
||||
(item) => item.level != null && item.level > level
|
||||
);
|
||||
if (i < 0) {
|
||||
this.metadataTransducers.push(transducer);
|
||||
} else {
|
||||
|
||||
@ -4,6 +4,7 @@ import {
|
||||
IPublicTypeContextMenuItem,
|
||||
IPublicApiMaterial,
|
||||
IPublicModelPluginContext,
|
||||
IPublicTypeDisposable
|
||||
} from '@alilc/lowcode-types';
|
||||
import { IDesigner, INode } from './designer';
|
||||
import {
|
||||
@ -12,16 +13,18 @@ import {
|
||||
parseContextMenuProperties,
|
||||
uniqueId,
|
||||
} from '@alilc/lowcode-utils';
|
||||
import { type AnyFunction } from '@alilc/lowcode-shared';
|
||||
import { Menu } from '@alifd/next';
|
||||
import { engineConfig } from '@alilc/lowcode-editor-core';
|
||||
import './context-menu-actions.scss';
|
||||
|
||||
let adjustMenuLayoutFn: Function = (actions: IPublicTypeContextMenuAction[]) => actions;
|
||||
import './context-menu-actions.less';
|
||||
|
||||
let adjustMenuLayoutFn: AnyFunction = (actions: IPublicTypeContextMenuAction[]) => actions;
|
||||
|
||||
export class GlobalContextMenuActions {
|
||||
enableContextMenu: boolean;
|
||||
|
||||
dispose: Function[];
|
||||
dispose: IPublicTypeDisposable[];
|
||||
|
||||
contextMenuActionsMap: Map<string, ContextMenuActions> = new Map();
|
||||
|
||||
@ -50,7 +53,7 @@ export class GlobalContextMenuActions {
|
||||
actions.push(...contextMenu.actions);
|
||||
});
|
||||
|
||||
let destroyFn: Function | undefined;
|
||||
let destroyFn: AnyFunction | undefined = undefined;
|
||||
|
||||
const destroy = () => {
|
||||
destroyFn?.();
|
||||
@ -79,8 +82,7 @@ export class GlobalContextMenuActions {
|
||||
});
|
||||
|
||||
const target = event.target;
|
||||
|
||||
const { top, left } = (target as any)?.getBoundingClientRect();
|
||||
const { top, left } = (target as any).getBoundingClientRect();
|
||||
|
||||
const menuInstance = Menu.create({
|
||||
target: event.target,
|
||||
@ -120,7 +122,7 @@ export class ContextMenuActions {
|
||||
|
||||
designer: IDesigner;
|
||||
|
||||
dispose: Function[];
|
||||
dispose: AnyFunction[];
|
||||
|
||||
enableContextMenu: boolean;
|
||||
|
||||
@ -154,7 +156,7 @@ export class ContextMenuActions {
|
||||
const { bounds } = designer.project.simulator?.viewport || { bounds: { left: 0, top: 0 } };
|
||||
const { left: simulatorLeft, top: simulatorTop } = bounds;
|
||||
|
||||
let destroyFn: Function | undefined;
|
||||
let destroyFn: AnyFunction | undefined = undefined;
|
||||
|
||||
const destroy = () => {
|
||||
destroyFn?.();
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
import { Component, ReactElement } from 'react';
|
||||
import { observer, observable, Title, makeObservable, action } from '@alilc/lowcode-editor-core';
|
||||
import { Designer } from '../designer';
|
||||
import { isSimulatorHost } from '../../simulator';
|
||||
import './ghost.less';
|
||||
import { observer, observable, makeObservable, action } from '@alilc/lowcode-editor-core';
|
||||
import {
|
||||
IPublicTypeI18nData,
|
||||
IPublicTypeNodeSchema,
|
||||
IPublicModelDragObject,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { isDragNodeObject } from '@alilc/lowcode-utils';
|
||||
import { Designer } from '../designer';
|
||||
import { isSimulatorHost } from '../../simulator';
|
||||
import { Title } from '../../widgets';
|
||||
|
||||
import './ghost.less';
|
||||
|
||||
type offBinding = () => any;
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ import { valueToSource } from './value-to-source';
|
||||
import { IPropParent } from './props';
|
||||
import type { IProps } from './props';
|
||||
import { ISlotNode, INode } from '../node';
|
||||
// import { TransformStage } from '../transform-stage';
|
||||
|
||||
const { set: mobxSet, isObservableArray } = mobx;
|
||||
export const UNSET = Symbol.for('unset');
|
||||
|
||||
@ -5,7 +5,6 @@ import { uniqueId, compatStage } from '@alilc/lowcode-utils';
|
||||
import { Prop, UNSET } from './prop';
|
||||
import type { IProp } from './prop';
|
||||
import { INode } from '../node';
|
||||
// import { TransformStage } from '../transform-stage';
|
||||
|
||||
interface ExtrasObject {
|
||||
[key: string]: any;
|
||||
|
||||
@ -4,6 +4,6 @@ export * from './designer';
|
||||
export * from './document';
|
||||
export * from './project';
|
||||
export * from './builtin-simulator';
|
||||
export * from './plugin';
|
||||
export * from './types';
|
||||
export * from './context-menu-actions';
|
||||
export * from './widgets';
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
export * from './plugin-context';
|
||||
export * from './plugin-manager';
|
||||
export * from './plugin-types';
|
||||
export * from './plugin';
|
||||
@ -1,89 +0,0 @@
|
||||
/* eslint-disable no-multi-assign */
|
||||
import { engineConfig, createModuleEventBus } from '@alilc/lowcode-editor-core';
|
||||
import {
|
||||
IPublicApiHotkey,
|
||||
IPublicApiProject,
|
||||
IPublicApiSkeleton,
|
||||
IPublicApiSetters,
|
||||
IPublicApiMaterial,
|
||||
IPublicApiEvent,
|
||||
IPublicApiCommon,
|
||||
IPublicModelPluginContext,
|
||||
IPluginPreferenceMananger,
|
||||
IPublicTypePreferenceValueType,
|
||||
IPublicModelEngineConfig,
|
||||
IPublicApiLogger,
|
||||
IPublicApiPlugins,
|
||||
IPublicTypePluginDeclaration,
|
||||
IPublicApiCanvas,
|
||||
IPublicApiWorkspace,
|
||||
IPublicEnumPluginRegisterLevel,
|
||||
IPublicModelWindow,
|
||||
IPublicApiCommonUI,
|
||||
IPublicApiCommand,
|
||||
} from '@alilc/lowcode-types';
|
||||
import {
|
||||
IPluginContextOptions,
|
||||
ILowCodePluginContextApiAssembler,
|
||||
ILowCodePluginContextPrivate,
|
||||
} from './plugin-types';
|
||||
import { isValidPreferenceKey } from './plugin-utils';
|
||||
|
||||
export default class PluginContext implements
|
||||
IPublicModelPluginContext, ILowCodePluginContextPrivate {
|
||||
hotkey: IPublicApiHotkey;
|
||||
project: IPublicApiProject;
|
||||
skeleton: IPublicApiSkeleton;
|
||||
setters: IPublicApiSetters;
|
||||
material: IPublicApiMaterial;
|
||||
event: IPublicApiEvent;
|
||||
config: IPublicModelEngineConfig;
|
||||
common: IPublicApiCommon;
|
||||
logger: IPublicApiLogger;
|
||||
plugins: IPublicApiPlugins;
|
||||
preference: IPluginPreferenceMananger;
|
||||
pluginEvent: IPublicApiEvent;
|
||||
canvas: IPublicApiCanvas;
|
||||
workspace: IPublicApiWorkspace;
|
||||
registerLevel: IPublicEnumPluginRegisterLevel;
|
||||
editorWindow: IPublicModelWindow;
|
||||
commonUI: IPublicApiCommonUI;
|
||||
isPluginRegisteredInWorkspace: false;
|
||||
command: IPublicApiCommand;
|
||||
|
||||
constructor(
|
||||
options: IPluginContextOptions,
|
||||
contextApiAssembler: ILowCodePluginContextApiAssembler,
|
||||
) {
|
||||
const { pluginName = 'anonymous', meta = {} } = options;
|
||||
contextApiAssembler.assembleApis(this, pluginName, meta);
|
||||
this.pluginEvent = createModuleEventBus(pluginName, 200);
|
||||
const enhancePluginContextHook = engineConfig.get('enhancePluginContextHook');
|
||||
if (enhancePluginContextHook) {
|
||||
enhancePluginContextHook(this);
|
||||
}
|
||||
}
|
||||
|
||||
setPreference(
|
||||
pluginName: string,
|
||||
preferenceDeclaration: IPublicTypePluginDeclaration,
|
||||
): void {
|
||||
const getPreferenceValue = (
|
||||
key: string,
|
||||
defaultValue?: IPublicTypePreferenceValueType,
|
||||
): IPublicTypePreferenceValueType | undefined => {
|
||||
if (!isValidPreferenceKey(key, preferenceDeclaration)) {
|
||||
return undefined;
|
||||
}
|
||||
const pluginPreference = this.plugins.getPluginPreference(pluginName) || {};
|
||||
if (pluginPreference[key] === undefined || pluginPreference[key] === null) {
|
||||
return defaultValue;
|
||||
}
|
||||
return pluginPreference[key];
|
||||
};
|
||||
|
||||
this.preference = {
|
||||
getPreferenceValue,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,104 +0,0 @@
|
||||
import {
|
||||
IPublicApiHotkey,
|
||||
IPublicApiProject,
|
||||
IPublicApiSkeleton,
|
||||
IPublicApiSetters,
|
||||
IPublicApiMaterial,
|
||||
IPublicApiEvent,
|
||||
IPublicApiCommon,
|
||||
IPublicApiPlugins,
|
||||
IPublicTypePluginConfig,
|
||||
IPublicApiLogger,
|
||||
IPublicTypePreferenceValueType,
|
||||
IPublicModelEngineConfig,
|
||||
IPublicTypePlugin,
|
||||
IPublicApiCanvas,
|
||||
IPublicApiWorkspace,
|
||||
IPublicTypePluginMeta,
|
||||
IPublicTypePluginRegisterOptions,
|
||||
IPublicModelWindow,
|
||||
IPublicEnumPluginRegisterLevel,
|
||||
IPublicApiCommonUI,
|
||||
IPublicApiCommand,
|
||||
} from '@alilc/lowcode-types';
|
||||
import PluginContext from './plugin-context';
|
||||
|
||||
export type PluginPreference = Map<string, Record<string, IPublicTypePreferenceValueType>>;
|
||||
|
||||
export interface ILowCodePluginRuntimeCore {
|
||||
name: string;
|
||||
dep: string[];
|
||||
disabled: boolean;
|
||||
config: IPublicTypePluginConfig;
|
||||
logger: IPublicApiLogger;
|
||||
meta: IPublicTypePluginMeta;
|
||||
init(forceInit?: boolean): void;
|
||||
isInited(): boolean;
|
||||
destroy(): void;
|
||||
toProxy(): any;
|
||||
setDisabled(flag: boolean): void;
|
||||
}
|
||||
|
||||
interface ILowCodePluginRuntimeExportsAccessor {
|
||||
[propName: string]: any;
|
||||
}
|
||||
|
||||
export type ILowCodePluginRuntime =
|
||||
ILowCodePluginRuntimeCore & ILowCodePluginRuntimeExportsAccessor;
|
||||
|
||||
export interface ILowCodePluginContextPrivate {
|
||||
set hotkey(hotkey: IPublicApiHotkey);
|
||||
set project(project: IPublicApiProject);
|
||||
set skeleton(skeleton: IPublicApiSkeleton);
|
||||
set setters(setters: IPublicApiSetters);
|
||||
set material(material: IPublicApiMaterial);
|
||||
set event(event: IPublicApiEvent);
|
||||
set config(config: IPublicModelEngineConfig);
|
||||
set common(common: IPublicApiCommon);
|
||||
set plugins(plugins: IPublicApiPlugins);
|
||||
set logger(plugins: IPublicApiLogger);
|
||||
set pluginEvent(event: IPublicApiEvent);
|
||||
set canvas(canvas: IPublicApiCanvas);
|
||||
set workspace(workspace: IPublicApiWorkspace);
|
||||
set editorWindow(window: IPublicModelWindow);
|
||||
set registerLevel(level: IPublicEnumPluginRegisterLevel);
|
||||
set isPluginRegisteredInWorkspace(flag: boolean);
|
||||
set commonUI(commonUI: IPublicApiCommonUI);
|
||||
set command(command: IPublicApiCommand);
|
||||
}
|
||||
export interface ILowCodePluginContextApiAssembler {
|
||||
assembleApis(
|
||||
context: ILowCodePluginContextPrivate,
|
||||
pluginName: string,
|
||||
meta: IPublicTypePluginMeta,
|
||||
): void;
|
||||
}
|
||||
|
||||
interface ILowCodePluginManagerPluginAccessor {
|
||||
[pluginName: string]: ILowCodePluginRuntime | any;
|
||||
}
|
||||
|
||||
export interface ILowCodePluginManagerCore {
|
||||
register(
|
||||
pluginModel: IPublicTypePlugin,
|
||||
pluginOptions?: any,
|
||||
options?: IPublicTypePluginRegisterOptions,
|
||||
): Promise<void>;
|
||||
init(
|
||||
pluginPreference?: Map<string, Record<string, IPublicTypePreferenceValueType>>
|
||||
): Promise<void>;
|
||||
get(pluginName: string): ILowCodePluginRuntime | undefined;
|
||||
getAll(): ILowCodePluginRuntime[];
|
||||
has(pluginName: string): boolean;
|
||||
delete(pluginName: string): any;
|
||||
setDisabled(pluginName: string, flag: boolean): void;
|
||||
dispose(): void;
|
||||
_getLowCodePluginContext (options: IPluginContextOptions): PluginContext;
|
||||
}
|
||||
|
||||
export type ILowCodePluginManager = ILowCodePluginManagerCore & ILowCodePluginManagerPluginAccessor;
|
||||
|
||||
export interface IPluginContextOptions {
|
||||
pluginName: string;
|
||||
meta?: IPublicTypePluginMeta;
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
import { isPlainObject } from 'lodash-es';
|
||||
import {
|
||||
IPublicTypePluginRegisterOptions,
|
||||
IPublicTypePluginDeclaration,
|
||||
} from '@alilc/lowcode-types';
|
||||
|
||||
export function isValidPreferenceKey(
|
||||
key: string,
|
||||
preferenceDeclaration: IPublicTypePluginDeclaration,
|
||||
): boolean {
|
||||
if (!preferenceDeclaration || !Array.isArray(preferenceDeclaration.properties)) {
|
||||
return false;
|
||||
}
|
||||
return preferenceDeclaration.properties.some((prop) => {
|
||||
return prop.key === key;
|
||||
});
|
||||
}
|
||||
|
||||
export function isLowCodeRegisterOptions(opts: any): opts is IPublicTypePluginRegisterOptions {
|
||||
return opts && ('autoInit' in opts || 'override' in opts);
|
||||
}
|
||||
|
||||
export function filterValidOptions(opts: any, preferenceDeclaration: IPublicTypePluginDeclaration) {
|
||||
if (!opts || !isPlainObject(opts)) return opts;
|
||||
const filteredOpts = {} as any;
|
||||
Object.keys(opts).forEach((key) => {
|
||||
if (isValidPreferenceKey(key, preferenceDeclaration)) {
|
||||
const v = opts[key];
|
||||
if (v !== undefined && v !== null) {
|
||||
filteredOpts[key] = v;
|
||||
}
|
||||
}
|
||||
});
|
||||
return filteredOpts;
|
||||
}
|
||||
@ -2,6 +2,7 @@ import { Component } from 'react';
|
||||
import { observer, engineConfig } from '@alilc/lowcode-editor-core';
|
||||
import { Designer } from '../designer';
|
||||
import { BuiltinSimulatorHostView } from '../builtin-simulator';
|
||||
|
||||
import './project.less';
|
||||
|
||||
export class BuiltinLoading extends Component {
|
||||
|
||||
@ -6,8 +6,7 @@ import { INode } from './document';
|
||||
import { IProject } from './project';
|
||||
|
||||
export type AutoFit = '100%';
|
||||
// eslint-disable-next-line no-redeclare
|
||||
export const AutoFit = '100%';
|
||||
export const AUTO_FIT: AutoFit = '100%';
|
||||
|
||||
export interface IScrollable extends IPublicTypeScrollable {
|
||||
}
|
||||
|
||||
@ -1,20 +1,9 @@
|
||||
import { isFormEvent, compatibleLegaoSchema, getNodeSchemaById, isNodeSchema } from '@alilc/lowcode-utils';
|
||||
|
||||
export type NodeRemoveOptions = {
|
||||
suppressRemoveEvent?: boolean;
|
||||
};
|
||||
|
||||
export const utils = {
|
||||
isNodeSchema,
|
||||
isFormEvent,
|
||||
compatibleLegaoSchema,
|
||||
getNodeSchemaById,
|
||||
};
|
||||
|
||||
export enum EDITOR_EVENT {
|
||||
NODE_CHILDREN_CHANGE = 'node.children.change',
|
||||
|
||||
NODE_VISIBLE_CHANGE = 'node.visible.change',
|
||||
}
|
||||
|
||||
export type Utils = typeof utils;
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
export * from './invariant';
|
||||
export * from './slot';
|
||||
export * from './tree';
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
// TODO move another place
|
||||
export * from './tip';
|
||||
export * from './title';
|
||||
@ -8,6 +8,7 @@ import {
|
||||
} from '@alilc/lowcode-types';
|
||||
import { intl } from '../../intl';
|
||||
import { Tip } from '../tip';
|
||||
|
||||
import './title.less';
|
||||
|
||||
/**
|
||||
@ -41,12 +42,7 @@ function splitLabelByKeywords(label: string, keywords: string): string[] {
|
||||
}
|
||||
|
||||
export class Title extends Component<IPublicTypeTitleProps> {
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
}
|
||||
|
||||
handleClick(e: React.MouseEvent) {
|
||||
handleClick = (e: React.MouseEvent) => {
|
||||
const { title, onClick } = this.props as any;
|
||||
const url = title && (title.docUrl || title.url);
|
||||
if (url) {
|
||||
@ -56,7 +52,7 @@ export class Title extends Component<IPublicTypeTitleProps> {
|
||||
}
|
||||
// TODO: 操作交互冲突,目前 mixedSetter 仅有 2 个 setter 注册时用到了 onClick
|
||||
onClick && onClick(e);
|
||||
}
|
||||
};
|
||||
|
||||
renderLabel = (label: string | IPublicTypeI18nData | ReactNode) => {
|
||||
const { match, keywords } = this.props;
|
||||
@ -34,8 +34,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@alifd/next": "^1.27.8",
|
||||
"@alilc/lowcode-types": "workspace:*",
|
||||
"@alilc/lowcode-utils": "workspace:*",
|
||||
"@alilc/lowcode-shared": "workspace:*",
|
||||
"classnames": "^2.5.1",
|
||||
"intl-messageformat": "^10.5.1",
|
||||
"lodash-es": "^4.17.21",
|
||||
@ -44,8 +43,8 @@
|
||||
"power-di": "^2.4.4",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"semver": "^7.6.0",
|
||||
"store": "^2.0.12",
|
||||
"strict-event-emitter-types": "^2.0.0",
|
||||
"events": "^3.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -53,12 +52,12 @@
|
||||
"@types/react": "^18.2.0",
|
||||
"@types/react-dom": "^18.2.0",
|
||||
"@types/store": "^2.0.2",
|
||||
"@types/semver": "^7.5.8",
|
||||
"less": "^4.2.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@alifd/next": "^1.27.8",
|
||||
"@alilc/lowcode-types": "workspace:*",
|
||||
"@alilc/lowcode-utils": "workspace:*",
|
||||
"@alilc/lowcode-shared": "workspace:*",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
},
|
||||
|
||||
@ -1,17 +1,76 @@
|
||||
import { IPublicApiCommand, IPublicEnumTransitionType, IPublicModelPluginContext, IPublicTypeCommand, IPublicTypeCommandHandlerArgs, IPublicTypeListCommand } from '@alilc/lowcode-types';
|
||||
import { checkPropTypes } from '@alilc/lowcode-utils';
|
||||
import { type AnyFunction } from '@alilc/lowcode-shared';
|
||||
|
||||
export interface ICommand extends Command {}
|
||||
export interface Command {
|
||||
/**
|
||||
* 命令名称
|
||||
* 命名规则:commandName
|
||||
* 使用规则:commandScope:commandName (commandScope 在插件 meta 中定义,用于区分不同插件的命令)
|
||||
*/
|
||||
name: string;
|
||||
|
||||
export interface ICommandOptions {
|
||||
/**
|
||||
* 命令参数
|
||||
*/
|
||||
parameters?: CommandParameter[];
|
||||
|
||||
/**
|
||||
* 命令描述
|
||||
*/
|
||||
description?: string;
|
||||
|
||||
/**
|
||||
* 命令处理函数
|
||||
*/
|
||||
handler: (args: any) => void;
|
||||
}
|
||||
|
||||
export interface CommandParameter {
|
||||
/**
|
||||
* 参数名称
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* 参数类型或详细类型描述
|
||||
*/
|
||||
propType: string | IPublicTypePropType;
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
*/
|
||||
description: string;
|
||||
|
||||
/**
|
||||
* 参数默认值(可选)
|
||||
*/
|
||||
defaultValue?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义命令参数的接口
|
||||
*/
|
||||
export interface CommandHandlerArgs {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export type ListCommand = Pick<Command, 'name' | 'description' | 'parameters'>;
|
||||
|
||||
export interface CommandOptions {
|
||||
commandScope?: string;
|
||||
}
|
||||
|
||||
export class Command implements Omit<IPublicApiCommand, 'registerCommand' | 'batchExecuteCommand'> {
|
||||
private commands: Map<string, IPublicTypeCommand> = new Map();
|
||||
private commandErrors: Function[] = [];
|
||||
/**
|
||||
* 该模块使得与命令系统的交互成为可能,提供了一种全面的方式来处理、执行和管理应用程序中的命令。
|
||||
*/
|
||||
export class CommandManager {
|
||||
private commands: Map<string, Command> = new Map();
|
||||
private commandErrors: AnyFunction[] = [];
|
||||
|
||||
registerCommand(command: IPublicTypeCommand, options?: ICommandOptions): void {
|
||||
/**
|
||||
* 注册一个新命令及其处理函数
|
||||
*/
|
||||
registerCommand(command: Command, options?: CommandOptions): void {
|
||||
if (!options?.commandScope) {
|
||||
throw new Error('plugin meta.commandScope is required.');
|
||||
}
|
||||
@ -25,6 +84,9 @@ export class Command implements Omit<IPublicApiCommand, 'registerCommand' | 'bat
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销一个已存在的命令
|
||||
*/
|
||||
unregisterCommand(name: string): void {
|
||||
if (!this.commands.has(name)) {
|
||||
throw new Error(`Command '${name}' is not registered.`);
|
||||
@ -32,7 +94,10 @@ export class Command implements Omit<IPublicApiCommand, 'registerCommand' | 'bat
|
||||
this.commands.delete(name);
|
||||
}
|
||||
|
||||
executeCommand(name: string, args: IPublicTypeCommandHandlerArgs): void {
|
||||
/**
|
||||
* 通过名称和给定参数执行一个命令,会校验参数是否符合命令定义
|
||||
*/
|
||||
executeCommand(name: string, args: CommandHandlerArgs): void {
|
||||
const command = this.commands.get(name);
|
||||
if (!command) {
|
||||
throw new Error(`Command '${name}' is not registered.`);
|
||||
@ -53,8 +118,11 @@ export class Command implements Omit<IPublicApiCommand, 'registerCommand' | 'bat
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量执行命令,执行完所有命令后再进行一次重绘,历史记录中只会记录一次
|
||||
*/
|
||||
batchExecuteCommand(
|
||||
commands: { name: string; args: IPublicTypeCommandHandlerArgs }[],
|
||||
commands: { name: string; args: CommandHandlerArgs }[],
|
||||
pluginContext: IPublicModelPluginContext
|
||||
): void {
|
||||
if (!commands || !commands.length) {
|
||||
@ -65,9 +133,12 @@ export class Command implements Omit<IPublicApiCommand, 'registerCommand' | 'bat
|
||||
}, IPublicEnumTransitionType.REPAINT);
|
||||
}
|
||||
|
||||
listCommands(): IPublicTypeListCommand[] {
|
||||
/**
|
||||
* 列出所有已注册的命令
|
||||
*/
|
||||
listCommands(): ListCommand[] {
|
||||
return Array.from(this.commands.values()).map(d => {
|
||||
const result: IPublicTypeListCommand = {
|
||||
const result: ListCommand = {
|
||||
name: d.name,
|
||||
};
|
||||
|
||||
@ -83,6 +154,9 @@ export class Command implements Omit<IPublicApiCommand, 'registerCommand' | 'bat
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册错误处理回调函数
|
||||
*/
|
||||
onCommandError(callback: (name: string, error: Error) => void): void {
|
||||
this.commandErrors.push(callback);
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import { get as lodashGet } from 'lodash-es';
|
||||
import { isPlainObject, getLogger } from '@alilc/lowcode-utils';
|
||||
import { isPlainObject, createLogger } from '@alilc/lowcode-utils';
|
||||
import {
|
||||
IPublicTypeEngineOptions,
|
||||
IPublicModelEngineConfig,
|
||||
IPublicModelPreference,
|
||||
} from '@alilc/lowcode-types';
|
||||
import Preference from './utils/preference';
|
||||
import Preference from './preference';
|
||||
|
||||
const logger = getLogger({ level: 'log', bizName: 'config' });
|
||||
const logger = createLogger({ level: 'log', bizName: 'config' });
|
||||
|
||||
// this default behavior will be different later
|
||||
const STRICT_PLUGIN_MODE_DEFAULT = true;
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
export * from './setter';
|
||||
export * from './ioc-context';
|
||||
export * from '../widgets/tip/tip';
|
||||
@ -1,4 +1,4 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import EventEmitter from 'events';
|
||||
import { EventBus, IEventBus } from './event-bus';
|
||||
import {
|
||||
IPublicModelEditor,
|
||||
@ -12,12 +12,10 @@ import {
|
||||
} from '@alilc/lowcode-types';
|
||||
import { engineConfig } from './config';
|
||||
import { globalLocale } from './intl';
|
||||
import { observable } from './utils';
|
||||
import { observable } from './obx';
|
||||
import { IPublicTypeAssetsJson, AssetLoader } from '@alilc/lowcode-utils';
|
||||
import { assetsTransform } from './utils/assets-transform';
|
||||
|
||||
EventEmitter.defaultMaxListeners = 100;
|
||||
|
||||
// inner instance keys which should not be stored in config
|
||||
const keyBlacklist = [
|
||||
'designer',
|
||||
@ -31,23 +29,19 @@ const keyBlacklist = [
|
||||
'innerPlugins',
|
||||
];
|
||||
|
||||
const AssetsCache: {
|
||||
[key: string]: IPublicTypeRemoteComponentDescription;
|
||||
} = {};
|
||||
const AssetsCache: Record<string, IPublicTypeRemoteComponentDescription> = {};
|
||||
|
||||
export interface IEditor extends IPublicModelEditor {
|
||||
config?: EditorConfig;
|
||||
|
||||
components?: PluginClassSet;
|
||||
|
||||
eventBus: IEventBus;
|
||||
|
||||
init(config?: EditorConfig, components?: PluginClassSet): Promise<any>;
|
||||
}
|
||||
|
||||
export class Editor extends EventEmitter implements IEditor {
|
||||
/**
|
||||
* Ioc Container
|
||||
* ???
|
||||
*/
|
||||
@observable.shallow private context = new Map<IPublicTypeEditorValueKey, any>();
|
||||
|
||||
@ -61,8 +55,6 @@ export class Editor extends EventEmitter implements IEditor {
|
||||
|
||||
components?: PluginClassSet;
|
||||
|
||||
// readonly utils = utils;
|
||||
|
||||
private hooks: HookConfig[] = [];
|
||||
|
||||
private waits = new Map<
|
||||
@ -122,7 +114,6 @@ export class Editor extends EventEmitter implements IEditor {
|
||||
}
|
||||
});
|
||||
assets.components = componentDescriptions;
|
||||
assets.componentList = assets.componentList || [];
|
||||
|
||||
// 如果有远程组件描述协议,则自动加载并补充到资产包中,同时出发 designer.incrementalAssetsReady 通知组件面板更新数据
|
||||
if (remoteComponentDescriptions && remoteComponentDescriptions.length) {
|
||||
@ -143,7 +134,6 @@ export class Editor extends EventEmitter implements IEditor {
|
||||
AssetsCache[exportName] = component;
|
||||
function setAssetsComponent(component: any, extraNpmInfo: any = {}) {
|
||||
const components = component.components;
|
||||
assets.componentList = assets.componentList?.concat(component.componentList || []);
|
||||
if (Array.isArray(components)) {
|
||||
components.forEach((d) => {
|
||||
assets.components = assets.components.concat(
|
||||
|
||||
@ -2,6 +2,8 @@ import { IPublicApiEvent } from '@alilc/lowcode-types';
|
||||
import { Logger } from '@alilc/lowcode-utils';
|
||||
import EventEmitter from 'events';
|
||||
|
||||
EventEmitter.defaultMaxListeners = 100;
|
||||
|
||||
const logger = new Logger({ level: 'warn', bizName: 'event-bus' });
|
||||
const moduleLogger = new Logger({ level: 'warn', bizName: 'module-event-bus' });
|
||||
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* key event helper:https://www.toptal.com/developers/keycode
|
||||
*/
|
||||
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { globalContext } from './di';
|
||||
import {
|
||||
@ -226,7 +230,7 @@ function getReverseMap(): CtrlKeyMap {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (MAP.hasOwnProperty(key)) {
|
||||
if (Object.prototype.hasOwnProperty.call(MAP, key)) {
|
||||
REVERSE_MAP[MAP[key]] = key;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,9 @@ export * from './editor';
|
||||
export * from './utils';
|
||||
export * from './di';
|
||||
export * from './hotkey';
|
||||
export * from './widgets';
|
||||
export * from './config';
|
||||
export * from './event-bus';
|
||||
export * from './command';
|
||||
export * from './setter';
|
||||
export * from './plugin';
|
||||
export * from './obx';
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { IEventBus, createModuleEventBus } from '../event-bus';
|
||||
import { observable, computed } from '../utils/obx';
|
||||
import { Logger } from '@alilc/lowcode-utils';
|
||||
import { observable, computed } from '../obx';
|
||||
import { createLogger } from '@alilc/lowcode-shared';
|
||||
|
||||
const logger = new Logger({ level: 'warn', bizName: 'globalLocale' });
|
||||
const logger = createLogger({ level: 'warn', bizName: 'globalLocale' });
|
||||
|
||||
const languageMap: { [key: string]: string } = {
|
||||
en: 'en-US',
|
||||
|
||||
83
packages/editor-core/src/plugin/context.ts
Normal file
83
packages/editor-core/src/plugin/context.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import { type IEventBus, createModuleEventBus } from '../event-bus';
|
||||
import type { PluginMeta, PluginPreferenceValue, PluginDeclaration } from './plugin';
|
||||
import { type LowCodePluginManager } from './manager';
|
||||
import { isValidPreferenceKey } from './utils';
|
||||
import { engineConfig } from '../config';
|
||||
|
||||
export interface PluginContextOptions {
|
||||
pluginName: string;
|
||||
meta?: PluginMeta;
|
||||
}
|
||||
|
||||
export interface LowCodePluginContextApiAssembler<ContextExtra extends Record<string, any>> {
|
||||
assembleApis(
|
||||
context: LowCodePluginContext<ContextExtra>,
|
||||
pluginName: string,
|
||||
meta: PluginMeta,
|
||||
): void;
|
||||
}
|
||||
|
||||
export interface PluginPreferenceMananger {
|
||||
getPreferenceValue: (
|
||||
key: string,
|
||||
defaultValue?: PluginPreferenceValue,
|
||||
) => PluginPreferenceValue | undefined;
|
||||
}
|
||||
|
||||
export type LowCodePluginContext<ContextExtra extends Record<string, any>> = {
|
||||
pluginEvent: IEventBus;
|
||||
preference: PluginPreferenceMananger;
|
||||
setPreference(pluginName: string, preferenceDeclaration: PluginDeclaration): void;
|
||||
} & ContextExtra;
|
||||
|
||||
/**
|
||||
* create plugin context
|
||||
* todo: refactor setPreference
|
||||
*/
|
||||
export function createPluginContext<ContextExtra extends Record<string, any>>(
|
||||
options: PluginContextOptions,
|
||||
manager: LowCodePluginManager<ContextExtra>,
|
||||
contextApiAssembler: LowCodePluginContextApiAssembler<LowCodePluginContext<ContextExtra>>
|
||||
): LowCodePluginContext<ContextExtra> {
|
||||
const { pluginName = 'anonymous', meta = {} } = options;
|
||||
const pluginEvent = createModuleEventBus(pluginName, 200);
|
||||
|
||||
let _pluginName = pluginName;
|
||||
let _preferenceDeclaration: PluginDeclaration;
|
||||
|
||||
const preferenceMananger: PluginPreferenceMananger = {
|
||||
getPreferenceValue: (
|
||||
key,
|
||||
defaultValue?,
|
||||
) => {
|
||||
if (!isValidPreferenceKey(key, _preferenceDeclaration)) {
|
||||
return undefined;
|
||||
}
|
||||
const pluginPreference = manager.getPluginPreference(_pluginName) || {};
|
||||
if (pluginPreference[key] === undefined || pluginPreference[key] === null) {
|
||||
return defaultValue;
|
||||
}
|
||||
return pluginPreference[key];
|
||||
}
|
||||
};
|
||||
|
||||
const contextBase = {
|
||||
pluginEvent,
|
||||
preference: preferenceMananger,
|
||||
setPreference(
|
||||
pluginName: string,
|
||||
preferenceDeclaration: PluginDeclaration,
|
||||
): void {
|
||||
_pluginName = pluginName;
|
||||
_preferenceDeclaration = preferenceDeclaration;
|
||||
}
|
||||
} as LowCodePluginContext<ContextExtra>;
|
||||
|
||||
contextApiAssembler.assembleApis(contextBase, pluginName, meta);
|
||||
const enhancePluginContextHook = engineConfig.get('enhancePluginContextHook');
|
||||
if (enhancePluginContextHook) {
|
||||
enhancePluginContextHook(contextBase);
|
||||
}
|
||||
|
||||
return contextBase;
|
||||
}
|
||||
4
packages/editor-core/src/plugin/index.ts
Normal file
4
packages/editor-core/src/plugin/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './context';
|
||||
export * from './manager';
|
||||
export * from './runtime';
|
||||
export * from './plugin';
|
||||
@ -1,25 +1,17 @@
|
||||
import { engineConfig } from '@alilc/lowcode-editor-core';
|
||||
import { getLogger } from '@alilc/lowcode-utils';
|
||||
import { createLogger, invariant } from '@alilc/lowcode-shared';
|
||||
import { filterValidOptions, isLowCodeRegisterOptions, sequencify } from './utils';
|
||||
import { LowCodePluginRuntime } from './runtime';
|
||||
import { satisfies as semverSatisfies } from 'semver';
|
||||
import type { PluginCreater, PluginPreferenceValue, PluginPreference } from './plugin';
|
||||
import { engineConfig } from '../config';
|
||||
import {
|
||||
ILowCodePluginRuntime,
|
||||
ILowCodePluginManager,
|
||||
IPluginContextOptions,
|
||||
PluginPreference,
|
||||
ILowCodePluginContextApiAssembler,
|
||||
} from './plugin-types';
|
||||
import { filterValidOptions, isLowCodeRegisterOptions } from './plugin-utils';
|
||||
import { LowCodePluginRuntime } from './plugin';
|
||||
import LowCodePluginContext from './plugin-context';
|
||||
import { invariant } from '../utils';
|
||||
import sequencify from './sequencify';
|
||||
import semverSatisfies from 'semver/functions/satisfies';
|
||||
import {
|
||||
IPublicTypePluginRegisterOptions,
|
||||
IPublicTypePreferenceValueType,
|
||||
IPublicTypePlugin,
|
||||
} from '@alilc/lowcode-types';
|
||||
type LowCodePluginContext,
|
||||
type LowCodePluginContextApiAssembler,
|
||||
createPluginContext,
|
||||
PluginContextOptions
|
||||
} from './context';
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'designer:pluginManager' });
|
||||
const logger = createLogger({ level: 'warn', bizName: 'designer:pluginManager' });
|
||||
|
||||
// 保留的事件前缀
|
||||
const RESERVED_EVENT_PREFIX = [
|
||||
@ -42,28 +34,43 @@ const RESERVED_EVENT_PREFIX = [
|
||||
'context',
|
||||
];
|
||||
|
||||
export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
private plugins: ILowCodePluginRuntime[] = [];
|
||||
export interface PluginRegisterOptions {
|
||||
/**
|
||||
* Will enable plugin registered with auto-initialization immediately
|
||||
* other than plugin-manager init all plugins at certain time.
|
||||
* It is helpful when plugin register is later than plugin-manager initialization.
|
||||
*/
|
||||
autoInit?: boolean;
|
||||
/**
|
||||
* allow overriding existing plugin with same name when override === true
|
||||
*/
|
||||
override?: boolean;
|
||||
}
|
||||
|
||||
pluginsMap: Map<string, ILowCodePluginRuntime> = new Map();
|
||||
pluginContextMap: Map<string, LowCodePluginContext> = new Map();
|
||||
/**
|
||||
* plugin manager
|
||||
*/
|
||||
export class LowCodePluginManager<ContextExtra extends Record<string, any>> {
|
||||
private plugins: LowCodePluginRuntime<ContextExtra>[] = [];
|
||||
|
||||
private pluginsMap: Map<string, LowCodePluginRuntime<ContextExtra>> = new Map();
|
||||
|
||||
private pluginContextMap: Map<string, LowCodePluginContext<ContextExtra>> = new Map();
|
||||
|
||||
private pluginPreference?: PluginPreference = new Map();
|
||||
|
||||
contextApiAssembler: ILowCodePluginContextApiAssembler;
|
||||
|
||||
constructor(
|
||||
contextApiAssembler: ILowCodePluginContextApiAssembler,
|
||||
private contextApiAssembler: LowCodePluginContextApiAssembler<
|
||||
LowCodePluginContext<ContextExtra>
|
||||
>,
|
||||
readonly viewName = 'global',
|
||||
) {
|
||||
this.contextApiAssembler = contextApiAssembler;
|
||||
}
|
||||
) {}
|
||||
|
||||
_getLowCodePluginContext = (options: IPluginContextOptions) => {
|
||||
private _getLowCodePluginContext = (options: PluginContextOptions) => {
|
||||
const { pluginName } = options;
|
||||
let context = this.pluginContextMap.get(pluginName);
|
||||
if (!context) {
|
||||
context = new LowCodePluginContext(options, this.contextApiAssembler);
|
||||
context = createPluginContext(options, this, this.contextApiAssembler);
|
||||
this.pluginContextMap.set(pluginName, context);
|
||||
}
|
||||
return context;
|
||||
@ -83,9 +90,9 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
* @param registerOptions - the plugin register options
|
||||
*/
|
||||
async register(
|
||||
pluginModel: IPublicTypePlugin,
|
||||
pluginModel: PluginCreater<LowCodePluginContext<ContextExtra>>,
|
||||
options?: any,
|
||||
registerOptions?: IPublicTypePluginRegisterOptions,
|
||||
registerOptions?: PluginRegisterOptions,
|
||||
): Promise<void> {
|
||||
// registerOptions maybe in the second place
|
||||
if (isLowCodeRegisterOptions(options)) {
|
||||
@ -104,6 +111,7 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
`plugin ${pluginName} is trying to use ${eventPrefix} as event prefix, which is a reserved event prefix, please use another one`,
|
||||
);
|
||||
}
|
||||
|
||||
const ctx = this._getLowCodePluginContext({ pluginName, meta });
|
||||
const customFilterValidOptions = engineConfig.get(
|
||||
'customPluginFilterOptions',
|
||||
@ -136,7 +144,7 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
'plugin override, originalPlugin with name ',
|
||||
pluginName,
|
||||
' will be destroyed, config:',
|
||||
originalPlugin?.config,
|
||||
originalPlugin?.instance,
|
||||
);
|
||||
originalPlugin?.destroy();
|
||||
this.pluginsMap.delete(pluginName);
|
||||
@ -161,11 +169,11 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
logger.log(`plugin registered with pluginName: ${pluginName}, config: `, config, 'meta:', meta);
|
||||
}
|
||||
|
||||
get(pluginName: string): ILowCodePluginRuntime | undefined {
|
||||
get(pluginName: string): LowCodePluginRuntime<ContextExtra> | undefined {
|
||||
return this.pluginsMap.get(pluginName);
|
||||
}
|
||||
|
||||
getAll(): ILowCodePluginRuntime[] {
|
||||
getAll(): LowCodePluginRuntime<ContextExtra>[] {
|
||||
return this.plugins;
|
||||
}
|
||||
|
||||
@ -184,7 +192,7 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
|
||||
async init(pluginPreference?: PluginPreference) {
|
||||
const pluginNames: string[] = [];
|
||||
const pluginObj: { [name: string]: ILowCodePluginRuntime } = {};
|
||||
const pluginObj: { [name: string]: LowCodePluginRuntime<ContextExtra> } = {};
|
||||
this.pluginPreference = pluginPreference;
|
||||
this.plugins.forEach((plugin) => {
|
||||
pluginNames.push(plugin.name);
|
||||
@ -218,7 +226,7 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
|
||||
getPluginPreference(
|
||||
pluginName: string,
|
||||
): Record<string, IPublicTypePreferenceValueType> | null | undefined {
|
||||
): Record<string, PluginPreferenceValue> | null | undefined {
|
||||
if (!this.pluginPreference) {
|
||||
return null;
|
||||
}
|
||||
@ -240,7 +248,6 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
});
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
setDisabled(pluginName: string, flag = true) {
|
||||
logger.warn(`plugin:${pluginName} has been set disable:${flag}`);
|
||||
this.pluginsMap.get(pluginName)?.setDisabled(flag);
|
||||
76
packages/editor-core/src/plugin/plugin.ts
Normal file
76
packages/editor-core/src/plugin/plugin.ts
Normal file
@ -0,0 +1,76 @@
|
||||
export interface PluginInstance {
|
||||
init(): Promise<void> | void;
|
||||
destroy?(): Promise<void> | void;
|
||||
exports?(): any;
|
||||
}
|
||||
|
||||
export interface PluginMeta {
|
||||
/**
|
||||
* define dependencies which the plugin depends on
|
||||
*/
|
||||
dependencies?: string[];
|
||||
|
||||
/**
|
||||
* specify which engine version is compatible with the plugin
|
||||
*/
|
||||
engines?: {
|
||||
/** e.g. '^1.0.0' */
|
||||
lowcodeEngine?: string;
|
||||
};
|
||||
|
||||
preferenceDeclaration?: PluginDeclaration;
|
||||
|
||||
/**
|
||||
* use 'common' as event prefix when eventPrefix is not set.
|
||||
* strongly recommend using pluginName as eventPrefix
|
||||
*
|
||||
* eg.
|
||||
* case 1, when eventPrefix is not specified
|
||||
* event.emit('someEventName') is actually sending event with name 'common:someEventName'
|
||||
*
|
||||
* case 2, when eventPrefix is 'myEvent'
|
||||
* event.emit('someEventName') is actually sending event with name 'myEvent:someEventName'
|
||||
*/
|
||||
eventPrefix?: string;
|
||||
|
||||
/**
|
||||
* 如果要使用 command 注册命令,需要在插件 meta 中定义 commandScope
|
||||
*/
|
||||
commandScope?: string;
|
||||
}
|
||||
|
||||
export interface PluginDeclaration {
|
||||
// this will be displayed on configuration UI, can be plugin name
|
||||
title: string;
|
||||
properties: PluginDeclarationProperty[];
|
||||
}
|
||||
|
||||
export interface PluginDeclarationProperty {
|
||||
// shape like 'name' or 'group.name' or 'group.subGroup.name'
|
||||
key: string;
|
||||
// must have either one of description & markdownDescription
|
||||
description: string;
|
||||
// value in 'number', 'string', 'boolean'
|
||||
type: string;
|
||||
// default value
|
||||
// NOTE! this is only used in configuration UI, won`t affect runtime
|
||||
default?: PluginPreferenceValue;
|
||||
// only works when type === 'string', default value false
|
||||
useMultipleLineTextInput?: boolean;
|
||||
// enum values, only works when type === 'string'
|
||||
enum?: any[];
|
||||
// descriptions for enum values
|
||||
enumDescriptions?: string[];
|
||||
// message that describing deprecation of this property
|
||||
deprecationMessage?: string;
|
||||
}
|
||||
|
||||
export type PluginPreferenceValue = string | number | boolean;
|
||||
|
||||
export type PluginPreference = Map<string, Record<string, PluginPreferenceValue>>;
|
||||
|
||||
export interface PluginCreater<Context> {
|
||||
(ctx: Context, options: any): PluginInstance;
|
||||
pluginName: string;
|
||||
meta?: PluginMeta;
|
||||
}
|
||||
@ -1,43 +1,43 @@
|
||||
import { getLogger, Logger } from '@alilc/lowcode-utils';
|
||||
import {
|
||||
ILowCodePluginRuntime,
|
||||
ILowCodePluginManager,
|
||||
} from './plugin-types';
|
||||
import {
|
||||
IPublicTypePluginConfig,
|
||||
IPublicTypePluginMeta,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { invariant } from '../utils';
|
||||
|
||||
export class LowCodePluginRuntime implements ILowCodePluginRuntime {
|
||||
config: IPublicTypePluginConfig;
|
||||
import { type LowCodePluginManager } from './manager';
|
||||
import { type PluginInstance, type PluginMeta } from './plugin';
|
||||
import { invariant, createLogger, type Logger } from '@alilc/lowcode-shared';
|
||||
|
||||
export interface IPluginRuntimeCore {
|
||||
name: string;
|
||||
dep: string[];
|
||||
disabled: boolean;
|
||||
instance: PluginInstance;
|
||||
logger: Logger;
|
||||
meta: PluginMeta;
|
||||
|
||||
private manager: ILowCodePluginManager;
|
||||
init(forceInit?: boolean): void;
|
||||
isInited(): boolean;
|
||||
destroy(): void;
|
||||
toProxy(): any;
|
||||
setDisabled(flag: boolean): void;
|
||||
}
|
||||
|
||||
export interface IPluginRuntimeExportsAccessor {
|
||||
[propName: string]: any;
|
||||
}
|
||||
|
||||
export class LowCodePluginRuntime<ContextExtra extends Record<string, any>>
|
||||
implements IPluginRuntimeCore,IPluginRuntimeExportsAccessor {
|
||||
private _inited: boolean;
|
||||
|
||||
private pluginName: string;
|
||||
|
||||
meta: IPublicTypePluginMeta;
|
||||
|
||||
/**
|
||||
* 标识插件状态,是否被 disabled
|
||||
*/
|
||||
private _disabled: boolean;
|
||||
|
||||
logger: Logger;
|
||||
|
||||
constructor(
|
||||
pluginName: string,
|
||||
manager: ILowCodePluginManager,
|
||||
config: IPublicTypePluginConfig,
|
||||
meta: IPublicTypePluginMeta,
|
||||
private pluginName: string,
|
||||
private manager: LowCodePluginManager<ContextExtra>,
|
||||
public instance: PluginInstance,
|
||||
public meta: PluginMeta,
|
||||
) {
|
||||
this.manager = manager;
|
||||
this.config = config;
|
||||
this.pluginName = pluginName;
|
||||
this.meta = meta;
|
||||
this.logger = getLogger({ level: 'warn', bizName: `plugin:${pluginName}` });
|
||||
this.logger = createLogger({ level: 'warn', bizName: `plugin:${pluginName}` });
|
||||
}
|
||||
|
||||
get name() {
|
||||
@ -49,7 +49,7 @@ export class LowCodePluginRuntime implements ILowCodePluginRuntime {
|
||||
return [this.meta.dependencies];
|
||||
}
|
||||
// compat legacy way to declare dependencies
|
||||
const legacyDepValue = (this.config as any).dep;
|
||||
const legacyDepValue = (this.instance as any).dep;
|
||||
if (typeof legacyDepValue === 'string') {
|
||||
return [legacyDepValue];
|
||||
}
|
||||
@ -67,14 +67,14 @@ export class LowCodePluginRuntime implements ILowCodePluginRuntime {
|
||||
async init(forceInit?: boolean) {
|
||||
if (this._inited && !forceInit) return;
|
||||
this.logger.log('method init called');
|
||||
await this.config.init?.call(undefined);
|
||||
await this.instance.init?.call(undefined);
|
||||
this._inited = true;
|
||||
}
|
||||
|
||||
async destroy() {
|
||||
if (!this._inited) return;
|
||||
this.logger.log('method destroy called');
|
||||
await this.config?.destroy?.call(undefined);
|
||||
await this.instance?.destroy?.call(undefined);
|
||||
this._inited = false;
|
||||
}
|
||||
|
||||
@ -84,7 +84,8 @@ export class LowCodePluginRuntime implements ILowCodePluginRuntime {
|
||||
|
||||
toProxy() {
|
||||
invariant(this._inited, 'Could not call toProxy before init');
|
||||
const exports = this.config.exports?.();
|
||||
|
||||
const exports = this.instance.exports?.();
|
||||
return new Proxy(this, {
|
||||
get(target, prop, receiver) {
|
||||
if ({}.hasOwnProperty.call(exports, prop)) {
|
||||
@ -1,3 +1,37 @@
|
||||
import { isPlainObject } from 'lodash-es';
|
||||
import type { PluginDeclaration } from './plugin';
|
||||
import type { PluginRegisterOptions } from './manager';
|
||||
|
||||
export function isValidPreferenceKey(
|
||||
key: string,
|
||||
preferenceDeclaration: PluginDeclaration,
|
||||
): boolean {
|
||||
if (!preferenceDeclaration || !Array.isArray(preferenceDeclaration.properties)) {
|
||||
return false;
|
||||
}
|
||||
return preferenceDeclaration.properties.some((prop) => {
|
||||
return prop.key === key;
|
||||
});
|
||||
}
|
||||
|
||||
export function isLowCodeRegisterOptions(opts: any): opts is PluginRegisterOptions {
|
||||
return opts && ('autoInit' in opts || 'override' in opts);
|
||||
}
|
||||
|
||||
export function filterValidOptions(opts: any, preferenceDeclaration: PluginDeclaration) {
|
||||
if (!opts || !isPlainObject(opts)) return opts;
|
||||
const filteredOpts = {} as any;
|
||||
Object.keys(opts).forEach((key) => {
|
||||
if (isValidPreferenceKey(key, preferenceDeclaration)) {
|
||||
const v = opts[key];
|
||||
if (v !== undefined && v !== null) {
|
||||
filteredOpts[key] = v;
|
||||
}
|
||||
}
|
||||
});
|
||||
return filteredOpts;
|
||||
}
|
||||
|
||||
interface ITaks {
|
||||
[key: string]: {
|
||||
name: string;
|
||||
@ -5,6 +39,16 @@ interface ITaks {
|
||||
};
|
||||
}
|
||||
|
||||
interface Options {
|
||||
tasks: ITaks;
|
||||
names: string[];
|
||||
results: string[];
|
||||
missing: string[];
|
||||
recursive: string[][];
|
||||
nest: string[];
|
||||
parentName: string;
|
||||
}
|
||||
|
||||
export function sequence({
|
||||
tasks,
|
||||
names,
|
||||
@ -13,15 +57,7 @@ export function sequence({
|
||||
recursive,
|
||||
nest,
|
||||
parentName,
|
||||
}: {
|
||||
tasks: ITaks;
|
||||
names: string[];
|
||||
results: string[];
|
||||
missing: string[];
|
||||
recursive: string[][];
|
||||
nest: string[];
|
||||
parentName: string;
|
||||
}) {
|
||||
}: Options) {
|
||||
names.forEach((name) => {
|
||||
if (results.indexOf(name) !== -1) {
|
||||
return; // de-dup results
|
||||
@ -52,7 +88,7 @@ export function sequence({
|
||||
|
||||
// tasks: object with keys as task names
|
||||
// names: array of task names
|
||||
export default function (tasks: ITaks, names: string[]) {
|
||||
export function sequencify(tasks: ITaks, names: string[]) {
|
||||
let results: string[] = []; // the final sequence
|
||||
const missing: string[] = []; // missing tasks
|
||||
const recursive: string[][] = []; // recursive task dependencies
|
||||
@ -76,3 +112,4 @@ export default function (tasks: ITaks, names: string[]) {
|
||||
recursiveDependencies: recursive,
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,20 +1,22 @@
|
||||
import store from 'store';
|
||||
import { getLogger } from '@alilc/lowcode-utils';
|
||||
import { IPublicModelPreference } from '@alilc/lowcode-types';
|
||||
import { createLogger } from '@alilc/lowcode-utils';
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'Preference' });
|
||||
const logger = createLogger({ level: 'warn', bizName: 'Preference' });
|
||||
const STORAGE_KEY_PREFIX = 'ale';
|
||||
|
||||
/**
|
||||
* used to store user preferences, such as pinned status of a pannel.
|
||||
* save to local storage.
|
||||
*/
|
||||
export default class Preference implements IPublicModelPreference {
|
||||
getStorageKey(key: string, module?: string): string {
|
||||
export default class Preference {
|
||||
private getStorageKey(key: string, module?: string): string {
|
||||
const moduleKey = module || '__inner__';
|
||||
return `${STORAGE_KEY_PREFIX}_${moduleKey}.${key}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* set value from local storage by module and key
|
||||
*/
|
||||
set(key: string, value: any, module?: string): void {
|
||||
if (!key || typeof key !== 'string' || key.length === 0) {
|
||||
logger.error('Invalid key when setting preference', key);
|
||||
@ -25,6 +27,9 @@ export default class Preference implements IPublicModelPreference {
|
||||
store.set(storageKey, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* get value from local storage by module and key
|
||||
*/
|
||||
get(key: string, module: string): any {
|
||||
if (!key || typeof key !== 'string' || key.length === 0) {
|
||||
logger.error('Invalid key when getting from preference', key);
|
||||
@ -1,59 +1,39 @@
|
||||
import { IPublicApiSetters, IPublicModelSettingField, IPublicTypeCustomView, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
|
||||
import { IPublicModelSettingField, IPublicTypeCustomView, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
|
||||
import { isCustomView } from '@alilc/lowcode-utils';
|
||||
|
||||
const settersMap = new Map<string, IPublicTypeRegisteredSetter & {
|
||||
type: string;
|
||||
}>();
|
||||
|
||||
export function registerSetter(
|
||||
typeOrMaps: string | { [key: string]: IPublicTypeCustomView | IPublicTypeRegisteredSetter },
|
||||
setter?: IPublicTypeCustomView | IPublicTypeRegisteredSetter,
|
||||
) {
|
||||
if (typeof typeOrMaps === 'object') {
|
||||
Object.keys(typeOrMaps).forEach(type => {
|
||||
registerSetter(type, typeOrMaps[type]);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!setter) {
|
||||
return;
|
||||
}
|
||||
if (isCustomView(setter)) {
|
||||
setter = {
|
||||
component: setter,
|
||||
// todo: intl
|
||||
title: (setter as any).displayName || (setter as any).name || 'CustomSetter',
|
||||
};
|
||||
}
|
||||
if (!setter.initialValue) {
|
||||
const initial = getInitialFromSetter(setter.component);
|
||||
if (initial) {
|
||||
setter.initialValue = (field: IPublicModelSettingField) => {
|
||||
return initial.call(field, field.getValue());
|
||||
};
|
||||
}
|
||||
}
|
||||
settersMap.set(typeOrMaps, { type: typeOrMaps, ...setter });
|
||||
}
|
||||
|
||||
function getInitialFromSetter(setter: any) {
|
||||
return setter && (
|
||||
setter.initial || setter.Initial
|
||||
|| (setter.type && (setter.type.initial || setter.type.Initial))
|
||||
) || null; // eslint-disable-line
|
||||
}
|
||||
|
||||
export class Setters implements IPublicApiSetters {
|
||||
export class Setters {
|
||||
settersMap = new Map<string, IPublicTypeRegisteredSetter & {
|
||||
type: string;
|
||||
}>();
|
||||
|
||||
constructor(readonly viewName: string = 'global') {}
|
||||
|
||||
/**
|
||||
* 获取指定 setter
|
||||
* get setter by type
|
||||
* @param type
|
||||
* @returns
|
||||
*/
|
||||
getSetter = (type: string): IPublicTypeRegisteredSetter | null => {
|
||||
return this.settersMap.get(type) || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取已注册的所有 settersMap
|
||||
* get map of all registered setters
|
||||
* @returns
|
||||
*/
|
||||
getSettersMap = () => {
|
||||
return this.settersMap;
|
||||
};
|
||||
|
||||
/**
|
||||
* 注册一个 setter
|
||||
* register a setter
|
||||
* @param typeOrMaps
|
||||
* @param setter
|
||||
* @returns
|
||||
*/
|
||||
registerSetter = (
|
||||
typeOrMaps: string | { [key: string]: IPublicTypeCustomView | IPublicTypeRegisteredSetter },
|
||||
setter?: IPublicTypeCustomView | IPublicTypeRegisteredSetter,
|
||||
@ -84,8 +64,11 @@ export class Setters implements IPublicApiSetters {
|
||||
}
|
||||
this.settersMap.set(typeOrMaps, { type: typeOrMaps, ...setter });
|
||||
};
|
||||
|
||||
getSettersMap = () => {
|
||||
return this.settersMap;
|
||||
};
|
||||
}
|
||||
|
||||
function getInitialFromSetter(setter: any) {
|
||||
return setter && (
|
||||
setter.initial || setter.Initial
|
||||
|| (setter.type && (setter.type.initial || setter.type.Initial))
|
||||
) || null;
|
||||
}
|
||||
@ -6,6 +6,7 @@ import {
|
||||
} from '@alilc/lowcode-types';
|
||||
|
||||
// TODO: 该转换逻辑未来需要消化掉
|
||||
// 低代码 schema 转换逻辑
|
||||
export function assetsTransform(assets: IPublicTypeAssetsJson) {
|
||||
const { components, packages } = assets;
|
||||
const packageMaps = (packages || []).reduce(
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { AnyFunction } from '@alilc/lowcode-shared';
|
||||
|
||||
let globalEventOn = true;
|
||||
|
||||
export function setGlobalEventFlag(flag: boolean) {
|
||||
@ -16,7 +18,7 @@ export function isGlobalEventOn() {
|
||||
return globalEventOn;
|
||||
}
|
||||
|
||||
export function runWithGlobalEventOff(fn: Function) {
|
||||
export function runWithGlobalEventOff(fn: AnyFunction) {
|
||||
switchGlobalEventOff();
|
||||
fn();
|
||||
switchGlobalEventOn();
|
||||
|
||||
@ -3,6 +3,10 @@ export class FocusTracker {
|
||||
|
||||
private modals: Array<{ checkDown: (e: MouseEvent) => boolean; checkOpen: () => boolean }> = [];
|
||||
|
||||
get first() {
|
||||
return this.actives[0];
|
||||
}
|
||||
|
||||
mount(win: Window) {
|
||||
const checkDown = (e: MouseEvent) => {
|
||||
if (this.checkModalDown(e)) {
|
||||
@ -20,10 +24,6 @@ export class FocusTracker {
|
||||
};
|
||||
}
|
||||
|
||||
get first() {
|
||||
return this.actives[0];
|
||||
}
|
||||
|
||||
addModal(checkDown: (e: MouseEvent) => boolean, checkOpen: () => boolean) {
|
||||
this.modals.push({
|
||||
checkDown,
|
||||
@ -129,9 +129,7 @@ export class Focusable {
|
||||
}
|
||||
|
||||
internalTriggerBlur() {
|
||||
if (this.config.onBlur) {
|
||||
this.config.onBlur();
|
||||
}
|
||||
this.config.onBlur?.();
|
||||
}
|
||||
|
||||
internalTriggerSave() {
|
||||
@ -143,14 +141,10 @@ export class Focusable {
|
||||
}
|
||||
|
||||
internalTriggerEsc() {
|
||||
if (this.config.onEsc) {
|
||||
this.config.onEsc();
|
||||
}
|
||||
this.config.onEsc?.();
|
||||
}
|
||||
|
||||
internalTriggerActive() {
|
||||
if (this.config.onActive) {
|
||||
this.config.onActive();
|
||||
}
|
||||
this.config.onActive?.();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
export * from './get-public-path';
|
||||
export * from './obx';
|
||||
export * from './request';
|
||||
export * from './focus-tracker';
|
||||
export * from './control';
|
||||
export * from './preference';
|
||||
export * from '../preference';
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
"@alifd/next": "^1.27.8",
|
||||
"@alilc/lowcode-designer": "workspace:*",
|
||||
"@alilc/lowcode-editor-core": "workspace:*",
|
||||
"@alilc/lowcode-shared": "workspace:*",
|
||||
"@alilc/lowcode-types": "workspace:*",
|
||||
"@alilc/lowcode-utils": "workspace:*",
|
||||
"classnames": "^2.2.6",
|
||||
@ -55,6 +56,7 @@
|
||||
"@alifd/next": "^1.27.8",
|
||||
"@alilc/lowcode-designer": "workspace:*",
|
||||
"@alilc/lowcode-editor-core": "workspace:*",
|
||||
"@alilc/lowcode-shared": "workspace:*",
|
||||
"@alilc/lowcode-types": "workspace:*",
|
||||
"@alilc/lowcode-utils": "workspace:*",
|
||||
"react": "^18.2.0",
|
||||
|
||||
@ -16,7 +16,8 @@ export interface IArea<C, T> {
|
||||
show(): void;
|
||||
}
|
||||
|
||||
export class Area<C extends IPublicTypeWidgetBaseConfig = any, T extends IWidget = IWidget> implements IArea<C, T> {
|
||||
export class Area<C extends IPublicTypeWidgetBaseConfig = any, T extends IWidget = IWidget>
|
||||
implements IArea<C, T> {
|
||||
@observable private _visible = true;
|
||||
|
||||
@computed get visible() {
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import { ReactNode, createElement } from 'react';
|
||||
import { IPublicTypeTitleContent } from '@alilc/lowcode-types';
|
||||
import './index.less';
|
||||
import { Field, PopupField, EntryField, PlainField } from './fields';
|
||||
|
||||
import './index.less';
|
||||
|
||||
export interface FieldProps {
|
||||
className?: string;
|
||||
title?: IPublicTypeTitleContent | null;
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import React, { Component } from 'react';
|
||||
import { Tab, Breadcrumb } from '@alifd/next';
|
||||
import {
|
||||
Title,
|
||||
observer,
|
||||
Editor,
|
||||
observable,
|
||||
@ -9,7 +8,7 @@ import {
|
||||
engineConfig,
|
||||
makeObservable,
|
||||
} from '@alilc/lowcode-editor-core';
|
||||
import { Node, SettingField, INode } from '@alilc/lowcode-designer';
|
||||
import { Node, SettingField, INode, Title } from '@alilc/lowcode-designer';
|
||||
import classNames from 'classnames';
|
||||
import { SettingsMain } from './main';
|
||||
import { SettingsPane } from './settings-pane';
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { Component, ReactElement } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { Title, observer, HelpTip } from '@alilc/lowcode-editor-core';
|
||||
import { observer } from '@alilc/lowcode-editor-core';
|
||||
import { Title, HelpTip } from '@alilc/lowcode-designer';
|
||||
import { DockProps } from '../../types';
|
||||
import { PanelDock } from '../../widget/panel-dock';
|
||||
import { composeTitle } from '../../widget/utils';
|
||||
|
||||
@ -9,4 +9,3 @@ export * from './context';
|
||||
export * from './register-defaults';
|
||||
export * from './widget';
|
||||
export * from './layouts';
|
||||
export * from './event';
|
||||
|
||||
@ -19,5 +19,4 @@ export const registerDefaults = (ctx: IPublicModelPluginContext) => {
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
registerDefaults.pluginName = '___register_defaults___';
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { IPublicTypeTransformedComponentMetadata } from '@alilc/lowcode-types';
|
||||
import { isPlainObject, isJSFunction, getLogger } from '@alilc/lowcode-utils';
|
||||
import { isPlainObject, isJSFunction, createLogger } from '@alilc/lowcode-utils';
|
||||
|
||||
const leadingFnRe = /^function/;
|
||||
const leadingFnNameRe = /^\w+\s*\(/;
|
||||
const logger = getLogger({ level: 'warn', bizName: 'skeleton:transducers' });
|
||||
const logger = createLogger({ level: 'warn', bizName: 'skeleton:transducers' });
|
||||
|
||||
/**
|
||||
* 将函数字符串转成函数,支持几种类型
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { ReactNode, createElement } from 'react';
|
||||
import { makeObservable, observable } from '@alilc/lowcode-editor-core';
|
||||
import { uniqueId, createContent } from '@alilc/lowcode-utils';
|
||||
import { getEvent } from '../event';
|
||||
import { getEvent } from '../../../engine/src/shell/api/event';
|
||||
import { DockConfig } from '../types';
|
||||
import { ISkeleton } from '../skeleton';
|
||||
import { DockView, WidgetView } from '../components/widget-views';
|
||||
|
||||
@ -13,7 +13,7 @@ import {
|
||||
IPublicTypeTitleContent,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { WidgetContainer } from './widget-container';
|
||||
import { getEvent } from '../event';
|
||||
import { getEvent } from '../../../engine/src/shell/api/event';
|
||||
import { TitledPanelView, TabsPanelView, PanelView } from '../components/widget-views';
|
||||
import { ISkeleton } from '../skeleton';
|
||||
import { composeTitle } from './utils';
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// import { uniqueId } from '@alilc/lowcode-utils';
|
||||
import { Widget } from './widget';
|
||||
import { ISkeleton } from '../skeleton';
|
||||
import { WidgetConfig } from '../types';
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { ReactNode, createElement } from 'react';
|
||||
import { makeObservable, observable } from '@alilc/lowcode-editor-core';
|
||||
import { createContent, uniqueId } from '@alilc/lowcode-utils';
|
||||
import { getEvent } from '../event';
|
||||
import { getEvent } from '../../../engine/src/shell/api/event';
|
||||
import { WidgetConfig } from '../types';
|
||||
import { ISkeleton } from '../skeleton';
|
||||
import { WidgetView } from '../components/widget-views';
|
||||
|
||||
@ -5,5 +5,5 @@
|
||||
},
|
||||
"include": [
|
||||
"./src/"
|
||||
]
|
||||
, "../engine/src/shell/api/event.ts" ]
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
Hotkey as InnerHotkey,
|
||||
IEditor,
|
||||
Command as InnerCommand,
|
||||
LowCodePluginManager
|
||||
} from '@alilc/lowcode-editor-core';
|
||||
import {
|
||||
IPublicTypeEngineOptions,
|
||||
@ -22,10 +23,6 @@ import {
|
||||
} from '@alilc/lowcode-types';
|
||||
import {
|
||||
Designer,
|
||||
LowCodePluginManager,
|
||||
ILowCodePluginContextPrivate,
|
||||
ILowCodePluginContextApiAssembler,
|
||||
PluginPreference,
|
||||
IDesigner,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import { Skeleton as InnerSkeleton, registerDefaults, Workbench } from '@alilc/lowcode-editor-skeleton';
|
||||
|
||||
@ -17,7 +17,6 @@ import {
|
||||
import { editorSymbol, designerSymbol, nodeSymbol } from '../symbols';
|
||||
import {
|
||||
Dragon as ShellDragon,
|
||||
DropLocation as ShellDropLocation,
|
||||
ActiveTracker as ShellActiveTracker,
|
||||
Clipboard as ShellClipboard,
|
||||
DropLocation,
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { IEditor, IEventBus } from '@alilc/lowcode-editor-core';
|
||||
import { getLogger, isPluginEventName } from '@alilc/lowcode-utils';
|
||||
import { createLogger, isPluginEventName } from '@alilc/lowcode-utils';
|
||||
import { IPublicApiEvent, IPublicTypeDisposable } from '@alilc/lowcode-types';
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'shell-event' });
|
||||
const logger = createLogger({ level: 'warn', bizName: 'shell-event' });
|
||||
|
||||
type EventOptions = {
|
||||
prefix: string;
|
||||
@ -12,3 +12,4 @@ export * from './workspace';
|
||||
export * from './config';
|
||||
export * from './commonUI';
|
||||
export * from './command';
|
||||
export * from './event';
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
import { getLogger } from '@alilc/lowcode-utils';
|
||||
import { createLogger } from '@alilc/lowcode-utils';
|
||||
import { IPublicApiLogger, ILoggerOptions } from '@alilc/lowcode-types';
|
||||
|
||||
const innerLoggerSymbol = Symbol('logger');
|
||||
@ -8,7 +8,7 @@ export class Logger implements IPublicApiLogger {
|
||||
private readonly [innerLoggerSymbol]: any;
|
||||
|
||||
constructor(options: ILoggerOptions) {
|
||||
this[innerLoggerSymbol] = getLogger(options as any);
|
||||
this[innerLoggerSymbol] = createLogger(options as any);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { globalContext } from '@alilc/lowcode-editor-core';
|
||||
import { IDesigner, isComponentMeta } from '@alilc/lowcode-designer';
|
||||
import { IPublicTypeAssetsJson, getLogger } from '@alilc/lowcode-utils';
|
||||
import { IPublicTypeAssetsJson, createLogger } from '@alilc/lowcode-utils';
|
||||
import {
|
||||
IPublicTypeComponentAction,
|
||||
IPublicTypeComponentMetadata,
|
||||
@ -18,7 +18,7 @@ import { editorSymbol, designerSymbol } from '../symbols';
|
||||
import { ComponentMeta as ShellComponentMeta } from '../model';
|
||||
import { ComponentType } from 'react';
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'shell-material' });
|
||||
const logger = createLogger({ level: 'warn', bizName: 'shell-material' });
|
||||
|
||||
const innerEditorSymbol = Symbol('editor');
|
||||
export class Material implements IPublicApiMaterial {
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
IPublicModelPluginInstance,
|
||||
IPublicTypePlugin,
|
||||
IPublicTypePluginRegisterOptions,
|
||||
IPublicTypePreferenceValueType,
|
||||
IPublicTypePluginPreferenceValueType,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { PluginInstance as ShellPluginInstance } from '../model';
|
||||
import { pluginsSymbol } from '../symbols';
|
||||
@ -45,7 +45,7 @@ export class Plugins implements IPublicApiPlugins {
|
||||
|
||||
getPluginPreference(
|
||||
pluginName: string,
|
||||
): Record<string, IPublicTypePreferenceValueType> | null | undefined {
|
||||
): Record<string, IPublicTypePluginPreferenceValueType> | null | undefined {
|
||||
return this[pluginsSymbol].getPluginPreference(pluginName);
|
||||
}
|
||||
|
||||
|
||||
@ -18,9 +18,9 @@ import {
|
||||
import { DocumentModel as ShellDocumentModel } from '../model';
|
||||
import { SimulatorHost } from './simulator-host';
|
||||
import { editorSymbol, projectSymbol, simulatorHostSymbol, documentSymbol } from '../symbols';
|
||||
import { getLogger } from '@alilc/lowcode-utils';
|
||||
import { createLogger } from '@alilc/lowcode-utils';
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'shell-project' });
|
||||
const logger = createLogger({ level: 'warn', bizName: 'shell-project' });
|
||||
|
||||
const innerProjectSymbol = Symbol('innerProject');
|
||||
export class Project implements IPublicApiProject {
|
||||
@ -192,7 +192,7 @@ export class Project implements IPublicApiProject {
|
||||
* 当前 project 的模拟器 ready 事件
|
||||
*/
|
||||
onSimulatorHostReady(fn: (host: IPublicApiSimulatorHost) => void): IPublicTypeDisposable {
|
||||
// @ts-ignore
|
||||
// @ts-expect-error: a
|
||||
const offFn = this[projectSymbol].onSimulatorReady((simulator: BuiltinSimulatorHost) => {
|
||||
fn(SimulatorHost.create(simulator)!);
|
||||
});
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
import { IPublicTypeCustomView, IPublicApiSetters, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
|
||||
import { ISetters, globalContext, untracked } from '@alilc/lowcode-editor-core';
|
||||
import { ReactNode } from 'react';
|
||||
import { getLogger } from '@alilc/lowcode-utils';
|
||||
import { createLogger } from '@alilc/lowcode-utils';
|
||||
|
||||
const innerSettersSymbol = Symbol('setters');
|
||||
const settersSymbol = Symbol('setters');
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'shell-setters' });
|
||||
const logger = createLogger({ level: 'warn', bizName: 'shell-setters' });
|
||||
|
||||
export class Setters implements IPublicApiSetters {
|
||||
readonly [innerSettersSymbol]: ISetters;
|
||||
|
||||
@ -5,12 +5,12 @@ import {
|
||||
} from '@alilc/lowcode-editor-skeleton';
|
||||
import { skeletonSymbol } from '../symbols';
|
||||
import { IPublicApiSkeleton, IPublicModelSkeletonItem, IPublicTypeConfigTransducer, IPublicTypeDisposable, IPublicTypeSkeletonConfig, IPublicTypeWidgetConfigArea } from '@alilc/lowcode-types';
|
||||
import { getLogger } from '@alilc/lowcode-utils';
|
||||
import { createLogger } from '@alilc/lowcode-utils';
|
||||
import { SkeletonItem } from '../model/skeleton-item';
|
||||
|
||||
const innerSkeletonSymbol = Symbol('skeleton');
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'shell-skeleton' });
|
||||
const logger = createLogger({ level: 'warn', bizName: 'shell-skeleton' });
|
||||
|
||||
export class Skeleton implements IPublicApiSkeleton {
|
||||
private readonly [innerSkeletonSymbol]: ISkeleton;
|
||||
|
||||
@ -28,8 +28,9 @@ import {
|
||||
Config,
|
||||
CommonUI,
|
||||
Command,
|
||||
getEvent,
|
||||
Event
|
||||
} from './api';
|
||||
import { getEvent, Event } from '@alilc/lowcode-editor-skeleton';
|
||||
|
||||
export * from './symbols';
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ import {
|
||||
IPublicModelPluginContext,
|
||||
IPublicTypePluginMeta,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { getLogger, Logger as InnerLogger } from '@alilc/lowcode-utils';
|
||||
import { createLogger, Logger as InnerLogger } from '@alilc/lowcode-utils';
|
||||
import { IWorkspace } from '../workspace';
|
||||
import { IEditorWindow } from '../window';
|
||||
|
||||
@ -113,7 +113,7 @@ implements
|
||||
const project = new Project(innerProject, true);
|
||||
const config = engineConfig;
|
||||
const event = new Event(commonEvent, { prefix: 'common' });
|
||||
const logger = getLogger({ level: 'warn', bizName: 'common' });
|
||||
const logger = createLogger({ level: 'warn', bizName: 'common' });
|
||||
const skeleton = new Skeleton(innerSkeleton, 'any', true);
|
||||
const canvas = new Canvas(editor, true);
|
||||
const commonUI = new CommonUI(editor);
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import { Editor, engineConfig } from '@alilc/lowcode-editor-core';
|
||||
import { DesignerView, Designer } from '@alilc/lowcode-designer';
|
||||
import { Asset, getLogger } from '@alilc/lowcode-utils';
|
||||
import { Asset, createLogger } from '@alilc/lowcode-utils';
|
||||
import './index.scss';
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'plugin:plugin-designer' });
|
||||
const logger = createLogger({ level: 'warn', bizName: 'plugin:plugin-designer' });
|
||||
|
||||
export interface PluginProps {
|
||||
engineEditor: Editor;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { KeyboardEvent, FocusEvent, Fragment, PureComponent } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { Title, Tip } from '@alilc/lowcode-editor-core';
|
||||
import { Title, Tip } from '@alilc/lowcode-designer';
|
||||
import { createIcon } from '@alilc/lowcode-utils';
|
||||
import { IPublicApiEvent } from '@alilc/lowcode-types';
|
||||
import TreeNode from '../controllers/tree-node';
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
"test:watch": "vitest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@alilc/lowcode-shared": "workspace:*",
|
||||
"lodash-es": "^4.17.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { Project, Package, PlainObject } from '../types';
|
||||
import type { Project, Package, PlainObject } from '@alilc/lowcode-shared';
|
||||
import { type PackageManager, createPackageManager } from '../package';
|
||||
import { createPluginManager, type Plugin } from '../plugin';
|
||||
import { createScope, type CodeScope } from '../code-runtime';
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import type { PlainObject, InstanceStateApi } from '@alilc/lowcode-shared';
|
||||
import { type CreateContainerOptions, createContainer, type Container } from '../container';
|
||||
import type { PlainObject, InstanceStateApi } from '../types';
|
||||
|
||||
export type CreateComponentBaseOptions<T extends string> = Omit<
|
||||
CreateContainerOptions<T>,
|
||||
|
||||
@ -11,7 +11,6 @@ export * from './utils/value';
|
||||
export * from './widget';
|
||||
|
||||
/* --------------- types ---------------- */
|
||||
export * from './types';
|
||||
export type { CodeRuntime, CodeScope } from './code-runtime';
|
||||
export type { Plugin, PluginSetupContext } from './plugin';
|
||||
export type { PackageManager, PackageLoader } from './package';
|
||||
|
||||
8
packages/shared/package.json
Normal file
8
packages/shared/package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "@alilc/lowcode-shared",
|
||||
"version": "2.0.0-beta.0",
|
||||
"type": "module",
|
||||
"main": "dist/low-code-shared.cjs",
|
||||
"module": "dist/low-code-shared.js",
|
||||
"types": "dist/index.d.ts"
|
||||
}
|
||||
2
packages/shared/src/helper/index.ts
Normal file
2
packages/shared/src/helper/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './invariant';
|
||||
export * from './logger';
|
||||
@ -1,9 +1,8 @@
|
||||
/* eslint-disable no-console */
|
||||
/* eslint-disable no-param-reassign */
|
||||
import { isObject } from './is-object';
|
||||
import { isObject } from '../../../utils/src/is-object';
|
||||
|
||||
export type Level = 'debug' | 'log' | 'info' | 'warn' | 'error';
|
||||
interface Options {
|
||||
|
||||
export interface LoggerOptions {
|
||||
level: Level;
|
||||
bizName: string;
|
||||
}
|
||||
@ -117,7 +116,8 @@ const getLogArgs = (args: any, bizName: string, logLevel: string) => {
|
||||
processedArgs = processedArgs.concat(argsArray);
|
||||
return processedArgs;
|
||||
};
|
||||
const parseLogConf = (logConf: string, options: Options): { level: string; bizName: string} => {
|
||||
|
||||
const parseLogConf = (logConf: string, options: LoggerOptions) => {
|
||||
if (!logConf) {
|
||||
return {
|
||||
level: options.level,
|
||||
@ -137,16 +137,16 @@ const parseLogConf = (logConf: string, options: Options): { level: string; bizNa
|
||||
};
|
||||
};
|
||||
|
||||
const defaultOptions: Options = {
|
||||
const defaultOptions: LoggerOptions = {
|
||||
level: 'warn',
|
||||
bizName: '*',
|
||||
};
|
||||
|
||||
class Logger {
|
||||
export class Logger {
|
||||
bizName: string;
|
||||
targetBizName: string;
|
||||
targetLevel: string;
|
||||
constructor(options: Options) {
|
||||
constructor(options: LoggerOptions) {
|
||||
options = { ...defaultOptions, ...options };
|
||||
const _location = location || {} as any;
|
||||
// __logConf__ 格式为 logLevel[:bizName], bizName is used as: targetBizName like '%bizName%'
|
||||
@ -191,8 +191,6 @@ class Logger {
|
||||
}
|
||||
}
|
||||
|
||||
export { Logger };
|
||||
|
||||
export function getLogger(config: { level: Level; bizName: string }): Logger {
|
||||
export function createLogger(config: { level: Level; bizName: string }): Logger {
|
||||
return new Logger(config);
|
||||
}
|
||||
2
packages/shared/src/index.ts
Normal file
2
packages/shared/src/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './types';
|
||||
export * from './helper';
|
||||
@ -1,3 +1,5 @@
|
||||
export type VoidFunction = (...args: any[]) => void;
|
||||
|
||||
export type AnyFunction = (...args: any[]) => any;
|
||||
|
||||
export type PlainObject = Record<PropertyKey, any>;
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* https://lowcode-engine.cn/site/docs/specs/assets-spec
|
||||
* 低代码引擎资产包协议规范 for runtime
|
||||
* 低代码引擎资产包协议规范
|
||||
*/
|
||||
import { Project } from './lowcode-spec';
|
||||
|
||||
9
packages/shared/tsconfig.declaration.json
Normal file
9
packages/shared/tsconfig.declaration.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"emitDeclarationOnly": true,
|
||||
"declaration": true,
|
||||
"outDir": "temp",
|
||||
"stripInternal": true
|
||||
}
|
||||
}
|
||||
7
packages/shared/tsconfig.json
Normal file
7
packages/shared/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user