Skip to content

Commit 76f612b

Browse files
JackLianliujuping
authored andcommitted
docs(prop): optimize api doc for model/prop, and fix related lint issues
1 parent 7ddc155 commit 76f612b

File tree

12 files changed

+147
-37
lines changed

12 files changed

+147
-37
lines changed

docs/docs/api/model/document-model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): voi
334334

335335
### onChangeNodeChildren
336336

337-
onChangeNodeChildren(fn: (info?: IPublicOnChangeOptions) => void)
337+
onChangeNodeChildren(fn: (info?: IPublicTypeOnChangeOptions) => void)
338338

339339
当前 document 的节点 children 变更事件
340340

docs/docs/api/model/prop.md

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,94 @@ sidebar_position: 3
1515

1616
id
1717

18+
`@type {string}`
19+
1820
### key
1921

2022
key 值
2123

24+
`@type {string | number | undefined}`
25+
2226
### path
2327

2428
返回当前 prop 的路径
2529

30+
`@type {string[]}`
31+
2632
### node
2733

2834
返回所属的节点实例
2935

36+
`@type {IPublicModelNode | null}`
37+
38+
相关类型:[IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts)
39+
40+
### slotNode
41+
42+
当本 prop 代表一个 Slot 时,返回对应的 slotNode
43+
44+
`@type {IPublicModelNode | undefined | null}`
45+
46+
相关类型:[IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts)
47+
48+
3049
## 方法签名
3150

3251
### setValue
3352

34-
setValue(val: CompositeValue)
35-
3653
设置值
3754

38-
### getValue
55+
```typescript
56+
/**
57+
* 设置值
58+
* set value for this prop
59+
* @param val
60+
*/
61+
setValue(val: IPublicTypeCompositeValue): void;
62+
```
3963

40-
getValue()
64+
相关类型:[IPublicTypeCompositeValue](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/composite-value.ts)
65+
66+
### getValue
4167

4268
获取值
4369

70+
```typescript
71+
/**
72+
* 获取值
73+
* get value of this prop
74+
*/
75+
getValue(): any;
76+
```
77+
4478
### remove
79+
4580
移除值
4681

82+
```typescript
83+
/**
84+
* 移除值
85+
* remove value of this prop
86+
* @since v1.0.16
87+
*/
88+
remove(): void;
89+
```
90+
4791
**@since v1.0.16**
4892

4993
### exportSchema
5094

51-
exportSchema(stage: IPublicEnumTransformStage = IPublicEnumTransformStage.Render)
95+
导出值
96+
97+
```typescript
98+
/**
99+
* 导出值
100+
* export schema
101+
* @param stage
102+
*/
103+
exportSchema(stage: IPublicEnumTransformStage): IPublicTypeCompositeValue;
104+
```
52105

53-
导出值
106+
相关类型:
107+
- [IPublicEnumTransformStage](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/enum/transform-stage.ts)
108+
- [IPublicTypeCompositeValue](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/composite-value.ts)

docs/docs/guide/design/editor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ simulator-renderer 通过调用 host 的方法,将 schema、components 等参
313313

314314
- 被拖拽对象 - `DragObject`
315315
- 拖拽到的目标位置 - `DropLocation`
316-
- 拖拽感应区 - `ISensor`
316+
- 拖拽感应区 - `IPublicModelSensor`
317317
- 定位事件 - `LocateEvent`
318318

319319
##### Sensor

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export type GetDataType<T, NodeType> = T extends undefined
3737
: T;
3838
export interface IDocumentModel extends IPublicModelDocumentModel {
3939

40+
readonly designer: Designer;
41+
4042
}
4143

4244
export class DocumentModel implements IDocumentModel {

packages/designer/src/document/node/node.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import { compatStage, isDOMText, isJSExpression } from '@alilc/lowcode-utils';
2020
import { SettingTopEntry } from '@alilc/lowcode-designer';
2121
import { Props, getConvertedExtraKey } from './props/props';
22-
import { DocumentModel } from '../document-model';
22+
import { DocumentModel, IDocumentModel } from '../document-model';
2323
import { NodeChildren, INodeChildren } from './node-children';
2424
import { Prop } from './props/prop';
2525
import { ComponentMeta } from '../../component-meta';
@@ -55,6 +55,21 @@ export interface INode extends IPublicModelNode {
5555
unlinkSlot(slotNode: Node): void;
5656

5757
didDropOut(dragment: Node): void;
58+
59+
/**
60+
* 导出 schema
61+
*/
62+
export(stage: IPublicEnumTransformStage, options?: any): IPublicTypeNodeSchema;
63+
64+
get document(): IDocumentModel;
65+
66+
emitPropChange(val: IPublicTypePropChangeOptions): void;
67+
68+
import(data: IPublicTypeNodeSchema, checkId?: boolean): void;
69+
70+
internalSetSlotFor(slotFor: Prop | null | undefined): void;
71+
72+
addSlot(slotNode: INode): void;
5873
}
5974

6075
/**
@@ -189,7 +204,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
189204

190205
isInited = false;
191206

192-
constructor(readonly document: DocumentModel, nodeSchema: Schema, options: any = {}) {
207+
constructor(readonly document: IDocumentModel, nodeSchema: Schema, options: any = {}) {
193208
makeObservable(this);
194209
const { componentName, id, children, props, ...extras } = nodeSchema;
195210
this.id = document.nextId(id);
@@ -521,7 +536,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
521536
return this.props.export(IPublicEnumTransformStage.Serilize).props || null;
522537
}
523538

524-
@obx.shallow _slots: Node[] = [];
539+
@obx.shallow _slots: INode[] = [];
525540

526541
hasSlots() {
527542
return this._slots.length > 0;
@@ -885,7 +900,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
885900
return false;
886901
}
887902

888-
addSlot(slotNode: Node) {
903+
addSlot(slotNode: INode) {
889904
const slotName = slotNode?.getExtraProp('name')?.getAsString();
890905
// 一个组件下的所有 slot,相同 slotName 的 slot 应该是唯一的
891906
if (includeSlot(this, slotName)) {

packages/designer/src/document/node/props/prop.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
import { untracked, computed, obx, engineConfig, action, makeObservable, mobx, runInAction } from '@alilc/lowcode-editor-core';
2-
import { IPublicTypeCompositeValue, GlobalEvent, IPublicTypeJSSlot, IPublicTypeSlotSchema, IPublicEnumTransformStage } from '@alilc/lowcode-types';
2+
import { IPublicTypeCompositeValue, GlobalEvent, IPublicTypeJSSlot, IPublicTypeSlotSchema, IPublicEnumTransformStage, IPublicModelProp } from '@alilc/lowcode-types';
33
import { uniqueId, isPlainObject, hasOwnProperty, compatStage, isJSExpression, isJSSlot } from '@alilc/lowcode-utils';
44
import { valueToSource } from './value-to-source';
55
import { Props } from './props';
6-
import { SlotNode, Node } from '../node';
6+
import { SlotNode, INode } from '../node';
77
// import { TransformStage } from '../transform-stage';
88

99
const { set: mobxSet, isObservableArray } = mobx;
1010
export const UNSET = Symbol.for('unset');
1111
// eslint-disable-next-line no-redeclare
1212
export type UNSET = typeof UNSET;
1313

14-
export interface IPropParent {
14+
export interface IProp extends Omit<IPublicModelProp, 'exportSchema' | 'node'> {
15+
1516
delete(prop: Prop): void;
17+
1618
readonly props: Props;
17-
readonly owner: Node;
18-
readonly path: string[];
19+
20+
readonly owner: INode;
21+
22+
export(stage: IPublicEnumTransformStage): IPublicTypeCompositeValue;
23+
24+
getNode(): INode;
1925
}
2026

2127
export type ValueTypes = 'unset' | 'literal' | 'map' | 'list' | 'expression' | 'slot';
2228

23-
export class Prop implements IPropParent {
29+
export class Prop implements IProp {
2430
readonly isProp = true;
2531

26-
readonly owner: Node;
32+
readonly owner: INode;
2733

2834
/**
2935
* 键值
@@ -40,7 +46,7 @@ export class Prop implements IPropParent {
4046
readonly options: any;
4147

4248
constructor(
43-
public parent: IPropParent,
49+
public parent: IProp,
4450
value: IPublicTypeCompositeValue | UNSET = UNSET,
4551
key?: string | number,
4652
spread = false,
@@ -305,9 +311,9 @@ export class Prop implements IPropParent {
305311
}
306312
}
307313

308-
private _slotNode?: SlotNode;
314+
private _slotNode?: INode;
309315

310-
get slotNode() {
316+
get slotNode(): INode | undefined | null {
311317
return this._slotNode;
312318
}
313319

@@ -342,8 +348,10 @@ export class Prop implements IPropParent {
342348
} else {
343349
const { owner } = this.props;
344350
this._slotNode = owner.document.createNode<SlotNode>(slotSchema);
345-
owner.addSlot(this._slotNode);
346-
this._slotNode.internalSetSlotFor(this);
351+
if (this._slotNode) {
352+
owner.addSlot(this._slotNode);
353+
this._slotNode.internalSetSlotFor(this);
354+
}
347355
}
348356
}
349357

packages/designer/src/document/node/props/props.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { computed, makeObservable, obx, action } from '@alilc/lowcode-editor-core';
22
import { IPublicTypePropsMap, IPublicTypePropsList, IPublicTypeCompositeValue, IPublicEnumTransformStage } from '@alilc/lowcode-types';
33
import { uniqueId, compatStage } from '@alilc/lowcode-utils';
4-
import { Prop, IPropParent, UNSET } from './prop';
4+
import { Prop, IProp, UNSET } from './prop';
55
import { Node } from '../node';
66
// import { TransformStage } from '../transform-stage';
77

@@ -23,7 +23,7 @@ export function getConvertedExtraKey(key: string): string {
2323
export function getOriginalExtraKey(key: string): string {
2424
return key.replace(new RegExp(`${EXTRA_KEY_PREFIX}`, 'g'), '');
2525
}
26-
export class Props implements IPropParent {
26+
export class Props implements IProp {
2727
readonly id = uniqueId('props');
2828

2929
@obx.shallow private items: Prop[] = [];

packages/shell/src/model/prop.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { IPropParent as InnerProp } from '@alilc/lowcode-designer';
1+
import { IProp as InnerProp } from '@alilc/lowcode-designer';
22
import { IPublicTypeCompositeValue, IPublicEnumTransformStage, IPublicModelProp, IPublicModelNode } from '@alilc/lowcode-types';
33
import { propSymbol } from '../symbols';
4-
import { Node } from './node';
4+
import { Node as ShellNode } from './node';
55

66
export class Prop implements IPublicModelProp {
77
private readonly [propSymbol]: InnerProp;
@@ -26,6 +26,7 @@ export class Prop implements IPublicModelProp {
2626

2727
/**
2828
* key 值
29+
* get key of prop
2930
*/
3031
get key(): string | number | undefined {
3132
return this[propSymbol].key;
@@ -34,22 +35,22 @@ export class Prop implements IPublicModelProp {
3435
/**
3536
* 返回当前 prop 的路径
3637
*/
37-
get path(): any[] {
38+
get path(): string[] {
3839
return this[propSymbol].path;
3940
}
4041

4142
/**
4243
* 返回所属的节点实例
4344
*/
4445
get node(): IPublicModelNode | null {
45-
return Node.create(this[propSymbol].getNode());
46+
return ShellNode.create(this[propSymbol].getNode());
4647
}
4748

4849
/**
4950
* return the slot node (only if the current prop represents a slot)
5051
*/
5152
get slotNode(): IPublicModelNode | null {
52-
return Node.create(this[propSymbol].slotNode);
53+
return ShellNode.create(this[propSymbol].slotNode);
5354
}
5455

5556
/**

packages/shell/src/model/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IPropParent as InnerProps, getConvertedExtraKey } from '@alilc/lowcode-designer';
1+
import { IProp as InnerProps, getConvertedExtraKey } from '@alilc/lowcode-designer';
22
import { IPublicTypeCompositeValue, IPublicModelProps, IPublicModelNode, IPublicModelProp } from '@alilc/lowcode-types';
33
import { propsSymbol } from '../symbols';
44
import { Node } from './node';

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IPublicEnumTransformStage } from '../enum';
44
import { IPublicModelNodeChildren, IPublicModelComponentMeta, IPublicModelProp, IPublicModelProps, IPublicModelSettingTopEntry, IPublicModelDocumentModel, IPublicModelExclusiveGroup } from './';
55

66
export interface IPublicModelNode {
7+
78
/**
89
* 节点 id
910
* node id

0 commit comments

Comments
 (0)