Skip to content

Commit f6771fe

Browse files
JackLianliujuping
authored andcommitted
docs(detecting): optimize api doc for model/detecting, and fix related lint issues
1 parent ee8a63d commit f6771fe

File tree

5 files changed

+157
-101
lines changed

5 files changed

+157
-101
lines changed

docs/docs/api/model/detecting.md

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,63 @@ sidebar_position: 6
99

1010
画布节点悬停模型
1111

12+
## 变量
13+
14+
### current
15+
16+
当前 hover 的节点
17+
18+
`@type {IPublicModelNode | null}`
19+
20+
相关类型:[IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts)
21+
22+
**@since v1.0.16**
23+
24+
### enable
25+
26+
是否启用
27+
28+
`@type {boolean}`
29+
30+
1231
## 方法签名
1332
### capture
1433

15-
capture(id: string)
16-
1734
hover 指定节点
1835

19-
### release
36+
```typescript
37+
/**
38+
* hover 指定节点
39+
* capture node with nodeId
40+
* @param id 节点 id
41+
*/
42+
capture(id: string): void;
43+
```
2044

21-
release(id: string)
45+
### release
2246

2347
hover 离开指定节点
2448

25-
### leave
49+
```typescript
50+
/**
51+
* hover 离开指定节点
52+
* release node with nodeId
53+
* @param id 节点 id
54+
*/
55+
release(id: string): void;
56+
```
2657

27-
leave()
58+
### leave
2859

2960
清空 hover 态
3061

31-
### current
32-
当前 hover 的节点
33-
34-
**@since v1.0.16**
62+
```typescript
63+
/**
64+
* 清空 hover 态
65+
* clear all hover state
66+
*/
67+
leave(): void;
68+
```
3569

3670
### onDetectingChange
3771
hover 节点变化事件
@@ -42,6 +76,11 @@ hover 节点变化事件
4276
* set callback which will be called when hovering object changed.
4377
* @since v1.1.0
4478
*/
45-
onDetectingChange(fn: (node: IPublicModelNode) => void): () => void;
79+
onDetectingChange(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable;
4680
```
81+
82+
相关类型:
83+
- [IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts)
84+
- [IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
85+
4786
**@since v1.1.0**

packages/designer/src/designer/detecting.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import { makeObservable, obx, IEventBus, createModuleEventBus } from '@alilc/low
22
import { IPublicModelDetecting, IPublicModelNode, IPublicModelDocumentModel } from '@alilc/lowcode-types';
33

44
const DETECTING_CHANGE_EVENT = 'detectingChange';
5-
export interface IDetecting extends IPublicModelDetecting {
5+
export interface IDetecting extends Omit< IPublicModelDetecting, 'capture' | 'release' | 'leave' > {
66

7+
capture(node: IPublicModelNode | null): void;
8+
9+
release(node: IPublicModelNode | null): void;
10+
11+
leave(document: IPublicModelDocumentModel | undefined): void;
712
}
813

914
export class Detecting implements IDetecting {

packages/designer/src/document/document-model.ts

Lines changed: 83 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export interface IDocumentModel extends IPublicModelDocumentModel {
3939

4040
readonly designer: Designer;
4141

42+
/**
43+
* 根据 id 获取节点
44+
*/
45+
getNode(id: string): INode | null;
4246
}
4347

4448
export class DocumentModel implements IDocumentModel {
@@ -118,16 +122,85 @@ export class DocumentModel implements IDocumentModel {
118122

119123
@obx.ref private _drillDownNode: Node | null = null;
120124

121-
drillDown(node: Node | null) {
122-
this._drillDownNode = node;
123-
}
124-
125125
private _modalNode?: INode;
126126

127127
private _blank?: boolean;
128128

129129
private inited = false;
130130

131+
@obx.shallow private willPurgeSpace: Node[] = [];
132+
133+
get modalNode() {
134+
return this._modalNode;
135+
}
136+
137+
get currentRoot() {
138+
return this.modalNode || this.focusNode;
139+
}
140+
141+
@obx.shallow private activeNodes?: Node[];
142+
143+
@obx.ref private _dropLocation: IDropLocation | null = null;
144+
145+
set dropLocation(loc: IPublicModelDropLocation | null) {
146+
this._dropLocation = loc;
147+
// pub event
148+
this.designer.editor.eventBus.emit(
149+
'document.dropLocation.changed',
150+
{ document: this, location: loc },
151+
);
152+
}
153+
154+
/**
155+
* 投放插入位置标记
156+
*/
157+
get dropLocation() {
158+
return this._dropLocation;
159+
}
160+
161+
/**
162+
* 导出 schema 数据
163+
*/
164+
get schema(): IPublicTypeRootSchema {
165+
return this.rootNode?.schema as any;
166+
}
167+
168+
@obx.ref private _opened = false;
169+
170+
@obx.ref private _suspensed = false;
171+
172+
/**
173+
* 是否为非激活状态
174+
*/
175+
get suspensed(): boolean {
176+
return this._suspensed || !this._opened;
177+
}
178+
179+
/**
180+
* 与 suspensed 相反,是否为激活状态,这个函数可能用的更多一点
181+
*/
182+
get active(): boolean {
183+
return !this._suspensed;
184+
}
185+
186+
/**
187+
* @deprecated 兼容
188+
*/
189+
get actived(): boolean {
190+
return this.active;
191+
}
192+
193+
/**
194+
* 是否打开
195+
*/
196+
get opened() {
197+
return this._opened;
198+
}
199+
200+
get root() {
201+
return this.rootNode;
202+
}
203+
131204
constructor(project: Project, schema?: IPublicTypeRootSchema) {
132205
makeObservable(this);
133206
this.project = project;
@@ -162,6 +235,10 @@ export class DocumentModel implements IDocumentModel {
162235
this.inited = true;
163236
}
164237

238+
drillDown(node: Node | null) {
239+
this._drillDownNode = node;
240+
}
241+
165242
onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): () => void {
166243
this.designer.editor?.eventBus.on(EDITOR_EVENT.NODE_CHILDREN_CHANGE, fn);
167244

@@ -178,16 +255,6 @@ export class DocumentModel implements IDocumentModel {
178255
};
179256
}
180257

181-
@obx.shallow private willPurgeSpace: Node[] = [];
182-
183-
get modalNode() {
184-
return this._modalNode;
185-
}
186-
187-
get currentRoot() {
188-
return this.modalNode || this.focusNode;
189-
}
190-
191258
addWillPurge(node: Node) {
192259
this.willPurgeSpace.push(node);
193260
}
@@ -204,7 +271,7 @@ export class DocumentModel implements IDocumentModel {
204271
}
205272

206273
/**
207-
* 生成唯一id
274+
* 生成唯一 id
208275
*/
209276
nextId(possibleId: string | undefined) {
210277
let id = possibleId;
@@ -218,7 +285,7 @@ export class DocumentModel implements IDocumentModel {
218285
/**
219286
* 根据 id 获取节点
220287
*/
221-
getNode(id: string): Node | null {
288+
getNode(id: string): INode | null {
222289
return this._nodesMap.get(id) || null;
223290
}
224291

@@ -237,8 +304,6 @@ export class DocumentModel implements IDocumentModel {
237304
return node ? !node.isPurged : false;
238305
}
239306

240-
@obx.shallow private activeNodes?: Node[];
241-
242307
/**
243308
* 根据 schema 创建一个节点
244309
*/
@@ -338,24 +403,6 @@ export class DocumentModel implements IDocumentModel {
338403
this._nodesMap.delete(node.id);
339404
}
340405

341-
@obx.ref private _dropLocation: IDropLocation | null = null;
342-
343-
set dropLocation(loc: IPublicModelDropLocation | null) {
344-
this._dropLocation = loc;
345-
// pub event
346-
this.designer.editor.eventBus.emit(
347-
'document.dropLocation.changed',
348-
{ document: this, location: loc },
349-
);
350-
}
351-
352-
/**
353-
* 投放插入位置标记
354-
*/
355-
get dropLocation() {
356-
return this._dropLocation;
357-
}
358-
359406
/**
360407
* 包裹当前选区中的节点
361408
*/
@@ -378,13 +425,6 @@ export class DocumentModel implements IDocumentModel {
378425
return null;
379426
}
380427

381-
/**
382-
* 导出 schema 数据
383-
*/
384-
get schema(): IPublicTypeRootSchema {
385-
return this.rootNode?.schema as any;
386-
}
387-
388428
@action
389429
import(schema: IPublicTypeRootSchema, checkId = false) {
390430
const drillDownNodeId = this._drillDownNode?.id;
@@ -449,37 +489,6 @@ export class DocumentModel implements IDocumentModel {
449489
);
450490
}
451491

452-
@obx.ref private _opened = false;
453-
454-
@obx.ref private _suspensed = false;
455-
456-
/**
457-
* 是否为非激活状态
458-
*/
459-
get suspensed(): boolean {
460-
return this._suspensed || !this._opened;
461-
}
462-
463-
/**
464-
* 与 suspensed 相反,是否为激活状态,这个函数可能用的更多一点
465-
*/
466-
get active(): boolean {
467-
return !this._suspensed;
468-
}
469-
470-
/**
471-
* @deprecated 兼容
472-
*/
473-
get actived(): boolean {
474-
return this.active;
475-
}
476-
477-
/**
478-
* 是否打开
479-
*/
480-
get opened() {
481-
return this._opened;
482-
}
483492

484493
/**
485494
* 切换激活,只有打开的才能激活
@@ -617,10 +626,6 @@ export class DocumentModel implements IDocumentModel {
617626
return this.history;
618627
}
619628

620-
get root() {
621-
return this.rootNode;
622-
}
623-
624629
/**
625630
* @deprecated
626631
*/

packages/shell/src/model/detecting.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Node } from './node';
1+
import { Node as ShellNode } from './node';
22
import {
33
Detecting as InnerDetecting,
4-
DocumentModel as InnerDocumentModel,
4+
IDocumentModel as InnerDocumentModel,
55
} from '@alilc/lowcode-designer';
66
import { documentSymbol, detectingSymbol } from '../symbols';
7-
import { IPublicModelDetecting, IPublicModelNode } from '@alilc/lowcode-types';
7+
import { IPublicModelDetecting, IPublicModelNode, IPublicTypeDisposable } from '@alilc/lowcode-types';
88

99
export class Detecting implements IPublicModelDetecting {
1010
private readonly [documentSymbol]: InnerDocumentModel;
@@ -26,7 +26,7 @@ export class Detecting implements IPublicModelDetecting {
2626
* 当前 hover 的节点
2727
*/
2828
get current() {
29-
return Node.create(this[detectingSymbol].current);
29+
return ShellNode.create(this[detectingSymbol].current);
3030
}
3131

3232
/**
@@ -52,7 +52,7 @@ export class Detecting implements IPublicModelDetecting {
5252
this[detectingSymbol].leave(this[documentSymbol]);
5353
}
5454

55-
onDetectingChange(fn: (node: IPublicModelNode) => void): () => void {
55+
onDetectingChange(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable {
5656
return this[detectingSymbol].onDetectingChange(fn);
5757
}
5858
}

0 commit comments

Comments
 (0)