Skip to content

Commit

Permalink
docs(prop): optimize api doc for model/prop, and fix related lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JackLian authored and liujuping committed Jan 6, 2023
1 parent 7ddc155 commit 76f612b
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docs/docs/api/model/document-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): voi

### onChangeNodeChildren

onChangeNodeChildren(fn: (info?: IPublicOnChangeOptions) => void)
onChangeNodeChildren(fn: (info?: IPublicTypeOnChangeOptions) => void)

当前 document 的节点 children 变更事件

Expand Down
67 changes: 61 additions & 6 deletions docs/docs/api/model/prop.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,94 @@ sidebar_position: 3

id

`@type {string}`

### key

key 值

`@type {string | number | undefined}`

### path

返回当前 prop 的路径

`@type {string[]}`

### node

返回所属的节点实例

`@type {IPublicModelNode | null}`

相关类型:[IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts)

### slotNode

当本 prop 代表一个 Slot 时,返回对应的 slotNode

`@type {IPublicModelNode | undefined | null}`

相关类型:[IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts)


## 方法签名

### setValue

setValue(val: CompositeValue)

设置值

### getValue
```typescript
/**
* 设置值
* set value for this prop
* @param val
*/
setValue(val: IPublicTypeCompositeValue): void;
```

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

### getValue

获取值

```typescript
/**
* 获取值
* get value of this prop
*/
getValue(): any;
```

### remove

移除值

```typescript
/**
* 移除值
* remove value of this prop
* @since v1.0.16
*/
remove(): void;
```

**@since v1.0.16**

### exportSchema

exportSchema(stage: IPublicEnumTransformStage = IPublicEnumTransformStage.Render)
导出值

```typescript
/**
* 导出值
* export schema
* @param stage
*/
exportSchema(stage: IPublicEnumTransformStage): IPublicTypeCompositeValue;
```

导出值
相关类型:
- [IPublicEnumTransformStage](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/enum/transform-stage.ts)
- [IPublicTypeCompositeValue](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/composite-value.ts)
2 changes: 1 addition & 1 deletion docs/docs/guide/design/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ simulator-renderer 通过调用 host 的方法,将 schema、components 等参

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

##### Sensor
Expand Down
2 changes: 2 additions & 0 deletions packages/designer/src/document/document-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export type GetDataType<T, NodeType> = T extends undefined
: T;
export interface IDocumentModel extends IPublicModelDocumentModel {

readonly designer: Designer;

}

export class DocumentModel implements IDocumentModel {
Expand Down
23 changes: 19 additions & 4 deletions packages/designer/src/document/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { compatStage, isDOMText, isJSExpression } from '@alilc/lowcode-utils';
import { SettingTopEntry } from '@alilc/lowcode-designer';
import { Props, getConvertedExtraKey } from './props/props';
import { DocumentModel } from '../document-model';
import { DocumentModel, IDocumentModel } from '../document-model';
import { NodeChildren, INodeChildren } from './node-children';
import { Prop } from './props/prop';
import { ComponentMeta } from '../../component-meta';
Expand Down Expand Up @@ -55,6 +55,21 @@ export interface INode extends IPublicModelNode {
unlinkSlot(slotNode: Node): void;

didDropOut(dragment: Node): void;

/**
* 导出 schema
*/
export(stage: IPublicEnumTransformStage, options?: any): IPublicTypeNodeSchema;

get document(): IDocumentModel;

emitPropChange(val: IPublicTypePropChangeOptions): void;

import(data: IPublicTypeNodeSchema, checkId?: boolean): void;

internalSetSlotFor(slotFor: Prop | null | undefined): void;

addSlot(slotNode: INode): void;
}

/**
Expand Down Expand Up @@ -189,7 +204,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>

isInited = false;

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

@obx.shallow _slots: Node[] = [];
@obx.shallow _slots: INode[] = [];

hasSlots() {
return this._slots.length > 0;
Expand Down Expand Up @@ -885,7 +900,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
return false;
}

addSlot(slotNode: Node) {
addSlot(slotNode: INode) {
const slotName = slotNode?.getExtraProp('name')?.getAsString();
// 一个组件下的所有 slot,相同 slotName 的 slot 应该是唯一的
if (includeSlot(this, slotName)) {
Expand Down
32 changes: 20 additions & 12 deletions packages/designer/src/document/node/props/prop.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import { untracked, computed, obx, engineConfig, action, makeObservable, mobx, runInAction } from '@alilc/lowcode-editor-core';
import { IPublicTypeCompositeValue, GlobalEvent, IPublicTypeJSSlot, IPublicTypeSlotSchema, IPublicEnumTransformStage } from '@alilc/lowcode-types';
import { IPublicTypeCompositeValue, GlobalEvent, IPublicTypeJSSlot, IPublicTypeSlotSchema, IPublicEnumTransformStage, IPublicModelProp } from '@alilc/lowcode-types';
import { uniqueId, isPlainObject, hasOwnProperty, compatStage, isJSExpression, isJSSlot } from '@alilc/lowcode-utils';
import { valueToSource } from './value-to-source';
import { Props } from './props';
import { SlotNode, Node } from '../node';
import { SlotNode, INode } from '../node';
// import { TransformStage } from '../transform-stage';

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

export interface IPropParent {
export interface IProp extends Omit<IPublicModelProp, 'exportSchema' | 'node'> {

delete(prop: Prop): void;

readonly props: Props;
readonly owner: Node;
readonly path: string[];

readonly owner: INode;

export(stage: IPublicEnumTransformStage): IPublicTypeCompositeValue;

getNode(): INode;
}

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

export class Prop implements IPropParent {
export class Prop implements IProp {
readonly isProp = true;

readonly owner: Node;
readonly owner: INode;

/**
* 键值
Expand All @@ -40,7 +46,7 @@ export class Prop implements IPropParent {
readonly options: any;

constructor(
public parent: IPropParent,
public parent: IProp,
value: IPublicTypeCompositeValue | UNSET = UNSET,
key?: string | number,
spread = false,
Expand Down Expand Up @@ -305,9 +311,9 @@ export class Prop implements IPropParent {
}
}

private _slotNode?: SlotNode;
private _slotNode?: INode;

get slotNode() {
get slotNode(): INode | undefined | null {
return this._slotNode;
}

Expand Down Expand Up @@ -342,8 +348,10 @@ export class Prop implements IPropParent {
} else {
const { owner } = this.props;
this._slotNode = owner.document.createNode<SlotNode>(slotSchema);
owner.addSlot(this._slotNode);
this._slotNode.internalSetSlotFor(this);
if (this._slotNode) {
owner.addSlot(this._slotNode);
this._slotNode.internalSetSlotFor(this);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/designer/src/document/node/props/props.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed, makeObservable, obx, action } from '@alilc/lowcode-editor-core';
import { IPublicTypePropsMap, IPublicTypePropsList, IPublicTypeCompositeValue, IPublicEnumTransformStage } from '@alilc/lowcode-types';
import { uniqueId, compatStage } from '@alilc/lowcode-utils';
import { Prop, IPropParent, UNSET } from './prop';
import { Prop, IProp, UNSET } from './prop';
import { Node } from '../node';
// import { TransformStage } from '../transform-stage';

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

@obx.shallow private items: Prop[] = [];
Expand Down
11 changes: 6 additions & 5 deletions packages/shell/src/model/prop.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IPropParent as InnerProp } from '@alilc/lowcode-designer';
import { IProp as InnerProp } from '@alilc/lowcode-designer';
import { IPublicTypeCompositeValue, IPublicEnumTransformStage, IPublicModelProp, IPublicModelNode } from '@alilc/lowcode-types';
import { propSymbol } from '../symbols';
import { Node } from './node';
import { Node as ShellNode } from './node';

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

/**
* key 值
* get key of prop
*/
get key(): string | number | undefined {
return this[propSymbol].key;
Expand All @@ -34,22 +35,22 @@ export class Prop implements IPublicModelProp {
/**
* 返回当前 prop 的路径
*/
get path(): any[] {
get path(): string[] {
return this[propSymbol].path;
}

/**
* 返回所属的节点实例
*/
get node(): IPublicModelNode | null {
return Node.create(this[propSymbol].getNode());
return ShellNode.create(this[propSymbol].getNode());
}

/**
* return the slot node (only if the current prop represents a slot)
*/
get slotNode(): IPublicModelNode | null {
return Node.create(this[propSymbol].slotNode);
return ShellNode.create(this[propSymbol].slotNode);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/shell/src/model/props.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IPropParent as InnerProps, getConvertedExtraKey } from '@alilc/lowcode-designer';
import { IProp as InnerProps, getConvertedExtraKey } from '@alilc/lowcode-designer';
import { IPublicTypeCompositeValue, IPublicModelProps, IPublicModelNode, IPublicModelProp } from '@alilc/lowcode-types';
import { propsSymbol } from '../symbols';
import { Node } from './node';
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/shell/model/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IPublicEnumTransformStage } from '../enum';
import { IPublicModelNodeChildren, IPublicModelComponentMeta, IPublicModelProp, IPublicModelProps, IPublicModelSettingTopEntry, IPublicModelDocumentModel, IPublicModelExclusiveGroup } from './';

export interface IPublicModelNode {

/**
* 节点 id
* node id
Expand Down
Loading

0 comments on commit 76f612b

Please sign in to comment.