Skip to content

Commit 857685a

Browse files
liujupingJackLian
authored andcommitted
feat(node): add getRGL api
1 parent e3842b0 commit 857685a

File tree

5 files changed

+74
-25
lines changed

5 files changed

+74
-25
lines changed

docs/docs/api/model/node.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,4 +657,22 @@ setConditionalVisible(): void;
657657
*/
658658
getDOMNode(): HTMLElement;
659659

660+
```
661+
662+
### getRGL
663+
664+
获取磁贴相关信息
665+
666+
```typescript
667+
/**
668+
* 获取磁贴相关信息
669+
*/
670+
getRGL(): {
671+
isContainerNode: boolean;
672+
isEmptyNode: boolean;
673+
isRGLContainerNode: boolean;
674+
isRGLNode: boolean;
675+
isRGL: boolean;
676+
rglNode: Node | null;
677+
}
660678
```

packages/designer/src/component-actions.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IPublicTypeComponentAction, IPublicTypeMetadataTransducer } from '@alilc/lowcode-types';
1+
import { IPublicModelNode, IPublicTypeComponentAction, IPublicTypeMetadataTransducer } from '@alilc/lowcode-types';
22
import { engineConfig } from '@alilc/lowcode-editor-core';
33
import { intlNode } from './locale';
44
import {
@@ -8,18 +8,19 @@ import {
88
IconClone,
99
IconHidden,
1010
} from './icons';
11-
import { Node } from './document';
1211
import { componentDefaults, legacyIssues } from './transducers';
1312

1413
export class ComponentActions {
14+
private metadataTransducers: IPublicTypeMetadataTransducer[] = [];
15+
1516
actions: IPublicTypeComponentAction[] = [
1617
{
1718
name: 'remove',
1819
content: {
1920
icon: IconRemove,
2021
title: intlNode('remove'),
2122
/* istanbul ignore next */
22-
action(node: Node) {
23+
action(node: IPublicModelNode) {
2324
node.remove();
2425
},
2526
},
@@ -31,13 +32,13 @@ export class ComponentActions {
3132
icon: IconHidden,
3233
title: intlNode('hide'),
3334
/* istanbul ignore next */
34-
action(node: Node) {
35-
node.setVisible(false);
35+
action(node: IPublicModelNode) {
36+
node.visible = false;
3637
},
3738
},
3839
/* istanbul ignore next */
39-
condition: (node: Node) => {
40-
return node.componentMeta.isModal;
40+
condition: (node: IPublicModelNode) => {
41+
return node.componentMeta?.isModal;
4142
},
4243
important: true,
4344
},
@@ -47,25 +48,25 @@ export class ComponentActions {
4748
icon: IconClone,
4849
title: intlNode('copy'),
4950
/* istanbul ignore next */
50-
action(node: Node) {
51+
action(node: IPublicModelNode) {
5152
// node.remove();
5253
const { document: doc, parent, index } = node;
5354
if (parent) {
54-
const newNode = doc.insertNode(parent, node, index + 1, true);
55-
newNode.select();
56-
const { isRGL, rglNode } = node.getRGL();
55+
const newNode = doc?.insertNode(parent, node, (index ?? 0) + 1, true);
56+
newNode?.select();
57+
const { isRGL, rglNode } = node?.getRGL();
5758
if (isRGL) {
5859
// 复制 layout 信息
59-
const layout = rglNode.getPropValue('layout') || [];
60-
const curLayout = layout.filter((item) => item.i === node.getPropValue('fieldId'));
60+
const layout: any = rglNode?.getPropValue('layout') || [];
61+
const curLayout = layout.filter((item: any) => item.i === node.getPropValue('fieldId'));
6162
if (curLayout && curLayout[0]) {
6263
layout.push({
6364
...curLayout[0],
64-
i: newNode.getPropValue('fieldId'),
65+
i: newNode?.getPropValue('fieldId'),
6566
});
66-
rglNode.setPropValue('layout', layout);
67+
rglNode?.setPropValue('layout', layout);
6768
// 如果是磁贴块复制,则需要滚动到影响位置
68-
setTimeout(() => newNode.document.simulator?.scrollToNode(newNode), 10);
69+
setTimeout(() => newNode?.document?.project?.simulatorHost?.scrollToNode(newNode), 10);
6970
}
7071
}
7172
}
@@ -79,13 +80,13 @@ export class ComponentActions {
7980
icon: IconLock, // 锁定 icon
8081
title: intlNode('lock'),
8182
/* istanbul ignore next */
82-
action(node: Node) {
83+
action(node: IPublicModelNode) {
8384
node.lock();
8485
},
8586
},
8687
/* istanbul ignore next */
87-
condition: (node: Node) => {
88-
return engineConfig.get('enableCanvasLock', false) && node.isContainer() && !node.isLocked;
88+
condition: (node: IPublicModelNode) => {
89+
return engineConfig.get('enableCanvasLock', false) && node.isContainerNode && !node.isLocked;
8990
},
9091
important: true,
9192
},
@@ -95,13 +96,13 @@ export class ComponentActions {
9596
icon: IconUnlock, // 解锁 icon
9697
title: intlNode('unlock'),
9798
/* istanbul ignore next */
98-
action(node: Node) {
99+
action(node: IPublicModelNode) {
99100
node.lock(false);
100101
},
101102
},
102103
/* istanbul ignore next */
103-
condition: (node: Node) => {
104-
return engineConfig.get('enableCanvasLock', false) && node.isContainer() && node.isLocked;
104+
condition: (node: IPublicModelNode) => {
105+
return engineConfig.get('enableCanvasLock', false) && node.isContainerNode && node.isLocked;
105106
},
106107
important: true,
107108
},
@@ -132,8 +133,6 @@ export class ComponentActions {
132133
}
133134
}
134135

135-
private metadataTransducers: IPublicTypeMetadataTransducer[] = [];
136-
137136
registerMetadataTransducer(
138137
transducer: IPublicTypeMetadataTransducer,
139138
level = 100,

packages/designer/src/document/node/node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
12251225
const isRGLContainerNode = this.isRGLContainer;
12261226
const isRGLNode = this.getParent()?.isRGLContainer;
12271227
const isRGL = isRGLContainerNode || (isRGLNode && (!isContainerNode || !isEmptyNode));
1228-
let rglNode = isRGLContainerNode ? this : isRGL ? this?.getParent() : {};
1228+
let rglNode = isRGLContainerNode ? this : isRGL ? this?.getParent() : null;
12291229
return { isContainerNode, isEmptyNode, isRGLContainerNode, isRGLNode, isRGL, rglNode };
12301230
}
12311231

packages/shell/src/model/node.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,4 +655,24 @@ export class Node implements IPublicModelNode {
655655
setConditionalVisible(): void {
656656
this[nodeSymbol].setConditionalVisible();
657657
}
658+
659+
getRGL() {
660+
const {
661+
isContainerNode,
662+
isEmptyNode,
663+
isRGLContainerNode,
664+
isRGLNode,
665+
isRGL,
666+
rglNode,
667+
} = this[nodeSymbol].getRGL();
668+
669+
return {
670+
isContainerNode,
671+
isEmptyNode,
672+
isRGLContainerNode,
673+
isRGLNode,
674+
isRGL,
675+
rglNode: Node.create(rglNode),
676+
};
677+
}
658678
}

packages/types/src/shell/model/node.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,18 @@ export interface IBaseModelNode<
490490
* 获取节点实例对应的 dom 节点
491491
*/
492492
getDOMNode(): HTMLElement;
493+
494+
/**
495+
* 获取磁贴相关信息
496+
*/
497+
getRGL(): {
498+
isContainerNode: boolean;
499+
isEmptyNode: boolean;
500+
isRGLContainerNode: boolean;
501+
isRGLNode: boolean;
502+
isRGL: boolean;
503+
rglNode: Node | null;
504+
};
493505
}
494506

495507
export interface IPublicModelNode extends IBaseModelNode<IPublicModelDocumentModel, IPublicModelNode> {}

0 commit comments

Comments
 (0)