GeezerVison is showing github.com — docs(prop): optimize api doc for model/prop, and fix related lint issues · li55/lowcode-engine@76f612b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/docs/api/model/document-model.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -334,7 +334,7 @@ onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): voi | 334 | 334 |
| 335 | 335 | ### onChangeNodeChildren | 336 | 336 |
| 337 | | -onChangeNodeChildren(fn: (info?: IPublicOnChangeOptions) => void) | | 337 | +onChangeNodeChildren(fn: (info?: IPublicTypeOnChangeOptions) => void) | 338 | 338 |
| 339 | 339 | 当前 document 的节点 children 变更事件 | 340 | 340 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/docs/api/model/prop.md +61-6Lines changed: 61 additions & 6 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -15,39 +15,94 @@ sidebar_position: 3 | 15 | 15 |
| 16 | 16 | id | 17 | 17 |
| | 18 | +`@type {string}` | | 19 | + | 18 | 20 | ### key | 19 | 21 |
| 20 | 22 | key 值 | 21 | 23 |
| | 24 | +`@type {string | number | undefined}` | | 25 | + | 22 | 26 | ### path | 23 | 27 |
| 24 | 28 | 返回当前 prop 的路径 | 25 | 29 |
| | 30 | +`@type {string[]}` | | 31 | + | 26 | 32 | ### node | 27 | 33 |
| 28 | 34 | 返回所属的节点实例 | 29 | 35 |
| | 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 | + | 30 | 49 | ## 方法签名 | 31 | 50 |
| 32 | 51 | ### setValue | 33 | 52 |
| 34 | | -setValue(val: CompositeValue) | 35 | | - | 36 | 53 | 设置值 | 37 | 54 |
| 38 | | -### getValue | | 55 | +```typescript | | 56 | +/** | | 57 | + * 设置值 | | 58 | + * set value for this prop | | 59 | + * @param val | | 60 | + */ | | 61 | +setValue(val: IPublicTypeCompositeValue): void; | | 62 | +``` | 39 | 63 |
| 40 | | -getValue() | | 64 | +相关类型:[IPublicTypeCompositeValue](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/composite-value.ts) | | 65 | + | | 66 | +### getValue | 41 | 67 |
| 42 | 68 | 获取值 | 43 | 69 |
| | 70 | +```typescript | | 71 | +/** | | 72 | + * 获取值 | | 73 | + * get value of this prop | | 74 | + */ | | 75 | +getValue(): any; | | 76 | +``` | | 77 | + | 44 | 78 | ### remove | | 79 | + | 45 | 80 | 移除值 | 46 | 81 |
| | 82 | +```typescript | | 83 | +/** | | 84 | + * 移除值 | | 85 | + * remove value of this prop | | 86 | + * @since v1.0.16 | | 87 | + */ | | 88 | +remove(): void; | | 89 | +``` | | 90 | + | 47 | 91 | **@since v1.0.16** | 48 | 92 |
| 49 | 93 | ### exportSchema | 50 | 94 |
| 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 | +``` | 52 | 105 |
| 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) |
Collapse file Copy file name to clipboardExpand all lines: docs/docs/guide/design/editor.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -313,7 +313,7 @@ simulator-renderer 通过调用 host 的方法,将 schema、components 等参 | 313 | 313 |
| 314 | 314 | - 被拖拽对象 - `DragObject` | 315 | 315 | - 拖拽到的目标位置 - `DropLocation` | 316 | | -- 拖拽感应区 - `ISensor` | | 316 | +- 拖拽感应区 - `IPublicModelSensor` | 317 | 317 | - 定位事件 - `LocateEvent` | 318 | 318 |
| 319 | 319 | ##### Sensor | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/document/document-model.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,6 +37,8 @@ export type GetDataType<T, NodeType> = T extends undefined | 37 | 37 | : T; | 38 | 38 | export interface IDocumentModel extends IPublicModelDocumentModel { | 39 | 39 |
| | 40 | + readonly designer: Designer; | | 41 | + | 40 | 42 | } | 41 | 43 |
| 42 | 44 | export class DocumentModel implements IDocumentModel { | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/document/node/node.ts +19-4Lines changed: 19 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,7 +19,7 @@ import { | 19 | 19 | import { compatStage, isDOMText, isJSExpression } from '@alilc/lowcode-utils'; | 20 | 20 | import { SettingTopEntry } from '@alilc/lowcode-designer'; | 21 | 21 | import { Props, getConvertedExtraKey } from './props/props'; | 22 | | -import { DocumentModel } from '../document-model'; | | 22 | +import { DocumentModel, IDocumentModel } from '../document-model'; | 23 | 23 | import { NodeChildren, INodeChildren } from './node-children'; | 24 | 24 | import { Prop } from './props/prop'; | 25 | 25 | import { ComponentMeta } from '../../component-meta'; | @@ -55,6 +55,21 @@ export interface INode extends IPublicModelNode { | 55 | 55 | unlinkSlot(slotNode: Node): void; | 56 | 56 |
| 57 | 57 | 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; | 58 | 73 | } | 59 | 74 |
| 60 | 75 | /** | @@ -189,7 +204,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema> | 189 | 204 |
| 190 | 205 | isInited = false; | 191 | 206 |
| 192 | | - constructor(readonly document: DocumentModel, nodeSchema: Schema, options: any = {}) { | | 207 | + constructor(readonly document: IDocumentModel, nodeSchema: Schema, options: any = {}) { | 193 | 208 | makeObservable(this); | 194 | 209 | const { componentName, id, children, props, ...extras } = nodeSchema; | 195 | 210 | this.id = document.nextId(id); | @@ -521,7 +536,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema> | 521 | 536 | return this.props.export(IPublicEnumTransformStage.Serilize).props || null; | 522 | 537 | } | 523 | 538 |
| 524 | | - @obx.shallow _slots: Node[] = []; | | 539 | + @obx.shallow _slots: INode[] = []; | 525 | 540 |
| 526 | 541 | hasSlots() { | 527 | 542 | return this._slots.length > 0; | @@ -885,7 +900,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema> | 885 | 900 | return false; | 886 | 901 | } | 887 | 902 |
| 888 | | - addSlot(slotNode: Node) { | | 903 | + addSlot(slotNode: INode) { | 889 | 904 | const slotName = slotNode?.getExtraProp('name')?.getAsString(); | 890 | 905 | // 一个组件下的所有 slot,相同 slotName 的 slot 应该是唯一的 | 891 | 906 | if (includeSlot(this, slotName)) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/document/node/props/prop.ts +20-12Lines changed: 20 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 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'; | 3 | 3 | import { uniqueId, isPlainObject, hasOwnProperty, compatStage, isJSExpression, isJSSlot } from '@alilc/lowcode-utils'; | 4 | 4 | import { valueToSource } from './value-to-source'; | 5 | 5 | import { Props } from './props'; | 6 | | -import { SlotNode, Node } from '../node'; | | 6 | +import { SlotNode, INode } from '../node'; | 7 | 7 | // import { TransformStage } from '../transform-stage'; | 8 | 8 |
| 9 | 9 | const { set: mobxSet, isObservableArray } = mobx; | 10 | 10 | export const UNSET = Symbol.for('unset'); | 11 | 11 | // eslint-disable-next-line no-redeclare | 12 | 12 | export type UNSET = typeof UNSET; | 13 | 13 |
| 14 | | -export interface IPropParent { | | 14 | +export interface IProp extends Omit<IPublicModelProp, 'exportSchema' | 'node'> { | | 15 | + | 15 | 16 | delete(prop: Prop): void; | | 17 | + | 16 | 18 | 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; | 19 | 25 | } | 20 | 26 |
| 21 | 27 | export type ValueTypes = 'unset' | 'literal' | 'map' | 'list' | 'expression' | 'slot'; | 22 | 28 |
| 23 | | -export class Prop implements IPropParent { | | 29 | +export class Prop implements IProp { | 24 | 30 | readonly isProp = true; | 25 | 31 |
| 26 | | - readonly owner: Node; | | 32 | + readonly owner: INode; | 27 | 33 |
| 28 | 34 | /** | 29 | 35 | * 键值 | @@ -40,7 +46,7 @@ export class Prop implements IPropParent { | 40 | 46 | readonly options: any; | 41 | 47 |
| 42 | 48 | constructor( | 43 | | - public parent: IPropParent, | | 49 | + public parent: IProp, | 44 | 50 | value: IPublicTypeCompositeValue | UNSET = UNSET, | 45 | 51 | key?: string | number, | 46 | 52 | spread = false, | @@ -305,9 +311,9 @@ export class Prop implements IPropParent { | 305 | 311 | } | 306 | 312 | } | 307 | 313 |
| 308 | | - private _slotNode?: SlotNode; | | 314 | + private _slotNode?: INode; | 309 | 315 |
| 310 | | - get slotNode() { | | 316 | + get slotNode(): INode | undefined | null { | 311 | 317 | return this._slotNode; | 312 | 318 | } | 313 | 319 |
| @@ -342,8 +348,10 @@ export class Prop implements IPropParent { | 342 | 348 | } else { | 343 | 349 | const { owner } = this.props; | 344 | 350 | 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 | + } | 347 | 355 | } | 348 | 356 | } | 349 | 357 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/document/node/props/props.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { computed, makeObservable, obx, action } from '@alilc/lowcode-editor-core'; | 2 | 2 | import { IPublicTypePropsMap, IPublicTypePropsList, IPublicTypeCompositeValue, IPublicEnumTransformStage } from '@alilc/lowcode-types'; | 3 | 3 | import { uniqueId, compatStage } from '@alilc/lowcode-utils'; | 4 | | -import { Prop, IPropParent, UNSET } from './prop'; | | 4 | +import { Prop, IProp, UNSET } from './prop'; | 5 | 5 | import { Node } from '../node'; | 6 | 6 | // import { TransformStage } from '../transform-stage'; | 7 | 7 |
| @@ -23,7 +23,7 @@ export function getConvertedExtraKey(key: string): string { | 23 | 23 | export function getOriginalExtraKey(key: string): string { | 24 | 24 | return key.replace(new RegExp(`${EXTRA_KEY_PREFIX}`, 'g'), ''); | 25 | 25 | } | 26 | | -export class Props implements IPropParent { | | 26 | +export class Props implements IProp { | 27 | 27 | readonly id = uniqueId('props'); | 28 | 28 |
| 29 | 29 | @obx.shallow private items: Prop[] = []; | |
Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/model/prop.ts +6-5Lines changed: 6 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { IPropParent as InnerProp } from '@alilc/lowcode-designer'; | | 1 | +import { IProp as InnerProp } from '@alilc/lowcode-designer'; | 2 | 2 | import { IPublicTypeCompositeValue, IPublicEnumTransformStage, IPublicModelProp, IPublicModelNode } from '@alilc/lowcode-types'; | 3 | 3 | import { propSymbol } from '../symbols'; | 4 | | -import { Node } from './node'; | | 4 | +import { Node as ShellNode } from './node'; | 5 | 5 |
| 6 | 6 | export class Prop implements IPublicModelProp { | 7 | 7 | private readonly [propSymbol]: InnerProp; | @@ -26,6 +26,7 @@ export class Prop implements IPublicModelProp { | 26 | 26 |
| 27 | 27 | /** | 28 | 28 | * key 值 | | 29 | + * get key of prop | 29 | 30 | */ | 30 | 31 | get key(): string | number | undefined { | 31 | 32 | return this[propSymbol].key; | @@ -34,22 +35,22 @@ export class Prop implements IPublicModelProp { | 34 | 35 | /** | 35 | 36 | * 返回当前 prop 的路径 | 36 | 37 | */ | 37 | | - get path(): any[] { | | 38 | + get path(): string[] { | 38 | 39 | return this[propSymbol].path; | 39 | 40 | } | 40 | 41 |
| 41 | 42 | /** | 42 | 43 | * 返回所属的节点实例 | 43 | 44 | */ | 44 | 45 | get node(): IPublicModelNode | null { | 45 | | - return Node.create(this[propSymbol].getNode()); | | 46 | + return ShellNode.create(this[propSymbol].getNode()); | 46 | 47 | } | 47 | 48 |
| 48 | 49 | /** | 49 | 50 | * return the slot node (only if the current prop represents a slot) | 50 | 51 | */ | 51 | 52 | get slotNode(): IPublicModelNode | null { | 52 | | - return Node.create(this[propSymbol].slotNode); | | 53 | + return ShellNode.create(this[propSymbol].slotNode); | 53 | 54 | } | 54 | 55 |
| 55 | 56 | /** | |
Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/model/props.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { IPropParent as InnerProps, getConvertedExtraKey } from '@alilc/lowcode-designer'; | | 1 | +import { IProp as InnerProps, getConvertedExtraKey } from '@alilc/lowcode-designer'; | 2 | 2 | import { IPublicTypeCompositeValue, IPublicModelProps, IPublicModelNode, IPublicModelProp } from '@alilc/lowcode-types'; | 3 | 3 | import { propsSymbol } from '../symbols'; | 4 | 4 | import { Node } from './node'; | |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/model/node.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,7 @@ import { IPublicEnumTransformStage } from '../enum'; | 4 | 4 | import { IPublicModelNodeChildren, IPublicModelComponentMeta, IPublicModelProp, IPublicModelProps, IPublicModelSettingTopEntry, IPublicModelDocumentModel, IPublicModelExclusiveGroup } from './'; | 5 | 5 |
| 6 | 6 | export interface IPublicModelNode { | | 7 | + | 7 | 8 | /** | 8 | 9 | * 节点 id | 9 | 10 | * node id | |
|