diff --git a/docs/docs/api/plugins.md b/docs/docs/api/plugins.md index df025f49e..5d418667c 100644 --- a/docs/docs/api/plugins.md +++ b/docs/docs/api/plugins.md @@ -223,7 +223,7 @@ delete(pluginName: string): void; */ getPluginPreference( pluginName: string, - ): Record | null | undefined; + ): Record | null | undefined; ``` ## 相关类型定义 diff --git a/packages/designer/package.json b/packages/designer/package.json index 0884b46b5..1a52faa84 100644 --- a/packages/designer/package.json +++ b/packages/designer/package.json @@ -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", diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-container.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-container.tsx index 0854564bd..00ee5d15b 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-container.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-container.tsx @@ -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; diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx index a9211ee8d..73f7ef37d 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx @@ -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; diff --git a/packages/designer/src/builtin-simulator/node-selector/index.tsx b/packages/designer/src/builtin-simulator/node-selector/index.tsx index 9d0af9fa1..64e4284ee 100644 --- a/packages/designer/src/builtin-simulator/node-selector/index.tsx +++ b/packages/designer/src/builtin-simulator/node-selector/index.tsx @@ -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; diff --git a/packages/designer/src/builtin-simulator/viewport.ts b/packages/designer/src/builtin-simulator/viewport.ts index 5655d8c21..cf48a02d5 100644 --- a/packages/designer/src/builtin-simulator/viewport.ts +++ b/packages/designer/src/builtin-simulator/viewport.ts @@ -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; diff --git a/packages/designer/src/component-actions.ts b/packages/designer/src/component-actions.ts index 859290d2b..7abd04c79 100644 --- a/packages/designer/src/component-actions.ts +++ b/packages/designer/src/component-actions.ts @@ -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 { diff --git a/packages/designer/src/context-menu-actions.scss b/packages/designer/src/context-menu-actions.less similarity index 100% rename from packages/designer/src/context-menu-actions.scss rename to packages/designer/src/context-menu-actions.less diff --git a/packages/designer/src/context-menu-actions.ts b/packages/designer/src/context-menu-actions.ts index 4fa029a77..d4afb6033 100644 --- a/packages/designer/src/context-menu-actions.ts +++ b/packages/designer/src/context-menu-actions.ts @@ -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 = 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?.(); diff --git a/packages/designer/src/designer/drag-ghost/index.tsx b/packages/designer/src/designer/drag-ghost/index.tsx index aa42565ea..bdc293175 100644 --- a/packages/designer/src/designer/drag-ghost/index.tsx +++ b/packages/designer/src/designer/drag-ghost/index.tsx @@ -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; diff --git a/packages/designer/src/document/node/props/prop.ts b/packages/designer/src/document/node/props/prop.ts index 776115192..fd2d2562b 100644 --- a/packages/designer/src/document/node/props/prop.ts +++ b/packages/designer/src/document/node/props/prop.ts @@ -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'); diff --git a/packages/designer/src/document/node/props/props.ts b/packages/designer/src/document/node/props/props.ts index 8b67adb56..26c4113b5 100644 --- a/packages/designer/src/document/node/props/props.ts +++ b/packages/designer/src/document/node/props/props.ts @@ -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; diff --git a/packages/designer/src/index.ts b/packages/designer/src/index.ts index 11e6453b8..ec45d1c49 100644 --- a/packages/designer/src/index.ts +++ b/packages/designer/src/index.ts @@ -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'; diff --git a/packages/designer/src/plugin/index.ts b/packages/designer/src/plugin/index.ts deleted file mode 100644 index 40a5bb555..000000000 --- a/packages/designer/src/plugin/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './plugin-context'; -export * from './plugin-manager'; -export * from './plugin-types'; -export * from './plugin'; diff --git a/packages/designer/src/plugin/plugin-context.ts b/packages/designer/src/plugin/plugin-context.ts deleted file mode 100644 index 88d1921b9..000000000 --- a/packages/designer/src/plugin/plugin-context.ts +++ /dev/null @@ -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, - }; - } -} diff --git a/packages/designer/src/plugin/plugin-types.ts b/packages/designer/src/plugin/plugin-types.ts deleted file mode 100644 index 7846ccd52..000000000 --- a/packages/designer/src/plugin/plugin-types.ts +++ /dev/null @@ -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>; - -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; - init( - pluginPreference?: Map> - ): Promise; - 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; -} diff --git a/packages/designer/src/plugin/plugin-utils.ts b/packages/designer/src/plugin/plugin-utils.ts deleted file mode 100644 index f38b10cde..000000000 --- a/packages/designer/src/plugin/plugin-utils.ts +++ /dev/null @@ -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; -} diff --git a/packages/designer/src/project/project-view.tsx b/packages/designer/src/project/project-view.tsx index a16d4451a..48b8d14f5 100644 --- a/packages/designer/src/project/project-view.tsx +++ b/packages/designer/src/project/project-view.tsx @@ -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 { diff --git a/packages/designer/src/simulator.ts b/packages/designer/src/simulator.ts index d11f9722b..292bc557b 100644 --- a/packages/designer/src/simulator.ts +++ b/packages/designer/src/simulator.ts @@ -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 { } diff --git a/packages/designer/src/types/index.ts b/packages/designer/src/types/index.ts index f47ce9ac8..16528a93c 100644 --- a/packages/designer/src/types/index.ts +++ b/packages/designer/src/types/index.ts @@ -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; diff --git a/packages/designer/src/utils/index.ts b/packages/designer/src/utils/index.ts index 785586dcb..5b832ac95 100644 --- a/packages/designer/src/utils/index.ts +++ b/packages/designer/src/utils/index.ts @@ -1,3 +1,2 @@ -export * from './invariant'; export * from './slot'; export * from './tree'; diff --git a/packages/editor-core/src/widgets/index.ts b/packages/designer/src/widgets/index.ts similarity index 64% rename from packages/editor-core/src/widgets/index.ts rename to packages/designer/src/widgets/index.ts index d3260bcaa..f6eb9a1ff 100644 --- a/packages/editor-core/src/widgets/index.ts +++ b/packages/designer/src/widgets/index.ts @@ -1,3 +1,2 @@ -// TODO move another place export * from './tip'; export * from './title'; diff --git a/packages/editor-core/src/widgets/tip/help-tips.tsx b/packages/designer/src/widgets/tip/help-tips.tsx similarity index 100% rename from packages/editor-core/src/widgets/tip/help-tips.tsx rename to packages/designer/src/widgets/tip/help-tips.tsx diff --git a/packages/editor-core/src/widgets/tip/index.ts b/packages/designer/src/widgets/tip/index.ts similarity index 100% rename from packages/editor-core/src/widgets/tip/index.ts rename to packages/designer/src/widgets/tip/index.ts diff --git a/packages/editor-core/src/widgets/tip/style.less b/packages/designer/src/widgets/tip/style.less similarity index 100% rename from packages/editor-core/src/widgets/tip/style.less rename to packages/designer/src/widgets/tip/style.less diff --git a/packages/editor-core/src/widgets/tip/tip-container.tsx b/packages/designer/src/widgets/tip/tip-container.tsx similarity index 100% rename from packages/editor-core/src/widgets/tip/tip-container.tsx rename to packages/designer/src/widgets/tip/tip-container.tsx diff --git a/packages/editor-core/src/widgets/tip/tip-handler.ts b/packages/designer/src/widgets/tip/tip-handler.ts similarity index 100% rename from packages/editor-core/src/widgets/tip/tip-handler.ts rename to packages/designer/src/widgets/tip/tip-handler.ts diff --git a/packages/editor-core/src/widgets/tip/tip-item.tsx b/packages/designer/src/widgets/tip/tip-item.tsx similarity index 100% rename from packages/editor-core/src/widgets/tip/tip-item.tsx rename to packages/designer/src/widgets/tip/tip-item.tsx diff --git a/packages/editor-core/src/widgets/tip/tip.tsx b/packages/designer/src/widgets/tip/tip.tsx similarity index 100% rename from packages/editor-core/src/widgets/tip/tip.tsx rename to packages/designer/src/widgets/tip/tip.tsx diff --git a/packages/editor-core/src/widgets/tip/utils.ts b/packages/designer/src/widgets/tip/utils.ts similarity index 100% rename from packages/editor-core/src/widgets/tip/utils.ts rename to packages/designer/src/widgets/tip/utils.ts diff --git a/packages/editor-core/src/widgets/title/index.tsx b/packages/designer/src/widgets/title/index.tsx similarity index 96% rename from packages/editor-core/src/widgets/title/index.tsx rename to packages/designer/src/widgets/title/index.tsx index 48ca30c1b..d0a3a8f21 100644 --- a/packages/editor-core/src/widgets/title/index.tsx +++ b/packages/designer/src/widgets/title/index.tsx @@ -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 { - 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 { } // TODO: 操作交互冲突,目前 mixedSetter 仅有 2 个 setter 注册时用到了 onClick onClick && onClick(e); - } + }; renderLabel = (label: string | IPublicTypeI18nData | ReactNode) => { const { match, keywords } = this.props; diff --git a/packages/editor-core/src/widgets/title/title.less b/packages/designer/src/widgets/title/title.less similarity index 100% rename from packages/editor-core/src/widgets/title/title.less rename to packages/designer/src/widgets/title/title.less diff --git a/packages/editor-core/package.json b/packages/editor-core/package.json index dc979e387..7b3e08514 100644 --- a/packages/editor-core/package.json +++ b/packages/editor-core/package.json @@ -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" }, diff --git a/packages/editor-core/src/command.ts b/packages/editor-core/src/command.ts index 2ed1e364f..513592cc4 100644 --- a/packages/editor-core/src/command.ts +++ b/packages/editor-core/src/command.ts @@ -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; + +export interface CommandOptions { commandScope?: string; } -export class Command implements Omit { - private commands: Map = new Map(); - private commandErrors: Function[] = []; +/** + * 该模块使得与命令系统的交互成为可能,提供了一种全面的方式来处理、执行和管理应用程序中的命令。 + */ +export class CommandManager { + private commands: Map = 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 { - const result: IPublicTypeListCommand = { + const result: ListCommand = { name: d.name, }; @@ -83,6 +154,9 @@ export class Command implements Omit void): void { this.commandErrors.push(callback); } diff --git a/packages/editor-core/src/config.ts b/packages/editor-core/src/config.ts index c62acf244..41de6808d 100644 --- a/packages/editor-core/src/config.ts +++ b/packages/editor-core/src/config.ts @@ -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; diff --git a/packages/editor-core/src/di/ioc-context.ts b/packages/editor-core/src/di.ts similarity index 100% rename from packages/editor-core/src/di/ioc-context.ts rename to packages/editor-core/src/di.ts diff --git a/packages/editor-core/src/di/index.ts b/packages/editor-core/src/di/index.ts deleted file mode 100644 index 75a4e84f1..000000000 --- a/packages/editor-core/src/di/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './setter'; -export * from './ioc-context'; -export * from '../widgets/tip/tip'; diff --git a/packages/editor-core/src/editor.ts b/packages/editor-core/src/editor.ts index 117366e6c..6aa52f6b0 100644 --- a/packages/editor-core/src/editor.ts +++ b/packages/editor-core/src/editor.ts @@ -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 = {}; export interface IEditor extends IPublicModelEditor { config?: EditorConfig; - components?: PluginClassSet; - eventBus: IEventBus; - init(config?: EditorConfig, components?: PluginClassSet): Promise; } export class Editor extends EventEmitter implements IEditor { /** * Ioc Container + * ??? */ @observable.shallow private context = new Map(); @@ -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( diff --git a/packages/editor-core/src/event-bus.ts b/packages/editor-core/src/event-bus.ts index 0da18f877..bb817b50a 100644 --- a/packages/editor-core/src/event-bus.ts +++ b/packages/editor-core/src/event-bus.ts @@ -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' }); diff --git a/packages/editor-core/src/hotkey.ts b/packages/editor-core/src/hotkey.ts index b8235b558..757e71caf 100644 --- a/packages/editor-core/src/hotkey.ts +++ b/packages/editor-core/src/hotkey.ts @@ -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; } } diff --git a/packages/editor-core/src/index.ts b/packages/editor-core/src/index.ts index c4a54bccd..b963b29d6 100644 --- a/packages/editor-core/src/index.ts +++ b/packages/editor-core/src/index.ts @@ -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'; diff --git a/packages/editor-core/src/intl/global-locale.ts b/packages/editor-core/src/intl/global-locale.ts index 390442079..c39c23e7d 100644 --- a/packages/editor-core/src/intl/global-locale.ts +++ b/packages/editor-core/src/intl/global-locale.ts @@ -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', diff --git a/packages/editor-core/src/utils/obx.ts b/packages/editor-core/src/obx.ts similarity index 100% rename from packages/editor-core/src/utils/obx.ts rename to packages/editor-core/src/obx.ts diff --git a/packages/editor-core/src/plugin/context.ts b/packages/editor-core/src/plugin/context.ts new file mode 100644 index 000000000..095f8d670 --- /dev/null +++ b/packages/editor-core/src/plugin/context.ts @@ -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> { + assembleApis( + context: LowCodePluginContext, + pluginName: string, + meta: PluginMeta, + ): void; +} + +export interface PluginPreferenceMananger { + getPreferenceValue: ( + key: string, + defaultValue?: PluginPreferenceValue, + ) => PluginPreferenceValue | undefined; +} + +export type LowCodePluginContext> = { + pluginEvent: IEventBus; + preference: PluginPreferenceMananger; + setPreference(pluginName: string, preferenceDeclaration: PluginDeclaration): void; +} & ContextExtra; + +/** + * create plugin context + * todo: refactor setPreference + */ +export function createPluginContext>( + options: PluginContextOptions, + manager: LowCodePluginManager, + contextApiAssembler: LowCodePluginContextApiAssembler> +): LowCodePluginContext { + 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; + + contextApiAssembler.assembleApis(contextBase, pluginName, meta); + const enhancePluginContextHook = engineConfig.get('enhancePluginContextHook'); + if (enhancePluginContextHook) { + enhancePluginContextHook(contextBase); + } + + return contextBase; +} diff --git a/packages/editor-core/src/plugin/index.ts b/packages/editor-core/src/plugin/index.ts new file mode 100644 index 000000000..a930176e2 --- /dev/null +++ b/packages/editor-core/src/plugin/index.ts @@ -0,0 +1,4 @@ +export * from './context'; +export * from './manager'; +export * from './runtime'; +export * from './plugin'; diff --git a/packages/designer/src/plugin/plugin-manager.ts b/packages/editor-core/src/plugin/manager.ts similarity index 75% rename from packages/designer/src/plugin/plugin-manager.ts rename to packages/editor-core/src/plugin/manager.ts index 8104d7b17..2d91adf29 100644 --- a/packages/designer/src/plugin/plugin-manager.ts +++ b/packages/editor-core/src/plugin/manager.ts @@ -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 = new Map(); - pluginContextMap: Map = new Map(); +/** + * plugin manager + */ +export class LowCodePluginManager> { + private plugins: LowCodePluginRuntime[] = []; + + private pluginsMap: Map> = new Map(); + + private pluginContextMap: Map> = new Map(); private pluginPreference?: PluginPreference = new Map(); - contextApiAssembler: ILowCodePluginContextApiAssembler; - constructor( - contextApiAssembler: ILowCodePluginContextApiAssembler, + private contextApiAssembler: LowCodePluginContextApiAssembler< + LowCodePluginContext + >, 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>, options?: any, - registerOptions?: IPublicTypePluginRegisterOptions, + registerOptions?: PluginRegisterOptions, ): Promise { // 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 | undefined { return this.pluginsMap.get(pluginName); } - getAll(): ILowCodePluginRuntime[] { + getAll(): LowCodePluginRuntime[] { 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 } = {}; this.pluginPreference = pluginPreference; this.plugins.forEach((plugin) => { pluginNames.push(plugin.name); @@ -218,7 +226,7 @@ export class LowCodePluginManager implements ILowCodePluginManager { getPluginPreference( pluginName: string, - ): Record | null | undefined { + ): Record | 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); diff --git a/packages/editor-core/src/plugin/plugin.ts b/packages/editor-core/src/plugin/plugin.ts new file mode 100644 index 000000000..5e3571a08 --- /dev/null +++ b/packages/editor-core/src/plugin/plugin.ts @@ -0,0 +1,76 @@ +export interface PluginInstance { + init(): Promise | void; + destroy?(): Promise | 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>; + +export interface PluginCreater { + (ctx: Context, options: any): PluginInstance; + pluginName: string; + meta?: PluginMeta; +} diff --git a/packages/designer/src/plugin/plugin.ts b/packages/editor-core/src/plugin/runtime.ts similarity index 54% rename from packages/designer/src/plugin/plugin.ts rename to packages/editor-core/src/plugin/runtime.ts index dd57325fc..7ca41e40a 100644 --- a/packages/designer/src/plugin/plugin.ts +++ b/packages/editor-core/src/plugin/runtime.ts @@ -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> +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, + 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)) { diff --git a/packages/designer/src/plugin/sequencify.ts b/packages/editor-core/src/plugin/utils.ts similarity index 58% rename from packages/designer/src/plugin/sequencify.ts rename to packages/editor-core/src/plugin/utils.ts index 73f04e8d6..b17be4472 100644 --- a/packages/designer/src/plugin/sequencify.ts +++ b/packages/editor-core/src/plugin/utils.ts @@ -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, }; } + diff --git a/packages/editor-core/src/utils/preference.ts b/packages/editor-core/src/preference.ts similarity index 81% rename from packages/editor-core/src/utils/preference.ts rename to packages/editor-core/src/preference.ts index 2d04eea29..65f70175a 100644 --- a/packages/editor-core/src/utils/preference.ts +++ b/packages/editor-core/src/preference.ts @@ -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); diff --git a/packages/editor-core/src/di/setter.ts b/packages/editor-core/src/setter.ts similarity index 55% rename from packages/editor-core/src/di/setter.ts rename to packages/editor-core/src/setter.ts index 32eb7ddb6..bf9f4421e 100644 --- a/packages/editor-core/src/di/setter.ts +++ b/packages/editor-core/src/setter.ts @@ -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(); - -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(); 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; } diff --git a/packages/editor-core/src/utils/assets-transform.ts b/packages/editor-core/src/utils/assets-transform.ts index ffefa4947..442b5762e 100644 --- a/packages/editor-core/src/utils/assets-transform.ts +++ b/packages/editor-core/src/utils/assets-transform.ts @@ -6,6 +6,7 @@ import { } from '@alilc/lowcode-types'; // TODO: 该转换逻辑未来需要消化掉 +// 低代码 schema 转换逻辑 export function assetsTransform(assets: IPublicTypeAssetsJson) { const { components, packages } = assets; const packageMaps = (packages || []).reduce( diff --git a/packages/editor-core/src/utils/control.ts b/packages/editor-core/src/utils/control.ts index 985bfc31b..40e3c2c93 100644 --- a/packages/editor-core/src/utils/control.ts +++ b/packages/editor-core/src/utils/control.ts @@ -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(); diff --git a/packages/editor-core/src/utils/focus-tracker.ts b/packages/editor-core/src/utils/focus-tracker.ts index 23d509053..c7155cd09 100644 --- a/packages/editor-core/src/utils/focus-tracker.ts +++ b/packages/editor-core/src/utils/focus-tracker.ts @@ -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?.(); } } diff --git a/packages/editor-core/src/utils/index.ts b/packages/editor-core/src/utils/index.ts index c01cdfc17..c49a06ca0 100644 --- a/packages/editor-core/src/utils/index.ts +++ b/packages/editor-core/src/utils/index.ts @@ -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'; diff --git a/packages/editor-skeleton/package.json b/packages/editor-skeleton/package.json index b9f165ade..22c7a8fc7 100644 --- a/packages/editor-skeleton/package.json +++ b/packages/editor-skeleton/package.json @@ -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", diff --git a/packages/editor-skeleton/src/area.ts b/packages/editor-skeleton/src/area.ts index ff689023a..3ce363b1f 100644 --- a/packages/editor-skeleton/src/area.ts +++ b/packages/editor-skeleton/src/area.ts @@ -16,7 +16,8 @@ export interface IArea { show(): void; } -export class Area implements IArea { +export class Area +implements IArea { @observable private _visible = true; @computed get visible() { diff --git a/packages/editor-skeleton/src/components/field/index.ts b/packages/editor-skeleton/src/components/field/index.ts index 6d7128634..3f7a21330 100644 --- a/packages/editor-skeleton/src/components/field/index.ts +++ b/packages/editor-skeleton/src/components/field/index.ts @@ -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; diff --git a/packages/editor-skeleton/src/components/settings/settings-primary-pane.tsx b/packages/editor-skeleton/src/components/settings/settings-primary-pane.tsx index 0d8eb4178..c07262b5c 100644 --- a/packages/editor-skeleton/src/components/settings/settings-primary-pane.tsx +++ b/packages/editor-skeleton/src/components/settings/settings-primary-pane.tsx @@ -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'; diff --git a/packages/editor-skeleton/src/components/widget-views/index.tsx b/packages/editor-skeleton/src/components/widget-views/index.tsx index 7cdff4c01..4fe272e42 100644 --- a/packages/editor-skeleton/src/components/widget-views/index.tsx +++ b/packages/editor-skeleton/src/components/widget-views/index.tsx @@ -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'; diff --git a/packages/editor-skeleton/src/index.ts b/packages/editor-skeleton/src/index.ts index 7b36caa52..a39b445d1 100644 --- a/packages/editor-skeleton/src/index.ts +++ b/packages/editor-skeleton/src/index.ts @@ -9,4 +9,3 @@ export * from './context'; export * from './register-defaults'; export * from './widget'; export * from './layouts'; -export * from './event'; diff --git a/packages/editor-skeleton/src/register-defaults.ts b/packages/editor-skeleton/src/register-defaults.ts index 573631f78..6a6e9a20d 100644 --- a/packages/editor-skeleton/src/register-defaults.ts +++ b/packages/editor-skeleton/src/register-defaults.ts @@ -19,5 +19,4 @@ export const registerDefaults = (ctx: IPublicModelPluginContext) => { }; }; - registerDefaults.pluginName = '___register_defaults___'; diff --git a/packages/editor-skeleton/src/transducers/parse-func.ts b/packages/editor-skeleton/src/transducers/parse-func.ts index d908ecdfc..40dc319b3 100644 --- a/packages/editor-skeleton/src/transducers/parse-func.ts +++ b/packages/editor-skeleton/src/transducers/parse-func.ts @@ -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' }); /** * 将函数字符串转成函数,支持几种类型 diff --git a/packages/editor-skeleton/src/widget/dialog-dock.ts b/packages/editor-skeleton/src/widget/dialog-dock.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/editor-skeleton/src/widget/dock.ts b/packages/editor-skeleton/src/widget/dock.ts index 241b56325..35e2d5f80 100644 --- a/packages/editor-skeleton/src/widget/dock.ts +++ b/packages/editor-skeleton/src/widget/dock.ts @@ -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'; diff --git a/packages/editor-skeleton/src/widget/panel.ts b/packages/editor-skeleton/src/widget/panel.ts index 79316d2ab..9ce0756cb 100644 --- a/packages/editor-skeleton/src/widget/panel.ts +++ b/packages/editor-skeleton/src/widget/panel.ts @@ -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'; diff --git a/packages/editor-skeleton/src/widget/stage.ts b/packages/editor-skeleton/src/widget/stage.ts index 2b177af61..4c8a3f330 100644 --- a/packages/editor-skeleton/src/widget/stage.ts +++ b/packages/editor-skeleton/src/widget/stage.ts @@ -1,4 +1,3 @@ -// import { uniqueId } from '@alilc/lowcode-utils'; import { Widget } from './widget'; import { ISkeleton } from '../skeleton'; import { WidgetConfig } from '../types'; diff --git a/packages/editor-skeleton/src/widget/widget.ts b/packages/editor-skeleton/src/widget/widget.ts index 76d4f5635..0718b6e80 100644 --- a/packages/editor-skeleton/src/widget/widget.ts +++ b/packages/editor-skeleton/src/widget/widget.ts @@ -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'; diff --git a/packages/editor-skeleton/tsconfig.json b/packages/editor-skeleton/tsconfig.json index c37b76ecc..e081732e9 100644 --- a/packages/editor-skeleton/tsconfig.json +++ b/packages/editor-skeleton/tsconfig.json @@ -5,5 +5,5 @@ }, "include": [ "./src/" - ] +, "../engine/src/shell/api/event.ts" ] } diff --git a/packages/engine/src/engine-core.ts b/packages/engine/src/engine-core.ts index b1a95297b..cf2d38426 100644 --- a/packages/engine/src/engine-core.ts +++ b/packages/engine/src/engine-core.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'; diff --git a/packages/engine/src/shell/api/canvas.ts b/packages/engine/src/shell/api/canvas.ts index f18471c82..9ed278289 100644 --- a/packages/engine/src/shell/api/canvas.ts +++ b/packages/engine/src/shell/api/canvas.ts @@ -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, diff --git a/packages/editor-skeleton/src/event.ts b/packages/engine/src/shell/api/event.ts similarity index 94% rename from packages/editor-skeleton/src/event.ts rename to packages/engine/src/shell/api/event.ts index f2adca98c..ac0ae8b14 100644 --- a/packages/editor-skeleton/src/event.ts +++ b/packages/engine/src/shell/api/event.ts @@ -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; diff --git a/packages/engine/src/shell/api/index.ts b/packages/engine/src/shell/api/index.ts index ea8b1f843..953aeaceb 100644 --- a/packages/engine/src/shell/api/index.ts +++ b/packages/engine/src/shell/api/index.ts @@ -12,3 +12,4 @@ export * from './workspace'; export * from './config'; export * from './commonUI'; export * from './command'; +export * from './event'; diff --git a/packages/engine/src/shell/api/logger.ts b/packages/engine/src/shell/api/logger.ts index 1aa67d472..c3ea9f0f0 100644 --- a/packages/engine/src/shell/api/logger.ts +++ b/packages/engine/src/shell/api/logger.ts @@ -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); } /** diff --git a/packages/engine/src/shell/api/material.ts b/packages/engine/src/shell/api/material.ts index 3fd5ed14e..d71c2ca8d 100644 --- a/packages/engine/src/shell/api/material.ts +++ b/packages/engine/src/shell/api/material.ts @@ -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 { diff --git a/packages/engine/src/shell/api/plugins.ts b/packages/engine/src/shell/api/plugins.ts index b596acac6..7d2956c94 100644 --- a/packages/engine/src/shell/api/plugins.ts +++ b/packages/engine/src/shell/api/plugins.ts @@ -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 | null | undefined { + ): Record | null | undefined { return this[pluginsSymbol].getPluginPreference(pluginName); } diff --git a/packages/engine/src/shell/api/project.ts b/packages/engine/src/shell/api/project.ts index 2402da59f..b2e0878ea 100644 --- a/packages/engine/src/shell/api/project.ts +++ b/packages/engine/src/shell/api/project.ts @@ -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)!); }); diff --git a/packages/engine/src/shell/api/setters.ts b/packages/engine/src/shell/api/setters.ts index 921d6697a..76960f644 100644 --- a/packages/engine/src/shell/api/setters.ts +++ b/packages/engine/src/shell/api/setters.ts @@ -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; diff --git a/packages/engine/src/shell/api/skeleton.ts b/packages/engine/src/shell/api/skeleton.ts index 4d032f0ee..b5078dc1a 100644 --- a/packages/engine/src/shell/api/skeleton.ts +++ b/packages/engine/src/shell/api/skeleton.ts @@ -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; diff --git a/packages/engine/src/shell/index.ts b/packages/engine/src/shell/index.ts index 87e0c5a99..3ba12b357 100644 --- a/packages/engine/src/shell/index.ts +++ b/packages/engine/src/shell/index.ts @@ -28,8 +28,9 @@ import { Config, CommonUI, Command, + getEvent, + Event } from './api'; -import { getEvent, Event } from '@alilc/lowcode-editor-skeleton'; export * from './symbols'; diff --git a/packages/engine/src/workspace/context/base-context.ts b/packages/engine/src/workspace/context/base-context.ts index 78bbb8bfb..c823e40f8 100644 --- a/packages/engine/src/workspace/context/base-context.ts +++ b/packages/engine/src/workspace/context/base-context.ts @@ -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); diff --git a/packages/plugin-designer/src/index.tsx b/packages/plugin-designer/src/index.tsx index 4c769be58..00ce969cf 100644 --- a/packages/plugin-designer/src/index.tsx +++ b/packages/plugin-designer/src/index.tsx @@ -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; diff --git a/packages/plugin-outline-pane/src/views/tree-title.tsx b/packages/plugin-outline-pane/src/views/tree-title.tsx index ded7955e8..77e71955d 100644 --- a/packages/plugin-outline-pane/src/views/tree-title.tsx +++ b/packages/plugin-outline-pane/src/views/tree-title.tsx @@ -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'; diff --git a/packages/renderer-core/package.json b/packages/renderer-core/package.json index fee016ba7..443ca2ac8 100644 --- a/packages/renderer-core/package.json +++ b/packages/renderer-core/package.json @@ -28,6 +28,7 @@ "test:watch": "vitest" }, "dependencies": { + "@alilc/lowcode-shared": "workspace:*", "lodash-es": "^4.17.21" }, "devDependencies": { diff --git a/packages/renderer-core/src/api/app.ts b/packages/renderer-core/src/api/app.ts index 87f672d70..b87ca6ec7 100644 --- a/packages/renderer-core/src/api/app.ts +++ b/packages/renderer-core/src/api/app.ts @@ -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'; diff --git a/packages/renderer-core/src/api/component.ts b/packages/renderer-core/src/api/component.ts index 89e4611a8..75a5a6aae 100644 --- a/packages/renderer-core/src/api/component.ts +++ b/packages/renderer-core/src/api/component.ts @@ -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 = Omit< CreateContainerOptions, diff --git a/packages/renderer-core/src/index.ts b/packages/renderer-core/src/index.ts index ece74eac2..fdf79866a 100644 --- a/packages/renderer-core/src/index.ts +++ b/packages/renderer-core/src/index.ts @@ -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'; diff --git a/packages/shared/package.json b/packages/shared/package.json new file mode 100644 index 000000000..b1754d5a7 --- /dev/null +++ b/packages/shared/package.json @@ -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" +} diff --git a/packages/shared/src/helper/index.ts b/packages/shared/src/helper/index.ts new file mode 100644 index 000000000..2edf7455d --- /dev/null +++ b/packages/shared/src/helper/index.ts @@ -0,0 +1,2 @@ +export * from './invariant'; +export * from './logger'; diff --git a/packages/designer/src/utils/invariant.ts b/packages/shared/src/helper/invariant.ts similarity index 100% rename from packages/designer/src/utils/invariant.ts rename to packages/shared/src/helper/invariant.ts diff --git a/packages/utils/src/logger.ts b/packages/shared/src/helper/logger.ts similarity index 91% rename from packages/utils/src/logger.ts rename to packages/shared/src/helper/logger.ts index c188cde51..a08d8d9a0 100644 --- a/packages/utils/src/logger.ts +++ b/packages/shared/src/helper/logger.ts @@ -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); } diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts new file mode 100644 index 000000000..28f3a81f4 --- /dev/null +++ b/packages/shared/src/index.ts @@ -0,0 +1,2 @@ +export * from './types'; +export * from './helper'; diff --git a/packages/renderer-core/src/types/common.ts b/packages/shared/src/types/common.ts similarity index 65% rename from packages/renderer-core/src/types/common.ts rename to packages/shared/src/types/common.ts index 0a3d55393..dca288948 100644 --- a/packages/renderer-core/src/types/common.ts +++ b/packages/shared/src/types/common.ts @@ -1,3 +1,5 @@ +export type VoidFunction = (...args: any[]) => void; + export type AnyFunction = (...args: any[]) => any; export type PlainObject = Record; diff --git a/packages/renderer-core/src/types/index.ts b/packages/shared/src/types/index.ts similarity index 100% rename from packages/renderer-core/src/types/index.ts rename to packages/shared/src/types/index.ts diff --git a/packages/renderer-core/src/types/material.ts b/packages/shared/src/types/material.ts similarity index 100% rename from packages/renderer-core/src/types/material.ts rename to packages/shared/src/types/material.ts diff --git a/packages/renderer-core/src/types/specs/asset-spec.ts b/packages/shared/src/types/specs/asset-spec.ts similarity index 97% rename from packages/renderer-core/src/types/specs/asset-spec.ts rename to packages/shared/src/types/specs/asset-spec.ts index 22e28ec6e..f9ee84dd8 100644 --- a/packages/renderer-core/src/types/specs/asset-spec.ts +++ b/packages/shared/src/types/specs/asset-spec.ts @@ -1,6 +1,6 @@ /** * https://lowcode-engine.cn/site/docs/specs/assets-spec - * 低代码引擎资产包协议规范 for runtime + * 低代码引擎资产包协议规范 */ import { Project } from './lowcode-spec'; diff --git a/packages/renderer-core/src/types/specs/lowcode-spec.ts b/packages/shared/src/types/specs/lowcode-spec.ts similarity index 100% rename from packages/renderer-core/src/types/specs/lowcode-spec.ts rename to packages/shared/src/types/specs/lowcode-spec.ts diff --git a/packages/renderer-core/src/types/specs/runtime-api.ts b/packages/shared/src/types/specs/runtime-api.ts similarity index 100% rename from packages/renderer-core/src/types/specs/runtime-api.ts rename to packages/shared/src/types/specs/runtime-api.ts diff --git a/packages/shared/tsconfig.declaration.json b/packages/shared/tsconfig.declaration.json new file mode 100644 index 000000000..bccb9a3e5 --- /dev/null +++ b/packages/shared/tsconfig.declaration.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "emitDeclarationOnly": true, + "declaration": true, + "outDir": "temp", + "stripInternal": true + } +} diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json new file mode 100644 index 000000000..039e0b4d1 --- /dev/null +++ b/packages/shared/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": ["src"] +} diff --git a/packages/shared/vite.config.ts b/packages/shared/vite.config.ts new file mode 100644 index 000000000..245b2cb50 --- /dev/null +++ b/packages/shared/vite.config.ts @@ -0,0 +1,6 @@ +import { defineConfig } from 'vite'; +import baseConfigFn from '../../vite.base.config' + +export default defineConfig(async () => baseConfigFn({ + name: 'LowCodeShared', +})); diff --git a/packages/types/src/shell/api/event.ts b/packages/types/src/shell/api/event.ts index 5b8c59e13..72b173acf 100644 --- a/packages/types/src/shell/api/event.ts +++ b/packages/types/src/shell/api/event.ts @@ -1,7 +1,6 @@ import { IPublicTypeDisposable } from '../type'; export interface IPublicApiEvent { - /** * 监听事件 * add monitor to a event diff --git a/packages/types/src/shell/api/plugins.ts b/packages/types/src/shell/api/plugins.ts index cbac40566..dd99d114f 100644 --- a/packages/types/src/shell/api/plugins.ts +++ b/packages/types/src/shell/api/plugins.ts @@ -1,13 +1,13 @@ import { IPublicModelPluginInstance, IPublicTypePlugin } from '../model'; -import { IPublicTypePreferenceValueType } from '../type'; +import { IPublicTypePluginPreferenceValueType } from '../type'; import { IPublicTypePluginRegisterOptions } from '../type/plugin-register-options'; export interface IPluginPreferenceMananger { // eslint-disable-next-line max-len getPreferenceValue: ( key: string, - defaultValue?: IPublicTypePreferenceValueType, - ) => IPublicTypePreferenceValueType | undefined; + defaultValue?: IPublicTypePluginPreferenceValueType, + ) => IPublicTypePluginPreferenceValueType | undefined; } export type PluginOptionsType = string | number | boolean | object; @@ -31,7 +31,7 @@ export interface IPublicApiPlugins { */ getPluginPreference( pluginName: string, - ): Record | null | undefined; + ): Record | null | undefined; /** * 获取指定插件 diff --git a/packages/types/src/shell/model/editor.ts b/packages/types/src/shell/model/editor.ts index e6171f031..f8c5c1d76 100644 --- a/packages/types/src/shell/model/editor.ts +++ b/packages/types/src/shell/model/editor.ts @@ -1,11 +1,11 @@ -/* eslint-disable max-len */ import { EventEmitter } from 'events'; import StrictEventEmitter from 'strict-event-emitter-types'; import * as GlobalEvent from '../../event'; import { IPublicApiEvent } from '../api'; import { IPublicTypeEditorValueKey, IPublicTypeEditorGetOptions, IPublicTypeEditorGetResult, IPublicTypeEditorRegisterOptions, IPublicTypeAssetsJson } from '../type'; -export interface IPublicModelEditor extends StrictEventEmitter { +export interface IPublicModelEditor + extends StrictEventEmitter { get: ( keyOrType: KeyOrType, opt?: IPublicTypeEditorGetOptions @@ -18,7 +18,9 @@ export interface IPublicModelEditor extends StrictEventEmitter(keyOrType: KeyOrType) => Promise>; + onceGot: ( + keyOrType: KeyOrType + ) => Promise>; /** * 获取 keyOrType 多次 @@ -36,7 +38,11 @@ export interface IPublicModelEditor extends StrictEventEmitter) => void ) => () => void; - register: (data: any, key?: IPublicTypeEditorValueKey, options?: IPublicTypeEditorRegisterOptions) => void; + register: ( + data: any, + key?: IPublicTypeEditorValueKey, + options?: IPublicTypeEditorRegisterOptions + ) => void; get eventBus(): IPublicApiEvent; diff --git a/packages/types/src/shell/type/plugin-declaration-property.ts b/packages/types/src/shell/type/plugin-declaration-property.ts index f07b350a6..a7389ee04 100644 --- a/packages/types/src/shell/type/plugin-declaration-property.ts +++ b/packages/types/src/shell/type/plugin-declaration-property.ts @@ -1,4 +1,4 @@ -import { IPublicTypePreferenceValueType } from './'; +import { IPublicTypePluginPreferenceValueType } from './'; export interface IPublicTypePluginDeclarationProperty { // shape like 'name' or 'group.name' or 'group.subGroup.name' @@ -9,7 +9,7 @@ export interface IPublicTypePluginDeclarationProperty { type: string; // default value // NOTE! this is only used in configuration UI, won`t affect runtime - default?: IPublicTypePreferenceValueType; + default?: IPublicTypePluginPreferenceValueType; // only works when type === 'string', default value false useMultipleLineTextInput?: boolean; // enum values, only works when type === 'string' diff --git a/packages/types/src/shell/type/preference-value-type.ts b/packages/types/src/shell/type/preference-value-type.ts index 75b58824c..59c8045aa 100644 --- a/packages/types/src/shell/type/preference-value-type.ts +++ b/packages/types/src/shell/type/preference-value-type.ts @@ -1,2 +1,2 @@ -export type IPublicTypePreferenceValueType = string | number | boolean; +export type IPublicTypePluginPreferenceValueType = string | number | boolean; diff --git a/packages/utils/src/check-prop-types.ts b/packages/utils/src/check-prop-types.ts index 94b60cc4f..463a89238 100644 --- a/packages/utils/src/check-prop-types.ts +++ b/packages/utils/src/check-prop-types.ts @@ -5,7 +5,7 @@ import { default as ReactPropTypesSecret } from 'prop-types/lib/ReactPropTypesSe import { default as factoryWithTypeCheckers } from 'prop-types/factoryWithTypeCheckers'; import { IPublicTypePropType } from '@alilc/lowcode-types'; import { isRequiredPropType } from './check-types/is-required-prop-type'; -import { Logger } from './logger'; +import { Logger } from '../../shared/src/helper/logger'; const PropTypes2 = factoryWithTypeCheckers(ReactIs.isElement, true); const logger = new Logger({ level: 'warn', bizName: 'utils' }); diff --git a/packages/utils/src/context-menu.scss b/packages/utils/src/context-menu.less similarity index 100% rename from packages/utils/src/context-menu.scss rename to packages/utils/src/context-menu.less diff --git a/packages/utils/src/context-menu.tsx b/packages/utils/src/context-menu.tsx index bddd9e276..868626bf6 100644 --- a/packages/utils/src/context-menu.tsx +++ b/packages/utils/src/context-menu.tsx @@ -6,20 +6,20 @@ import { IPublicTypeContextMenuAction, IPublicTypeContextMenuItem, } from '@alilc/lowcode-types'; -import { Logger } from './logger'; +import { createLogger, type AnyFunction } from '@alilc/lowcode-shared'; import classNames from 'classnames'; import React from 'react'; -import './context-menu.scss'; +import './context-menu.less'; -const logger = new Logger({ level: 'warn', bizName: 'utils' }); +const logger = createLogger({ level: 'warn', bizName: 'utils' }); const { Item, Divider, PopupItem } = Menu; const MAX_LEVEL = 2; interface IOptions { nodes?: IPublicModelNode[] | null; - destroy?: Function; + destroy?: AnyFunction; pluginContext: IPublicModelPluginContext; } @@ -64,7 +64,7 @@ const Tree = (props: { ); }; -let destroyFn: Function | undefined; +let destroyFn: AnyFunction | undefined; export function parseContextMenuAsReactNode( menus: IPublicTypeContextMenuItem[], diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 752d48e4c..5bca82fbb 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -26,7 +26,7 @@ export * from './misc'; export * from './schema'; export * from './node-helper'; export * from './clone-enumerable-property'; -export * from './logger'; +export * from '../../shared/src/helper/logger'; export * from './is-shaken'; export * from './is-plugin-event-name'; export { css }; diff --git a/packages/utils/src/misc.ts b/packages/utils/src/misc.ts index 7c3151c7e..a5e80bde1 100644 --- a/packages/utils/src/misc.ts +++ b/packages/utils/src/misc.ts @@ -1,7 +1,7 @@ import { isI18NObject } from './is-object'; import { get } from 'lodash-es'; import { IPublicEnumTransformStage, IPublicModelComponentMeta } from '@alilc/lowcode-types'; -import { Logger } from './logger'; +import { Logger } from '../../shared/src/helper/logger'; const logger = new Logger({ level: 'warn', bizName: 'utils' }); diff --git a/packages/utils/src/script.ts b/packages/utils/src/script.ts index c4c476fac..383fa0b0f 100644 --- a/packages/utils/src/script.ts +++ b/packages/utils/src/script.ts @@ -1,5 +1,5 @@ import { createDefer } from './create-defer'; -import { Logger } from './logger'; +import { Logger } from '../../shared/src/helper/logger'; const logger = new Logger({ level: 'warn', bizName: 'utils' });