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

This commit is contained in:
JackLian 2023-01-06 16:31:24 +08:00 committed by 刘菊萍(絮黎)
parent 7ddc155f0a
commit 76f612b29c
12 changed files with 147 additions and 37 deletions

View File

@ -334,7 +334,7 @@ onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): voi
### onChangeNodeChildren ### onChangeNodeChildren
onChangeNodeChildren(fn: (info?: IPublicOnChangeOptions) => void) onChangeNodeChildren(fn: (info?: IPublicTypeOnChangeOptions) => void)
当前 document 的节点 children 变更事件 当前 document 的节点 children 变更事件

View File

@ -15,39 +15,94 @@ sidebar_position: 3
id id
`@type {string}`
### key ### key
key 值 key 值
`@type {string | number | undefined}`
### path ### path
返回当前 prop 的路径 返回当前 prop 的路径
`@type {string[]}`
### node ### 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
setValue(val: CompositeValue)
设置值 设置值
```typescript
/**
* 设置值
* set value for this prop
* @param val
*/
setValue(val: IPublicTypeCompositeValue): void;
```
相关类型:[IPublicTypeCompositeValue](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/composite-value.ts)
### getValue ### getValue
getValue()
获取值 获取值
```typescript
/**
* 获取值
* get value of this prop
*/
getValue(): any;
```
### remove ### remove
移除值 移除值
```typescript
/**
* 移除值
* remove value of this prop
* @since v1.0.16
*/
remove(): void;
```
**@since v1.0.16** **@since v1.0.16**
### exportSchema ### 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)

View File

@ -313,7 +313,7 @@ simulator-renderer 通过调用 host 的方法,将 schema、components 等参
- 被拖拽对象 - `DragObject` - 被拖拽对象 - `DragObject`
- 拖拽到的目标位置 - `DropLocation` - 拖拽到的目标位置 - `DropLocation`
- 拖拽感应区 - `ISensor` - 拖拽感应区 - `IPublicModelSensor`
- 定位事件 - `LocateEvent` - 定位事件 - `LocateEvent`
##### Sensor ##### Sensor

View File

@ -37,6 +37,8 @@ export type GetDataType<T, NodeType> = T extends undefined
: T; : T;
export interface IDocumentModel extends IPublicModelDocumentModel { export interface IDocumentModel extends IPublicModelDocumentModel {
readonly designer: Designer;
} }
export class DocumentModel implements IDocumentModel { export class DocumentModel implements IDocumentModel {

View File

@ -19,7 +19,7 @@ import {
import { compatStage, isDOMText, isJSExpression } from '@alilc/lowcode-utils'; import { compatStage, isDOMText, isJSExpression } from '@alilc/lowcode-utils';
import { SettingTopEntry } from '@alilc/lowcode-designer'; import { SettingTopEntry } from '@alilc/lowcode-designer';
import { Props, getConvertedExtraKey } from './props/props'; import { Props, getConvertedExtraKey } from './props/props';
import { DocumentModel } from '../document-model'; import { DocumentModel, IDocumentModel } from '../document-model';
import { NodeChildren, INodeChildren } from './node-children'; import { NodeChildren, INodeChildren } from './node-children';
import { Prop } from './props/prop'; import { Prop } from './props/prop';
import { ComponentMeta } from '../../component-meta'; import { ComponentMeta } from '../../component-meta';
@ -55,6 +55,21 @@ export interface INode extends IPublicModelNode {
unlinkSlot(slotNode: Node): void; unlinkSlot(slotNode: Node): void;
didDropOut(dragment: 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;
} }
/** /**
@ -189,7 +204,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
isInited = false; isInited = false;
constructor(readonly document: DocumentModel, nodeSchema: Schema, options: any = {}) { constructor(readonly document: IDocumentModel, nodeSchema: Schema, options: any = {}) {
makeObservable(this); makeObservable(this);
const { componentName, id, children, props, ...extras } = nodeSchema; const { componentName, id, children, props, ...extras } = nodeSchema;
this.id = document.nextId(id); this.id = document.nextId(id);
@ -521,7 +536,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
return this.props.export(IPublicEnumTransformStage.Serilize).props || null; return this.props.export(IPublicEnumTransformStage.Serilize).props || null;
} }
@obx.shallow _slots: Node[] = []; @obx.shallow _slots: INode[] = [];
hasSlots() { hasSlots() {
return this._slots.length > 0; return this._slots.length > 0;
@ -885,7 +900,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
return false; return false;
} }
addSlot(slotNode: Node) { addSlot(slotNode: INode) {
const slotName = slotNode?.getExtraProp('name')?.getAsString(); const slotName = slotNode?.getExtraProp('name')?.getAsString();
// 一个组件下的所有 slot相同 slotName 的 slot 应该是唯一的 // 一个组件下的所有 slot相同 slotName 的 slot 应该是唯一的
if (includeSlot(this, slotName)) { if (includeSlot(this, slotName)) {

View File

@ -1,9 +1,9 @@
import { untracked, computed, obx, engineConfig, action, makeObservable, mobx, runInAction } from '@alilc/lowcode-editor-core'; 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 { uniqueId, isPlainObject, hasOwnProperty, compatStage, isJSExpression, isJSSlot } from '@alilc/lowcode-utils';
import { valueToSource } from './value-to-source'; import { valueToSource } from './value-to-source';
import { Props } from './props'; import { Props } from './props';
import { SlotNode, Node } from '../node'; import { SlotNode, INode } from '../node';
// import { TransformStage } from '../transform-stage'; // import { TransformStage } from '../transform-stage';
const { set: mobxSet, isObservableArray } = mobx; const { set: mobxSet, isObservableArray } = mobx;
@ -11,19 +11,25 @@ export const UNSET = Symbol.for('unset');
// eslint-disable-next-line no-redeclare // eslint-disable-next-line no-redeclare
export type UNSET = typeof UNSET; export type UNSET = typeof UNSET;
export interface IPropParent { export interface IProp extends Omit<IPublicModelProp, 'exportSchema' | 'node'> {
delete(prop: Prop): void; delete(prop: Prop): void;
readonly props: Props; 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 type ValueTypes = 'unset' | 'literal' | 'map' | 'list' | 'expression' | 'slot';
export class Prop implements IPropParent { export class Prop implements IProp {
readonly isProp = true; readonly isProp = true;
readonly owner: Node; readonly owner: INode;
/** /**
* *
@ -40,7 +46,7 @@ export class Prop implements IPropParent {
readonly options: any; readonly options: any;
constructor( constructor(
public parent: IPropParent, public parent: IProp,
value: IPublicTypeCompositeValue | UNSET = UNSET, value: IPublicTypeCompositeValue | UNSET = UNSET,
key?: string | number, key?: string | number,
spread = false, spread = false,
@ -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; return this._slotNode;
} }
@ -342,8 +348,10 @@ export class Prop implements IPropParent {
} else { } else {
const { owner } = this.props; const { owner } = this.props;
this._slotNode = owner.document.createNode<SlotNode>(slotSchema); this._slotNode = owner.document.createNode<SlotNode>(slotSchema);
owner.addSlot(this._slotNode); if (this._slotNode) {
this._slotNode.internalSetSlotFor(this); owner.addSlot(this._slotNode);
this._slotNode.internalSetSlotFor(this);
}
} }
} }

View File

@ -1,7 +1,7 @@
import { computed, makeObservable, obx, action } from '@alilc/lowcode-editor-core'; import { computed, makeObservable, obx, action } from '@alilc/lowcode-editor-core';
import { IPublicTypePropsMap, IPublicTypePropsList, IPublicTypeCompositeValue, IPublicEnumTransformStage } from '@alilc/lowcode-types'; import { IPublicTypePropsMap, IPublicTypePropsList, IPublicTypeCompositeValue, IPublicEnumTransformStage } from '@alilc/lowcode-types';
import { uniqueId, compatStage } from '@alilc/lowcode-utils'; import { uniqueId, compatStage } from '@alilc/lowcode-utils';
import { Prop, IPropParent, UNSET } from './prop'; import { Prop, IProp, UNSET } from './prop';
import { Node } from '../node'; import { Node } from '../node';
// import { TransformStage } from '../transform-stage'; // import { TransformStage } from '../transform-stage';
@ -23,7 +23,7 @@ export function getConvertedExtraKey(key: string): string {
export function getOriginalExtraKey(key: string): string { export function getOriginalExtraKey(key: string): string {
return key.replace(new RegExp(`${EXTRA_KEY_PREFIX}`, 'g'), ''); return key.replace(new RegExp(`${EXTRA_KEY_PREFIX}`, 'g'), '');
} }
export class Props implements IPropParent { export class Props implements IProp {
readonly id = uniqueId('props'); readonly id = uniqueId('props');
@obx.shallow private items: Prop[] = []; @obx.shallow private items: Prop[] = [];

View File

@ -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 { IPublicTypeCompositeValue, IPublicEnumTransformStage, IPublicModelProp, IPublicModelNode } from '@alilc/lowcode-types';
import { propSymbol } from '../symbols'; import { propSymbol } from '../symbols';
import { Node } from './node'; import { Node as ShellNode } from './node';
export class Prop implements IPublicModelProp { export class Prop implements IPublicModelProp {
private readonly [propSymbol]: InnerProp; private readonly [propSymbol]: InnerProp;
@ -26,6 +26,7 @@ export class Prop implements IPublicModelProp {
/** /**
* key * key
* get key of prop
*/ */
get key(): string | number | undefined { get key(): string | number | undefined {
return this[propSymbol].key; return this[propSymbol].key;
@ -34,7 +35,7 @@ export class Prop implements IPublicModelProp {
/** /**
* prop * prop
*/ */
get path(): any[] { get path(): string[] {
return this[propSymbol].path; return this[propSymbol].path;
} }
@ -42,14 +43,14 @@ export class Prop implements IPublicModelProp {
* *
*/ */
get node(): IPublicModelNode | null { 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) * return the slot node (only if the current prop represents a slot)
*/ */
get slotNode(): IPublicModelNode | null { get slotNode(): IPublicModelNode | null {
return Node.create(this[propSymbol].slotNode); return ShellNode.create(this[propSymbol].slotNode);
} }
/** /**

View File

@ -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 { IPublicTypeCompositeValue, IPublicModelProps, IPublicModelNode, IPublicModelProp } from '@alilc/lowcode-types';
import { propsSymbol } from '../symbols'; import { propsSymbol } from '../symbols';
import { Node } from './node'; import { Node } from './node';

View File

@ -4,6 +4,7 @@ import { IPublicEnumTransformStage } from '../enum';
import { IPublicModelNodeChildren, IPublicModelComponentMeta, IPublicModelProp, IPublicModelProps, IPublicModelSettingTopEntry, IPublicModelDocumentModel, IPublicModelExclusiveGroup } from './'; import { IPublicModelNodeChildren, IPublicModelComponentMeta, IPublicModelProp, IPublicModelProps, IPublicModelSettingTopEntry, IPublicModelDocumentModel, IPublicModelExclusiveGroup } from './';
export interface IPublicModelNode { export interface IPublicModelNode {
/** /**
* id * id
* node id * node id

View File

@ -3,6 +3,7 @@ import { IPublicTypeCompositeValue } from '../type';
import { IPublicModelNode } from './'; import { IPublicModelNode } from './';
export interface IPublicModelProp { export interface IPublicModelProp {
/** /**
* id * id
*/ */
@ -10,50 +11,60 @@ export interface IPublicModelProp {
/** /**
* key * key
* get key of prop
*/ */
get key(): string | number | undefined; get key(): string | number | undefined;
/** /**
* prop * prop
* get path of current prop
*/ */
get path(): any[]; get path(): string[];
/** /**
* *
* get node instance, which this prop belongs to
*/ */
get node(): IPublicModelNode | null; get node(): IPublicModelNode | null;
/** /**
* prop Slot slotNode
* return the slot node (only if the current prop represents a slot) * return the slot node (only if the current prop represents a slot)
* @since v1.1.0
*/ */
get slotNode(): IPublicModelNode | null; get slotNode(): IPublicModelNode | undefined | null;
/** /**
* judge if it is a prop or not * Prop , true
* check if it is a prop or not, and of course always return true
* @experimental
*/ */
get isProp(): boolean; get isProp(): boolean;
/** /**
* *
* set value for this prop
* @param val * @param val
*/ */
setValue(val: IPublicTypeCompositeValue): void; setValue(val: IPublicTypeCompositeValue): void;
/** /**
* *
* @returns * get value of this prop
*/ */
getValue(): any; getValue(): any;
/** /**
* *
* remove value of this prop
* @since v1.0.16
*/ */
remove(): void; remove(): void;
/** /**
* *
* export schema
* @param stage * @param stage
* @returns
*/ */
exportSchema(stage: IPublicEnumTransformStage): IPublicTypeCompositeValue; exportSchema(stage: IPublicEnumTransformStage): IPublicTypeCompositeValue;
} }

View File

@ -7,16 +7,19 @@ import { IPublicTypeNodeData, IPublicTypeCompositeValue, IPublicTypeNodeSchema }
*/ */
export interface IPublicTypeJSExpression { export interface IPublicTypeJSExpression {
type: 'JSExpression'; type: 'JSExpression';
/** /**
* *
*/ */
value: string; value: string;
/** /**
* *
* *
* @todo * @todo
*/ */
mock?: any; mock?: any;
/** /**
* *
* *
@ -33,6 +36,7 @@ export interface IPublicTypeJSExpression {
*/ */
export interface IPublicTypeJSFunction { export interface IPublicTypeJSFunction {
type: 'JSFunction'; type: 'JSFunction';
/** /**
* *
*/ */
@ -66,21 +70,34 @@ export interface IPublicTypeJSFunction {
* ReactNode Function return ReactNode * ReactNode Function return ReactNode
*/ */
export interface IPublicTypeJSSlot { export interface IPublicTypeJSSlot {
/**
* type
*/
type: 'JSSlot'; type: 'JSSlot';
/** /**
* @todo * @todo
*/ */
title?: string; title?: string;
/**
* @todo
*/
id?: string;
/** /**
* Function return ReactNode * Function return ReactNode
* *
* this[] * this[]
*/ */
params?: string[]; params?: string[];
/** /**
* *
*/ */
value?: IPublicTypeNodeData[] | IPublicTypeNodeData; value?: IPublicTypeNodeData[] | IPublicTypeNodeData;
/** /**
* @todo * @todo
*/ */