GeezerVison is showing github.com — feat: add getDOMNode api definition in node module · EsonSu2000/lowcode-engine@9648331
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/node.md +11Lines changed: 11 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -645,3 +645,14 @@ setConditionalVisible(): void; | 645 | 645 | ``` | 646 | 646 |
| 647 | 647 | **@since v1.1.0** | | 648 | + | | 649 | +### getDOMNode | | 650 | +获取节点实例对应的 dom 节点 | | 651 | + | | 652 | +```typescript | | 653 | +/** | | 654 | + * 获取节点实例对应的 dom 节点 | | 655 | + */ | | 656 | +getDOMNode(): HTMLElement; | | 657 | + | | 658 | +``` |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/jest.config.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,6 +15,7 @@ const jestConfig = { | 15 | 15 | // testMatch: ['**/document-model.test.ts'], | 16 | 16 | // testMatch: ['**/prop.test.ts'], | 17 | 17 | // testMatch: ['(/tests?/.*(test))\\.[jt]s$'], | | 18 | + // testMatch: ['**/document/node/node.add.test.ts'], | 18 | 19 | transformIgnorePatterns: [ | 19 | 20 | `/node_modules/(?!${esModules})/`, | 20 | 21 | ], | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/designer/designer.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -71,6 +71,8 @@ export interface IDesigner { | 71 | 71 |
| 72 | 72 | get editor(): IPublicModelEditor; | 73 | 73 |
| | 74 | + get detecting(): Detecting; | | 75 | + | 74 | 76 | createScroller(scrollable: IPublicTypeScrollable): IPublicModelScroller; | 75 | 77 |
| 76 | 78 | /** | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/designer/setting/setting-top-entry.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,6 +17,7 @@ function generateSessionId(nodes: INode[]) { | 17 | 17 | } | 18 | 18 |
| 19 | 19 | export interface ISettingTopEntry extends ISettingEntry { | | 20 | + purge(): void; | 20 | 21 | } | 21 | 22 |
| 22 | 23 | export class SettingTopEntry implements ISettingTopEntry { | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/document/document-model.ts +13-5Lines changed: 13 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -87,6 +87,8 @@ export interface IDocumentModel extends Omit< IPublicModelDocumentModel< | 87 | 87 |
| 88 | 88 | get active(): boolean; | 89 | 89 |
| | 90 | + get nodesMap(): Map<string, INode>; | | 91 | + | 90 | 92 | /** | 91 | 93 | * 根据 id 获取节点 | 92 | 94 | */ | @@ -114,6 +116,12 @@ export interface IDocumentModel extends Omit< IPublicModelDocumentModel< | 114 | 116 | onChangeNodeVisible(fn: (node: INode, visible: boolean) => void): IPublicTypeDisposable; | 115 | 117 |
| 116 | 118 | addWillPurge(node: INode): void; | | 119 | + | | 120 | + removeWillPurge(node: INode): void; | | 121 | + | | 122 | + getComponentMeta(componentName: string): IComponentMeta; | | 123 | + | | 124 | + insertNodes(parent: INode, thing: INode[] | IPublicTypeNodeData[], at?: number | null, copy?: boolean): INode[]; | 117 | 125 | } | 118 | 126 |
| 119 | 127 | export class DocumentModel implements IDocumentModel { | @@ -379,7 +387,7 @@ export class DocumentModel implements IDocumentModel { | 379 | 387 | * 根据 schema 创建一个节点 | 380 | 388 | */ | 381 | 389 | @action | 382 | | - createNode<T extends INode = INode, C = undefined>(data: GetDataType<C, T>, checkId: boolean = true): T { | | 390 | + createNode<T extends INode = INode, C = undefined>(data: GetDataType<C, T>): T { | 383 | 391 | let schema: any; | 384 | 392 | if (isDOMText(data) || isJSExpression(data)) { | 385 | 393 | schema = { | @@ -410,7 +418,7 @@ export class DocumentModel implements IDocumentModel { | 410 | 418 | } | 411 | 419 | } | 412 | 420 | if (!node) { | 413 | | - node = new Node(this, schema, { checkId }); | | 421 | + node = new Node(this, schema); | 414 | 422 | // will add | 415 | 423 | // todo: this.activeNodes?.push(node); | 416 | 424 | } | @@ -429,7 +437,7 @@ export class DocumentModel implements IDocumentModel { | 429 | 437 | /** | 430 | 438 | * 插入一个节点 | 431 | 439 | */ | 432 | | - insertNode(parent: INode, thing: INode | IPublicTypeNodeData, at?: number | null, copy?: boolean): INode { | | 440 | + insertNode(parent: INode, thing: INode | IPublicTypeNodeData, at?: number | null, copy?: boolean): INode | null { | 433 | 441 | return insertChild(parent, thing, at, copy); | 434 | 442 | } | 435 | 443 |
| @@ -445,7 +453,7 @@ export class DocumentModel implements IDocumentModel { | 445 | 453 | */ | 446 | 454 | removeNode(idOrNode: string | INode) { | 447 | 455 | let id: string; | 448 | | - let node: INode | null; | | 456 | + let node: INode | null = null; | 449 | 457 | if (typeof idOrNode === 'string') { | 450 | 458 | id = idOrNode; | 451 | 459 | node = this.getNode(id); | @@ -859,7 +867,7 @@ export class DocumentModel implements IDocumentModel { | 859 | 867 | onReady(fn: Function) { | 860 | 868 | this.designer.editor.eventBus.on('document-open', fn); | 861 | 869 | return () => { | 862 | | - this.designer.editor.removeListener('document-open', fn); | | 870 | + this.designer.editor.eventBus.off('document-open', fn); | 863 | 871 | }; | 864 | 872 | } | 865 | 873 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/document/node/exclusive-group.ts +30-20Lines changed: 30 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { obx, computed, makeObservable } from '@alilc/lowcode-editor-core'; | 2 | 2 | import { uniqueId } from '@alilc/lowcode-utils'; | 3 | 3 | import { IPublicTypeTitleContent, IPublicModelExclusiveGroup } from '@alilc/lowcode-types'; | 4 | | -import { Node } from './node'; | | 4 | +import { INode } from './node'; | 5 | 5 | import { intl } from '../../locale'; | 6 | 6 |
| | 7 | +export interface IExclusiveGroup extends IPublicModelExclusiveGroup<INode> { | | 8 | + readonly name: string; | | 9 | + | | 10 | + remove(node: INode): void; | | 11 | + | | 12 | + add(node: INode): void; | | 13 | + | | 14 | + isVisible(node: INode): boolean; | | 15 | +} | | 16 | + | 7 | 17 | // modals assoc x-hide value, initial: check is Modal, yes will put it in modals, cross levels | 8 | 18 | // if-else-if assoc conditionGroup value, should be the same level, | 9 | 19 | // and siblings, need renderEngine support | 10 | | -export class ExclusiveGroup implements IPublicModelExclusiveGroup { | | 20 | +export class ExclusiveGroup implements IExclusiveGroup { | 11 | 21 | readonly isExclusiveGroup = true; | 12 | 22 |
| 13 | 23 | readonly id = uniqueId('exclusive'); | 14 | 24 |
| 15 | | - @obx.shallow readonly children: Node[] = []; | | 25 | + readonly title: IPublicTypeTitleContent; | | 26 | + | | 27 | + @obx.shallow readonly children: INode[] = []; | 16 | 28 |
| 17 | 29 | @obx private visibleIndex = 0; | 18 | 30 |
| @@ -28,28 +40,36 @@ export class ExclusiveGroup implements IPublicModelExclusiveGroup { | 28 | 40 | return this.children.length; | 29 | 41 | } | 30 | 42 |
| 31 | | - @computed get visibleNode(): Node { | | 43 | + @computed get visibleNode(): INode { | 32 | 44 | return this.children[this.visibleIndex]; | 33 | 45 | } | 34 | 46 |
| 35 | | - @computed get firstNode(): Node { | | 47 | + @computed get firstNode(): INode { | 36 | 48 | return this.children[0]!; | 37 | 49 | } | 38 | 50 |
| 39 | 51 | get index() { | 40 | 52 | return this.firstNode.index; | 41 | 53 | } | 42 | 54 |
| 43 | | - add(node: Node) { | 44 | | - if (node.nextSibling && node.nextSibling.conditionGroup === this) { | | 55 | + constructor(readonly name: string, title?: IPublicTypeTitleContent) { | | 56 | + makeObservable(this); | | 57 | + this.title = title || { | | 58 | + type: 'i18n', | | 59 | + intl: intl('Condition Group'), | | 60 | + }; | | 61 | + } | | 62 | + | | 63 | + add(node: INode) { | | 64 | + if (node.nextSibling && node.nextSibling.conditionGroup?.id === this.id) { | 45 | 65 | const i = this.children.indexOf(node.nextSibling); | 46 | 66 | this.children.splice(i, 0, node); | 47 | 67 | } else { | 48 | 68 | this.children.push(node); | 49 | 69 | } | 50 | 70 | } | 51 | 71 |
| 52 | | - remove(node: Node) { | | 72 | + remove(node: INode) { | 53 | 73 | const i = this.children.indexOf(node); | 54 | 74 | if (i > -1) { | 55 | 75 | this.children.splice(i, 1); | @@ -61,27 +81,17 @@ export class ExclusiveGroup implements IPublicModelExclusiveGroup { | 61 | 81 | } | 62 | 82 | } | 63 | 83 |
| 64 | | - setVisible(node: Node) { | | 84 | + setVisible(node: INode) { | 65 | 85 | const i = this.children.indexOf(node); | 66 | 86 | if (i > -1) { | 67 | 87 | this.visibleIndex = i; | 68 | 88 | } | 69 | 89 | } | 70 | 90 |
| 71 | | - isVisible(node: Node) { | | 91 | + isVisible(node: INode) { | 72 | 92 | const i = this.children.indexOf(node); | 73 | 93 | return i === this.visibleIndex; | 74 | 94 | } | 75 | | - | 76 | | - readonly title: IPublicTypeTitleContent; | 77 | | - | 78 | | - constructor(readonly name: string, title?: IPublicTypeTitleContent) { | 79 | | - makeObservable(this); | 80 | | - this.title = title || { | 81 | | - type: 'i18n', | 82 | | - intl: intl('Condition Group'), | 83 | | - }; | 84 | | - } | 85 | 95 | } | 86 | 96 |
| 87 | 97 | export function isExclusiveGroup(obj: any): obj is ExclusiveGroup { | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/document/node/node-children.ts +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { obx, computed, globalContext, makeObservable, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core'; | 2 | 2 | import { Node, INode } from './node'; | 3 | | -import { IPublicTypeNodeData, IPublicModelNodeChildren, IPublicEnumTransformStage } from '@alilc/lowcode-types'; | | 3 | +import { IPublicTypeNodeData, IPublicModelNodeChildren, IPublicEnumTransformStage, IPublicTypeDisposable } from '@alilc/lowcode-types'; | 4 | 4 | import { shallowEqual, compatStage, isNodeSchema } from '@alilc/lowcode-utils'; | 5 | 5 | import { foreachReverse } from '../../utils/tree'; | 6 | 6 | import { NodeRemoveOptions } from '../../types'; | @@ -18,6 +18,8 @@ export interface INodeChildren extends Omit<IPublicModelNodeChildren<INode>, | 18 | 18 | > { | 19 | 19 | get owner(): INode; | 20 | 20 |
| | 21 | + get length(): number; | | 22 | + | 21 | 23 | unlinkChild(node: INode): void; | 22 | 24 |
| 23 | 25 | /** | @@ -58,6 +60,8 @@ export interface INodeChildren extends Omit<IPublicModelNodeChildren<INode>, | 58 | 60 |
| 59 | 61 | internalInitParent(): void; | 60 | 62 |
| | 63 | + onChange(fn: (info?: IOnChangeOptions) => void): IPublicTypeDisposable; | | 64 | + | 61 | 65 | /** overriding methods end */ | 62 | 66 | } | 63 | 67 | export class NodeChildren implements INodeChildren { | @@ -478,7 +482,7 @@ export class NodeChildren implements INodeChildren { | 478 | 482 | } | 479 | 483 | } | 480 | 484 |
| 481 | | - onChange(fn: (info?: IOnChangeOptions) => void): () => void { | | 485 | + onChange(fn: (info?: IOnChangeOptions) => void): IPublicTypeDisposable { | 482 | 486 | this.emitter.on('change', fn); | 483 | 487 | return () => { | 484 | 488 | this.emitter.removeListener('change', fn); | |
|