mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 11:20:11 +00:00
feat(node): add getRGL api
This commit is contained in:
parent
e3842b0531
commit
857685a3b4
@ -658,3 +658,21 @@ setConditionalVisible(): void;
|
|||||||
getDOMNode(): HTMLElement;
|
getDOMNode(): HTMLElement;
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### getRGL
|
||||||
|
|
||||||
|
获取磁贴相关信息
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
/**
|
||||||
|
* 获取磁贴相关信息
|
||||||
|
*/
|
||||||
|
getRGL(): {
|
||||||
|
isContainerNode: boolean;
|
||||||
|
isEmptyNode: boolean;
|
||||||
|
isRGLContainerNode: boolean;
|
||||||
|
isRGLNode: boolean;
|
||||||
|
isRGL: boolean;
|
||||||
|
rglNode: Node | null;
|
||||||
|
}
|
||||||
|
```
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { IPublicTypeComponentAction, IPublicTypeMetadataTransducer } from '@alilc/lowcode-types';
|
import { IPublicModelNode, IPublicTypeComponentAction, IPublicTypeMetadataTransducer } from '@alilc/lowcode-types';
|
||||||
import { engineConfig } from '@alilc/lowcode-editor-core';
|
import { engineConfig } from '@alilc/lowcode-editor-core';
|
||||||
import { intlNode } from './locale';
|
import { intlNode } from './locale';
|
||||||
import {
|
import {
|
||||||
@ -8,10 +8,11 @@ import {
|
|||||||
IconClone,
|
IconClone,
|
||||||
IconHidden,
|
IconHidden,
|
||||||
} from './icons';
|
} from './icons';
|
||||||
import { Node } from './document';
|
|
||||||
import { componentDefaults, legacyIssues } from './transducers';
|
import { componentDefaults, legacyIssues } from './transducers';
|
||||||
|
|
||||||
export class ComponentActions {
|
export class ComponentActions {
|
||||||
|
private metadataTransducers: IPublicTypeMetadataTransducer[] = [];
|
||||||
|
|
||||||
actions: IPublicTypeComponentAction[] = [
|
actions: IPublicTypeComponentAction[] = [
|
||||||
{
|
{
|
||||||
name: 'remove',
|
name: 'remove',
|
||||||
@ -19,7 +20,7 @@ export class ComponentActions {
|
|||||||
icon: IconRemove,
|
icon: IconRemove,
|
||||||
title: intlNode('remove'),
|
title: intlNode('remove'),
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
action(node: Node) {
|
action(node: IPublicModelNode) {
|
||||||
node.remove();
|
node.remove();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -31,13 +32,13 @@ export class ComponentActions {
|
|||||||
icon: IconHidden,
|
icon: IconHidden,
|
||||||
title: intlNode('hide'),
|
title: intlNode('hide'),
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
action(node: Node) {
|
action(node: IPublicModelNode) {
|
||||||
node.setVisible(false);
|
node.visible = false;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
condition: (node: Node) => {
|
condition: (node: IPublicModelNode) => {
|
||||||
return node.componentMeta.isModal;
|
return node.componentMeta?.isModal;
|
||||||
},
|
},
|
||||||
important: true,
|
important: true,
|
||||||
},
|
},
|
||||||
@ -47,25 +48,25 @@ export class ComponentActions {
|
|||||||
icon: IconClone,
|
icon: IconClone,
|
||||||
title: intlNode('copy'),
|
title: intlNode('copy'),
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
action(node: Node) {
|
action(node: IPublicModelNode) {
|
||||||
// node.remove();
|
// node.remove();
|
||||||
const { document: doc, parent, index } = node;
|
const { document: doc, parent, index } = node;
|
||||||
if (parent) {
|
if (parent) {
|
||||||
const newNode = doc.insertNode(parent, node, index + 1, true);
|
const newNode = doc?.insertNode(parent, node, (index ?? 0) + 1, true);
|
||||||
newNode.select();
|
newNode?.select();
|
||||||
const { isRGL, rglNode } = node.getRGL();
|
const { isRGL, rglNode } = node?.getRGL();
|
||||||
if (isRGL) {
|
if (isRGL) {
|
||||||
// 复制 layout 信息
|
// 复制 layout 信息
|
||||||
const layout = rglNode.getPropValue('layout') || [];
|
const layout: any = rglNode?.getPropValue('layout') || [];
|
||||||
const curLayout = layout.filter((item) => item.i === node.getPropValue('fieldId'));
|
const curLayout = layout.filter((item: any) => item.i === node.getPropValue('fieldId'));
|
||||||
if (curLayout && curLayout[0]) {
|
if (curLayout && curLayout[0]) {
|
||||||
layout.push({
|
layout.push({
|
||||||
...curLayout[0],
|
...curLayout[0],
|
||||||
i: newNode.getPropValue('fieldId'),
|
i: newNode?.getPropValue('fieldId'),
|
||||||
});
|
});
|
||||||
rglNode.setPropValue('layout', layout);
|
rglNode?.setPropValue('layout', layout);
|
||||||
// 如果是磁贴块复制,则需要滚动到影响位置
|
// 如果是磁贴块复制,则需要滚动到影响位置
|
||||||
setTimeout(() => newNode.document.simulator?.scrollToNode(newNode), 10);
|
setTimeout(() => newNode?.document?.project?.simulatorHost?.scrollToNode(newNode), 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,13 +80,13 @@ export class ComponentActions {
|
|||||||
icon: IconLock, // 锁定 icon
|
icon: IconLock, // 锁定 icon
|
||||||
title: intlNode('lock'),
|
title: intlNode('lock'),
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
action(node: Node) {
|
action(node: IPublicModelNode) {
|
||||||
node.lock();
|
node.lock();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
condition: (node: Node) => {
|
condition: (node: IPublicModelNode) => {
|
||||||
return engineConfig.get('enableCanvasLock', false) && node.isContainer() && !node.isLocked;
|
return engineConfig.get('enableCanvasLock', false) && node.isContainerNode && !node.isLocked;
|
||||||
},
|
},
|
||||||
important: true,
|
important: true,
|
||||||
},
|
},
|
||||||
@ -95,13 +96,13 @@ export class ComponentActions {
|
|||||||
icon: IconUnlock, // 解锁 icon
|
icon: IconUnlock, // 解锁 icon
|
||||||
title: intlNode('unlock'),
|
title: intlNode('unlock'),
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
action(node: Node) {
|
action(node: IPublicModelNode) {
|
||||||
node.lock(false);
|
node.lock(false);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
condition: (node: Node) => {
|
condition: (node: IPublicModelNode) => {
|
||||||
return engineConfig.get('enableCanvasLock', false) && node.isContainer() && node.isLocked;
|
return engineConfig.get('enableCanvasLock', false) && node.isContainerNode && node.isLocked;
|
||||||
},
|
},
|
||||||
important: true,
|
important: true,
|
||||||
},
|
},
|
||||||
@ -132,8 +133,6 @@ export class ComponentActions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private metadataTransducers: IPublicTypeMetadataTransducer[] = [];
|
|
||||||
|
|
||||||
registerMetadataTransducer(
|
registerMetadataTransducer(
|
||||||
transducer: IPublicTypeMetadataTransducer,
|
transducer: IPublicTypeMetadataTransducer,
|
||||||
level = 100,
|
level = 100,
|
||||||
|
|||||||
@ -1225,7 +1225,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
|
|||||||
const isRGLContainerNode = this.isRGLContainer;
|
const isRGLContainerNode = this.isRGLContainer;
|
||||||
const isRGLNode = this.getParent()?.isRGLContainer;
|
const isRGLNode = this.getParent()?.isRGLContainer;
|
||||||
const isRGL = isRGLContainerNode || (isRGLNode && (!isContainerNode || !isEmptyNode));
|
const isRGL = isRGLContainerNode || (isRGLNode && (!isContainerNode || !isEmptyNode));
|
||||||
let rglNode = isRGLContainerNode ? this : isRGL ? this?.getParent() : {};
|
let rglNode = isRGLContainerNode ? this : isRGL ? this?.getParent() : null;
|
||||||
return { isContainerNode, isEmptyNode, isRGLContainerNode, isRGLNode, isRGL, rglNode };
|
return { isContainerNode, isEmptyNode, isRGLContainerNode, isRGLNode, isRGL, rglNode };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -655,4 +655,24 @@ export class Node implements IPublicModelNode {
|
|||||||
setConditionalVisible(): void {
|
setConditionalVisible(): void {
|
||||||
this[nodeSymbol].setConditionalVisible();
|
this[nodeSymbol].setConditionalVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRGL() {
|
||||||
|
const {
|
||||||
|
isContainerNode,
|
||||||
|
isEmptyNode,
|
||||||
|
isRGLContainerNode,
|
||||||
|
isRGLNode,
|
||||||
|
isRGL,
|
||||||
|
rglNode,
|
||||||
|
} = this[nodeSymbol].getRGL();
|
||||||
|
|
||||||
|
return {
|
||||||
|
isContainerNode,
|
||||||
|
isEmptyNode,
|
||||||
|
isRGLContainerNode,
|
||||||
|
isRGLNode,
|
||||||
|
isRGL,
|
||||||
|
rglNode: Node.create(rglNode),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -490,6 +490,18 @@ export interface IBaseModelNode<
|
|||||||
* 获取节点实例对应的 dom 节点
|
* 获取节点实例对应的 dom 节点
|
||||||
*/
|
*/
|
||||||
getDOMNode(): HTMLElement;
|
getDOMNode(): HTMLElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取磁贴相关信息
|
||||||
|
*/
|
||||||
|
getRGL(): {
|
||||||
|
isContainerNode: boolean;
|
||||||
|
isEmptyNode: boolean;
|
||||||
|
isRGLContainerNode: boolean;
|
||||||
|
isRGLNode: boolean;
|
||||||
|
isRGL: boolean;
|
||||||
|
rglNode: Node | null;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPublicModelNode extends IBaseModelNode<IPublicModelDocumentModel, IPublicModelNode> {}
|
export interface IPublicModelNode extends IBaseModelNode<IPublicModelDocumentModel, IPublicModelNode> {}
|
||||||
Loading…
x
Reference in New Issue
Block a user