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:
力皓 2021-01-21 10:01:01 +08:00
commit 20f3a927ae
5 changed files with 52 additions and 3 deletions

View File

@ -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;
});

View 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;
};

View File

@ -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;
}

View File

@ -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;
});

View File

@ -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;
}