feat: workspace window add onSave api

This commit is contained in:
liujuping 2023-05-19 17:19:31 +08:00 committed by 林熠
parent 62288a139f
commit b984ef72d2
6 changed files with 45 additions and 7 deletions

View File

@ -45,6 +45,8 @@ sidebar_position: 12
关联模型 [IPublicModelEditorView](./editor-view) 关联模型 [IPublicModelEditorView](./editor-view)
**@since v1.1.7**
### editorViews ### editorViews
窗口所有视图 窗口所有视图
@ -53,6 +55,7 @@ sidebar_position: 12
关联模型 [IPublicModelEditorView](./editor-view) 关联模型 [IPublicModelEditorView](./editor-view)
**@since v1.1.7**
## 方法 ## 方法
@ -90,3 +93,15 @@ onChangeViewType(fn: (viewName: string) => void): IPublicTypeDisposable;
``` ```
相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) 相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
### onSave
窗口视图保存事件
```
onSave(fn: () => void): IPublicTypeDisposable;
```
相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
**@since v1.1.7**

View File

@ -4,7 +4,7 @@ import { IPublicModelPluginContext, IPublicModelDocumentModel } from '@alilc/low
import { MasterPaneName, BackupPaneName } from './helper/consts'; import { MasterPaneName, BackupPaneName } from './helper/consts';
import { TreeMaster } from './controllers/tree-master'; import { TreeMaster } from './controllers/tree-master';
import { PaneController } from './controllers/pane-controller'; import { PaneController } from './controllers/pane-controller';
import { useState } from 'react'; import { useState, useEffect } from 'react';
export function OutlinePaneContext(props: { export function OutlinePaneContext(props: {
treeMaster?: TreeMaster; treeMaster?: TreeMaster;
@ -19,9 +19,11 @@ export function OutlinePaneContext(props: {
}) { }) {
const treeMaster = props.treeMaster || new TreeMaster(props.pluginContext, props.options); const treeMaster = props.treeMaster || new TreeMaster(props.pluginContext, props.options);
const [masterPaneController, setMasterPaneController] = useState(new PaneController(props.paneName || MasterPaneName, treeMaster)); const [masterPaneController, setMasterPaneController] = useState(new PaneController(props.paneName || MasterPaneName, treeMaster));
treeMaster.onPluginContextChange(() => { useEffect(() => {
return treeMaster.onPluginContextChange(() => {
setMasterPaneController(new PaneController(props.paneName || MasterPaneName, treeMaster)); setMasterPaneController(new PaneController(props.paneName || MasterPaneName, treeMaster));
}); });
}, []);
return ( return (
<Pane <Pane

View File

@ -43,6 +43,10 @@ export class Window implements IPublicModelWindow {
return await this[windowSymbol].save(); return await this[windowSymbol].save();
} }
onSave(fn: () => void) {
return this[windowSymbol].onSave(fn);
}
get currentEditorView() { get currentEditorView() {
if (this[windowSymbol].editorView) { if (this[windowSymbol].editorView) {
return new EditorView(this[windowSymbol].editorView).toProxy() as any; return new EditorView(this[windowSymbol].editorView).toProxy() as any;

View File

@ -13,7 +13,7 @@ import {
IPublicApiWorkspace, IPublicApiWorkspace,
} from '../api'; } from '../api';
import { IPublicEnumPluginRegisterLevel } from '../enum'; import { IPublicEnumPluginRegisterLevel } from '../enum';
import { IPublicModelEngineConfig, IPublicModelEditorView } from './'; import { IPublicModelEngineConfig, IPublicModelWindow } from './';
export interface IPublicModelPluginContext { export interface IPublicModelPluginContext {
@ -108,7 +108,7 @@ export interface IPublicModelPluginContext {
*/ */
get registerLevel(): IPublicEnumPluginRegisterLevel; get registerLevel(): IPublicEnumPluginRegisterLevel;
get editorWindow(): IPublicModelEditorView; get editorWindow(): IPublicModelWindow;
} }
/** /**

View File

@ -42,4 +42,10 @@ export interface IPublicModelWindow<
/** 窗口视图变更事件 */ /** 窗口视图变更事件 */
onChangeViewType(fn: (viewName: string) => void): IPublicTypeDisposable; onChangeViewType(fn: (viewName: string) => void): IPublicTypeDisposable;
/**
*
* @since 1.1.7
*/
onSave(fn: () => void): IPublicTypeDisposable;
} }

View File

@ -77,7 +77,18 @@ export class EditorWindow implements IEditorWindow {
const saveResult = await this.editorViews.get(name)?.save(); const saveResult = await this.editorViews.get(name)?.save();
value[name] = saveResult; value[name] = saveResult;
} }
return await this.resource.save(value); const result = await this.resource.save(value);
this.emitter.emit('handle.save');
return result;
}
onSave(fn: () => void) {
this.emitter.on('handle.save', fn);
return () => {
this.emitter.off('handle.save', fn);
};
} }
async init() { async init() {