docs(detecting): optimize api doc for model/detecting, and fix related lint issues

This commit is contained in:
JackLian 2023-01-10 14:47:07 +08:00 committed by 刘菊萍(絮黎)
parent ee8a63d8d2
commit f6771fefac
5 changed files with 157 additions and 101 deletions

View File

@ -9,29 +9,63 @@ sidebar_position: 6
画布节点悬停模型
## 变量
### current
当前 hover 的节点
`@type {IPublicModelNode | null}`
相关类型:[IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts)
**@since v1.0.16**
### enable
是否启用
`@type {boolean}`
## 方法签名
### capture
capture(id: string)
hover 指定节点
```typescript
/**
* hover 指定节点
* capture node with nodeId
* @param id 节点 id
*/
capture(id: string): void;
```
### release
release(id: string)
hover 离开指定节点
```typescript
/**
* hover 离开指定节点
* release node with nodeId
* @param id 节点 id
*/
release(id: string): void;
```
### leave
leave()
清空 hover 态
### current
当前 hover 的节点
**@since v1.0.16**
```typescript
/**
* 清空 hover 态
* clear all hover state
*/
leave(): void;
```
### onDetectingChange
hover 节点变化事件
@ -42,6 +76,11 @@ hover 节点变化事件
* set callback which will be called when hovering object changed.
* @since v1.1.0
*/
onDetectingChange(fn: (node: IPublicModelNode) => void): () => void;
onDetectingChange(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable;
```
相关类型:
- [IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts)
- [IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
**@since v1.1.0**

View File

@ -2,8 +2,13 @@ import { makeObservable, obx, IEventBus, createModuleEventBus } from '@alilc/low
import { IPublicModelDetecting, IPublicModelNode, IPublicModelDocumentModel } from '@alilc/lowcode-types';
const DETECTING_CHANGE_EVENT = 'detectingChange';
export interface IDetecting extends IPublicModelDetecting {
export interface IDetecting extends Omit< IPublicModelDetecting, 'capture' | 'release' | 'leave' > {
capture(node: IPublicModelNode | null): void;
release(node: IPublicModelNode | null): void;
leave(document: IPublicModelDocumentModel | undefined): void;
}
export class Detecting implements IDetecting {

View File

@ -39,6 +39,10 @@ export interface IDocumentModel extends IPublicModelDocumentModel {
readonly designer: Designer;
/**
* id
*/
getNode(id: string): INode | null;
}
export class DocumentModel implements IDocumentModel {
@ -118,16 +122,85 @@ export class DocumentModel implements IDocumentModel {
@obx.ref private _drillDownNode: Node | null = null;
drillDown(node: Node | null) {
this._drillDownNode = node;
}
private _modalNode?: INode;
private _blank?: boolean;
private inited = false;
@obx.shallow private willPurgeSpace: Node[] = [];
get modalNode() {
return this._modalNode;
}
get currentRoot() {
return this.modalNode || this.focusNode;
}
@obx.shallow private activeNodes?: Node[];
@obx.ref private _dropLocation: IDropLocation | null = null;
set dropLocation(loc: IPublicModelDropLocation | null) {
this._dropLocation = loc;
// pub event
this.designer.editor.eventBus.emit(
'document.dropLocation.changed',
{ document: this, location: loc },
);
}
/**
*
*/
get dropLocation() {
return this._dropLocation;
}
/**
* schema
*/
get schema(): IPublicTypeRootSchema {
return this.rootNode?.schema as any;
}
@obx.ref private _opened = false;
@obx.ref private _suspensed = false;
/**
*
*/
get suspensed(): boolean {
return this._suspensed || !this._opened;
}
/**
* suspensed
*/
get active(): boolean {
return !this._suspensed;
}
/**
* @deprecated
*/
get actived(): boolean {
return this.active;
}
/**
*
*/
get opened() {
return this._opened;
}
get root() {
return this.rootNode;
}
constructor(project: Project, schema?: IPublicTypeRootSchema) {
makeObservable(this);
this.project = project;
@ -162,6 +235,10 @@ export class DocumentModel implements IDocumentModel {
this.inited = true;
}
drillDown(node: Node | null) {
this._drillDownNode = node;
}
onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): () => void {
this.designer.editor?.eventBus.on(EDITOR_EVENT.NODE_CHILDREN_CHANGE, fn);
@ -178,16 +255,6 @@ export class DocumentModel implements IDocumentModel {
};
}
@obx.shallow private willPurgeSpace: Node[] = [];
get modalNode() {
return this._modalNode;
}
get currentRoot() {
return this.modalNode || this.focusNode;
}
addWillPurge(node: Node) {
this.willPurgeSpace.push(node);
}
@ -218,7 +285,7 @@ export class DocumentModel implements IDocumentModel {
/**
* id
*/
getNode(id: string): Node | null {
getNode(id: string): INode | null {
return this._nodesMap.get(id) || null;
}
@ -237,8 +304,6 @@ export class DocumentModel implements IDocumentModel {
return node ? !node.isPurged : false;
}
@obx.shallow private activeNodes?: Node[];
/**
* schema
*/
@ -338,24 +403,6 @@ export class DocumentModel implements IDocumentModel {
this._nodesMap.delete(node.id);
}
@obx.ref private _dropLocation: IDropLocation | null = null;
set dropLocation(loc: IPublicModelDropLocation | null) {
this._dropLocation = loc;
// pub event
this.designer.editor.eventBus.emit(
'document.dropLocation.changed',
{ document: this, location: loc },
);
}
/**
*
*/
get dropLocation() {
return this._dropLocation;
}
/**
*
*/
@ -378,13 +425,6 @@ export class DocumentModel implements IDocumentModel {
return null;
}
/**
* schema
*/
get schema(): IPublicTypeRootSchema {
return this.rootNode?.schema as any;
}
@action
import(schema: IPublicTypeRootSchema, checkId = false) {
const drillDownNodeId = this._drillDownNode?.id;
@ -449,37 +489,6 @@ export class DocumentModel implements IDocumentModel {
);
}
@obx.ref private _opened = false;
@obx.ref private _suspensed = false;
/**
*
*/
get suspensed(): boolean {
return this._suspensed || !this._opened;
}
/**
* suspensed
*/
get active(): boolean {
return !this._suspensed;
}
/**
* @deprecated
*/
get actived(): boolean {
return this.active;
}
/**
*
*/
get opened() {
return this._opened;
}
/**
*
@ -617,10 +626,6 @@ export class DocumentModel implements IDocumentModel {
return this.history;
}
get root() {
return this.rootNode;
}
/**
* @deprecated
*/

View File

@ -1,10 +1,10 @@
import { Node } from './node';
import { Node as ShellNode } from './node';
import {
Detecting as InnerDetecting,
DocumentModel as InnerDocumentModel,
IDocumentModel as InnerDocumentModel,
} from '@alilc/lowcode-designer';
import { documentSymbol, detectingSymbol } from '../symbols';
import { IPublicModelDetecting, IPublicModelNode } from '@alilc/lowcode-types';
import { IPublicModelDetecting, IPublicModelNode, IPublicTypeDisposable } from '@alilc/lowcode-types';
export class Detecting implements IPublicModelDetecting {
private readonly [documentSymbol]: InnerDocumentModel;
@ -26,7 +26,7 @@ export class Detecting implements IPublicModelDetecting {
* hover
*/
get current() {
return Node.create(this[detectingSymbol].current);
return ShellNode.create(this[detectingSymbol].current);
}
/**
@ -52,7 +52,7 @@ export class Detecting implements IPublicModelDetecting {
this[detectingSymbol].leave(this[documentSymbol]);
}
onDetectingChange(fn: (node: IPublicModelNode) => void): () => void {
onDetectingChange(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable {
return this[detectingSymbol].onDetectingChange(fn);
}
}

View File

@ -1,39 +1,46 @@
import { IPublicModelNode } from './';
import { IPublicTypeDisposable } from '../type';
export interface IPublicModelDetecting {
/**
* hover
*
* check if current detecting is enabled
* @since v1.1.0
*/
get enable(): boolean;
/**
* hover
* get current hovering node
* @since v1.0.16
*/
get current(): any;
get current(): IPublicModelNode | null;
/**
* hover
* capture node with nodeId
* @param id id
*/
capture(id: string): any;
capture(id: string): void;
/**
* hover
* release node with nodeId
* @param id id
*/
release(id: string): any;
release(id: string): void;
/**
* hover
* clear all hover state
*/
leave(): any;
leave(): void;
/**
* hover
* set callback which will be called when hovering object changed.
* @since v1.1.0
*/
onDetectingChange(fn: (node: IPublicModelNode) => void): () => void;
onDetectingChange(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable;
}