fix: support dropObject is data

This commit is contained in:
mario.gk 2020-08-19 10:08:29 +08:00
parent 89bf07f1b6
commit 809fda73be
4 changed files with 41 additions and 4 deletions

View File

@ -855,9 +855,10 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
return canMove; return canMove;
}); });
if (!operationalNodes || operationalNodes.length === 0) { if (nodes && (!operationalNodes || operationalNodes.length === 0)) {
return; return;
} }
this.sensing = true; this.sensing = true;
this.scroller.scrolling(e); this.scroller.scrolling(e);
const dropContainer = this.getDropContainer(e); const dropContainer = this.getDropContainer(e);
@ -867,7 +868,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
!dropContainer || !dropContainer ||
canDropIn === false || canDropIn === false ||
// too dirty // too dirty
(typeof canDropIn === 'function' && !canDropIn(operationalNodes[0])) (nodes && typeof canDropIn === 'function' && !canDropIn(operationalNodes[0]))
) { ) {
return null; return null;
} }
@ -899,7 +900,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
event: e, event: e,
}; };
if (dragObject.type === 'node' && operationalNodes[0]?.getPrototype()?.isModal()) { if (dragObject.type === 'node' && nodes && operationalNodes[0]?.getPrototype()?.isModal()) {
return this.designer.createLocation({ return this.designer.createLocation({
target: this.document.rootNode, target: this.document.rootNode,
detail: { detail: {

View File

@ -8,6 +8,7 @@ import {
IEditor, IEditor,
CompositeObject, CompositeObject,
PropsList, PropsList,
isNodeSchema,
} from '@ali/lowcode-types'; } from '@ali/lowcode-types';
import { Project } from '../project'; import { Project } from '../project';
import { Node, DocumentModel, insertChildren, isRootNode, ParentalNode, TransformStage } from '../document'; import { Node, DocumentModel, insertChildren, isRootNode, ParentalNode, TransformStage } from '../document';
@ -111,10 +112,14 @@ export class Designer {
if (isLocationChildrenDetail(loc.detail) && loc.detail.valid !== false) { if (isLocationChildrenDetail(loc.detail) && loc.detail.valid !== false) {
let nodes: Node[] | undefined; let nodes: Node[] | undefined;
if (isDragNodeObject(dragObject)) { if (isDragNodeObject(dragObject)) {
nodes = insertChildren(loc.target, dragObject.nodes, loc.detail.index, copy); nodes = insertChildren(loc.target, [...dragObject.nodes], loc.detail.index, copy);
} else if (isDragNodeDataObject(dragObject)) { } else if (isDragNodeDataObject(dragObject)) {
// process nodeData // process nodeData
const nodeData = Array.isArray(dragObject.data) ? dragObject.data : [dragObject.data]; const nodeData = Array.isArray(dragObject.data) ? dragObject.data : [dragObject.data];
const isNotNodeSchema = nodeData.find(item => !isNodeSchema(item));
if (isNotNodeSchema) {
return;
}
nodes = insertChildren(loc.target, nodeData, loc.detail.index); nodes = insertChildren(loc.target, nodeData, loc.detail.index);
} }
if (nodes) { if (nodes) {

View File

@ -149,4 +149,29 @@ export class DropLocation {
event, event,
}); });
} }
/**
* @deprecated
* vision
*/
getContainer() {
return this.target;
}
/**
* @deprecated
* vision
*/
getInsertion() {
if (!this.detail) {
return null;
}
if (this.detail.type === 'Children') {
if (this.detail.index <= 0) {
return null;
}
return this.target.children.get(this.detail.index - 1);
}
return (this.detail as any)?.near?.node;
}
} }

View File

@ -734,6 +734,12 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
return this.componentName; return this.componentName;
} }
/**
* @deprecated
*/
insert(node: Node, ref?: Node, useMutator = true) {
this.insertAfter(node, ref, useMutator);
}
insertBefore(node: Node, ref?: Node, useMutator = true) { insertBefore(node: Node, ref?: Node, useMutator = true) {
this.children?.insert(node, ref ? ref.index : null, useMutator); this.children?.insert(node, ref ? ref.index : null, useMutator);
} }