docs: add workspace docs

This commit is contained in:
liujuping 2022-12-26 12:07:19 +08:00 committed by 林熠
parent fadce950f9
commit 840e70e3d0
9 changed files with 123 additions and 27 deletions

View File

@ -0,0 +1,23 @@
---
title: Window
sidebar_position: 12
---
> **@types** [IPublicModelWindow](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/window.ts)<br/>
> **@since** v1.1.0
## 基本介绍
低代码设计器窗口模型
## 方法签名
### importSchema(schema: IPublicTypeNodeSchema)
当前窗口导入 schema
### changeViewType(viewName: string)
修改当前窗口视图类型
### async save
调用当前窗口视图保存钩子

View File

@ -0,0 +1,34 @@
---
title: workspace - 应用级 API
sidebar_position: 12
---
> **@types** [IPublicApiWorkspace](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/workspace.ts)<br/>
> **@since** v1.1.0
## 模块简介
通过该模块可以开发应用级低代码设计器。
## 变量
### isActive
是否启用 workspace 模式
### window
当前设计器窗口模型
关联模型 [IPublicModelWindow](./model/window)
## 方法签名
### registerResourceType
注册资源
```typescript
/** 注册资源 */
registerResourceType(resourceName: string, resourceType: 'editor', options: IPublicResourceOptions): void;
```

View File

@ -17,7 +17,7 @@ export class Window implements IPublicModelWindow {
this[windowSymbol].changeViewType(viewName);
}
save() {
return this[windowSymbol].save();
async save() {
return await this[windowSymbol].save();
}
}

View File

@ -1 +1,13 @@
export interface IPublicApiWorkspace {}
import { IPublicModelWindow } from '../model';
import { IPublicResourceOptions } from '../type';
export interface IPublicApiWorkspace {
/** 是否启用 workspace 模式 */
isActive: boolean;
/** 当前设计器窗口 */
window: IPublicModelWindow;
/** 注册资源 */
registerResourceType(resourceName: string, resourceType: 'editor', options: IPublicResourceOptions): void;
}

View File

@ -1 +1,14 @@
export interface IPublicModelWindow {}
import { IPublicTypeNodeSchema } from '../type';
export interface IPublicModelWindow {
/** 当前窗口导入 schema */
importSchema(schema: IPublicTypeNodeSchema): void;
/** 修改当前窗口视图类型 */
changeViewType(viewName: string): void;
/** 调用当前窗口视图保存钩子 */
save(): Promise<{
[viewName: string]: IPublicTypeNodeSchema | any;
}>;
}

View File

@ -72,4 +72,5 @@ export * from './setter-config';
export * from './tip-config';
export * from './widget-config-area';
export * from './hotkey-callback';
export * from './plugin-register-options';
export * from './plugin-register-options';
export * from './resource-options';

View File

@ -0,0 +1,32 @@
export interface IPublicViewFunctions {
/** 视图初始化 */
init?: () => Promise<void>;
/** 资源保存时调用视图的钩子 */
save?: () => Promise<void>;
}
export interface IPublicEditorView {
/** 资源名字 */
viewName: string;
(ctx: any): IPublicViewFunctions;
}
export interface IPublicResourceOptions {
/** 资源名字 */
name: string;
/** 资源描述 */
description?: string;
/** 默认视图类型 */
defaultViewType: string;
/** 资源视图 */
editorViews: IPublicEditorView[];
/** save 钩子 */
save?: () => Promise<void>;
/** import 钩子 */
import?: () => Promise<void>;
}

View File

@ -26,7 +26,7 @@ export class EditorWindow {
const saveResult = await this.editorViews.get(name)?.save();
value[name] = saveResult;
}
this.resource.save(value);
return await this.resource.save(value);
}
async init() {

View File

@ -2,6 +2,7 @@ import { Editor } from '@alilc/lowcode-editor-core';
import {
Skeleton as InnerSkeleton,
} from '@alilc/lowcode-editor-skeleton';
import { IPublicResourceOptions } from '@alilc/lowcode-types';
import { EditorWindow } from './editor-window/context';
import { Resource } from './resource';
@ -35,7 +36,7 @@ export class Workspace {
private resources: Map<string, Resource> = new Map();
registerResourceType(resourceName: string, resourceType: 'editor' | 'webview', options: ResourceOptions): void {
registerResourceType(resourceName: string, resourceType: 'editor' | 'webview', options: IPublicResourceOptions): void {
if (resourceType === 'editor') {
const resource = new Resource(options);
this.resources.set(resourceName, resource);
@ -62,23 +63,3 @@ export class Workspace {
openEditorWindow() {}
}
export interface ResourceOptions {
description: string;
defaultViewType?: string;
editorViews?: EditorViewOptions[];
init: (ctx: any) => Promise<void>;
dispose: (ctx: any) => Promise<void>;
import: (ctx: any) => Promise<any>;
save: (value: any) => Promise<any>;
}
export interface ViewFunctions {
init: () => Promise<void>;
save: () => Promise<void>;
}
export type EditorViewOptions = {
viewName: string;
(ctx: any): ViewFunctions;
};