lowcode-engine/packages/utils/src/node-helper.ts
2023-03-14 11:17:24 +08:00

30 lines
875 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 仅使用类型
import { IPublicModelNode } from '@alilc/lowcode-types';
export const getClosestNode = <Node extends IPublicModelNode = IPublicModelNode>(
node: Node,
until: (n: Node) => boolean,
): Node | undefined => {
if (!node) {
return undefined;
}
if (until(node)) {
return node;
} else {
// @ts-ignore
return getClosestNode(node.getParent(), until);
}
};
/**
* 判断节点是否可被点击
* @param {Node} node 节点
* @param {unknown} e 点击事件
* @returns {boolean} 是否可点击true表示可点击
*/
export function canClickNode<Node extends IPublicModelNode = IPublicModelNode>(node: Node, e: unknown): boolean {
const onClickHook = node.componentMeta?.advanced?.callbacks?.onClickHook;
const canClick = typeof onClickHook === 'function' ? onClickHook(e as MouseEvent, node) : true;
return canClick;
};