Skip to content

Commit b984ef7

Browse files
liujupingJackLian
authored andcommitted
feat: workspace window add onSave api
1 parent 62288a1 commit b984ef7

File tree

6 files changed

+45
-7
lines changed

6 files changed

+45
-7
lines changed

docs/docs/api/model/window.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ sidebar_position: 12
4545

4646
关联模型 [IPublicModelEditorView](./editor-view)
4747

48+
**@since v1.1.7**
49+
4850
### editorViews
4951

5052
窗口所有视图
@@ -53,6 +55,7 @@ sidebar_position: 12
5355

5456
关联模型 [IPublicModelEditorView](./editor-view)
5557

58+
**@since v1.1.7**
5659

5760
## 方法
5861

@@ -90,3 +93,15 @@ onChangeViewType(fn: (viewName: string) => void): IPublicTypeDisposable;
9093
```
9194

9295
相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
96+
97+
### onSave
98+
99+
窗口视图保存事件
100+
101+
```
102+
onSave(fn: () => void): IPublicTypeDisposable;
103+
```
104+
105+
相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
106+
107+
**@since v1.1.7**

packages/plugin-outline-pane/src/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IPublicModelPluginContext, IPublicModelDocumentModel } from '@alilc/low
44
import { MasterPaneName, BackupPaneName } from './helper/consts';
55
import { TreeMaster } from './controllers/tree-master';
66
import { PaneController } from './controllers/pane-controller';
7-
import { useState } from 'react';
7+
import { useState, useEffect } from 'react';
88

99
export function OutlinePaneContext(props: {
1010
treeMaster?: TreeMaster;
@@ -19,9 +19,11 @@ export function OutlinePaneContext(props: {
1919
}) {
2020
const treeMaster = props.treeMaster || new TreeMaster(props.pluginContext, props.options);
2121
const [masterPaneController, setMasterPaneController] = useState(new PaneController(props.paneName || MasterPaneName, treeMaster));
22-
treeMaster.onPluginContextChange(() => {
23-
setMasterPaneController(new PaneController(props.paneName || MasterPaneName, treeMaster));
24-
});
22+
useEffect(() => {
23+
return treeMaster.onPluginContextChange(() => {
24+
setMasterPaneController(new PaneController(props.paneName || MasterPaneName, treeMaster));
25+
});
26+
}, []);
2527

2628
return (
2729
<Pane

packages/shell/src/model/window.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export class Window implements IPublicModelWindow {
4343
return await this[windowSymbol].save();
4444
}
4545

46+
onSave(fn: () => void) {
47+
return this[windowSymbol].onSave(fn);
48+
}
49+
4650
get currentEditorView() {
4751
if (this[windowSymbol].editorView) {
4852
return new EditorView(this[windowSymbol].editorView).toProxy() as any;

packages/types/src/shell/model/plugin-context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
IPublicApiWorkspace,
1414
} from '../api';
1515
import { IPublicEnumPluginRegisterLevel } from '../enum';
16-
import { IPublicModelEngineConfig, IPublicModelEditorView } from './';
16+
import { IPublicModelEngineConfig, IPublicModelWindow } from './';
1717

1818
export interface IPublicModelPluginContext {
1919

@@ -108,7 +108,7 @@ export interface IPublicModelPluginContext {
108108
*/
109109
get registerLevel(): IPublicEnumPluginRegisterLevel;
110110

111-
get editorWindow(): IPublicModelEditorView;
111+
get editorWindow(): IPublicModelWindow;
112112
}
113113

114114
/**

packages/types/src/shell/model/window.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,10 @@ export interface IPublicModelWindow<
4242

4343
/** 窗口视图变更事件 */
4444
onChangeViewType(fn: (viewName: string) => void): IPublicTypeDisposable;
45+
46+
/**
47+
* 窗口视图保存事件
48+
* @since 1.1.7
49+
*/
50+
onSave(fn: () => void): IPublicTypeDisposable;
4551
}

packages/workspace/src/window.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,18 @@ export class EditorWindow implements IEditorWindow {
7777
const saveResult = await this.editorViews.get(name)?.save();
7878
value[name] = saveResult;
7979
}
80-
return await this.resource.save(value);
80+
const result = await this.resource.save(value);
81+
this.emitter.emit('handle.save');
82+
83+
return result;
84+
}
85+
86+
onSave(fn: () => void) {
87+
this.emitter.on('handle.save', fn);
88+
89+
return () => {
90+
this.emitter.off('handle.save', fn);
91+
};
8192
}
8293

8394
async init() {

0 commit comments

Comments
 (0)