diff --git a/docs/docs/api/model/resource-type.md b/docs/docs/api/model/resource-type.md
deleted file mode 100644
index 327788ce3..000000000
--- a/docs/docs/api/model/resource-type.md
+++ /dev/null
@@ -1,26 +0,0 @@
----
-title: ResourceType
-sidebar_position: 12
----
-
-> **[@experimental](./#experimental)**
-> **@types** [IPublicModelWindow](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/resource-type.ts)
-> **@since** v1.1.0
-
-## 变量
-
-### description
-
-资源描述
-
-`@type {string}`
-
-### icon
-
-资源 icon
-
-`@type {ReactElement}`
-
-### name
-
-`@type {string}`
diff --git a/docs/docs/api/model/resource.md b/docs/docs/api/model/resource.md
index fb3e8a6d8..33a6e3119 100644
--- a/docs/docs/api/model/resource.md
+++ b/docs/docs/api/model/resource.md
@@ -15,6 +15,24 @@ sidebar_position: 12
`@type {string}`
+### name
+
+资源名字
+
+`@type {string}`
+
+### type
+
+资源类型
+
+`@type {string}`
+
+### category
+
+资源分类
+
+`@type {string}`
+
### icon
资源 icon
@@ -25,12 +43,4 @@ sidebar_position: 12
资源配置信息
-`@type {Object}`
-
-### resourceType
-
-资源所属的资源类型
-
-`@type {IPublicModelResourceType}`
-
-关联模型 [IPublicModelResourceType](./resource-type)
+`@type {Object}`
\ No newline at end of file
diff --git a/docs/docs/api/model/window.md b/docs/docs/api/model/window.md
index 9d96f20a8..f70c33e4d 100644
--- a/docs/docs/api/model/window.md
+++ b/docs/docs/api/model/window.md
@@ -30,13 +30,13 @@ sidebar_position: 12
`@type {ReactElement}`
-### resourceType
+### resource
-窗口资源类型
+窗口对应资源
-`@type {IPublicModelResourceType}`
+`@type {IPublicModelResource}`
-关联模型 [IPublicModelResourceType](./resource-type)
+关联模型 [IPublicModelResource](./resource)
## 方法签名
diff --git a/docs/docs/api/workspace.md b/docs/docs/api/workspace.md
index bf0755537..138693cfa 100644
--- a/docs/docs/api/workspace.md
+++ b/docs/docs/api/workspace.md
@@ -64,10 +64,10 @@ get resourceList(): IPublicModelResource;
```typescript
/** 注册资源 */
-registerResourceType(name: string, type: 'editor', options: IPublicResourceOptions): void;
+registerResourceType(resourceTypeModel: IPublicTypeResourceType): void;
```
-相关类型:[IPublicResourceOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/resource-options.ts)
+相关类型:[IPublicTypeResourceType](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/resource-type.ts)
### onChangeWindows
diff --git a/packages/designer/src/designer/designer.ts b/packages/designer/src/designer/designer.ts
index bf98a812a..6e4b3c63e 100644
--- a/packages/designer/src/designer/designer.ts
+++ b/packages/designer/src/designer/designer.ts
@@ -39,12 +39,14 @@ import { ComponentActions } from '../component-actions';
const logger = new Logger({ level: 'warn', bizName: 'designer' });
export interface DesignerProps {
+ [key: string]: any;
editor: IPublicModelEditor;
shellModelFactory: IShellModelFactory;
className?: string;
style?: object;
defaultSchema?: IPublicTypeProjectSchema;
hotkeys?: object;
+ viewName?: string;
simulatorProps?: object | ((document: DocumentModel) => object);
simulatorComponent?: ComponentType;
dragGhostComponent?: ComponentType;
@@ -55,8 +57,6 @@ export interface DesignerProps {
onDragstart?: (e: ILocateEvent) => void;
onDrag?: (e: ILocateEvent) => void;
onDragend?: (e: { dragObject: IPublicModelDragObject; copy: boolean }, loc?: DropLocation) => void;
- viewName?: string;
- [key: string]: any;
}
export interface IDesigner {
@@ -71,7 +71,9 @@ export interface IDesigner {
}
export class Designer implements IDesigner {
- dragon: Dragon;
+ public dragon: Dragon;
+
+ public viewName: string | undefined;
readonly componentActions = new ComponentActions();
@@ -87,6 +89,24 @@ export class Designer implements IDesigner {
readonly shellModelFactory: IShellModelFactory;
+ private _dropLocation?: DropLocation;
+
+ private propsReducers = new Map();
+
+ private _lostComponentMetasMap = new Map();
+
+ private props?: DesignerProps;
+
+ private oobxList: OffsetObserver[] = [];
+
+ @obx.ref private _componentMetasMap = new Map();
+
+ @obx.ref private _simulatorComponent?: ComponentType;
+
+ @obx.ref private _simulatorProps?: object | ((project: Project) => object);
+
+ @obx.ref private _suspensed = false;
+
get currentDocument() {
return this.project.currentDocument;
}
@@ -99,8 +119,6 @@ export class Designer implements IDesigner {
return this.currentDocument?.selection;
}
- viewName: string | undefined;
-
constructor(props: DesignerProps) {
makeObservable(this);
const { editor, viewName, shellModelFactory } = props;
@@ -234,8 +252,6 @@ export class Designer implements IDesigner {
this.editor.eventBus.emit(`designer.${event}`, ...args);
}
- private _dropLocation?: DropLocation;
-
get dropLocation() {
return this._dropLocation;
}
@@ -270,8 +286,6 @@ export class Designer implements IDesigner {
return new Scroller(scrollable);
}
- private oobxList: OffsetObserver[] = [];
-
createOffsetObserver(nodeInstance: INodeSelector): OffsetObserver | null {
const oobx = createOffsetObserver(nodeInstance);
this.clearOobxList();
@@ -342,8 +356,6 @@ export class Designer implements IDesigner {
return { target, index };
}
- private props?: DesignerProps;
-
setProps(nextProps: DesignerProps) {
const props = this.props ? { ...this.props, ...nextProps } : nextProps;
if (this.props) {
@@ -421,14 +433,10 @@ export class Designer implements IDesigner {
return this.props?.[key];
}
- @obx.ref private _simulatorComponent?: ComponentType;
-
@computed get simulatorComponent(): ComponentType | undefined {
return this._simulatorComponent;
}
- @obx.ref private _simulatorProps?: object | ((project: Project) => object);
-
@computed get simulatorProps(): object {
if (typeof this._simulatorProps === 'function') {
return this._simulatorProps(this.project);
@@ -451,8 +459,6 @@ export class Designer implements IDesigner {
};
}
- @obx.ref private _suspensed = false;
-
get suspensed(): boolean {
return this._suspensed;
}
@@ -473,16 +479,15 @@ export class Designer implements IDesigner {
this.project.load(schema);
}
- @obx.ref private _componentMetasMap = new Map();
-
- private _lostComponentMetasMap = new Map();
-
buildComponentMetasMap(metas: IPublicTypeComponentMetadata[]) {
metas.forEach((data) => this.createComponentMeta(data));
}
- createComponentMeta(data: IPublicTypeComponentMetadata): ComponentMeta {
+ createComponentMeta(data: IPublicTypeComponentMetadata): ComponentMeta | null {
const key = data.componentName;
+ if (!key) {
+ return null;
+ }
let meta = this._componentMetasMap.get(key);
if (meta) {
meta.setMetadata(data);
@@ -552,8 +557,6 @@ export class Designer implements IDesigner {
return maps;
}
- private propsReducers = new Map();
-
transformProps(props: IPublicTypeCompositeObject | IPublicTypePropsList, node: Node, stage: IPublicEnumTransformStage) {
if (Array.isArray(props)) {
// current not support, make this future
diff --git a/packages/shell/src/api/workspace.ts b/packages/shell/src/api/workspace.ts
index 09e1b4ca6..f32b403b1 100644
--- a/packages/shell/src/api/workspace.ts
+++ b/packages/shell/src/api/workspace.ts
@@ -1,4 +1,4 @@
-import { IPublicApiWorkspace, IPublicResourceList, IPublicResourceOptions } from '@alilc/lowcode-types';
+import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeResourceType } from '@alilc/lowcode-types';
import { Workspace as InnerWorkSpace } from '@alilc/lowcode-workspace';
import { Plugins } from '@alilc/lowcode-shell';
import { Window } from '../model/window';
@@ -32,8 +32,8 @@ export class Workspace implements IPublicApiWorkspace {
return new Window(this[workspaceSymbol].window);
}
- registerResourceType(name: string, type: 'editor', options: IPublicResourceOptions): void {
- this[workspaceSymbol].registerResourceType(name, type, options);
+ registerResourceType(resourceTypeModel: IPublicTypeResourceType): void {
+ this[workspaceSymbol].registerResourceType(resourceTypeModel);
}
openEditorWindow(resourceName: string, title: string, extra: Object, viewName?: string) {
diff --git a/packages/shell/src/model/index.ts b/packages/shell/src/model/index.ts
index 5f5e50220..d0e45cc94 100644
--- a/packages/shell/src/model/index.ts
+++ b/packages/shell/src/model/index.ts
@@ -14,5 +14,4 @@ export * from './props';
export * from './selection';
export * from './setting-prop-entry';
export * from './setting-top-entry';
-export * from './resource';
-export * from './resource-type';
\ No newline at end of file
+export * from './resource';
\ No newline at end of file
diff --git a/packages/shell/src/model/resource-type.ts b/packages/shell/src/model/resource-type.ts
deleted file mode 100644
index b5ed549f1..000000000
--- a/packages/shell/src/model/resource-type.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { IPublicModelResourceType } from '@alilc/lowcode-types';
-import { ResourceType as InnerResourceType } from '@alilc/lowcode-workspace';
-import { resourceTypeSymbol } from '../symbols';
-
-export class ResourceType implements IPublicModelResourceType {
- readonly [resourceTypeSymbol]: InnerResourceType;
- constructor(resourceType: InnerResourceType) {
- this[resourceTypeSymbol] = resourceType;
- }
-
- get name() {
- return this[resourceTypeSymbol].name;
- }
-
- get description() {
- return this[resourceTypeSymbol].options.description;
- }
-
- get icon() {
- return this[resourceTypeSymbol].options.icon;
- }
-}
\ No newline at end of file
diff --git a/packages/shell/src/model/resource.ts b/packages/shell/src/model/resource.ts
index df8190549..0ca3f2445 100644
--- a/packages/shell/src/model/resource.ts
+++ b/packages/shell/src/model/resource.ts
@@ -22,7 +22,15 @@ export class Resource implements IPublicModelResource {
return this[resourceSymbol].options;
}
- get resourceType() {
- return new ResourceType(this[resourceSymbol].resourceType);
+ get name() {
+ return this[resourceSymbol].resourceType.name;
+ }
+
+ get type() {
+ return this[resourceSymbol].resourceType.type;
+ }
+
+ get category() {
+ return this[resourceSymbol].category;
}
}
\ No newline at end of file
diff --git a/packages/shell/src/model/window.ts b/packages/shell/src/model/window.ts
index fcb282490..8645e3e09 100644
--- a/packages/shell/src/model/window.ts
+++ b/packages/shell/src/model/window.ts
@@ -1,13 +1,13 @@
import { windowSymbol } from '../symbols';
-import { IPublicModelWindow } from '@alilc/lowcode-types';
+import { IPublicModelResource, IPublicModelWindow } from '@alilc/lowcode-types';
import { EditorWindow } from '@alilc/lowcode-workspace';
-import { ResourceType } from './resource-type';
+import { Resource } from './resource';
export class Window implements IPublicModelWindow {
private readonly [windowSymbol]: EditorWindow;
get id() {
- return this[windowSymbol].id;
+ return this[windowSymbol]?.id;
}
get title() {
@@ -18,8 +18,8 @@ export class Window implements IPublicModelWindow {
return this[windowSymbol].icon;
}
- get resourceType(): ResourceType {
- return new ResourceType(this[windowSymbol].resourceType);
+ get resource(): IPublicModelResource {
+ return new Resource(this[windowSymbol].resource);
}
constructor(editorWindow: EditorWindow) {
diff --git a/packages/types/src/shell/api/workspace.ts b/packages/types/src/shell/api/workspace.ts
index 165565fe7..ca4b3cc34 100644
--- a/packages/types/src/shell/api/workspace.ts
+++ b/packages/types/src/shell/api/workspace.ts
@@ -1,6 +1,5 @@
import { IPublicModelWindow } from '../model';
-import { IPublicResourceOptions } from '../type';
-import { IPublicApiPlugins, IPublicModelResource, IPublicResourceList } from '@alilc/lowcode-types';
+import { IPublicApiPlugins, IPublicModelResource, IPublicResourceList, IPublicTypeResourceType } from '@alilc/lowcode-types';
export interface IPublicApiWorkspace {
@@ -10,6 +9,11 @@ export interface IPublicApiWorkspace {
/** 当前设计器窗口 */
window: IPublicModelWindow;
+ plugins: IPublicApiPlugins;
+
+ /** 当前设计器的编辑窗口 */
+ windows: IPublicModelWindow[];
+
/** 获取资源树列表 */
get resourceList(): IPublicModelResource[];
@@ -20,7 +24,7 @@ export interface IPublicApiWorkspace {
onResourceListChange(fn: (resourceList: IPublicResourceList) => void): () => void;
/** 注册资源 */
- registerResourceType(resourceName: string, type: 'editor', options: IPublicResourceOptions): void;
+ registerResourceType(resourceTypeModel: IPublicTypeResourceType): void;
/** 打开视图窗口 */
openEditorWindow(resourceName: string, title: string, extra: Object, viewName?: string): void;
@@ -34,14 +38,9 @@ export interface IPublicApiWorkspace {
/** 通过视图 id 移除窗口 */
removeEditorWindowById(id: string): void;
- plugins: IPublicApiPlugins;
-
- /** 当前设计器的编辑窗口 */
- windows: IPublicModelWindow[];
-
/** 窗口新增/删除的事件 */
- onChangeWindows: (fn: () => void) => void;
+ onChangeWindows(fn: () => void): void;
/** active 窗口变更事件 */
- onChangeActiveWindow: (fn: () => void) => void;
+ onChangeActiveWindow(fn: () => void): void;
}
\ No newline at end of file
diff --git a/packages/types/src/shell/model/index.ts b/packages/types/src/shell/model/index.ts
index 669fdfc99..e59216faa 100644
--- a/packages/types/src/shell/model/index.ts
+++ b/packages/types/src/shell/model/index.ts
@@ -28,5 +28,4 @@ export * from './editor';
export * from './preference';
export * from './plugin-instance';
export * from './sensor';
-export * from './resource-type';
export * from './resource';
\ No newline at end of file
diff --git a/packages/types/src/shell/model/resource-type.ts b/packages/types/src/shell/model/resource-type.ts
deleted file mode 100644
index e8031145e..000000000
--- a/packages/types/src/shell/model/resource-type.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { ReactElement } from 'react';
-
-export interface IPublicModelResourceType {
- get description(): string | undefined;
-
- get icon(): ReactElement | undefined;
-}
\ No newline at end of file
diff --git a/packages/types/src/shell/model/resource.ts b/packages/types/src/shell/model/resource.ts
index 23dbfb50f..cfa48f189 100644
--- a/packages/types/src/shell/model/resource.ts
+++ b/packages/types/src/shell/model/resource.ts
@@ -2,11 +2,15 @@ import { ReactElement } from 'react';
import { IPublicModelResourceType } from './resource-type';
export interface IPublicModelResource {
- get title(): string;
+ get title(): string | undefined;
get icon(): ReactElement | undefined;
get options(): Object;
- get resourceType(): IPublicModelResourceType | undefined;
+ get name(): string | undefined;
+
+ get type(): string | undefined;
+
+ get category(): string | undefined;
}
\ No newline at end of file
diff --git a/packages/types/src/shell/model/window.ts b/packages/types/src/shell/model/window.ts
index 7a12fc8e6..741ac1c8e 100644
--- a/packages/types/src/shell/model/window.ts
+++ b/packages/types/src/shell/model/window.ts
@@ -1,18 +1,9 @@
import { ReactElement } from 'react';
import { IPublicTypeNodeSchema } from '../type';
-import { IPublicModelResourceType } from './resource-type';
+import { IPublicModelResource } from './resource';
export interface IPublicModelWindow {
- /** 当前窗口导入 schema */
- importSchema(schema: IPublicTypeNodeSchema): void;
-
- /** 修改当前窗口视图类型 */
- changeViewType(viewName: string): void;
-
- /** 调用当前窗口视图保存钩子 */
- save(): Promise;
-
/** 窗口 id */
id: string;
@@ -23,5 +14,14 @@ export interface IPublicModelWindow {
icon?: ReactElement;
/** 窗口资源类型 */
- resourceType?: IPublicModelResourceType;
+ resource?: IPublicModelResource;
+
+ /** 当前窗口导入 schema */
+ importSchema(schema: IPublicTypeNodeSchema): void;
+
+ /** 修改当前窗口视图类型 */
+ changeViewType(viewName: string): void;
+
+ /** 调用当前窗口视图保存钩子 */
+ save(): Promise;
}
\ No newline at end of file
diff --git a/packages/types/src/shell/type/editor-view-config.ts b/packages/types/src/shell/type/editor-view-config.ts
new file mode 100644
index 000000000..2b36a718a
--- /dev/null
+++ b/packages/types/src/shell/type/editor-view-config.ts
@@ -0,0 +1,8 @@
+export interface IPublicEditorViewConfig {
+
+ /** 视图初始化钩子 */
+ init?: () => Promise;
+
+ /** 资源保存时,会调用视图的钩子 */
+ save?: () => Promise;
+}
\ No newline at end of file
diff --git a/packages/types/src/shell/type/editor-view.ts b/packages/types/src/shell/type/editor-view.ts
new file mode 100644
index 000000000..2357a48f5
--- /dev/null
+++ b/packages/types/src/shell/type/editor-view.ts
@@ -0,0 +1,12 @@
+import { IPublicEditorViewConfig } from './editor-view-config';
+
+export interface IPublicTypeEditorView {
+
+ /** 资源名字 */
+ viewName: string;
+
+ /** 资源类型 */
+ viewType?: 'editor' | 'webview';
+
+ (ctx: any, options: any): IPublicEditorViewConfig;
+}
\ No newline at end of file
diff --git a/packages/types/src/shell/type/index.ts b/packages/types/src/shell/type/index.ts
index 9a44dade4..f66094f3d 100644
--- a/packages/types/src/shell/type/index.ts
+++ b/packages/types/src/shell/type/index.ts
@@ -73,7 +73,7 @@ export * from './tip-config';
export * from './widget-config-area';
export * from './hotkey-callback';
export * from './plugin-register-options';
-export * from './resource-options';
+export * from './resource-list';
export * from './engine-options';
export * from './on-change-options';
export * from './slot-schema';
@@ -82,4 +82,8 @@ export * from './node-instance';
export * from './editor-value-key';
export * from './editor-get-options';
export * from './editor-get-result';
-export * from './editor-register-options';
\ No newline at end of file
+export * from './editor-register-options';
+export * from './editor-view';
+export * from './resource-type';
+export * from './resource-type-config';
+export * from './editor-view-config';
\ No newline at end of file
diff --git a/packages/types/src/shell/type/resource-list.ts b/packages/types/src/shell/type/resource-list.ts
new file mode 100644
index 000000000..e5fbcba7e
--- /dev/null
+++ b/packages/types/src/shell/type/resource-list.ts
@@ -0,0 +1,10 @@
+export interface IPublicResourceData {
+ resourceName: string;
+ title: string;
+ category: string;
+ options: {
+ [key: string]: any;
+ };
+}
+
+export type IPublicResourceList = IPublicResourceData[];
\ No newline at end of file
diff --git a/packages/types/src/shell/type/resource-options.ts b/packages/types/src/shell/type/resource-options.ts
deleted file mode 100644
index 4954aa7fa..000000000
--- a/packages/types/src/shell/type/resource-options.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-export interface IPublicViewFunctions {
-
- /** 视图初始化钩子 */
- init?: () => Promise;
-
- /** 资源保存时,会调用视图的钩子 */
- save?: () => Promise;
-}
-
-export interface IPublicEditorView {
-
- /** 资源名字 */
- viewName: string;
-
- /** 资源类型 */
- viewType?: 'editor' | 'webview';
- (ctx: any, options: any): IPublicViewFunctions;
-}
-
-export interface IPublicResourceOptions {
-
- /** 资源描述 */
- description?: string;
-
- /** 资源 icon 标识 */
- icon?: React.ReactElement;
-
- /** 默认视图类型 */
- defaultViewType: string;
-
- /** 资源视图 */
- editorViews: IPublicEditorView[];
-
- /** save 钩子 */
- save?: (schema: {
- [viewName: string]: any;
- }) => Promise;
-
- /** import 钩子 */
- import?: (schema: any) => Promise<{
- [viewName: string]: any;
- }>;
-
- /** 默认标题 */
- defaultTitle?: string;
-}
-
-export interface IPublicResourceData {
- resourceName: string;
- title: string;
- options: {
- [key: string]: any;
- };
-}
-
-export type IPublicResourceList = IPublicResourceData[];
\ No newline at end of file
diff --git a/packages/types/src/shell/type/resource-type-config.ts b/packages/types/src/shell/type/resource-type-config.ts
new file mode 100644
index 000000000..93534fea2
--- /dev/null
+++ b/packages/types/src/shell/type/resource-type-config.ts
@@ -0,0 +1,31 @@
+import { IPublicTypeEditorView } from './editor-view';
+
+export interface IPublicResourceTypeConfig {
+
+ /** 资源描述 */
+ description?: string;
+
+ /** 资源 icon 标识 */
+ icon?: React.ReactElement;
+
+ /** 默认视图类型 */
+ defaultViewType: string;
+
+ /** 资源视图 */
+ editorViews: IPublicTypeEditorView[];
+
+ init?: () => void;
+
+ /** save 钩子 */
+ save?: (schema: {
+ [viewName: string]: any;
+ }) => Promise;
+
+ /** import 钩子 */
+ import?: (schema: any) => Promise<{
+ [viewName: string]: any;
+ }>;
+
+ /** 默认标题 */
+ defaultTitle?: string;
+}
diff --git a/packages/types/src/shell/type/resource-type.ts b/packages/types/src/shell/type/resource-type.ts
new file mode 100644
index 000000000..64ec85c79
--- /dev/null
+++ b/packages/types/src/shell/type/resource-type.ts
@@ -0,0 +1,10 @@
+import { IPublicModelPluginContext } from '../model';
+import { IPublicResourceTypeConfig } from './resource-type-config';
+
+export interface IPublicTypeResourceType {
+ resourceName: string;
+
+ resourceType: string;
+
+ (ctx: IPublicModelPluginContext): IPublicResourceTypeConfig;
+}
\ No newline at end of file
diff --git a/packages/workspace/src/editor-view/context.ts b/packages/workspace/src/editor-view/context.ts
index 12e63b255..b991532fb 100644
--- a/packages/workspace/src/editor-view/context.ts
+++ b/packages/workspace/src/editor-view/context.ts
@@ -1,5 +1,5 @@
import { makeObservable, obx } from '@alilc/lowcode-editor-core';
-import { IPublicEditorView, IPublicViewFunctions } from '@alilc/lowcode-types';
+import { IPublicEditorViewConfig, IPublicTypeEditorView } from '@alilc/lowcode-types';
import { flow } from 'mobx';
import { Workspace as InnerWorkspace } from '../workspace';
import { BasicContext } from '../base-context';
@@ -9,31 +9,12 @@ import { getWebviewPlugin } from '../inner-plugins/webview';
export class Context extends BasicContext {
viewName = 'editor-view';
- instance: IPublicViewFunctions;
+ instance: IPublicEditorViewConfig;
viewType: 'editor' | 'webview';
- constructor(public workspace: InnerWorkspace, public editorWindow: EditorWindow, public editorView: IPublicEditorView, options: Object) {
- super(workspace, editorView.viewName, editorWindow);
- this.viewType = editorView.viewType || 'editor';
- this.viewName = editorView.viewName;
- this.instance = editorView(this.innerPlugins._getLowCodePluginContext({
- pluginName: 'any',
- }), options);
- makeObservable(this);
- }
-
@obx _activate = false;
- setActivate = (_activate: boolean) => {
- this._activate = _activate;
- this.innerHotkey.activate(this._activate);
- };
-
- get active() {
- return this._activate;
- }
-
@obx isInit: boolean = false;
init = flow(function* (this: any) {
@@ -48,6 +29,25 @@ export class Context extends BasicContext {
this.isInit = true;
});
+ constructor(public workspace: InnerWorkspace, public editorWindow: EditorWindow, public editorView: IPublicTypeEditorView, options: Object) {
+ super(workspace, editorView.viewName, editorWindow);
+ this.viewType = editorView.viewType || 'editor';
+ this.viewName = editorView.viewName;
+ this.instance = editorView(this.innerPlugins._getLowCodePluginContext({
+ pluginName: 'any',
+ }), options);
+ makeObservable(this);
+ }
+
+ setActivate = (_activate: boolean) => {
+ this._activate = _activate;
+ this.innerHotkey.activate(this._activate);
+ };
+
+ get active() {
+ return this._activate;
+ }
+
async save() {
return await this.instance?.save?.();
}
diff --git a/packages/workspace/src/editor-window/context.ts b/packages/workspace/src/editor-window/context.ts
index 5e3fb172f..680647587 100644
--- a/packages/workspace/src/editor-window/context.ts
+++ b/packages/workspace/src/editor-window/context.ts
@@ -2,20 +2,24 @@ import { uniqueId } from '@alilc/lowcode-utils';
import { makeObservable, obx } from '@alilc/lowcode-editor-core';
import { Context } from '../editor-view/context';
import { Workspace } from '../workspace';
-import { ResourceType } from '../resource-type';
+import { Resource } from '../resource';
export class EditorWindow {
id: string = uniqueId('window');
icon: React.ReactElement | undefined;
- constructor(readonly resourceType: ResourceType, readonly workspace: Workspace, public title: string | undefined = '', private options: Object = {}) {
+ @obx.ref editorView: Context;
+
+ @obx editorViews: Map = new Map();
+
+ constructor(readonly resource: Resource, readonly workspace: Workspace, public title: string | undefined = '', private options: Object = {}) {
makeObservable(this);
this.init();
- this.icon = resourceType.icon;
+ this.icon = resource.icon;
}
async importSchema(schema: any) {
- const newSchema = await this.resourceType.import(schema);
+ const newSchema = await this.resource.import(schema);
if (!newSchema) {
return;
@@ -29,13 +33,13 @@ export class EditorWindow {
async save() {
const value: any = {};
- const editorViews = this.resourceType.editorViews;
+ const editorViews = this.resource.editorViews;
for (let i = 0; i < editorViews.length; i++) {
const name = editorViews[i].viewName;
const saveResult = await this.editorViews.get(name)?.save();
value[name] = saveResult;
}
- return await this.resourceType.save(value);
+ return await this.resource.save(value);
}
async init() {
@@ -45,7 +49,7 @@ export class EditorWindow {
}
initViewTypes = async () => {
- const editorViews = this.resourceType.editorViews;
+ const editorViews = this.resource.editorViews;
for (let i = 0; i < editorViews.length; i++) {
const name = editorViews[i].viewName;
await this.initViewType(name);
@@ -56,7 +60,7 @@ export class EditorWindow {
};
execViewTypesInit = async () => {
- const editorViews = this.resourceType.editorViews;
+ const editorViews = this.resource.editorViews;
for (let i = 0; i < editorViews.length; i++) {
const name = editorViews[i].viewName;
this.changeViewType(name);
@@ -65,15 +69,11 @@ export class EditorWindow {
};
setDefaultViewType = () => {
- this.changeViewType(this.resourceType.defaultViewType);
+ this.changeViewType(this.resource.defaultViewType);
};
- @obx.ref editorView: Context;
-
- @obx editorViews: Map = new Map();
-
initViewType = async (name: string) => {
- const viewInfo = this.resourceType.getEditorView(name);
+ const viewInfo = this.resource.getEditorView(name);
if (this.editorViews.get(name)) {
return;
}
diff --git a/packages/workspace/src/index.ts b/packages/workspace/src/index.ts
index 8c71771a9..2f6da97a8 100644
--- a/packages/workspace/src/index.ts
+++ b/packages/workspace/src/index.ts
@@ -1,5 +1,4 @@
export { Workspace } from './workspace';
-export { ResourceType } from './resource-type';
export * from './editor-window/context';
export * from './layouts/workbench';
export { Resource } from './resource';
diff --git a/packages/workspace/src/layouts/top-area.tsx b/packages/workspace/src/layouts/top-area.tsx
index 457e928d2..cecaee2a7 100644
--- a/packages/workspace/src/layouts/top-area.tsx
+++ b/packages/workspace/src/layouts/top-area.tsx
@@ -48,9 +48,7 @@ class Contents extends Component<{ area: Area; itemClassName?: string }> {
right.push(content);
}
});
- if (!center || !center.length) {
- return null;
- }
+
return (
{left}
diff --git a/packages/workspace/src/resource-type.ts b/packages/workspace/src/resource-type.ts
index 60a2832ee..b52183068 100644
--- a/packages/workspace/src/resource-type.ts
+++ b/packages/workspace/src/resource-type.ts
@@ -1,53 +1,14 @@
-import { IPublicEditorView, IPublicModelResourceType, IPublicResourceOptions } from '@alilc/lowcode-types';
+import { IPublicTypeResourceType } from '@alilc/lowcode-types';
-export class ResourceType implements IPublicModelResourceType {
- constructor(readonly name: string, readonly type: 'editor' | 'webview', options: IPublicResourceOptions) {
- if (options.editorViews) {
- options.editorViews.forEach((d: any) => {
- this.editorViewMap.set(d.viewName, d);
- });
- }
-
- this.options = options;
+export class ResourceType {
+ constructor(readonly resourceTypeModel: IPublicTypeResourceType) {
}
- get description() {
- return this.options.description;
+ get name() {
+ return this.resourceTypeModel.resourceName;
}
- options: IPublicResourceOptions;
-
- editorViewMap: Map = new Map();
-
- init(ctx: any) {
- this.options.init(ctx);
- }
-
- get icon() {
- return this.options.icon;
- }
-
- async import(schema: any) {
- return await this.options.import?.(schema);
- }
-
- getEditorView(name: string) {
- return this.editorViewMap.get(name);
- }
-
- get defaultViewType() {
- return this.options.defaultViewType || this.editorViewMap.keys().next().value;
- }
-
- get editorViews() {
- return Array.from(this.editorViewMap.values());
- }
-
- async save(value: any) {
- return await this.options.save?.(value);
- }
-
- get title() {
- return this.options.defaultTitle;
+ get type() {
+ return this.resourceTypeModel.resourceType;
}
}
\ No newline at end of file
diff --git a/packages/workspace/src/resource.ts b/packages/workspace/src/resource.ts
index 5c44785ce..9753339f0 100644
--- a/packages/workspace/src/resource.ts
+++ b/packages/workspace/src/resource.ts
@@ -1,29 +1,72 @@
-import { IPublicModelResource, IPublicResourceData } from '@alilc/lowcode-types';
+import { IPublicTypeEditorView, IPublicModelResource, IPublicResourceData, IPublicResourceTypeConfig } from '@alilc/lowcode-types';
import { Logger } from '@alilc/lowcode-utils';
+import { BasicContext } from './base-context';
import { ResourceType } from './resource-type';
+import { Workspace as InnerWorkSpace } from './workspace';
const logger = new Logger({ level: 'warn', bizName: 'workspace:resource' });
export class Resource implements IPublicModelResource {
- constructor(readonly resourceData: IPublicResourceData, readonly resourceType: ResourceType) {
+ resourceTypeInstance: IPublicResourceTypeConfig;
+
+ editorViewMap: Map = new Map();
+
+ constructor(readonly resourceData: IPublicResourceData, readonly resourceType: ResourceType, workspace: InnerWorkSpace) {
+ this.resourceTypeInstance = resourceType.resourceTypeModel(new BasicContext(workspace, ''), {});
+ if (this.resourceTypeInstance.editorViews) {
+ this.resourceTypeInstance.editorViews.forEach((d: any) => {
+ this.editorViewMap.set(d.viewName, d);
+ });
+ }
if (!resourceType) {
logger.error(`resourceType[${resourceType}] is unValid.`);
}
}
+ get name() {
+ return this.resourceType.name;
+ }
+
+ get description() {
+ return this.resourceTypeInstance?.description;
+ }
+
get icon() {
- return this.resourceType?.icon;
+ return this.resourceTypeInstance?.icon;
}
get type() {
- return this.resourceData.resourceName;
+ return this.resourceType.type;
}
- get title() {
- return this.resourceData.title;
+ get title(): string | undefined {
+ return this.resourceData.title || this.resourceTypeInstance.defaultTitle;
}
get options() {
return this.resourceData.options;
}
+
+ get category() {
+ return this.resourceData?.category;
+ }
+
+ async import(schema: any) {
+ return await this.resourceTypeInstance.import?.(schema);
+ }
+ async save(value: any) {
+ return await this.resourceTypeInstance.save?.(value);
+ }
+
+ get editorViews() {
+ return this.resourceTypeInstance.editorViews;
+ }
+
+ get defaultViewType() {
+ return this.resourceTypeInstance.defaultViewType;
+ }
+
+ getEditorView(name: string) {
+ return this.editorViewMap.get(name);
+ }
}
\ No newline at end of file
diff --git a/packages/workspace/src/workspace.ts b/packages/workspace/src/workspace.ts
index ca7265cb3..c4462a71a 100644
--- a/packages/workspace/src/workspace.ts
+++ b/packages/workspace/src/workspace.ts
@@ -1,7 +1,7 @@
import { Designer } from '@alilc/lowcode-designer';
import { createModuleEventBus, Editor, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
import { Plugins } from '@alilc/lowcode-shell';
-import { IPublicApiWorkspace, IPublicResourceList, IPublicResourceOptions } from '@alilc/lowcode-types';
+import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeResourceType } from '@alilc/lowcode-types';
import { BasicContext } from './base-context';
import { EditorWindow } from './editor-window/context';
import { Resource } from './resource';
@@ -16,7 +16,7 @@ enum event {
const CHANGE_EVENT = 'resource.list.change';
export class Workspace implements IPublicApiWorkspace {
- private context: BasicContext;
+ context: BasicContext;
private emitter: IEventBus = createModuleEventBus('workspace');
@@ -28,6 +28,18 @@ export class Workspace implements IPublicApiWorkspace {
return this.context.innerPlugins;
}
+ private _isActive = false;
+
+ windows: EditorWindow[] = [];
+
+ editorWindowMap: Map = new Map();
+
+ @obx.ref window: EditorWindow;
+
+ private resourceTypeMap: Map = new Map();
+
+ private resourceList: Resource[] = [];
+
constructor(
readonly registryInnerPlugin: (designer: Designer, editor: Editor, plugins: Plugins) => Promise,
readonly shellModelFactory: any,
@@ -42,19 +54,18 @@ export class Workspace implements IPublicApiWorkspace {
}
initWindow() {
- if (!this.defaultResource) {
+ if (!this.defaultResourceType) {
return;
}
- const title = this.defaultResource.description;
- this.window = new EditorWindow(this.defaultResource, this, title);
+ const title = this.defaultResourceType.name;
+ const resource = new Resource({}, this.defaultResourceType, this);
+ this.window = new EditorWindow(resource, this, title);
this.editorWindowMap.set(this.window.id, this.window);
this.windows.push(this.window);
this.emitChangeWindow();
this.emitChangeActiveWindow();
}
- private _isActive = false;
-
get isActive() {
return this._isActive;
}
@@ -63,22 +74,12 @@ export class Workspace implements IPublicApiWorkspace {
this._isActive = value;
}
- windows: EditorWindow[] = [];
+ async registerResourceType(resourceTypeModel: IPublicTypeResourceType): Promise {
+ if (resourceTypeModel.resourceType === 'editor') {
+ const resourceType = new ResourceType(resourceTypeModel);
+ this.resourceTypeMap.set(resourceTypeModel.resourceName, resourceType);
- editorWindowMap: Map = new Map();
-
- @obx.ref window: EditorWindow;
-
- private resourceTypeMap: Map = new Map();
-
- private resourceList: Resource[] = [];
-
- async registerResourceType(resourceName: string, type: 'editor' | 'webview', options: IPublicResourceOptions): Promise {
- if (type === 'editor') {
- const resourceType = new ResourceType(resourceName, type, options);
- this.resourceTypeMap.set(resourceName, resourceType);
-
- if (!this.window && this.defaultResource) {
+ if (!this.window && this.defaultResourceType) {
this.initWindow();
}
}
@@ -89,7 +90,7 @@ export class Workspace implements IPublicApiWorkspace {
}
setResourceList(resourceList: IPublicResourceList) {
- this.resourceList = resourceList.map(d => new Resource(d, this.getResourceType(d.resourceName)));
+ this.resourceList = resourceList.map(d => new Resource(d, this.getResourceType(d.resourceName), this));
this.emitter.emit(CHANGE_EVENT, resourceList);
}
@@ -104,9 +105,9 @@ export class Workspace implements IPublicApiWorkspace {
return this.resourceTypeMap.get(resourceName)!;
}
- get defaultResource(): ResourceType | null {
- if (this.resourceTypeMap.size > 1) {
- return this.resourceTypeMap.values().next().value;
+ get defaultResourceType(): ResourceType | null {
+ if (this.resourceTypeMap.size >= 1) {
+ return Array.from(this.resourceTypeMap.values())[0];
}
return null;
@@ -134,7 +135,7 @@ export class Workspace implements IPublicApiWorkspace {
}
removeEditorWindow(resourceName: string, title: string) {
- const index = this.windows.findIndex(d => (d.resourceType.name === resourceName && d.title));
+ const index = this.windows.findIndex(d => (d.resource.name === resourceName && d.title));
this.remove(index);
}
@@ -152,13 +153,14 @@ export class Workspace implements IPublicApiWorkspace {
console.error(`${name} is not available`);
return;
}
- const filterWindows = this.windows.filter(d => (d.resourceType.name === name && d.title == title));
+ const filterWindows = this.windows.filter(d => (d.resource.name === name && d.title == title));
if (filterWindows && filterWindows.length) {
this.window = filterWindows[0];
this.emitChangeActiveWindow();
return;
}
- this.window = new EditorWindow(resourceType, this, title, options);
+ const resource = new Resource({}, resourceType, this);
+ this.window = new EditorWindow(resource, this, title, options);
this.windows.push(this.window);
this.editorWindowMap.set(this.window.id, this.window);
this.emitChangeWindow();