GeezerVison is showing github.com — feat: the event supplements the dispose function as the return value · stantoxt/lowcode-engine@69ab81a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/docs/api/material.md +4-1Lines changed: 4 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -358,8 +358,11 @@ material.getRegisteredMetadataTransducers(); | 358 | 358 | * add callback for assets changed event | 359 | 359 | * @param fn | 360 | 360 | */ | 361 | | -onChangeAssets(fn: () => void): void; | | 361 | +onChangeAssets(fn: () => void): IPublicTypeDisposable; | 362 | 362 | ``` | | 363 | + | | 364 | +相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) | | 365 | + | 363 | 366 | ##### 示例 | 364 | 367 | ```typescript | 365 | 368 | import { material } from '@alilc/lowcode-engine'; | |
Collapse file Copy file name to clipboardExpand all lines: docs/docs/api/model/document-model.md +9-5Lines changed: 9 additions & 5 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -327,27 +327,31 @@ onChangeSelection(fn: (ids: string[]) => void): IPublicTypeDisposable; | 327 | 327 | * set callback for event on visibility changed for certain node | 328 | 328 | * @param fn | 329 | 329 | */ | 330 | | -onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): void; | | 330 | +onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): IPublicTypeDisposable; | 331 | 331 | ``` | 332 | 332 |
| 333 | | -相关类型:[IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts) | | 333 | +- 相关类型:[IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts) | | 334 | +- 相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) | 334 | 335 |
| 335 | 336 | ### onChangeNodeChildren | 336 | 337 |
| 337 | | -onChangeNodeChildren(fn: (info?: IPublicTypeOnChangeOptions) => void) | 338 | | - | 339 | 338 | 当前 document 的节点 children 变更事件 | 340 | 339 |
| 341 | 340 | ```typescript | | 341 | +onChangeNodeChildren(fn: (info?: IPublicTypeOnChangeOptions) => void): IPublicTypeDisposable; | 342 | 342 | ``` | 343 | 343 |
| | 344 | +相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) | | 345 | + | 344 | 346 | ### onChangeNodeProp | 345 | 347 | 当前 document 节点属性修改事件 | 346 | 348 |
| 347 | 349 | ```typescript | 348 | | -onChangeNodeProp(fn: (info: IPublicTypePropChangeOptions) => void) | | 350 | +onChangeNodeProp(fn: (info: IPublicTypePropChangeOptions) => void): IPublicTypeDisposable; | 349 | 351 | ``` | 350 | 352 |
| | 353 | +相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) | | 354 | + | 351 | 355 | ### onImportSchema | 352 | 356 | 当前 document 导入新的 schema 事件 | 353 | 357 | ```typescript | |
Collapse file Copy file name to clipboardExpand all lines: docs/docs/api/skeleton.md +11-4Lines changed: 11 additions & 4 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -295,9 +295,11 @@ hideArea(areaName: string): void; | 295 | 295 | * @param listener | 296 | 296 | * @returns | 297 | 297 | */ | 298 | | -onShowPanel(listener: (...args: any[]) => void): () => void; | | 298 | +onShowPanel(listener: (...args: any[]) => void): IPublicTypeDisposable; | 299 | 299 | ``` | 300 | 300 |
| | 301 | +相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) | | 302 | + | 301 | 303 | ### onHidePanel | 302 | 304 |
| 303 | 305 | 监听 Panel 实例隐藏事件 | @@ -309,9 +311,11 @@ onShowPanel(listener: (...args: any[]) => void): () => void; | 309 | 311 | * @param listener | 310 | 312 | * @returns | 311 | 313 | */ | 312 | | -onHidePanel(listener: (...args: any[]) => void): () => void; | | 314 | +onHidePanel(listener: (...args: any[]) => void): IPublicTypeDisposable; | 313 | 315 | ``` | 314 | 316 |
| | 317 | +相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) | | 318 | + | 315 | 319 |
| 316 | 320 | ### onShowWidget | 317 | 321 |
| @@ -324,9 +328,10 @@ onHidePanel(listener: (...args: any[]) => void): () => void; | 324 | 328 | * @param listener | 325 | 329 | * @returns | 326 | 330 | */ | 327 | | -onShowWidget(listener: (...args: any[]) => void): () => void; | | 331 | +onShowWidget(listener: (...args: any[]) => void): IPublicTypeDisposable; | 328 | 332 | ``` | 329 | 333 |
| | 334 | +相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) | 330 | 335 |
| 331 | 336 | ### onHideWidget | 332 | 337 |
| @@ -339,9 +344,11 @@ onShowWidget(listener: (...args: any[]) => void): () => void; | 339 | 344 | * @param listener | 340 | 345 | * @returns | 341 | 346 | */ | 342 | | -onHideWidget(listener: (...args: any[]) => void): () => void; | | 347 | +onHideWidget(listener: (...args: any[]) => void): IPublicTypeDisposable; | 343 | 348 | ``` | 344 | 349 |
| | 350 | +相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) | | 351 | + | 345 | 352 | ## 使用示例 | 346 | 353 |
| 347 | 354 | ```typescript | |
Collapse file Copy file name to clipboardExpand all lines: docs/docs/api/workspace.md +35-27Lines changed: 35 additions & 27 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -69,22 +69,6 @@ registerResourceType(resourceTypeModel: IPublicTypeResourceType): void; | 69 | 69 |
| 70 | 70 | 相关类型:[IPublicTypeResourceType](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/resource-type.ts) | 71 | 71 |
| 72 | | -### onChangeWindows | 73 | | - | 74 | | -窗口新增/删除的事件 | 75 | | - | 76 | | -```typescript | 77 | | -function onChangeWindows(fn: () => void): void; | 78 | | -``` | 79 | | - | 80 | | -### onChangeActiveWindow | 81 | | - | 82 | | -active 窗口变更事件 | 83 | | - | 84 | | -```typescript | 85 | | -function onChangeActiveWindow(fn: () => void): void; | 86 | | -``` | 87 | | - | 88 | 72 | ### setResourceList | 89 | 73 |
| 90 | 74 | 设置设计器资源列表数据 | @@ -95,16 +79,6 @@ setResourceList(resourceList: IPublicResourceList) {} | 95 | 79 |
| 96 | 80 | 相关类型:[IPublicResourceOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/resource-options.ts) | 97 | 81 |
| 98 | | -### onResourceListChange | 99 | | - | 100 | | -设计器资源列表数据变更事件 | 101 | | - | 102 | | -```typescript | 103 | | -onResourceListChange(fn: (resourceList: IPublicResourceList): void): (): void; | 104 | | -``` | 105 | | -
| 106 | | -相关类型:[IPublicResourceOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/resource-options.ts) | 107 | | -
| 108 | 82 | ### openEditorWindow | 109 | 83 |
| 110 | 84 | 打开视图窗口 | @@ -135,4 +109,38 @@ removeEditorWindow(resourceName: string, title: string): void; | 135 | 109 |
| 136 | 110 | ```typescript | 137 | 111 | removeEditorWindowById(id: string): void; | 138 | | -``` | | 112 | +``` | | 113 | + | | 114 | +## 事件 | | 115 | + | | 116 | +### onChangeWindows | | 117 | + | | 118 | +窗口新增/删除的事件 | | 119 | + | | 120 | +```typescript | | 121 | +function onChangeWindows(fn: () => void): IPublicTypeDisposable; | | 122 | +``` | | 123 | + | | 124 | +相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) | | 125 | + | | 126 | +### onChangeActiveWindow | | 127 | + | | 128 | +active 窗口变更事件 | | 129 | + | | 130 | +```typescript | | 131 | +function onChangeActiveWindow(fn: () => void): IPublicTypeDisposable; | | 132 | +``` | | 133 | + | | 134 | +相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) | | 135 | + | | 136 | + | | 137 | +### onResourceListChange | | 138 | + | | 139 | +设计器资源列表数据变更事件 | | 140 | + | | 141 | +```typescript | | 142 | +onResourceListChange(fn: (resourceList: IPublicResourceList): void): (): IPublicTypeDisposable; | | 143 | +``` | | 144 | +
| | 145 | +- 相关类型:[IPublicResourceOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/resource-options.ts) | | 146 | +- 相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts) |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/project/project.ts -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -85,8 +85,6 @@ export class Project implements IProject { | 85 | 85 | return this._simulator || null; | 86 | 86 | } | 87 | 87 |
| 88 | | - key = Math.random(); | 89 | | - | 90 | 88 | @computed get currentDocument(): IDocumentModel | null { | 91 | 89 | return this.documents.find((doc) => doc.active); | 92 | 90 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/api/material.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ import { | 12 | 12 | IPublicModelComponentMeta, | 13 | 13 | IPublicTypeNpmInfo, | 14 | 14 | IPublicModelEditor, | | 15 | + IPublicTypeDisposable, | 15 | 16 | } from '@alilc/lowcode-types'; | 16 | 17 | import { Workspace as InnerWorkspace } from '@alilc/lowcode-workspace'; | 17 | 18 | import { editorSymbol, designerSymbol } from '../symbols'; | @@ -170,7 +171,7 @@ export class Material implements IPublicApiMaterial { | 170 | 171 | * 监听 assets 变化的事件 | 171 | 172 | * @param fn | 172 | 173 | */ | 173 | | - onChangeAssets(fn: () => void): Function { | | 174 | + onChangeAssets(fn: () => void): IPublicTypeDisposable { | 174 | 175 | const dispose = [ | 175 | 176 | // 设置 assets,经过 setAssets 赋值 | 176 | 177 | this[editorSymbol].onGot('assets', fn), | |
Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/api/skeleton.ts +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | SkeletonEvents, | 5 | 5 | } from '@alilc/lowcode-editor-skeleton'; | 6 | 6 | import { skeletonSymbol } from '../symbols'; | 7 | | -import { IPublicApiSkeleton, IPublicTypeWidgetBaseConfig, IPublicTypeWidgetConfigArea } from '@alilc/lowcode-types'; | | 7 | +import { IPublicApiSkeleton, IPublicTypeDisposable, IPublicTypeWidgetBaseConfig, IPublicTypeWidgetConfigArea } from '@alilc/lowcode-types'; | 8 | 8 |
| 9 | 9 | const innerSkeletonSymbol = Symbol('skeleton'); | 10 | 10 | export class Skeleton implements IPublicApiSkeleton { | @@ -129,7 +129,7 @@ export class Skeleton implements IPublicApiSkeleton { | 129 | 129 | * @param listener | 130 | 130 | * @returns | 131 | 131 | */ | 132 | | - onShowPanel(listener: (...args: any[]) => void) { | | 132 | + onShowPanel(listener: (...args: any[]) => void): IPublicTypeDisposable { | 133 | 133 | const { editor } = this[skeletonSymbol]; | 134 | 134 | editor.eventBus.on(SkeletonEvents.PANEL_SHOW, (name: any, panel: any) => { | 135 | 135 | // 不泄漏 skeleton | @@ -144,7 +144,7 @@ export class Skeleton implements IPublicApiSkeleton { | 144 | 144 | * @param listener | 145 | 145 | * @returns | 146 | 146 | */ | 147 | | - onHidePanel(listener: (...args: any[]) => void) { | | 147 | + onHidePanel(listener: (...args: any[]) => void): IPublicTypeDisposable { | 148 | 148 | const { editor } = this[skeletonSymbol]; | 149 | 149 | editor.eventBus.on(SkeletonEvents.PANEL_HIDE, (name: any, panel: any) => { | 150 | 150 | // 不泄漏 skeleton | @@ -159,7 +159,7 @@ export class Skeleton implements IPublicApiSkeleton { | 159 | 159 | * @param listener | 160 | 160 | * @returns | 161 | 161 | */ | 162 | | - onShowWidget(listener: (...args: any[]) => void) { | | 162 | + onShowWidget(listener: (...args: any[]) => void): IPublicTypeDisposable { | 163 | 163 | const { editor } = this[skeletonSymbol]; | 164 | 164 | editor.eventBus.on(SkeletonEvents.WIDGET_SHOW, (name: any, panel: any) => { | 165 | 165 | // 不泄漏 skeleton | @@ -174,7 +174,7 @@ export class Skeleton implements IPublicApiSkeleton { | 174 | 174 | * @param listener | 175 | 175 | * @returns | 176 | 176 | */ | 177 | | - onHideWidget(listener: (...args: any[]) => void) { | | 177 | + onHideWidget(listener: (...args: any[]) => void): IPublicTypeDisposable { | 178 | 178 | const { editor } = this[skeletonSymbol]; | 179 | 179 | editor.eventBus.on(SkeletonEvents.WIDGET_HIDE, (name: any, panel: any) => { | 180 | 180 | // 不泄漏 skeleton | |
Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/api/workspace.ts +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeResourceType } from '@alilc/lowcode-types'; | | 1 | +import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types'; | 2 | 2 | import { Workspace as InnerWorkSpace } from '@alilc/lowcode-workspace'; | 3 | 3 | import { Plugins } from '@alilc/lowcode-shell'; | 4 | 4 | import { workspaceSymbol } from '../symbols'; | @@ -19,7 +19,7 @@ export class Workspace implements IPublicApiWorkspace { | 19 | 19 | this[workspaceSymbol].setResourceList(resourceList); | 20 | 20 | } | 21 | 21 |
| 22 | | - onResourceListChange(fn: (resourceList: IPublicResourceList) => void): () => void { | | 22 | + onResourceListChange(fn: (resourceList: IPublicResourceList) => void): IPublicTypeDisposable { | 23 | 23 | return this[workspaceSymbol].onResourceListChange(fn); | 24 | 24 | } | 25 | 25 |
| @@ -59,11 +59,11 @@ export class Workspace implements IPublicApiWorkspace { | 59 | 59 | return this[workspaceSymbol].windows.map((d) => new ShellWindow(d)); | 60 | 60 | } | 61 | 61 |
| 62 | | - onChangeWindows(fn: () => void) { | | 62 | + onChangeWindows(fn: () => void): IPublicTypeDisposable { | 63 | 63 | return this[workspaceSymbol].onChangeWindows(fn); | 64 | 64 | } | 65 | 65 |
| 66 | | - onChangeActiveWindow(fn: () => void) { | | 66 | + onChangeActiveWindow(fn: () => void): IPublicTypeDisposable { | 67 | 67 | return this[workspaceSymbol].onChangeActiveWindow(fn); | 68 | 68 | } | 69 | 69 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/model/document-model.ts +22-14Lines changed: 22 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -288,8 +288,8 @@ export class DocumentModel implements IPublicModelDocumentModel { | 288 | 288 | * 当前 document 的节点显隐状态变更事件 | 289 | 289 | * @param fn | 290 | 290 | */ | 291 | | - onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): void { | 292 | | - this[documentSymbol].onChangeNodeVisible((node: IPublicModelNode, visible: boolean) => { | | 291 | + onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): IPublicTypeDisposable { | | 292 | + return this[documentSymbol].onChangeNodeVisible((node: IPublicModelNode, visible: boolean) => { | 293 | 293 | fn(ShellNode.create(node)!, visible); | 294 | 294 | }); | 295 | 295 | } | @@ -298,8 +298,8 @@ export class DocumentModel implements IPublicModelDocumentModel { | 298 | 298 | * 当前 document 的节点 children 变更事件 | 299 | 299 | * @param fn | 300 | 300 | */ | 301 | | - onChangeNodeChildren(fn: (info: IPublicTypeOnChangeOptions) => void): void { | 302 | | - this[documentSymbol].onChangeNodeChildren((info?: IPublicTypeOnChangeOptions) => { | | 301 | + onChangeNodeChildren(fn: (info: IPublicTypeOnChangeOptions) => void): IPublicTypeDisposable { | | 302 | + return this[documentSymbol].onChangeNodeChildren((info?: IPublicTypeOnChangeOptions) => { | 303 | 303 | if (!info) { | 304 | 304 | return; | 305 | 305 | } | @@ -314,19 +314,27 @@ export class DocumentModel implements IPublicModelDocumentModel { | 314 | 314 | * 当前 document 节点属性修改事件 | 315 | 315 | * @param fn | 316 | 316 | */ | 317 | | - onChangeNodeProp(fn: (info: IPublicTypePropChangeOptions) => void): void { | | 317 | + onChangeNodeProp(fn: (info: IPublicTypePropChangeOptions) => void): IPublicTypeDisposable { | | 318 | + const callback = (info: GlobalEvent.Node.Prop.ChangeOptions) => { | | 319 | + fn({ | | 320 | + key: info.key, | | 321 | + oldValue: info.oldValue, | | 322 | + newValue: info.newValue, | | 323 | + prop: ShellProp.create(info.prop)!, | | 324 | + node: ShellNode.create(info.node as any)!, | | 325 | + }); | | 326 | + }; | 318 | 327 | this[editorSymbol].on( | 319 | 328 | GlobalEvent.Node.Prop.InnerChange, | 320 | | - (info: GlobalEvent.Node.Prop.ChangeOptions) => { | 321 | | - fn({ | 322 | | - key: info.key, | 323 | | - oldValue: info.oldValue, | 324 | | - newValue: info.newValue, | 325 | | - prop: ShellProp.create(info.prop)!, | 326 | | - node: ShellNode.create(info.node as any)!, | 327 | | - }); | 328 | | - }, | | 329 | + callback, | 329 | 330 | ); | | 331 | + | | 332 | + return () => { | | 333 | + this[editorSymbol].off( | | 334 | + GlobalEvent.Node.Prop.InnerChange, | | 335 | + callback, | | 336 | + ); | | 337 | + }; | 330 | 338 | } | 331 | 339 |
| 332 | 340 | /** | |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/api/material.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { IPublicTypeAssetsJson, IPublicTypeMetadataTransducer, IPublicTypeComponentAction, IPublicTypeNpmInfo } from '../type'; | | 1 | +import { IPublicTypeAssetsJson, IPublicTypeMetadataTransducer, IPublicTypeComponentAction, IPublicTypeNpmInfo, IPublicTypeDisposable } from '../type'; | 2 | 2 | import { IPublicModelComponentMeta } from '../model'; | 3 | 3 | import { ComponentType } from 'react'; | 4 | 4 |
| @@ -104,5 +104,5 @@ export interface IPublicApiMaterial { | 104 | 104 | * add callback for assets changed event | 105 | 105 | * @param fn | 106 | 106 | */ | 107 | | - onChangeAssets(fn: () => void): Function; | | 107 | + onChangeAssets(fn: () => void): IPublicTypeDisposable; | 108 | 108 | } |
|