mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-12 17:08:14 +00:00
Merge branch 'feat/canSelecting' into 'release/1.0.32'
feat: 支持canSelecting & moMoveHook添加node参数 http://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/issues/99981 支持了 canSelecting & onClickHook See merge request !1129613
This commit is contained in:
commit
20f3a927ae
@ -33,6 +33,7 @@ import {
|
||||
Designer,
|
||||
} from '../designer';
|
||||
import { parseMetadata } from './utils/parse-metadata';
|
||||
import { getClosestClickableNode } from './utils/clickable';
|
||||
import { ComponentMetadata, ComponentSchema } from '@ali/lowcode-types';
|
||||
import { BuiltinSimulatorRenderer } from './renderer';
|
||||
import clipboard from '../designer/clipboard';
|
||||
@ -362,7 +363,12 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
(downEvent.target as HTMLElement).removeAttribute('for');
|
||||
|
||||
const nodeInst = this.getNodeInstanceFromElement(downEvent.target as Element);
|
||||
const node = nodeInst?.node || documentModel?.rootNode;
|
||||
const node = getClosestClickableNode(nodeInst?.node || documentModel?.rootNode, downEvent);
|
||||
// 如果找不到可点击的节点, 直接返回
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if (!node?.isValidComponent()) {
|
||||
// // 对于未注册组件直接返回
|
||||
// return;
|
||||
@ -968,7 +974,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
|
||||
const operationalNodes = nodes?.filter((node: any) => {
|
||||
const onMoveHook = node.componentMeta?.getMetadata()?.experimental?.callbacks?.onMoveHook;
|
||||
const canMove = onMoveHook && typeof onMoveHook === 'function' ? onMoveHook() : true;
|
||||
const canMove = onMoveHook && typeof onMoveHook === 'function' ? onMoveHook(node) : true;
|
||||
|
||||
return canMove;
|
||||
});
|
||||
|
||||
25
packages/designer/src/builtin-simulator/utils/clickable.ts
Normal file
25
packages/designer/src/builtin-simulator/utils/clickable.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Node } from '../../document';
|
||||
|
||||
/**
|
||||
* 获取离当前节点最近的可点击节点
|
||||
* @param currentNode
|
||||
* @param event
|
||||
*/
|
||||
export const getClosestClickableNode = (
|
||||
currentNode: Node | undefined | null,
|
||||
event: MouseEvent,
|
||||
) => {
|
||||
let node = currentNode;
|
||||
// 执行 onClickHook 来判断当前节点是否可点击
|
||||
while (node) {
|
||||
const onClickHook = node.componentMeta?.getMetadata()?.experimental?.callbacks?.onClickHook;
|
||||
const canClick =
|
||||
onClickHook && typeof onClickHook === 'function' ? onClickHook(event, node) : true;
|
||||
if (canClick) {
|
||||
break;
|
||||
}
|
||||
// 对于不可点击的节点, 继续向上找
|
||||
node = node.parent;
|
||||
}
|
||||
return node;
|
||||
};
|
||||
@ -145,6 +145,7 @@ export interface OldPrototypeConfig {
|
||||
canDraging?: boolean; // => onDrag
|
||||
canDragging?: boolean; // => ?
|
||||
|
||||
canSelecting?: boolean; // => onClickHook
|
||||
canOperating?: boolean; // => disabledActions
|
||||
canUseCondition?: boolean;
|
||||
canLoop?: boolean;
|
||||
@ -612,6 +613,7 @@ export function upgradeMetadata(oldConfig: OldPrototypeConfig) {
|
||||
// hooks
|
||||
canDraging,
|
||||
canDragging, // handleDragging
|
||||
canSelecting, // onClickHook
|
||||
// events
|
||||
didDropOut, // onNodeRemove
|
||||
didDropIn, // onNodeAdd
|
||||
@ -757,6 +759,13 @@ export function upgradeMetadata(oldConfig: OldPrototypeConfig) {
|
||||
}
|
||||
callbacks.onMoveHook = () => v;
|
||||
}
|
||||
if (canSelecting != null) {
|
||||
let v = true;
|
||||
if (canSelecting === false) {
|
||||
v = false;
|
||||
}
|
||||
callbacks.onClickHook = () => v;
|
||||
}
|
||||
if (didDropIn) {
|
||||
callbacks.onNodeAdd = didDropIn;
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ export class OutlineMain implements ISensor, ITreeBoard, IScrollable {
|
||||
|
||||
const operationalNodes = nodes?.filter((node: any) => {
|
||||
const onMoveHook = node.componentMeta?.getMetadata()?.experimental?.callbacks?.onMoveHook;
|
||||
const canMove = onMoveHook && typeof onMoveHook === 'function' ? onMoveHook() : true;
|
||||
const canMove = onMoveHook && typeof onMoveHook === 'function' ? onMoveHook(node) : true;
|
||||
|
||||
return canMove;
|
||||
});
|
||||
|
||||
@ -146,6 +146,7 @@ export interface OldPrototypeConfig {
|
||||
canDraging?: boolean; // => onDrag
|
||||
canDragging?: boolean; // => ?
|
||||
|
||||
canSelecting?: boolean; // => onClickHook
|
||||
canOperating?: boolean; // => disabledActions
|
||||
canUseCondition?: boolean;
|
||||
canLoop?: boolean;
|
||||
@ -613,6 +614,7 @@ export function upgradeMetadata(oldConfig: OldPrototypeConfig) {
|
||||
// hooks
|
||||
canDraging,
|
||||
canDragging, // handleDragging
|
||||
canSelecting, // onClickHook
|
||||
// events
|
||||
didDropOut, // onNodeRemove
|
||||
didDropIn, // onNodeAdd
|
||||
@ -758,6 +760,13 @@ export function upgradeMetadata(oldConfig: OldPrototypeConfig) {
|
||||
}
|
||||
callbacks.onMoveHook = () => v;
|
||||
}
|
||||
if (canSelecting != null) {
|
||||
let v = true;
|
||||
if (canSelecting === false) {
|
||||
v = false;
|
||||
}
|
||||
callbacks.onClickHook = () => v;
|
||||
}
|
||||
if (didDropIn) {
|
||||
callbacks.onNodeAdd = didDropIn;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user