mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-13 20:36:34 +00:00
docs(prop): optimize api doc for model/prop, and fix related lint issues
This commit is contained in:
parent
7ddc155f0a
commit
76f612b29c
@ -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 变更事件
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
设置值
|
||||
|
||||
```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()
|
||||
|
||||
获取值
|
||||
|
||||
```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)
|
||||
@ -313,7 +313,7 @@ simulator-renderer 通过调用 host 的方法,将 schema、components 等参
|
||||
|
||||
- 被拖拽对象 - `DragObject`
|
||||
- 拖拽到的目标位置 - `DropLocation`
|
||||
- 拖拽感应区 - `ISensor`
|
||||
- 拖拽感应区 - `IPublicModelSensor`
|
||||
- 定位事件 - `LocateEvent`
|
||||
|
||||
##### Sensor
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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';
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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);
|
||||
@ -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;
|
||||
@ -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)) {
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
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;
|
||||
@ -11,19 +11,25 @@ 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;
|
||||
|
||||
/**
|
||||
* 键值
|
||||
@ -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,
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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[] = [];
|
||||
|
||||
@ -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;
|
||||
@ -26,6 +26,7 @@ export class Prop implements IPublicModelProp {
|
||||
|
||||
/**
|
||||
* key 值
|
||||
* get key of prop
|
||||
*/
|
||||
get key(): string | number | undefined {
|
||||
return this[propSymbol].key;
|
||||
@ -34,7 +35,7 @@ export class Prop implements IPublicModelProp {
|
||||
/**
|
||||
* 返回当前 prop 的路径
|
||||
*/
|
||||
get path(): any[] {
|
||||
get path(): string[] {
|
||||
return this[propSymbol].path;
|
||||
}
|
||||
|
||||
@ -42,14 +43,14 @@ export class Prop implements IPublicModelProp {
|
||||
* 返回所属的节点实例
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -4,6 +4,7 @@ import { IPublicEnumTransformStage } from '../enum';
|
||||
import { IPublicModelNodeChildren, IPublicModelComponentMeta, IPublicModelProp, IPublicModelProps, IPublicModelSettingTopEntry, IPublicModelDocumentModel, IPublicModelExclusiveGroup } from './';
|
||||
|
||||
export interface IPublicModelNode {
|
||||
|
||||
/**
|
||||
* 节点 id
|
||||
* node id
|
||||
|
||||
@ -3,6 +3,7 @@ import { IPublicTypeCompositeValue } from '../type';
|
||||
import { IPublicModelNode } from './';
|
||||
|
||||
export interface IPublicModelProp {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@ -10,50 +11,60 @@ export interface IPublicModelProp {
|
||||
|
||||
/**
|
||||
* key 值
|
||||
* get key of prop
|
||||
*/
|
||||
get key(): string | number | undefined;
|
||||
|
||||
/**
|
||||
* 返回当前 prop 的路径
|
||||
* get path of current prop
|
||||
*/
|
||||
get path(): any[];
|
||||
get path(): string[];
|
||||
|
||||
/**
|
||||
* 返回所属的节点实例
|
||||
* get node instance, which this prop belongs to
|
||||
*/
|
||||
get node(): IPublicModelNode | null;
|
||||
|
||||
/**
|
||||
* 当本 prop 代表一个 Slot 时,返回对应的 slotNode
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 设置值
|
||||
* set value for this prop
|
||||
* @param val
|
||||
*/
|
||||
setValue(val: IPublicTypeCompositeValue): void;
|
||||
|
||||
/**
|
||||
* 获取值
|
||||
* @returns
|
||||
* get value of this prop
|
||||
*/
|
||||
getValue(): any;
|
||||
|
||||
/**
|
||||
* 移除值
|
||||
* remove value of this prop
|
||||
* @since v1.0.16
|
||||
*/
|
||||
remove(): void;
|
||||
|
||||
/**
|
||||
* 导出值
|
||||
* export schema
|
||||
* @param stage
|
||||
* @returns
|
||||
*/
|
||||
exportSchema(stage: IPublicEnumTransformStage): IPublicTypeCompositeValue;
|
||||
}
|
||||
|
||||
@ -7,16 +7,19 @@ import { IPublicTypeNodeData, IPublicTypeCompositeValue, IPublicTypeNodeSchema }
|
||||
*/
|
||||
export interface IPublicTypeJSExpression {
|
||||
type: 'JSExpression';
|
||||
|
||||
/**
|
||||
* 表达式字符串
|
||||
*/
|
||||
value: string;
|
||||
|
||||
/**
|
||||
* 模拟值
|
||||
*
|
||||
* @todo 待标准描述
|
||||
*/
|
||||
mock?: any;
|
||||
|
||||
/**
|
||||
* 源码
|
||||
*
|
||||
@ -33,6 +36,7 @@ export interface IPublicTypeJSExpression {
|
||||
*/
|
||||
export interface IPublicTypeJSFunction {
|
||||
type: 'JSFunction';
|
||||
|
||||
/**
|
||||
* 函数定义,或直接函数表达式
|
||||
*/
|
||||
@ -66,21 +70,34 @@ export interface IPublicTypeJSFunction {
|
||||
* 通常用于描述组件的某一个属性为 ReactNode 或 Function return ReactNode 的场景。
|
||||
*/
|
||||
export interface IPublicTypeJSSlot {
|
||||
|
||||
/**
|
||||
* type
|
||||
*/
|
||||
type: 'JSSlot';
|
||||
|
||||
/**
|
||||
* @todo 待标准描述
|
||||
*/
|
||||
title?: string;
|
||||
|
||||
/**
|
||||
* @todo 待标准描述
|
||||
*/
|
||||
id?: string;
|
||||
|
||||
/**
|
||||
* 组件的某一个属性为 Function return ReactNode 时,函数的入参
|
||||
*
|
||||
* 其子节点可以通过 this[参数名] 来获取对应的参数。
|
||||
*/
|
||||
params?: string[];
|
||||
|
||||
/**
|
||||
* 具体的值。
|
||||
*/
|
||||
value?: IPublicTypeNodeData[] | IPublicTypeNodeData;
|
||||
|
||||
/**
|
||||
* @todo 待标准描述
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user