mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-02-21 08:20:27 +00:00
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import DropLocation, { isLocationChildrenDetail } from '../../../designer/src/designer/helper/location';
|
|
import { NodeParent } from '../../../designer/src/designer/document/node/node';
|
|
|
|
const IndentSensitive = 15;
|
|
export class IndentTrack {
|
|
private indentStart: number | null = null;
|
|
reset() {
|
|
this.indentStart = null;
|
|
}
|
|
getIndentParent(lastLoc: DropLocation, loc: DropLocation): [NodeParent, number] | null {
|
|
if (
|
|
lastLoc.target !== loc.target ||
|
|
!isLocationChildrenDetail(lastLoc.detail) ||
|
|
!isLocationChildrenDetail(loc.detail) ||
|
|
lastLoc.source !== loc.source ||
|
|
lastLoc.detail.index !== loc.detail.index ||
|
|
loc.detail.index == null
|
|
) {
|
|
this.indentStart = null;
|
|
return null;
|
|
}
|
|
if (this.indentStart == null) {
|
|
this.indentStart = lastLoc.event.globalX;
|
|
}
|
|
const delta = loc.event.globalX - this.indentStart;
|
|
const indent = Math.floor(Math.abs(delta) / IndentSensitive);
|
|
if (indent < 1) {
|
|
return null;
|
|
}
|
|
this.indentStart = loc.event.globalX;
|
|
const direction = delta < 0 ? 'left' : 'right';
|
|
|
|
let parent = loc.target;
|
|
const index = loc.detail.index;
|
|
|
|
if (direction === 'left') {
|
|
if (!parent.parent || parent.isSlotRoot || index < parent.children.size) {
|
|
return null;
|
|
}
|
|
return [parent.parent, parent.index + 1];
|
|
} else {
|
|
if (index === 0) {
|
|
return null;
|
|
}
|
|
parent = parent.children.get(index - 1) as any;
|
|
if (parent && parent.isContainer()) {
|
|
return [parent, parent.children.size];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|