mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-10 09:56:20 +00:00
fix: node支持getRGL改造
This commit is contained in:
parent
f747f7934b
commit
cabb91ab8b
@ -557,14 +557,14 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
|||||||
});
|
});
|
||||||
const judgeEnterOtherRGL = (e: MouseEvent) => {
|
const judgeEnterOtherRGL = (e: MouseEvent) => {
|
||||||
const _nodeInst = this.getNodeInstanceFromElement(e.target as Element);
|
const _nodeInst = this.getNodeInstanceFromElement(e.target as Element);
|
||||||
const { isRGL: _isRGL, rglNode: _rglNode } = this.getRGLObject(
|
const _node = _nodeInst?.node;
|
||||||
_nodeInst as NodeInstance,
|
if (!_node) return { status: false };
|
||||||
);
|
const { isRGL: _isRGL, rglNode: _rglNode } = _node.getRGL();
|
||||||
const status = !!(
|
const status = !!(
|
||||||
_isRGL &&
|
_isRGL &&
|
||||||
_rglNode?.id !== rglNode?.id &&
|
_rglNode?.id !== rglNode?.id &&
|
||||||
_rglNode?.getParent() !== node &&
|
_rglNode?.getParent() !== node &&
|
||||||
nodeInst?.node !== _nodeInst?.node
|
_node !== nodeInst?.node
|
||||||
);
|
);
|
||||||
return { status, rglNode: _rglNode };
|
return { status, rglNode: _rglNode };
|
||||||
};
|
};
|
||||||
@ -734,19 +734,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
|||||||
|
|
||||||
private disableDetecting?: () => void;
|
private disableDetecting?: () => void;
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取node实例的磁贴相关信息
|
|
||||||
*/
|
|
||||||
getRGLObject(nodeInst: NodeInstance) {
|
|
||||||
const isContainerNode = nodeInst?.node.isContainer();
|
|
||||||
const isEmptyNode = nodeInst?.node?.isEmpty();
|
|
||||||
const isRGLContainerNode = nodeInst?.node?.isRGLContainer;
|
|
||||||
const isRGLNode = nodeInst?.node?.getParent()?.isRGLContainer;
|
|
||||||
const isRGL = isRGLContainerNode || (isRGLNode && (!isContainerNode || !isEmptyNode));
|
|
||||||
let rglNode = isRGLContainerNode ? nodeInst?.node : isRGL ? nodeInst?.node?.getParent() : {};
|
|
||||||
return { isContainerNode, isEmptyNode, isRGLContainerNode, isRGLNode, isRGL, rglNode };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置悬停处理
|
* 设置悬停处理
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -76,10 +76,6 @@ export interface ISensor {
|
|||||||
* 获取节点实例
|
* 获取节点实例
|
||||||
*/
|
*/
|
||||||
getNodeInstanceFromElement(e: Element | null): NodeInstance<ComponentInstance> | null;
|
getNodeInstanceFromElement(e: Element | null): NodeInstance<ComponentInstance> | null;
|
||||||
/**
|
|
||||||
* 获取RGL相关信息
|
|
||||||
*/
|
|
||||||
getRGLObject(nodeInst: NodeInstance): any;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DragObject = DragNodeObject | DragNodeDataObject | DragAnyObject;
|
export type DragObject = DragNodeObject | DragNodeDataObject | DragAnyObject;
|
||||||
@ -263,12 +259,12 @@ export class Dragon {
|
|||||||
|
|
||||||
this._dragging = false;
|
this._dragging = false;
|
||||||
|
|
||||||
const getRGLObject = (e: MouseEvent | DragEvent) => {
|
const getRGL = (e: MouseEvent | DragEvent) => {
|
||||||
const locateEvent = createLocateEvent(e);
|
const locateEvent = createLocateEvent(e);
|
||||||
const sensor = chooseSensor(locateEvent);
|
const sensor = chooseSensor(locateEvent);
|
||||||
if (!sensor || !sensor.getNodeInstanceFromElement) return {};
|
if (!sensor || !sensor.getNodeInstanceFromElement) return {};
|
||||||
const nodeInst = sensor.getNodeInstanceFromElement(e.target as Element);
|
const nodeInst = sensor.getNodeInstanceFromElement(e.target as Element);
|
||||||
return sensor.getRGLObject(nodeInst as NodeInstance);
|
return nodeInst?.node?.getRGL() || {};
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkesc = (e: KeyboardEvent) => {
|
const checkesc = (e: KeyboardEvent) => {
|
||||||
@ -324,7 +320,7 @@ export class Dragon {
|
|||||||
lastArrive = e;
|
lastArrive = e;
|
||||||
const locateEvent = createLocateEvent(e);
|
const locateEvent = createLocateEvent(e);
|
||||||
const sensor = chooseSensor(locateEvent);
|
const sensor = chooseSensor(locateEvent);
|
||||||
const { isRGL, rglNode } = getRGLObject(e);
|
const { isRGL, rglNode } = getRGL(e);
|
||||||
if (isRGL) {
|
if (isRGL) {
|
||||||
this._canDrop = !!sensor?.locate(locateEvent);
|
this._canDrop = !!sensor?.locate(locateEvent);
|
||||||
if (this._canDrop) {
|
if (this._canDrop) {
|
||||||
@ -403,7 +399,7 @@ export class Dragon {
|
|||||||
const over = (e?: any) => {
|
const over = (e?: any) => {
|
||||||
// 发送drop事件
|
// 发送drop事件
|
||||||
if (e) {
|
if (e) {
|
||||||
const { isRGL, rglNode } = getRGLObject(e);
|
const { isRGL, rglNode } = getRGL(e);
|
||||||
if (isRGL && this._canDrop) {
|
if (isRGL && this._canDrop) {
|
||||||
const tarNode = dragObject.nodes[0];
|
const tarNode = dragObject.nodes[0];
|
||||||
if (rglNode.id !== tarNode.id) {
|
if (rglNode.id !== tarNode.id) {
|
||||||
|
|||||||
@ -110,7 +110,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
private _addons: { [key: string]: { exportData: () => any; isProp: boolean; } } = {};
|
private _addons: { [key: string]: { exportData: () => any; isProp: boolean } } = {};
|
||||||
|
|
||||||
@obx.ref private _parent: ParentalNode | null = null;
|
@obx.ref private _parent: ParentalNode | null = null;
|
||||||
|
|
||||||
@ -177,7 +177,10 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
this.settingEntry = this.document.designer.createSettingEntry([this]);
|
this.settingEntry = this.document.designer.createSettingEntry([this]);
|
||||||
this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children));
|
this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children));
|
||||||
this._children.internalInitParent();
|
this._children.internalInitParent();
|
||||||
this.props.import(this.upgradeProps(this.initProps(props || {})), this.upgradeProps(extras || {}));
|
this.props.import(
|
||||||
|
this.upgradeProps(this.initProps(props || {})),
|
||||||
|
this.upgradeProps(extras || {}),
|
||||||
|
);
|
||||||
this.setupAutoruns();
|
this.setupAutoruns();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,6 +224,16 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
return children || [];
|
return children || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _isRGLContainer = false;
|
||||||
|
|
||||||
|
set isRGLContainer(status: boolean) {
|
||||||
|
this._isRGLContainer = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isRGLContainer(): boolean {
|
||||||
|
return !!this._isRGLContainer;
|
||||||
|
}
|
||||||
|
|
||||||
isContainer(): boolean {
|
isContainer(): boolean {
|
||||||
return this.isParental() && this.componentMeta.isContainer;
|
return this.isParental() && this.componentMeta.isContainer;
|
||||||
}
|
}
|
||||||
@ -335,7 +348,11 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
/**
|
/**
|
||||||
* 移除当前节点
|
* 移除当前节点
|
||||||
*/
|
*/
|
||||||
remove(useMutator = true, purge = true, options: NodeRemoveOptions = { suppressRemoveEvent: false }) {
|
remove(
|
||||||
|
useMutator = true,
|
||||||
|
purge = true,
|
||||||
|
options: NodeRemoveOptions = { suppressRemoveEvent: false },
|
||||||
|
) {
|
||||||
if (this.parent) {
|
if (this.parent) {
|
||||||
if (!options.suppressRemoveEvent) {
|
if (!options.suppressRemoveEvent) {
|
||||||
this.document.designer.editor?.emit('node.remove.topLevel', {
|
this.document.designer.editor?.emit('node.remove.topLevel', {
|
||||||
@ -616,15 +633,21 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
import(data: Schema, checkId = false) {
|
import(data: Schema, checkId = false) {
|
||||||
const { componentName, id, children, props, ...extras } = data;
|
const { componentName, id, children, props, ...extras } = data;
|
||||||
if (this.isSlot()) {
|
if (this.isSlot()) {
|
||||||
foreachReverse(this.children, (subNode: Node) => {
|
foreachReverse(
|
||||||
subNode.remove(true, true);
|
this.children,
|
||||||
}, (iterable, idx) => (iterable as NodeChildren).get(idx));
|
(subNode: Node) => {
|
||||||
|
subNode.remove(true, true);
|
||||||
|
},
|
||||||
|
(iterable, idx) => (iterable as NodeChildren).get(idx),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (this.isParental()) {
|
if (this.isParental()) {
|
||||||
this.props.import(props, extras);
|
this.props.import(props, extras);
|
||||||
(this._children as NodeChildren).import(children, checkId);
|
(this._children as NodeChildren).import(children, checkId);
|
||||||
} else {
|
} else {
|
||||||
this.props.get('children', true)!.setValue(isDOMText(children) || isJSExpression(children) ? children : '');
|
this.props
|
||||||
|
.get('children', true)!
|
||||||
|
.setValue(isDOMText(children) || isJSExpression(children) ? children : '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -792,7 +815,8 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
* 是否可执行某action
|
* 是否可执行某action
|
||||||
*/
|
*/
|
||||||
canPerformAction(action: string): boolean {
|
canPerformAction(action: string): boolean {
|
||||||
const availableActions = this.componentMeta?.availableActions?.map((action) => action.name) || [];
|
const availableActions =
|
||||||
|
this.componentMeta?.availableActions?.map((action) => action.name) || [];
|
||||||
return availableActions.indexOf(action) >= 0;
|
return availableActions.indexOf(action) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -854,7 +878,11 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
return this.children?.onChange(fn);
|
return this.children?.onChange(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeChildren(remover: () => any, adder: (children: Node[]) => NodeData[] | null, sorter: () => any) {
|
mergeChildren(
|
||||||
|
remover: () => any,
|
||||||
|
adder: (children: Node[]) => NodeData[] | null,
|
||||||
|
sorter: () => any,
|
||||||
|
) {
|
||||||
this.children?.mergeChildren(remover, adder, sorter);
|
this.children?.mergeChildren(remover, adder, sorter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -907,6 +935,21 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
return this.document;
|
return this.document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取磁贴相关信息
|
||||||
|
*/
|
||||||
|
getRGL() {
|
||||||
|
const isContainerNode = this.isContainer();
|
||||||
|
const isEmptyNode = this.isEmpty();
|
||||||
|
const isRGLContainerNode = this.isRGLContainer;
|
||||||
|
const isRGLNode = this.getParent()?.isRGLContainer;
|
||||||
|
const isRGL = isRGLContainerNode || (isRGLNode && (!isContainerNode || !isEmptyNode));
|
||||||
|
let rglNode = isRGLContainerNode ? this : isRGL ? this?.getParent() : {};
|
||||||
|
return { isContainerNode, isEmptyNode, isRGLContainerNode, isRGLNode, isRGL, rglNode };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@ -933,9 +976,11 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
return { container: dropElement, ref };
|
return { container: dropElement, ref };
|
||||||
}
|
}
|
||||||
const rootCanDropIn = this.componentMeta?.prototype?.options?.canDropIn;
|
const rootCanDropIn = this.componentMeta?.prototype?.options?.canDropIn;
|
||||||
if (rootCanDropIn === undefined
|
if (
|
||||||
|| rootCanDropIn === true
|
rootCanDropIn === undefined ||
|
||||||
|| (typeof rootCanDropIn === 'function' && rootCanDropIn(node))) {
|
rootCanDropIn === true ||
|
||||||
|
(typeof rootCanDropIn === 'function' && rootCanDropIn(node))
|
||||||
|
) {
|
||||||
return { container: this, ref };
|
return { container: this, ref };
|
||||||
}
|
}
|
||||||
// 假如最后找不到合适位置,返回 null 阻止继续插入节点
|
// 假如最后找不到合适位置,返回 null 阻止继续插入节点
|
||||||
@ -944,9 +989,11 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
|
|
||||||
const canDropIn = this.componentMeta?.prototype?.options?.canDropIn;
|
const canDropIn = this.componentMeta?.prototype?.options?.canDropIn;
|
||||||
if (this.isContainer()) {
|
if (this.isContainer()) {
|
||||||
if (canDropIn === undefined ||
|
if (
|
||||||
|
canDropIn === undefined ||
|
||||||
(typeof canDropIn === 'boolean' && canDropIn) ||
|
(typeof canDropIn === 'boolean' && canDropIn) ||
|
||||||
(typeof canDropIn === 'function' && canDropIn(node))) {
|
(typeof canDropIn === 'function' && canDropIn(node))
|
||||||
|
) {
|
||||||
return { container: this, ref };
|
return { container: this, ref };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1113,7 +1160,12 @@ export function comparePosition(node1: Node, node2: Node): PositionNO {
|
|||||||
return PositionNO.BeforeOrAfter;
|
return PositionNO.BeforeOrAfter;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function insertChild(container: ParentalNode, thing: Node | NodeData, at?: number | null, copy?: boolean): Node {
|
export function insertChild(
|
||||||
|
container: ParentalNode,
|
||||||
|
thing: Node | NodeData,
|
||||||
|
at?: number | null,
|
||||||
|
copy?: boolean,
|
||||||
|
): Node {
|
||||||
let node: Node;
|
let node: Node;
|
||||||
if (isNode(thing) && (copy || thing.isSlot())) {
|
if (isNode(thing) && (copy || thing.isSlot())) {
|
||||||
thing = thing.export(TransformStage.Clone);
|
thing = thing.export(TransformStage.Clone);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user