Skip to content

Commit

Permalink
fix: 放入自由节点之后,父容器无法再添加组件且报错
Browse files Browse the repository at this point in the history
  • Loading branch information
ken.yan committed Nov 13, 2023
1 parent d64c7d5 commit 066e206
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions packages/designer/src/designer/dragon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export function isDragNodeDataObject(obj: any): obj is IPublicTypeDragNodeDataOb
* @deprecated use same function in @alilc/lowcode-utils
*/
export function isDragAnyObject(obj: any): obj is IPublicTypeDragAnyObject {
return obj && obj.type !== IPublicEnumDragObjectType.NodeData && obj.type !== IPublicEnumDragObjectType.Node;
return (
obj &&
obj.type !== IPublicEnumDragObjectType.NodeData &&
obj.type !== IPublicEnumDragObjectType.Node
);
}

export function isLocateEvent(e: any): e is ILocateEvent {
Expand Down Expand Up @@ -95,10 +99,7 @@ function isDragEvent(e: any): e is DragEvent {
return e?.type?.startsWith('drag');
}

export interface IDragon extends IPublicModelDragon<
INode,
ILocateEvent
> {
export interface IDragon extends IPublicModelDragon<INode, ILocateEvent> {
emitter: IEventBus;
}

Expand Down Expand Up @@ -170,13 +171,20 @@ export class Dragon implements IDragon {
* @param dragObject 拖拽对象
* @param boostEvent 拖拽初始时事件
*/
boost(dragObject: IPublicModelDragObject, boostEvent: MouseEvent | DragEvent, fromRglNode?: INode | IPublicModelNode) {
boost(
dragObject: IPublicModelDragObject,
boostEvent: MouseEvent | DragEvent,
fromRglNode?: INode | IPublicModelNode,
) {
const { designer } = this;
const masterSensors = this.getMasterSensors();
const handleEvents = makeEventsHandler(boostEvent, masterSensors);
const newBie = !isDragNodeObject(dragObject);
const forceCopyState =
isDragNodeObject(dragObject) && dragObject.nodes.some((node: Node | IPublicModelNode) => (typeof node.isSlot === 'function' ? node.isSlot() : node.isSlot));
isDragNodeObject(dragObject) &&
dragObject.nodes.some((node: Node | IPublicModelNode) => {
return typeof node.isSlot === 'function' ? node.isSlot() : node.isSlotNode;
});
const isBoostFromDragAPI = isDragEvent(boostEvent);
let lastSensor: IPublicModelSensor | undefined;

Expand Down Expand Up @@ -247,9 +255,11 @@ export class Dragon implements IDragon {
const sensor = chooseSensor(locateEvent);

/* istanbul ignore next */
if (isRGL) {
// have to distinguish between the fixed point and the new component
const nodes = dragObject?.nodes || [];
if (isRGL && nodes.length > 0) {
// 禁止被拖拽元素的阻断
const nodeInst = dragObject.nodes[0].getDOMNode();
const nodeInst = dragObject?.nodes?.[0]?.getDOMNode();
if (nodeInst && nodeInst.style) {
this.nodeInstPointerEvents = true;
nodeInst.style.pointerEvents = 'none';
Expand All @@ -267,7 +277,7 @@ export class Dragon implements IDragon {
this.emitter.emit('rgl.add.placeholder', {
rglNode,
fromRglNode,
node: locateEvent.dragObject?.nodes[0],
node: locateEvent.dragObject?.nodes?.[0],
event: e,
});
designer.clearLocation();
Expand All @@ -276,6 +286,10 @@ export class Dragon implements IDragon {
return;
}
} else {
// reset the flag when leave rgl
if (fromRglNode) {
fromRglNode.isRGLContainerNode = false;
}
this._canDrop = false;
this.emitter.emit('rgl.remove.placeholder');
this.emitter.emit('rgl.sleeping', true);
Expand Down Expand Up @@ -433,7 +447,7 @@ export class Dragon implements IDragon {
if (!sourceDocument || sourceDocument === document) {
evt.globalX = e.clientX;
evt.globalY = e.clientY;
} else /* istanbul ignore next */ {
} /* istanbul ignore next */ else {
// event from simulator sandbox
let srcSim: ISimulatorHost | undefined;
const lastSim = lastSensor && isSimulatorHost(lastSensor) ? lastSensor : null;
Expand Down Expand Up @@ -467,7 +481,9 @@ export class Dragon implements IDragon {
/* istanbul ignore next */
const chooseSensor = (e: ILocateEvent) => {
// this.sensors will change on dragstart
const sensors: IPublicModelSensor[] = this.sensors.concat(masterSensors as IPublicModelSensor[]);
const sensors: IPublicModelSensor[] = this.sensors.concat(
masterSensors as IPublicModelSensor[],
);
let sensor =
e.sensor && e.sensor.isEnter(e)
? e.sensor
Expand Down

0 comments on commit 066e206

Please sign in to comment.